[antlr-interest] grammar that separates classpath from class name

Jim Idle jimi at temporal-wave.com
Mon Apr 9 14:08:41 PDT 2012


The ! only means don't include it in a tree that you are building. As you
are not building a tree, the answer given is not relevant to you and gives
the error you see.

In general, always use the broadest syntax and do not try to artificially
apply context to your rules.

Also, instead of:

(a DOT)? a

It is usually more efficient to use

a (DOT a)?


Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Scott
> Sent: Monday, April 09, 2012 2:00 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] grammar that separates classpath from
> class name
>
> I was just about to reply and say that David's code worked
> (thanks!).  John's code should work, but for some reason I'm getting an
> exception:
>
> [ERROR] Failed to execute goal org.codehaus.mojo:antlr3-maven-
> plugin:1.0:antlr (default) on project processors:
> MojoExecutionException: Can't find template tokenRefBang.st -> [Help 1]
>
>
> I'm using version 3.0.1 of antlr because that seems to be the version
> that works with the AntlrWorks plugin in IntelliJ, and works with the
> maven plugin for building antlr grammars.  I saw this by googling (came
> from this list):
>
> You can't have both AST operators (^ and !) and rewrites in the same
> rule.
> You are using ! in a rule with rewrites. Unfortunately currently the
> error message doesn't give the location, this is a known issue. I don't
> think this will be fixed in 3.1.
>
> I don't think I'm doing any rewrites, but maybe I've accidentally
> triggered one--I'll have to re-read a tutorial that demonstrated how to
> do this.
>
> Either way, thanks for the quick replies.
>
> Scott
>
>
>
>
> ________________________________
>  From: John B. Brodie <jbb at acm.org>
> To: antlr-interest at antlr.org
> Sent: Monday, April 9, 2012 4:51 PM
> Subject: Re: [antlr-interest] grammar that separates classpath from
> class name
>
> A small tweak (UNTESTED) so that you do not need the trailing DOT on
> each usage
>
> On 04/09/2012 04:41 PM, David Boden wrote:
> > Hi Scott,
> >
> > I'm a relative Antlr newbie too, but I've just completed a successful
> > project so may be able to help.
> >
> > Would this work for you?:
> > packageDecl        : Identifier (DOT Identifer)*;
> qualifiedJavaType
> > : (packageDecl DOT)? javaType;
>
> packageDecl : Identifier (DOT Identifier)* DOT! ; qualifiedJavaType :
> packageDecl? javaType ;
>
> (the `!` meta suffix operator tells ANTLR not to include the
> corresponding element in the generated AST).
>
> Hope this helps...
>     -jbb
>
>
> >
> > Regards,
> > Dave
> >
> >
> >
> > On 9 April 2012 21:28, Scott<jackett_dad at yahoo.com>  wrote:
> >
> >> All,
> >>
> >> I'm just starting with Antlr.  I have past experience with JavaCC,
> >> but it's been a while.
> >>
> >> I'm parsing a fully qualified java type name, and would like to
> >> differentiate the classpath from the class name.  So if I were
> parsing this:
> >>
> >> com.company.JavaType
> >>
> >> I would like to specify an expression for which the package and
> class
> >> name are distinct nodes in the parse tree.  I copied a Java 5
> grammar
> >> as a starting point, but that distinction is not made.  I could
> >> easily do this separation in a visitor, but since Antlr is so cool,
> >> I'd rather that it did the work for me.
> >>
> >> The catch is, I don't want to have the last dot character be part of
> >> the package name, and I don't want the dot to be part of the class
> >> name either.
> >>
> >> So here is what I have so far:
> >>
> >> genericTypeArgument : type | QUESTION_MARK (('extends' | 'super')
> >> type)?;
> >>
> >> type            : qualifiedJavaType arrayModifier* | primitiveType
> >> arrayModifier*;
> >>
> >> packageDecl        : (Identifier DOT)*;
> >>
> >> qualifiedJavaType    : packageDecl? javaType;
> >>
> >> javaType        : Identifier genericTypeArguments?;
> >>
> >> This works almost.  The package declaration includes the last dot.
> >> Is there a way that I can have the parser ignore(or not include)
> only
> >> the last dot in the package declaration?
> >>
> >> Thanks,
> >>
> >> Scott
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-email-
> addres
> >> s
> >>
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> > http://www.antlr.org/mailman/options/antlr-interest/your-email-
> address
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list