tags:

views:

60

answers:

1

Let's say I have two rules like the below:

printable_characters : '\u0020' .. '\uFFEF' ;

newline_characters : '\n' | '\r' ;

Now let's say that I want to make a new rule called printable_no_newlines. I would like to do this by subtracting newline_characters from printable_characters like so:

printable_no_newlines : printable_characters - newline_characters ;

That syntax doesn't work in ANTLR3 but does anyone know what the best way would be to emulate this without re-typing the entire rule?

+1  A: 

I don't think this is possible. I'm also skeptical that it would do what you want: for example, your printable_new_newlines would include "foo\nbar", since it matches printable_characters, but does not match newline_characters (as that only matches one-character strings).

Martin v. Löwis
Hi Martin. I edited my example to make more sense. I shouldn't have used .* for the printable_characters rule. If you re-examine the question now does it makes more sense what I am trying to do?
Jeffrey Cameron
Some of Martin's comment is no longer relevant, but the key point of it not being possible without manually writing the set difference is correct.
280Z28
@Jeffrey: your edit still doesn't make the request sensible. As `newline_characters` aren't included in `printable_characters` (since they are below U+0020), anyway, `printable_no_newlines` would be the same as `printable_characters`.
Martin v. Löwis