]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - parser/grammar.ebnf
Change grammar to support priority of operation
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / grammar.ebnf
index b657738ad5f30a6ab29508f8364b212faffa4708..4a702edf2bbcfa7f0bfcecb1c47171580cefacb9 100644 (file)
 # 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_]+/ ;