label value assigned to a block which is not a set ANTLR 4?

Viewed 177

When, I make a rule like this ,

/* date type */
date: 'date' '(' value = STRING ')' ;
/* field["value"] */
key: name = ID '[' value = STRING ']';
whereExpr: key op =('>'|'<'|'>='|'<='|'=') value = (STRING | ID | INTEGER | DOUBLE | date ) ;

in my grammar,ANTLR displays the following error.

error(130): WhereParser.g4:14:43: label value assigned to a block which is not a set
1 error(s)

Why ?. How I can fix that ?.

1 Answers

You can only assign labels to a set of tokens, not parser rules. In other words, value = (STRING | ID | INTEGER | DOUBLE | date) is invalid because date is a parser rule. Fix it by removing the value = label:

whereExpr
 : key op=('>'|'<'|'>='|'<='|'=') (STRING | ID | INTEGER | DOUBLE | date)
 ;
Related