ANTLR - Distinguish 'IS NOT NULL' from 'IS NULL'

走远了吗. 提交于 2019-12-08 11:14:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!