oneOrMore

Tries to match subrule 'r' one or more times. If 'r' fails from the very beginning, it fails and else succeeds.

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'.

alias oneOrMore!(or!(literal!"abc", literal!"d")) rule; // in PEG-speak:  '("abc" / "d")*'
ParseTree input = ParseTree("",false,[], "abcdabce");

ParseTree result = 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:
oneOrMore  [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); // fails, since it failed on the first try.
  1. ParseTree oneOrMore(ParseTree p)
    template oneOrMore(alias r)
  2. ParseTree oneOrMore(string input)
  3. string oneOrMore(GetName g)

Members

Functions

oneOrMore
ParseTree oneOrMore(ParseTree p)
Undocumented in source. Be warned that the author may not have intended to support it.
oneOrMore
string oneOrMore(GetName g)
Undocumented in source. Be warned that the author may not have intended to support it.
oneOrMore
ParseTree oneOrMore(string input)
Undocumented in source. Be warned that the author may not have intended to support it.

Manifest constants

name
enum name;
Undocumented in source.

Meta