问题
How can I differentiate 'IS NOT NULL' from 'IS NULL'?
'IS' and 'IS NOT' are defined in a parser rule, and 'NULL' in another rule, and the second follows the first.
What happens is that when I write 'IS NULL', the Parser is excepting 'IS NOT NULL' because both second words begin with 'N'.
How can I distinguish both?
Grammar File
query
: expr EOF -> ^(QUERY expr)
;
expr
: logical_expr
;
logical_expr
: equality_expr (logical_op^ equality_expr)*
;
equality_expr
: ID equality_op atom -> ^(equality_op ID atom)
;
atom
: ID
;
equality_op
: '='
| '!='
| 'IN'
| 'NOT IN'
| 'IS'
| 'IS NOT'
;
logical_op
: 'AND'
| 'OR'
;
Number
: Int ('.' Digit*)?
;
ID
: ('a'..'z' | 'A'..'Z' | '_' | '.' | '-' | Digit)*
;
...
来源:https://stackoverflow.com/questions/24363709/antlr-distinguish-is-not-null-from-is-null