Help with porting grammar from PEGjs to D for dustjs project!
Philippe Sigaud via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 6 01:17:02 PDT 2014
On Wed, Aug 6, 2014 at 9:09 AM, Uranuz via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
> What I was thinking about is possibility to change ParseTree struct with
> user-defined version of it. And I was thinking about setting tree type as
> template parameter to grammar:
>
> grammar!(MyParseTree)("
> Arithmetic:
> ...
> ");
That's already the case, look at
https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/parser.d
on line 134, for example.
struct GenericPegged(TParseTree)
{
...
}
And then, the library alias a standard version (line 1531):
alias GenericPegged!(ParseTree).Pegged Pegged;
Which means the customer-facing Pegged parser is in fact a generic
parser specialized on ParseTree. But you can substitute your own parse
tree.
That's of course the same for all parsers: GenericXXX(TParseTree)
{...} and then alias XXX = GenericXXX!(ParseTree);
But you're right, it's not really documented and I don't have a
template checking whether TParseTree respect some static inferface.
This parameterization was asked by someone on github, but I don't
think they used it finally.
ParseTree is described here:
https://github.com/PhilippeSigaud/Pegged/wiki/Parse-Trees
Maybe we can continue this thread by private mail? I'm not sure people
on the D list are that interested by the internals of a library.
More information about the Digitalmars-d-learn
mailing list