build method
Builds the expression parser.
Implementation
@useResult
Parser<T> build() {
final primitives = <Parser<T>>[
..._primitives,
..._groups.expand((group) => group.primitives),
];
assert(primitives.isNotEmpty, 'At least one primitive parser expected');
final parser = _groups.fold<Parser<T>>(
buildChoice(primitives),
(parser, group) => group.build(parser),
);
// Replace all uses of `_loopback` with `parser`. Do not use `resolve()`
// because that might try to resolve unrelated parsers outside of the scope
// of the `ExpressionBuilder` and cause infinite recursion.
for (final parent in allParser(parser)) {
parent.replace(_loopback, parser);
}
// Also update the loopback parser, just in case somebody keeps a reference
// to it (not that anybody should do that).
_loopback.set(parser);
return parser;
}