Since I want parser to make a Scripting Engine, I wrote ParserCombinator
which is popular in Scala in D.
However, when we devotedly write parser using ParserCombinator, the source
code is very dirty.
Like this
convert!(parseSeq!(parseOption(parseChar!('a')), parseChar!('b')),
funciton(~~~~){~~~~~})
We can easily convert PEG into parser by using ParserCombinator,
so I wrote the parser which parse a PEG and return the string of parser in
CTFE.
Like this
enum peg = q{
foo<int> = ('0' | '1') >> (char c) {
return c - '0';
};
}
mixin(defs(peg).value);
'defs' is the parser.
I call the parser PEGParser as a matter of convenience.
Template Library: http://ideone.com/3rKF4
ParserCombinator: http://ideone.com/YlGP2
PEGParser: http://ideone.com/vkTyh
Sample(Expression of four arithmetic operations): http://ideone.com/0uc3t
What do you think about this?