[antlr-interest] AntlrWorks - Interpreter fails for ! and ~

Gavin Lambert antlr at mirality.co.nz
Mon Feb 9 02:13:01 PST 2009


At 22:32 9/02/2009, Steve Flasby wrote:
 >I have the classic String rule:
 >
 >STRING_LITERAL
 >   : '"'!
 >     ( '"' '"'!
 >     | ~('"'|'\n'|'\r')
 >     )*
 >     ( '"'!
 >     | // nothing -- write error message
 >     )
 >    ;
 >
 >The presence of the '!' in this code causes the grammar checking 
to
 >fail with the message 'Illegal output option' is there an
 >alternative I should be using instead?

The use of ! in lexer rules is a v2ism, and doesn't work in 
v3.  (! is still supported in parser rules to indicate tokens that 
shouldn't be included in the AST.)

See also:
   http://www.antlr.org/wiki/pages/viewpage.action?pageId=1461

 >Also (but I am less sure about this) I think the '~' is not 
being
 >correctly recognized as any string in my test input which I 
expect
 >to match this fails. Has this been reported by anyone else?

~ does work (but only when used on sets, not sequences; what you 
have above should be ok though).  Possibly the !s are confusing 
it; try taking them out and see if it behaves better.

There might also be an issue with your 'unterminated string' 
clause.  I'm not entirely certain, but I suspect that it could 
cause something weird to happen.  Try changing it to just a simple 
'"' with no alternative and see if that helps.



More information about the antlr-interest mailing list