[antlr-interest] Re: Getting at the token text in a parser
lgcraymer
lgc at mail1.jpl.nasa.gov
Mon Mar 1 20:38:22 PST 2004
Looks like you haven't set buildAST=true in your parser options
section. Also, use the #label syntax (#grp instead of grp)--antlr
name "mangling" could change.
--Loring
--- In antlr-interest at yahoogroups.com, "offline314159" <offline at s...>
wrote:
> --- In antlr-interest at yahoogroups.com, "lgcraymer" <lgc at m...> wrote:
> > $getText works in the lexer, not in the parser--in the lexer, there is
> > text associated with a rule, but not in the parser.. What you want to
> > do is label the AST (or Token) nodes that you want to extract text
> > from--say
> > v:value { #v.getText(); }
> >
> > (assuming Java, not C++).
>
> So sounds good, but if that's the case, what's the deal with this not
> working? If i have this here: (note that group is just a basic word
> rule, nothing fancy)
>
> groups
> returns [String g]
> :
> grp:group {g.append(grp);} ( DOT group )*
> ;
>
> When i try to run this code, antlr generates the parser but when it
> hits this point i get this:
>
> java.lang.Error: Unresolved compilation problem:
> grp cannot be resolved
>
> at aimedia.vcard.util.parser.VCardParser.groups(VCardParser.java:273)
>
> And the surrounding code is:
>
> public final String groups() throws RecognitionException,
> TokenStreamException {
> String g;
>
> try { // for error handling
> group();
> g.append(grp);
> {
> _loop2607:
> do {
> if ((LA(1)==DOT)) {
> match(DOT);
> group();
> }
> else {
> break _loop2607;
> }
>
> } while (true);
> }
> }
> catch (RecognitionException ex) {
> reportError(ex);
> consume();
> consumeUntil(_tokenSet_4);
> }
> return g;
> }
>
> how do i make that identifier work?
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list