[antlr-interest] grammar that separates classpath from class name
John B. Brodie
jbb at acm.org
Mon Apr 9 13:51:20 PDT 2012
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