[antlr-interest] tips on grammar subrules
William Tribbey
will at tribbey.net
Mon Jul 27 06:59:39 PDT 2009
Hello Everyone,
I am hoping someone can set me straight on values from subrules.
I am working with the Java 1.5 grammar done by Terence Parr that
I downloaded from the grammar page. I have Terence's book, which
has been very helpful, and I am having fun doing my work.
At one point I am trying to capture the import statements in a class
file. I am working with this rule:
importDeclaration
: 'import' 'static'? qualifiedName ('.' '*')? ';'
I can tell whether the import is static and get the qualifiedName value
easily
doing this:
importDeclaration
: 'import' s='static'? name=qualifiedName ('.' '*')? ';'
Of course, I have some actions and I am using some scope variables to save
these values. I would also like to get the .* if present, but so far I have
only been
able to do that with something like this:
importDeclaration
: 'import' s='static'? name=qualifiedName ('.' '*'
{$importDeclaration::star=true;})? ';'
This works but feels a tad kludgy to me, so I am wondering what am I missing
to do this
as neatly as possible.
Any hints appreciated.
Will Tribbey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090727/c0cf7f8e/attachment.html
More information about the antlr-interest
mailing list