[antlr-interest] rule classDef trapped: unexpected token: IDENTIFIER

Peter-Frank Spierenburg peter at fortha.org
Sun Nov 6 08:35:23 PST 2005


Greetings,

The TreeParser in the following grammar is giving me some problems. I
would actually prefer to have resourceTypeIdentifier in place of
IDENTIFIER in the toSQL rule, but

"The root of a tree pattern must be a token reference, but the children
elements can even be subrules." from
http://www.antlr.org/doc/sor.html#_bb1

I'm not sure why that is, but I can play along.

Does anyone have any ideas what I might be doing wrong?

$ java -cp ~/lib/antlr-2.7.5.jar antlr.Tool Query.g
ANTLR Parser Generator   Version 2.7.5 (20050128)   1989-2005 jGuru.com
Query.g:17:12: rule classDef trapped:
Query.g:17:12: unexpected token: IDENTIFIER
error: aborting grammar 'QueryTreeWalker' due to errors
Exiting due to errors.


// Query.g
class QueryParser extends Parser;
options {
    buildAST = true;
}
propertyExpression : resourceExpression OP_PROPERTY^
propertyNameIdentifier ;
resourceExpression : resourceTypeIdentifier ( OP_REFERENCE^
propertyNameIdentifier )* ;
resourceTypeIdentifier : IDENTIFIER ;
propertyNameIdentifier : IDENTIFIER ;

class QueryLexer extends Lexer;
WHITESPACE : ( ' ' | '\t' | '\n' { newline(); } | '\r' )+
{ $setType(Token.SKIP); } ;
IDENTIFIER : ('A'..'Z' | 'a'..'z')+ ;
OP_REFERENCE : '/' ;
OP_PROPERTY : '@' ;

class QueryTreeWalker extends TreeParser;
toSQL : #( IDENTIFIER ) ;



More information about the antlr-interest mailing list