spaceAnd

The engine formerly behind the '< ' Pegged rule: all sequence subelements of a rule are interspersed with a space-consuming rule, given as the first template parameter. It's not used by Pegged anymore but can be useful for low-level code. It might become deprecated, but it's not there yet.

alias and!(literal!"abc", literal!"def") rule1; // "abc" "def", equivalent to "abcdef"
alias spaceAnd!(oneOrMore!blank, literal!"abc", literal!"def") rule2; // "abc" "def", but with spaces in-between.

string input1 = "abcdef";
string input2 = "  abc

def  "; // with spaces and end of line markers.

assert(rule1(input1).successful); // OK
assert(!rule1(input2).successful); // NOK, couldn't find "def" after "abc"

assert(rule2(input1).successful); // OK
assert(rule2(input2).successful); // Still OK
assert(rule2(input2).matches == ["abc","def"]);// rule2 finds the literals among the spaces

As you can see on the previous line, spaceAnd discards the matched spaces and returns matches only for the 'real' subrules.

Note: by using a non-space rule as the first template argument, you can use spaceAnd as a generic 'find these patterns, possibly separated by this pattern' rule.

For example, using digits as separators:

alias spaceAnd!(digit, literal!"abc", litera!"def") rule3;

ParseTree result = rule3("123abc45def67890");
assert(rule3.successful);
assert(rule3.matches == ["abc", "def"]);
assert(rule3.children.length == 2);

assert(rule3.begin == 0;)
assert(rule3.end == "123abc45def67890".length);

Members

Aliases

spaceAnd
alias spaceAnd = and!(discard!(zeroOrMore!sp), staticMap!(AddSpace!(zeroOrMore!sp), rules))
Undocumented in source.

Meta