delegatingParser function

Parser<List<Object>> delegatingParser({
  1. required List<Parser<Object>> delegates,
  2. required String tagStart,
  3. required String tagEnd,
})

A delegatingParser delegates to work to other parsers. Text that is not handled by the delegates will also be collected

Implementation

Parser<List<Object>> delegatingParser({
  required List<Parser<Object>> delegates,
  required String tagStart,
  required String tagEnd,
}) {
  if (delegates.isEmpty) {
    return any().star().flatten().map((value) => [value]);
  }

  var parser = ChoiceParser<Object>([
    ChoiceParser<Object>(delegates),
    untilEndOfTagParser(tagStart, tagEnd),
    untilEndParser(),
  ]);
  return parser.plus();
}