Help with porting grammar from PEGjs to D for dustjs project!

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Aug 3 13:13:03 PDT 2014


Uranuz:
> http://akdubya.github.io/dustjs/

> So I need some help with rewriting grammar from PEGjs into PEGGED.

Is this the grammar?

https://github.com/akdubya/dustjs/blob/master/src/dust.pegjs

If so, then I think I can provide some help. But I don't get what
output you want (see below).

> Also I don't understand in PEGGED (I have not tried to use it yet) how to
> generate some logic from AST. Where should I describe it or should I walk
> around all nodes for somehow and generate code for them.

You can put semantic actions in the grammar (code between curly
brackets). dust.pegjs seems
to have that in their grammar definition also (all these { return
something } blocks)

Or you can walk the parse tree afterwards.

See the Pegged tutorial here:

https://github.com/PhilippeSigaud/Pegged/wiki/Pegged-Tutorial

More particularly:

https://github.com/PhilippeSigaud/Pegged/wiki/Using-the-Parse-Tree

The example explains (I hope) how to use a wiki grammar to parse wiki
text and output LaTeX code.


> Goal of this is to use dust template system as template engine at server
> side.

More concretely, what's the goal? A template as input and... what
should be output? If I understand correctly, dustjs produces
Javascript code. Is that what you want? Or do you want D code?

Also, did you have a look at vide.d and its Diet templates?


More information about the Digitalmars-d-learn mailing list