build method

  1. @override
String build(
  1. Context context,
  2. ParserResult? result
)
inherited

Implementation

@override
String build(Context context, ParserResult? result) {
  final parsers = _getParsers();
  if (parsers.length < 2) {
    throw StateError('The list of parsers must contain at least 2 elements');
  }

  var template = '{{body}}';
  final errors = <String>[];
  for (var i = 0; i < parsers.length; i++) {
    final error = context.allocateLocal();
    errors.add(error);
    final parser = parsers[i];
    final values = {
      'error': error,
      'p1': parser.build(context, result),
    };
    final templateParser = render(_templateParser, values);
    values.clear();
    values.addAll({
      'body': templateParser,
    });
    template = render(template, values);
  }

  final values = {
    'errors': errors.join(', '),
  };
  final templateFailure = render(_templateFailure, values);
  values.clear();
  values.addAll({
    'body': templateFailure,
  });
  return render(template, values);
}