Hi all
I am building Excel grammar and encountered the following problem: the grammar below works fine parsing expression "=123 + 456" (note spaces next to "+")
grammar Excel;
formula
: scalarFormula
| arrayFormula
;
...
additiveExpression
: multiplicativeExpression
| additiveExpression ('+'|'-') multiplicativeExpression
;
...
intersectRange
: simpleRange
// | intersectRange ' '+ simpleRange
;
...
WHITESPACE : [ \t\n\r]+ -> skip ;
However, if I uncomment the line with intersection operator (which is space in Excel), so that intersectRange definition reads as follows:
intersectRange
: simpleRange
| intersectRange ' '+ simpleRange
;
I get an error:
line 1:4 extraneous input ' ' expecting {<EOF>, '%', '^', '+', '*', '-', '/', '=', '<', '<=', '>', '>=', NE, '&'}
line 1:6 no viable alternative at input ' '
Changing grammar to
additiveExpression
: multiplicativeExpression
| additiveExpression WHITESPACE* ('+'|'-') WHITESPACE* multiplicativeExpression
;
...
WHITESPACE : [ \t\n\r] ;
does not help a lot:
line 1:4 extraneous input ' ' expecting {<EOF>, '%', '^', '+', '*', '-', '/', '=', '<', '<=', '>', '>=', NE, '&', WHITESPACE}
line 1:6 extraneous input ' ' expecting {'-', '[', '{', '$', INTEGER, FLOAT, STRING, IDENTIFIER, ERROR, COLUMN, ROW, WHITESPACE, BOOL}
Does anybody know about how to overcome this error? I believe that the problem is that ANTLR starts to recognize space (" ") as a token rather than a white space but how do I override this? Thank you.