ParserCobinator like scala in D

美馬久行 youxkei at gmail.com
Sat Oct 9 23:12:28 PDT 2010


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101010/af87d7d2/attachment-0001.html>


More information about the Digitalmars-d mailing list