grammar LogicalQueryParser rule exp sp* exp:(logic_exp / paren_exp / literal_exp / literal) sp* end rule logic_exp lexp:(paren_exp / literal_exp / literal) logic:(and / or) rexp:exp end rule paren_exp negative:not* lparen exp rparen rexp:exp* end rule literal_exp literal sp+ exp end rule literal negative:not* word end rule word (quoted_word / unquoted_word) end rule quoted_word '"' ('\"' / !'"' .)* '"' end rule unquoted_word !ope atom+ / ope atom+ end rule lparen '(' end rule rparen ')' end rule and sp+ and_ope sp+ end rule or sp+ or_ope sp+ end rule not (not_ope sp+ / not_sym sp*) end rule ope and_ope / or_ope / not_ope end rule and_ope 'AND' / 'and' / '&&' / '&' end rule or_ope 'OR' / 'or' / '||' / '|' end rule not_ope 'NOT' / 'not' end rule not_sym '-' / '-' / '-' end rule sp ' ' / ' ' end rule atom !(lparen / rparen / sp) . end end