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

2

6

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

Sypher answered 17/6, 2014 at 15:43 Comment(0)
L
22

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]+;
Lampkin answered 17/6, 2014 at 15:49 Comment(0)
H
0

the problem is the syntax in ANTLR should be '[a-zA-Z]+'

Halfblooded answered 7/2, 2023 at 5:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.