or

Basic operator: it matches if one of its subrules (stored in the rules template parameter tuple) match the input. The subrules are tested in order, from rules[0] to rules[$-1].

The matching subrule parse trees is stored as its only child and its matches field will contain all the subrule matches, in order.

alias or!(literal!"abc", charRange!('a','z')) rule; // abc or, failing that, any letter between a and z.
ParseTree input = ParseTree("",false,[],"defg"); // low-level plumbing, the rules described here act on ParseTree's not strings.
                                                 // It's equivalent to "defg" as input
auto result = rule(input);

assert(result.successful); // OK
assert(result.matches == ["d"]); // stores the (in this case) only match
assert(result.children.length == 1); // one child, the result of "abc" or [a-z], depending on which rule succeeded.

input.input = "abc"; // changing the input string;
assert(rule(input)).successful); // Still OK
input.input = "1abc";
assert(!rule(input)).successful); // NOK, does not begin by abc nor by [a-z]

If it fails, the last children will contain the failed node that matched furthest (longes match). That way, when printing, as sort of diagnostic is given:

alias or!(literal!"abc", and!(literal!"ab", charRange!('0','9'))) rule; // 'abc' or 'ab[0-9]'
ParseTree input = ParseTree("",false,[],"abd"); // equivalent to "abd"

auto failure = rule(input);
writeln(failure);
/+
or (failure)
 +-and (failure)
    +-literal(ab) [0, 2]["ab"]
    +-charRange(0,9) failure at line 0, col 2, after "ab" expected a char between '0' and '9', but got "d"
+/

So we know 'or' failed, that the 'and' sub-rule had the longest match, matching 'ab' and failing for [0-9] on index 2.

  1. ParseTree or(ParseTree p)
    template or(rules...)
    if (
    rules.length > 0
    )
  2. ParseTree or(string input)
  3. string or(GetName g)

Members

Functions

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

Manifest constants

name
enum name;
Undocumented in source.

Meta