Tries to match subrule 'r' zero or more times. It always succeeds, since if 'r' fails
from the very beginning, it matched 'r' zero times...
Its matches are those of its subrules (they might be different for each match) and its
children are all the parse trees returned by the successive application of 'r'.
aliaszeroOrMore!(or!(literal!"abc", literal!"d")) rule; // in PEG-speak: '("abc" / "d")*'ParseTreeinput = ParseTree("",false,[], "abcdabce");
ParseTreeresult = rule(input);
assert(result.successful);
assert(result.matches == ["abc", "d", "abc"]);
assert(result.end == 7); // matched "abcdabce"[0..7] => "abcdabc". "e" at the end is not part of the parse tree.assert(result.children.length == 3);
writeln(result);
/+
writes:
zeroOrMore [0, 7]["abc", "d", "abc"]
+-or [0, 3]["abc"]
| +-literal(abc) [0, 3]["abc"]
+-or [3, 4]["d"]
| +-literal(d) [3, 4]["d"]
+-or [4, 7]["abc"]
+-literal(abc) [4, 7]["abc"]
+/
So we know the first child used the 'literal!"abc"' sub-rule and matched input[0..3].
The second matched input[3..4] and the third input[4..7].
input = ParseTree("",false,[], "efgh");
result = rule(input);
assert(result.successful); // succeed, even though all patterns failed.assert(result.children.length == 0);
Tries to match subrule 'r' zero or more times. It always succeeds, since if 'r' fails from the very beginning, it matched 'r' zero times...
Its matches are those of its subrules (they might be different for each match) and its children are all the parse trees returned by the successive application of 'r'.
So we know the first child used the 'literal!"abc"' sub-rule and matched input[0..3]. The second matched input[3..4] and the third input[4..7].