[antlr-interest] grammar that separates classpath from class name
David Boden
dave at daveboden.com
Mon Apr 9 13:41:36 PDT 2012
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;
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-address
>
More information about the antlr-interest
mailing list