# 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)
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 ')'
"""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])
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):