1 # Grammar rules for tag searching; EBNF.
3 # The grammar defines expressions in the following forms:
4 # TAG - search blog posts that contain the tag;
5 # !TAG - search blog posts that don't contain the tag;
6 # TAG & TAG - search blog posts that contain both tags;
7 # TAG | TAG - search blog posts that contain any of the tags;
8 # Parentheses are allowed to group expressions; for example:
11 # Allowed operators: conjunction - & && AND and
12 # disjunction - | || OR or
13 # negation - ! NOT not
14 # Usual priority: NOT recognized before AND, AND before OR.
15 # This is a simple version of the grammar and it allows
16 # rather stupid expressions, like (TAG) or ((TAG)) or !(!(TAG)).
20 start = expression $ ;
22 expression = expression1 !&or_op | or_expression ;
24 or_expression = expression1 or_op expression ;
26 and_expression = expression2 and_op expression1 ;
28 not_expression = not_op expression3 ;
30 parens_expression = '(' expression ')' ;
32 expression1 = expression2 !&and_op | and_expression ;
34 expression2 = !¬_op expression3 | not_expression ;
36 expression3 = parens_expression | name ;
38 and_op = '&&' | '&' | 'AND' | 'and' ;
40 or_op = '||' | '|' | 'OR' | 'or' ;
42 not_op = '!' | 'NOT' | 'not' ;
44 name = /[a-z][a-z0-9_]+/ ;