Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
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
Exemple #6
0
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()
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
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