Closed ghost closed 5 years ago
Can you elaborate? You want to generate a graph? Of what exactly?
My example of XML (using dot from Graphviz):
digraph ComplexGraph {
nodesep=.05;
rankdir=LR;
node[shape=record,width=.1,height=.1];
subgraph g_Document {
n_Document[fontsize=18, shape=ellipse, label="Document"];
n_Document -> n_Document_opts
n_Document_opts [shape=record, label="Option sets | <optset0> 0"];
node [width=1.5];
n_Document_optset0[shape=record, label="{<opt0> Prolog | <opt1> emit Element | <opt2> emit Misc*}"];
n_Document_opts:optset0 -> n_Document_optset0;
n_Document_optset0:opt0 -> n_Prolog;
n_Document_optset0:opt1 -> n_Element;
n_Document_optset0:opt2 -> n_Misc;
}
}
Of the grammar. The picture above is what inspires the request.
Maybe you can use something like
version (tracer) { bool cond(string ruleName, const ref ParseTree p) { static startTrace = false; if (ruleName.startsWith("MyGrammar.RuleOfInterest")) startTrace = true; return startTrace && ruleName.startsWith("MyGrammar"); } setTraceConditionFunction(&cond); }
and just output the specific graphviz node information require(from just graphing the node names to also including the expressions and maybe sub-graphs of them)?
It would be pretty cool to be able visualize a grammar. Probably help a lot with design and bugs.
Also, I didn't know D could output files at compile time, but
"This will create the arithmetic.d file in the current directory, with the necessary infrastructure."
(maybe this is runtime?)
So, could it create a png at compile time using graphviz? Sort of automate the process for quick grammar visualization.
At least just generate the script file with edges and nodes.
Maybe you can use something like
version (tracer)
Unless I am misunderstanding, no. A trace produces a log of the parse (rules tried), not of the grammar. It is specific for a particular input. Logs also quickly grow into the GBs for any non-trivial case, much too big to represent in a graph.
But the problem is not all that hard. Producing a dotfile generator to represent any Pegged grammar as a graph should be pretty easy for any Pegged user that is familiar with the dot format and knows how he/she wants a grammar to be represented graphically. The grammar of all Pegged grammars is right here, just use Pegged for what it is meant to be used for :-)
Yeah, I didn't realize it would only trace out to a failure.
It could be used though to display the trace in a more visual format to help debug. Would probably be very similar code.
Not at all. The typical usage is to have a graphical representation of a grammar, e.g the documentation of a programming language. For example in Object Pascal doc:
I'll rather do my own tool. I think that processing the input file will work, no need to put this in the library.
Possible (?) enhancement