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.
aliasand!(literal!"abc", literal!"def") rule1; // "abc" "def", equivalent to "abcdef"aliasspaceAnd!(oneOrMore!blank, literal!"abc", literal!"def") rule2; // "abc" "def", but with spaces in-between.stringinput1 = "abcdef";
stringinput2 = " abc
def "; // with spaces and end of line markers.assert(rule1(input1).successful); // OKassert(!rule1(input2).successful); // NOK, couldn't find "def" after "abc"assert(rule2(input1).successful); // OKassert(rule2(input2).successful); // Still OKassert(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.
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.
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: