]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - parser/grammar.ebnf
Use grako instead of PLY to compile EBNF to Python
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / grammar.ebnf
diff --git a/parser/grammar.ebnf b/parser/grammar.ebnf
new file mode 100644 (file)
index 0000000..b657738
--- /dev/null
@@ -0,0 +1,36 @@
+# 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
+# This  is a simple version of the grammar and it allows
+# rather stupid expressions, like !!TAG or ((TAG))
+
+@@grammar :: Tags
+
+start = expression $ ;
+
+expression = (
+           | expression and_op expression
+           | expression or_op expression
+           | not_op expression
+           | expression_parens
+           | name ) ;
+
+expression_parens = '(' expression ')' ;
+
+name = /[a-z][a-z0-9_]+/ ;
+
+and_op = '&' | '&&' | 'AND' | 'and' ;
+
+or_op = '|' | '||' | 'OR' | 'or' ;
+
+not_op = '!' | 'NOT' | 'not' ;