]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blobdiff - parser/build_ast.py
Change grammar to support priority of operation
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / build_ast.py
index de87f84b3a08c8784da9a9f4c31d272fe9cd6644..42bf9207b14e67314d9f0f31f1e94dd6e420caa8 100644 (file)
@@ -2,20 +2,16 @@
 from parser import TagsSemantics as _TagsSemantics
 
 class TagsSemantics(_TagsSemantics):
-    def expression(self, ast):
-        if isinstance(ast, str):  # name
-            return ast
-        if isinstance(ast, unicode):  # name
-            return str(ast)
-        if isinstance(ast, list):
-            ast = tuple(ast)
-        elif not isinstance(ast, tuple):
-            raise TypeError("Expected a list, got %r %s" % (type(ast), ast))
-        if len(ast) == 3:
-            return (ast[1], ast[0], ast[2])
-        return ast
-
-    def expression_parens(self, ast):
+    def or_expression(self, ast):
+        return ('OR', ast[0], ast[2])
+
+    def and_expression(self, ast):
+        return ('AND', ast[0], ast[2])
+
+    def not_expression(self, ast):
+        return ('NOT', ast[1])
+
+    def parens_expression(self, ast):
         return ('PARENS', ast[1])
 
     def name(self, ast):