X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=parser%2Fbuild_ast.py;fp=parser%2Fbuild_ast.py;h=de87f84b3a08c8784da9a9f4c31d272fe9cd6644;hb=3eadd8423e41b70e89854bd63e0e9875e259978c;hp=0000000000000000000000000000000000000000;hpb=d6033c7330cb5b2d397663a8297b86d0873211d2;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/parser/build_ast.py b/parser/build_ast.py new file mode 100644 index 0000000..de87f84 --- /dev/null +++ b/parser/build_ast.py @@ -0,0 +1,31 @@ + +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): + return ('PARENS', ast[1]) + + def name(self, ast): + return ('NAME', str(ast)) + + def and_op(self, ast): + return 'AND' + + def or_op(self, ast): + return 'OR' + + def not_op(self, ast): + return 'NOT'