[antlr-interest] grammar that separates classpath from class name
jackett_dad at yahoo.com
Mon Apr 9 13:59:50 PDT 2012
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.
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
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...
> On 9 April 2012 21:28, Scott<jackett_dad at yahoo.com> wrote:
>> 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:
>> 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
>> So here is what I have so far:
>> genericTypeArgument : type | QUESTION_MARK (('extends' | 'super') type)?;
>> type : qualifiedJavaType arrayModifier* | primitiveType
>> 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?
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> 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