I am trying to parse a SQL statement that allows for both a BETWEEN expr1 AND expr2
and also expr1 AND expr2
. An example would be:
SELECT * FROM tbl WHERE
col1 BETWEEN 1 AND 5
AND col3 = 10;
What would be a good way to disambiguate this, as my grammar is currently like the following:
grammar DBParser;
statement:expr EOF;
expr
: '(' expr ')'
| expr '=' expr
| expr 'BETWEEN' expr 'AND' expr
| expr 'AND' expr
| ATOM
;
ATOM: [a-zA-Z0-9]+;
WHITESPACE: [ \t\r\n] -> skip;
And with the input (col1 BETWEEN 1 AND 5) AND (col3 = 10);
: