dsl for transforming results of a parser
dsl for alternatives e.g. match("abc") | match("def") matches "abc" or "def"
dsl for sequences e.g. match("a") ~ match("b") matches "ab"
dsl for repetition of a parser e.g. (*match("a")) matches sequences of a
dsl for optional parser e.g. (-match("abc")) matches "abc" and "efg"
this must be implemented by subclasses
helper to create a successfull result
transforming from regexp string to integer
import std.conv; auto res = (regex("\\d+") ^^ (input) { return variantArray(input[0].get!string .to!int); }).parse("123"); res.success.should == true; res.results[0].should == 123;
the pc4d.alternative parser and its dsl '|'
auto parser = match("abc") | match("def"); auto res = parser.parse("abc"); res.success.should == true; res = parser.parse("def"); res.success.should == true; res = parser.parse("ghi"); res.success.should == false;
trying to parse all of the input
auto parser = match("test"); auto res = parser.parseAll("test"); res.success.should == true; res.rest.length.should == 0; res = parser.parseAll("test1"); res.success.should == false;
trying to parse part of the input
auto parser = match("test"); auto res = parser.parse("test"); res.success.should == true; res.rest.length.should == 0; res = parser.parse("test1"); res.success.should == true; res.rest.should == "1";
interface for all parser combinators parse must be implemented.