]> 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:27:27 +0000 (23:27 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 21 Jun 2014 19:27:27 +0000 (23:27 +0400)
ChangeLog
TODO
parser/grammar
parser/parser.py
parser/test_parser.py

index e6ffcb891ecc1374a09c309d9438db2a47a34e30..30d3438821525aa32ea89dc216b6497f2ed31c37 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
 Version 0.3 (2014-06-??)
 
-   Allow '&&'.
+   Allow '&&' and '||'.
 
 Version 0.2 (2014-06-06)
 
diff --git a/TODO b/TODO
index 312cfd352b97e20a6252be608a1b2a32ab8bed42..12fe231194b12d0cb18f0a6920cc91db8b561499 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,6 @@
-Allow ' and ' and ' AND '.
+Allow ' AND ' and ' and '.
 
-Allow '||', ' or ' and ' OR '.
+Allow ' OR ' and ' or '.
 
 Allow 'NOT ' and 'not '.
 
index 17d3098324c6117c5c509a4c27ece95030766876..0017a96479b35acc8e1b1962e63f8844850668a2 100644 (file)
@@ -4,7 +4,7 @@
 #  TAG - search blog posts that contain the tag;
 #  !TAG - search blog posts that don't contain the tag;
 #  TAG && TAG, TAG & TAG - search blog posts that contain both tags;
-#  TAG | TAG - search blog posts that contain any of the tags;
+#  TAG || TAG, TAG | TAG - search blog posts that contain any of the tags;
 # Parentheses are allowed to group expressions:
 #  TAG & (TAG | TAG)
 #  !(TAG | TAG)
@@ -25,6 +25,7 @@ SP1 : '[ \t]+'
 expression : NAME
            | expression AND_OP AND_OP expression
            | expression AND_OP expression
+           | expression OR_OP OR_OP expression
            | expression OR_OP expression
            | NOT_OP expression
            | '(' expression ')'
index 38c4cd236084d9bfb050214193503d64ced96c4c..1fb9903c62ee93794a22925678df963c728d4f2c 100644 (file)
@@ -37,6 +37,10 @@ def p_expression_not(p):
     """expression : NOT_OP expression"""
     p[0] = ('NOT', p[2])
 
+def p_expression_or_or(p):
+    """expression : expression OR_OP OR_OP expression"""
+    p[0] = ('OR', p[1], p[4])
+
 def p_expression_or(p):
     """expression : expression OR_OP expression"""
     p[0] = ('OR', p[1], p[3])
index a8d52270a9c52a0fa8dca6bb9186c889e17b1929..628c9843b8d8509b11b7fc676e9452ef27329006 100755 (executable)
@@ -21,11 +21,14 @@ class TestParser(unittest.TestCase):
         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'))
+        )
         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'))
+        self.assertEqual(parser.parse('!(xxx || yyy)'),
+            ('NOT', ('PARENS', ('OR', ('NAME', 'xxx'), ('NAME', 'yyy'))))
         )
 
     def test_05_bad_expression(self):