[antlr-interest] newbie question, escaped characters
Rob Shields
rob at cmsnet.org.uk
Tue Mar 11 11:08:47 PDT 2008
Hi,
I'm maintaining a project that uses antlr. Let's say I have some syntax
that looks like this:
<snip>
protected SIMPLETERM: (TERM_CHAR)+;
protected TERM_CHAR: SIMPLE_TERM_CHAR | ESCAPED_TERM_CHAR;
protected SIMPLE_TERM_CHAR: ~( ' ' | '\t' | '!' | '(' | ')' | ':' |
'^' | '[' | ']' | '\\' | '\"' | '{' | '}' | '~' | '/' | '\r' | '\n' );
protected ESCAPED_TERM_CHAR: '\\'! ( '\\' | '+' | '-' | '!' | '(' |
')' | ':' | '^' | '[' | ']' | '\"' | '{' | '}' | '~' | '*' | '?' |
'/');
<snip>
So the '\\'! swallows the backslash of the escaped characters. However,
I want to preserve the backslash for the * and ? characters because they
have special significance. I thought about something like this:
<snip>
protected TERM_CHAR: SIMPLE_TERM_CHAR | ESCAPED_TERM_CHAR |
WILDCARD_TERM_CHAR;
<snip>
protected WILDCARD_TERM_CHAR: '\\' ( '*' | '?' );
<snip>
Of course that doesn't work because of lexical nondeterminism between
ESCAPED_TERM_CHAR and WILDCARD_TERM_CHAR.
Is it possible to do what I want? Any thoughts?
Thanks :)
Rob
More information about the antlr-interest
mailing list