Lexer and parser generators using CTFE

Philippe Sigaud philippe.sigaud at gmail.com
Thu Mar 1 07:10:26 PST 2012


>> mixin(Grammar!("Doc <- Node*"
>> "Node <- OpeningTag (Text / Node)* ClosingTag", NodeAction,
>> "OpeningTag <- '<' Identifier '>'", OpeningAction,
>> "ClosingTag <-  `</` Identifier '>'", ClosingAction,
>> "Text <- (!(OpeningTag / ClosingTag) _)+"));
>
>
> That looks about right, but still has a fair amount of noise. I think the
approach of putting the entire grammar in one string is best.

Yes, using one string is indeed better. That won't be too difficult to code.

But how to associate actions with a rule, in that case? I mean, some rules
will have actions, some not.

In my case, a parse tree is automatically generated (indeed, it's almost
the only thing returned by a parse call, that with recognized string and
named captures). I have some additional syntax to 'drop' a node ans such,
similar to what you proposed a few posts ago.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120301/39fbbd08/attachment.html>


More information about the Digitalmars-d mailing list