Reputation: 8364
I have the following grammar. My grammar needs to accept these kind of statements:
X IN (10,20,30)
X IN (10 20 30)
expr
: expr IN '(' constant_list ')' #InExp
;
constant_list
: constant ((',') constant)*
;
constant
: numeric_constant
| character_constant
;
SPACE
: [ \t\r\n] -> skip
;
I just tried to edit the rule constant_list
to:
constant_list
: constant ((','|SPACE) constant)*
;
But the spaces ate being ignored. How can I handle this situation? Do I need to use the Hidden Channel?
Upvotes: 1
Views: 1068
Reputation: 170138
No, you can't use the SPACE
token in your parser rules: they are skipped (discarded from the lexer).
What you could do is this:
constant_list
: constant (','? constant)*
;
Upvotes: 4
Reputation: 8364
I solved editing the rule:
constant_list
: constant (',' constant)*
| constant ( constant)*
;
Upvotes: 1