defined

Internal helper template, to get a parse tree node with a name, while keeping the original node (see also named). For example, given:

alias or!(literal!("abc"), charRange!('0','9')) myRule;

myRule gives nodes named "or", since its the parent rule. If you want nodes to be named "myRule", use defined. Contrary to named (see before), the original node is pushed as the child.

template defined(alias r, string name)
defined

See Also

named.

1 alias or!(literal!("abc"), charRange!('0','9')) rule;
2 alias defined!(rule, "myRule") myRule;
3 
4 auto input = "abc3";
5 auto p1 = rule(input);
6 auto p2 = myRule(input);
7 
8 // They are both successful
9 assert(p1.successful && p2.successful);
10 assert(p1.matches == p2.matches);
11 // But the names are different
12 assert(p1.name == `or!(literal!("abc"), charRange!('0','9'))`);
13 assert(p2.name == `myRule`);
14 // Here the original tree is not discarded:
15 assert(p2.children[0] == p1);

Meta