option

Given a subrule 'r', represents the expression 'r?'. It tries to match 'r' and if this matches successfully, it returns this match. If 'r' failed, 'r?' is still a success, but without any child nor match.

1 alias option!(literal!"abc") rule; // Aka '"abc"?'
2 ParseTree input = ParseTree("",false,[],"abcd");
3 
4 ParseTree result = rule(input);
5 assert(result.successful);
6 assert(result.matches == ["abc"]);
7 assert(result.children.length == 1);
8 assert(result.children[0] == literal!"abc"(input));
template option(alias r)
option

Meta