and

Basic operator: it matches if all its subrules (stored in the rules template parameter tuple) match the input successively. Its subrules parse trees are stored as its children and its matches field will contain all its subrules matches, in order.

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

assert(result.successful); // OK, 'abc' followed by 'd'
assert(result.matches == ["abc", "d"]); // stores the matches
assert(result.children.length == 2); // two children, the result of "abc" on "abcd" and the result of [a-z] on "d"

input.input = "abc"; // changing the input string;
assert(!rule(input)).successful); // NOK, abc alone
input.input = "ab";
assert(!rule(input)).successful); // NOK, does not begin by abc

If it fails, the last children will contain the failed node. That way, when printing, as sort of diagnostic is given:

alias and!(literal!"abc", charRange!('a','z')) rule; // 'abc[a-z]', aka 'abc' followed by any letter between 'a' and 'z'.
ParseTree input = ParseTree("",false,[],"abc1"); // equivalent to "abc1"

auto failure = rule(input);
writeln(failure);
/+
writes:
and (failure)
 +-literal(abc) [0, 3]["abc"]
 +-charRange(a,z) failure at line 0, col 3, after "abc" a char between 'a' and 'z', but got "1"
+/

So we know the global 'and' failed, that the first sub-rule ('abc') succeeded on input[0..3] with "abc" and that the second subrule ('[a-z]') failed at position 3 (so, on '1').

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

Members

Functions

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

Manifest constants

name
enum name;
Undocumented in source.

Meta