]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - grammar
Add parser
[phdru.name/cgi-bin/blog-ru/search-tags.git] / grammar
diff --git a/grammar b/grammar
new file mode 100644 (file)
index 0000000..7ded1c2
--- /dev/null
+++ b/grammar
@@ -0,0 +1,27 @@
+# Grammar rules for tag searching; BNF.
+
+# 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 one of the tags or both;
+# Parentheses are allowed to group expressions:
+#  TAG & (TAG | TAG)
+#  !(TAG | TAG)
+# and so on. This  is the first version of the grammar and it allows
+# rather stupid expressions, like !!TAG or ((TAG)); in the future
+# it will be fixed by making the grammar stricter and more complex.
+
+NAME : '[a-z][a-z0-9_]+'
+
+AND_OP : '&'
+
+OR_OP : '|'
+
+NOT_OP : '!'
+
+expression : NAME
+           | expression AND_OP expression
+           | NOT_OP expression
+           | expression OR_OP expression
+           | '(' expression ')'