View mode: basic / threaded / horizontal-split · Log in · Help
July 06, 2012
Re: Parser generator?
On Friday, 6 July 2012 at 06:10:28 UTC, Philippe Sigaud wrote:
>> void buildGraph(Output o) {
>>         void parseToGraph(ParseTree p) {
>>                 writeln(p.ruleName);
>>         }
>>
>>         parseToGraph(o.parseTree);
>> }
> What do parseToGraph and buildGraph do?

buildGraph unwraps parseTree from output, and parseToGraph writes 
a line with rule name of a parse tree. ;)))
July 06, 2012
Re: Parser generator?
Philippe Sigaud <philippe.sigaud@gmail.com> writes:

>> > Yeah. It's pretty cool. It really shows up D's metaprogramming
>> > capabilities.
>>
>> It's a bit hell to debug it, though. But I finally managed to get a
>> working parser out of it.
>
> I received your suggestion of a full debug mode explaining what rules where
> activated and wich did not.

Good :-)

>> Except now I can't use it, for some reason. Code:
>>
>> void buildGraph(Output o) {
>>         void parseToGraph(ParseTree p) {
>>                 writeln(p.ruleName);
>>         }
>>
>>         parseToGraph(o.parseTree);
>> }
>>
>> void parseconfigs() {
>>         Output o = ENI.parse(readText("/tmp/ifaces_data"));
>>         buildGraph(o);
>> }
>>
>> produces the following error message:
>>
>> dmd  -gc -w -unittest -I../../Pegged -c -ofmain.o main.d
>> ipcfg/parser.d(45): Error: struct pegged.peg.Output(TParseTree) if
> (isParseTree!(TParseTree)) is used as a type
>> make: *** [main.o] Error 1
>>
>> Help?
>
> Roman recently templated the parse tree to allow multiple outputs and we didn't
> update the docs, sorry. That makes Pegged output something other than `Output`.
> One consequence is hat semantic actions should be templates to function on
> different kinds of parse trees.
>
> Try:
>
>> void buildGraph(O)(O o) {

Ah yes, that explains. Thanks.

>>         void parseToGraph(ParseTree p) {
>>                 writeln(p.ruleName);
>>         }
>>
>>         parseToGraph(o.parseTree);
>> }
>>
>> void parseconfigs() {
>>         auto o = ENI.parse(readText("/tmp/ifaces_data"));
>>         buildGraph(o);
>> }
>
> What do parseToGraph and buildGraph do?

Nothing more than that, _currently_. The plan is for them to eventually
build data structures in memory, but I'm not there yet.

>> What does cause problems, though, is that it won't compile with gdc:
>>
>> gdmd -release  -I../../Pegged -c -ofmain.o main.d
>> /home/wouter/code/d/Pegged/pegged/grammar.d:128: Error: template
> pegged.grammar.PEGGED!(ParseTree).PEGGED.parse(ParseLevel pl =
> ParseLevel.parsing) parse(ParseLevel pl = ParseLevel.parsing) matches more than
> one template declaration, /home/wouter/code/d/Pegged/pegged/grammar.d
> (111):parse(ParseLevel pl = ParseLevel.parsing) and /home/wouter/code/d/Pegged/
> pegged/grammar.d(126):parse(ParseLevel pl = ParseLevel.parsing)
>> make: *** [main.o] Error 1
>>
>> GDC 4.6, though, so I'll wait until Iain uploads 4.7 to Debian; if that
>> doesn't fix it, I'll file bugs where appropriate.
>
> I find it strange that I don't get that error with DMD.

Agreed.

-- 
The volume of a pizza of thickness a and radius z can be described by
the following formula:

pi zz a
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home