# Grammar rules for tag searching; EBNF. # The grammar defines expressions in the following forms: # TAG - search blog posts that contain the tag; # !TAG - search blog posts that don't contain the tag; # TAG & TAG - search blog posts that contain both tags; # TAG | TAG - search blog posts that contain any of the tags; # Parentheses are allowed to group expressions; for example: # TAG & (TAG | TAG) # !(TAG | TAG) # Allowed operators: conjunction - & && AND and # disjunction - | || OR or # negation - ! NOT not # Usual priority: NOT recognized before AND, AND before OR. # This is a simple version of the grammar and it allows # rather stupid expressions, like (TAG) or ((TAG)) or !(!(TAG)). @@grammar :: Tags start = expression $ ; expression = expression1 !or_op | or_expression ; or_expression = expression1 or_op expression ; and_expression = expression2 and_op expression1 ; not_expression = not_op expression3 ; parens_expression = '(' expression ')' ; expression1 = expression2 !and_op | and_expression ; expression2 = !not_op expression3 | not_expression ; expression3 = parens_expression | name ; and_op = '&&' | '&' | 'AND' | 'and' ; or_op = '||' | '|' | 'OR' | 'or' ; not_op = '!' | 'NOT' | 'not' ; name = /[a-z][a-z0-9_]+/ ;