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