- return _grammar.parse(input)
-
-
-def cleanup_children(visited_children):
- children = [c for c in visited_children if c]
- if len(children) == 1:
- return children[0]
- else:
- return children
-
-
-class Compiler(NodeVisitor):
- def generic_visit(self, node, visited_children):
- return cleanup_children(visited_children)
-
- def visit_or_expression(self, node, visited_children):
- return ('OR', visited_children[0], visited_children[2])
-
- def visit_and_expression(self, node, visited_children):
- return ('AND', visited_children[0], visited_children[2])
-
- def visit_not_expression(self, node, visited_children):
- return ('NOT', visited_children[2])
-
- def visit_parens_expression(self, node, visited_children):
- return ('PARENS', visited_children[2])
-
- def visit_name(self, node, visited_children):
- return ('NAME', node.text)
-
-
-def compile(tree):
- if isinstance(tree, str):
- tree = parse(tree)
- return Compiler().visit(tree)
+ tree = _grammar.parse(input)
+ return TagsTransformer().transform(tree)
+
+
+if __name__ == '__main__':
+ print('----------')
+ print(parse('test'))
+ print(parse('!test'))
+ print(parse('not test'))
+ print(parse('foo or bar'))
+ print(parse('foo && bar'))
+ print(parse('foo && bar && baz'))
+ print(parse('!foo && bar && baz'))
+ print(parse('(test)'))
+ print(parse('(foo || bar)'))
+ print(parse('(foo and !bar)'))
+ print('----------')