Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'a-zA-Z' came as a complete surprise to me while matching alternative

I have problem generating my grammar defintion with antlr v4:

grammar TagExpression;

expr : not expr
| expr and expr
| expr or expr
| '(' expr ')'
| tag
;

tag : [a-zA-Z]+ ;

and : '&' ;

or : '|' ;

not : '!' ;

WS : [ \t\n\r]+ -> skip ;

The syntax error happens here: tag : [a-zA-Z]+ ;

error(50): c:\temp\antlr\TagExpression.g4:10:6: syntax error: 'a-zA-Z' came as a complete surprise to me while matching alternative

The examples I saw had very similar constructs. Any idea why this happens?

Thanks

like image 639
user3749218 Avatar asked Jun 17 '14 15:06

user3749218


1 Answers

The character set notation can only be used in a lexer rule (rules that start with a capital letter, and produce tokens instead of parse trees).

Tag : [a-zA-Z]+;
like image 178
Sam Harwell Avatar answered Sep 21 '22 12:09

Sam Harwell