]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/commitdiff
Allow '&&'
authorOleg Broytman <phd@phdru.name>
Sat, 21 Jun 2014 19:23:14 +0000 (23:23 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 21 Jun 2014 19:23:14 +0000 (23:23 +0400)
ChangeLog
TODO
parser/grammar
parser/parser.py
parser/test_parser.py

index a1748bd7217deb8312a4420d8666d20045702406..e6ffcb891ecc1374a09c309d9438db2a47a34e30 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Version 0.3 (2014-06-??)
+
+   Allow '&&'.
+
 Version 0.2 (2014-06-06)
 
    Ignore spaces.
diff --git a/TODO b/TODO
index cfeb86577d1f6b6c716c9839b3e062e3b7887cd0..312cfd352b97e20a6252be608a1b2a32ab8bed42 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-Allow '&&', ' and ' and ' AND '.
+Allow ' and ' and ' AND '.
 
 Allow '||', ' or ' and ' OR '.
 
index ade8b129eceb5b65576ee8edca20a6308fe2a09f..17d3098324c6117c5c509a4c27ece95030766876 100644 (file)
@@ -3,14 +3,14 @@
 # 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;
+#  TAG && 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:
 #  TAG & (TAG | TAG)
 #  !(TAG | TAG)
-# and so on. This  is the first version of the grammar and it allows
+# and so on. This  is a simple 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.
+# it will be fixed by making the grammar more complex and stricter.
 
 NAME : '[a-z][a-z0-9_]+'
 
@@ -20,13 +20,11 @@ OR_OP : '|'
 
 NOT_OP : '!'
 
-SP0 : '[ \t]*'
-
 SP1 : '[ \t]+'
 
 expression : NAME
+           | expression AND_OP AND_OP expression
            | expression AND_OP expression
            | expression OR_OP expression
            | NOT_OP expression
            | '(' expression ')'
-           | SP0 expression SP0
index 2fcf716a8a37492e4b3965f20f4466c0b03dab91..38c4cd236084d9bfb050214193503d64ced96c4c 100644 (file)
@@ -25,6 +25,10 @@ def p_expression_name(p):
     """expression : NAME"""
     p[0] = ('NAME', p[1])
 
+def p_expression_and_and(p):
+    """expression : expression AND_OP AND_OP expression"""
+    p[0] = ('AND', p[1], p[4])
+
 def p_expression_and(p):
     """expression : expression AND_OP expression"""
     p[0] = ('AND', p[1], p[3])
index 804505fac06b0c2214c50d86e1c26d65f52ba289..a8d52270a9c52a0fa8dca6bb9186c889e17b1929 100755 (executable)
@@ -21,6 +21,9 @@ class TestParser(unittest.TestCase):
         self.assertEqual(parser.parse('!(xxx & yyy)'),
             ('NOT', ('PARENS', ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))))
         )
+        self.assertEqual(parser.parse('!(xxx && yyy)'),
+            ('NOT', ('PARENS', ('AND', ('NAME', 'xxx'), ('NAME', 'yyy'))))
+        )
         self.assertEqual(parser.parse('!xxx&yyy&zzz|ooo'),
             ('OR', ('AND', ('AND', ('NOT', ('NAME', 'xxx')), ('NAME', 'yyy')), ('NAME', 'zzz')), ('NAME', 'ooo'))
         )