X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=parser%2Fgrammar.ebnf;h=ce21b642621acec201493329aa4b1126d6dbfd01;hb=4102600cf242f72781c8fee326802e9bb2267c25;hp=b657738ad5f30a6ab29508f8364b212faffa4708;hpb=3eadd8423e41b70e89854bd63e0e9875e259978c;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/parser/grammar.ebnf b/parser/grammar.ebnf index b657738..ce21b64 100644 --- a/parser/grammar.ebnf +++ b/parser/grammar.ebnf @@ -11,26 +11,34 @@ # 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)) +# rather stupid expressions, like (TAG) or ((TAG)) or !(!(TAG)). @@grammar :: Tags start = expression $ ; -expression = ( - | expression and_op expression - | expression or_op expression - | not_op expression - | expression_parens - | name ) ; +expression = expression1 !or_op | or_expression ; -expression_parens = '(' expression ')' ; +or_expression = expression1 or_op expression ; -name = /[a-z][a-z0-9_]+/ ; +and_expression = expression2 and_op expression1 ; + +not_expression = not_op expression3 ; + +parens_expression = '(' expression ')' ; + +expression1 = expression2 !and_op | and_expression ; -and_op = '&' | '&&' | 'AND' | 'and' ; +expression2 = !not_op expression3 | not_expression ; -or_op = '|' | '||' | 'OR' | 'or' ; +expression3 = parens_expression | name ; + +and_op = '&&' | '&' | 'AND' | 'and' ; + +or_op = '||' | '|' | 'OR' | 'or' ; not_op = '!' | 'NOT' | 'not' ; + +name = /[a-z][a-z0-9_]+/ ;