I'm creating a simple boolean query parser. I would like to do something like this below.
grammar BooleanQuery; options { language = Java; output = AST; } LPAREN : ( '(' ) ; RPAREN : ( ')' ); QUOTE : ( '"' ); AND : ( 'AND' | '&' | 'EN' | '+' ) ; OR : ( 'OR' | '|' | 'OF' ); WS : ( ' ' | '\t' | '\r' | '\n') {$channel=HIDDEN;} ; WORD : (~( ' ' | '\t' | '\r' | '\n' | '(' | ')' | '"' ))*; MINUS : '-'; PLUS : '+'; expr : andexpr; andexpr : orexpr (AND^ orexpr)*; orexpr : part (OR^ part)*; phrase : QUOTE ( options {greedy=false;} : . )* QUOTE; requiredexpr : PLUS atom; excludedexpr : MINUS atom; part : excludedexpr | requiredexpr | atom; atom : phrase | WORD | LPAREN! expr RPAREN!;
The problem is that the MINUS and PLUS tokens 'collide' with the MINUS and PLUS signs in the AND and OR tokens. Sorry if I don't use the correct terminology. I'm a ANTLR newbie.
Below an example query:
foo OR (pow AND -"bar with cream" AND -bar)
What mistakes did I make?