module languages.tree_graph_listener
¶
Short summary¶
module pyensae.languages.tree_graph_listener
Helpers around language grammar. This module requires antlr4.
Classes¶
class |
truncated documentation |
---|---|
This class is an attempt to run through the tree and to convert into a graph. |
Properties¶
property |
truncated documentation |
---|---|
return edges |
|
return vertices |
Methods¶
method |
truncated documentation |
---|---|
constructor |
|
draw the graph with networkx on matplotlib |
|
event |
|
event |
|
export the graph to DOT format |
|
convert the graph into networkx |
|
event |
|
event |
Documentation¶
Helpers around language grammar. This module requires antlr4.
- class pyensae.languages.tree_graph_listener.TreeGraphListener(parser, verbose=False, fLOG=None)¶
Bases:
ParseTreeListener
This class is an attempt to run through the tree and to convert into a graph.
Draw a grammar graph for a small code
from pyensae.languages import get_parser_lexer, parse_code, get_tree_graph from pyensae.graph_helper import run_dot code = ''' namespace hello { public static class world { public static double function(double x, doubly y) { return x+y ; } } } ''' clparser, cllexer = get_parser_lexer("C#") parser = parse_code(code, clparser, cllexer) tree = parser.compilation_unit() st = get_tree_graph(tree, parser) dot = st.to_dot() with open(name, "w") as f: f.write(dot) img = os.path.join(temp, "graph.png") run_dot(name, img)
constructor
- Parameters:
parser – parser used to parse the code
verbose – display information along the path
fLOG – logging function
- property Edges¶
return edges
- property Vertices¶
return vertices
- __init__(parser, verbose=False, fLOG=None)¶
constructor
- Parameters:
parser – parser used to parse the code
verbose – display information along the path
fLOG – logging function
- _get_key_context(ctx)¶
- _get_key_node(node)¶
- draw(ax=None)¶
draw the graph with networkx on matplotlib
- Parameters:
matplotlib – axis
- enterEveryRule(ctx)¶
event
- exitEveryRule(ctx)¶
event
- to_dot()¶
export the graph to DOT format
- Returns:
string
- to_networkx()¶
convert the graph into networkx
- Returns:
- visitErrorNode(node)¶
event
- visitTerminal(node)¶
event