[antlr-interest] Comment parsing at beginning of file

Nathan Eloe powerofazure at gmail.com
Thu Jun 17 14:28:17 PDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

I'm working on a tree grammar that accepts the Bash language and have
run across the current problem:

Comments in bash are started by the "#" symbol.  From man bash:
"[...] a word beginning with # causes that word and all remaining
characters on that line to be ignored."

As such, I've added the following token to my file:

COMMENT
    :   (EOL|BLANK) '#' ~('\n'|'\r')* (EOL|EOF){$channel=HIDDEN;}
    ;

The EOL was put in to allow vertain parameter expansions that take the form:

${#param}
${name#word}
${name##word}

Before I tried to handle these cases, my test cases handled comments at
the beginning of files.  However, now it cannot.

What I need is either a semi-graceful way to either tell the token it
needs to be at the beginning of a line (including at the start of the
file) or something to add that it needs to be at the beginning of the file.

I've searched MarkMail and the internet, but everything I've come up
with (semantic predicates for position, etc, etc) will only work for
parser rules, and since I'm at the beginning of the file I can't emit a
beginning of line token to fix the problem.

Also, this will eventually be using the C runtime (right now I'm
outputting it in java so I can test the grammar with gunit and the
ANTLRworks debugger).

Thanks,
Nathan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.14 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwak3AACgkQFpoRlVgtqKZ0+QCbB5hLxL2S32RYolqE/UunFOSW
jZgAniHHEV3Z1Od0fEoPYCs8ggJiD5A6
=r4yz
-----END PGP SIGNATURE-----


More information about the antlr-interest mailing list