Lexer and parser generators using CTFE

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Mar 1 09:13:31 PST 2012


On Thu, Mar 01, 2012 at 04:10:26PM +0100, Philippe Sigaud wrote:
> >> 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.

You could maybe just put D code in the grammar string, which gets
compiled as a string mixin by CTFE?


T

-- 
"A man's wife has more power over him than the state has." -- Ralph Emerson


More information about the Digitalmars-d mailing list