]> git.phdru.name Git - phdru.name/cgi-bin/blog-ru/search-tags.git/blob - parser/build_ast.py
de87f84b3a08c8784da9a9f4c31d272fe9cd6644
[phdru.name/cgi-bin/blog-ru/search-tags.git] / parser / build_ast.py
1
2 from parser import TagsSemantics as _TagsSemantics
3
4 class TagsSemantics(_TagsSemantics):
5     def expression(self, ast):
6         if isinstance(ast, str):  # name
7             return ast
8         if isinstance(ast, unicode):  # name
9             return str(ast)
10         if isinstance(ast, list):
11             ast = tuple(ast)
12         elif not isinstance(ast, tuple):
13             raise TypeError("Expected a list, got %r %s" % (type(ast), ast))
14         if len(ast) == 3:
15             return (ast[1], ast[0], ast[2])
16         return ast
17
18     def expression_parens(self, ast):
19         return ('PARENS', ast[1])
20
21     def name(self, ast):
22         return ('NAME', str(ast))
23
24     def and_op(self, ast):
25         return 'AND'
26
27     def or_op(self, ast):
28         return 'OR'
29
30     def not_op(self, ast):
31         return 'NOT'