[antlr-interest] Comments, EOF, and Debugger

Nathan Eloe powerofazure at gmail.com
Tue Jun 1 06:33:15 PDT 2010

Hash: SHA1

Hello all,
I'm working on an AST parser for the Bash language and I've come across the following strange behavior:
I'm trying to handle comments, so I used the comments token you can get when you start a new grammar in ANTLRworks.  It works.  

    :   '#' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}

The problem arises when the comment is the last thing from the input (i.e, no new line before EOF).  Removing the '\n' from the token causes it to freak out when I run the tests, but I can't get it to match comments at the end of file.  Leaving that '\n' in lets the code compile, but I still can't match that last case.

Here's where the interesting part happens.  When I run it through the debugger with the same test case that I use in gunit, the debugger allows the input and parses it correctly (meaning, it ignores it as it should) and correctly generates the expected AST.

Does the debugger allow the code to be more robust in its decision making abilities?  Or does it do something to the input to allow it to be matched to a token.

Thanks for the help!

Version: GnuPG/MacGPG2 v2.0.14 (Darwin)


More information about the antlr-interest mailing list