def parse(sql_text, start="sql_script", **kwargs): antlr_tree = parse_ast(grammar, sql_text, start, **kwargs) simple_tree = process_tree( antlr_tree, base_visitor_cls=AstVisitor, transformer_cls=Transformer ) return simple_tree
def parse(text, start="root", **kwargs): antlr_tree = parse_ast( Grammar, text, start, **kwargs ) simple_tree = process_tree(antlr_tree, transformer_cls=Transformer) return simple_tree
def parse(sql_text, start="tsql_file", strict=False): antlr_tree = parse_ast(grammar, sql_text, start, strict) simple_tree = process_tree(antlr_tree, base_visitor_cls=AstVisitor, transformer_cls=Transformer) return simple_tree
def get_base_ast(grammar_name, code, start): if 'sql' in grammar_name: grammar = grammars.get(grammar_name) tree = parse_ast(grammar, code, start) return process_tree(tree, simplify=False) # else: # TODO return None
def parse(text, start="expr", **kwargs): antlr_tree = parse_ast(grammar, text, start, transform=CaseTransformInputStream.LOWER, **kwargs) simple_tree = process_tree(antlr_tree, transformer_cls=Transformer) return simple_tree
def parse(text, start="root", **kwargs): antlr_tree = parse_ast(Grammar, text, start, **kwargs) Transformer.bind_alias_nodes([ RootQueryNode, QueryNode, CreateTableNode, ColumnDefinitionNode, SimpSelectNode, InsertNode, DeleteNode ]) simple_tree = process_tree(antlr_tree, transformer_cls=Transformer) return simple_tree.build_ast()
def parse_from_grammar(grammar, text, start): tree = parse_ast(grammar, text, start) listener = CytoListener() Tree.ParseTreeWalker.DEFAULT.walk(listener, tree) elements = { "nodes": [listener.node_map[key] for key in listener.node_map.keys()], "edges": listener.node_edges, } return elements
def get_alias_ast(grammar_name, code, start): if 'sql' in grammar_name: grammar = grammars.get(grammar_name) parser = ast_parsers.get(grammar_name) tree = parse_ast(grammar, code, start) return process_tree(tree, transformer_cls=parser.Transformer, simplify=False) # else: # TODO return None
def parse(sql_text, start="tsql_file", **kwargs): antlr_tree = parse_ast(grammar, sql_text, start, transform=CaseTransformInputStream.UPPER, **kwargs) simple_tree = process_tree(antlr_tree, base_visitor_cls=AstVisitor, transformer_cls=Transformer) return simple_tree