Question

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?

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top