From: Oleg Broytman Date: Sat, 21 Jun 2014 19:23:14 +0000 (+0400) Subject: Allow '&&' X-Git-Tag: v0.3~10 X-Git-Url: https://git.phdru.name/?p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git;a=commitdiff_plain;h=2167fc0e09f4343c0fe67c8c754e29a41769e684 Allow '&&' --- diff --git a/ChangeLog b/ChangeLog index a1748bd..e6ffcb8 100644 --- 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 cfeb865..312cfd3 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -Allow '&&', ' and ' and ' AND '. +Allow ' and ' and ' AND '. Allow '||', ' or ' and ' OR '. diff --git a/parser/grammar b/parser/grammar index ade8b12..17d3098 100644 --- a/parser/grammar +++ b/parser/grammar @@ -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 diff --git a/parser/parser.py b/parser/parser.py index 2fcf716..38c4cd2 100644 --- a/parser/parser.py +++ b/parser/parser.py @@ -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]) diff --git a/parser/test_parser.py b/parser/test_parser.py index 804505f..a8d5227 100755 --- a/parser/test_parser.py +++ b/parser/test_parser.py @@ -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')) )