build method

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

Implementation

@override
String build(Context context, ParserResult? result) {
  if (reservedWords.isEmpty) {
    throw ArgumentError('The list of reserved words must not be empty');
  }

  for (final item in reservedWords) {
    if (item.isEmpty) {
      throw ArgumentError(
          'The list of reserved words must not contain empty elements');
    }
  }

  context.refersToStateSource = true;
  final fast = result == null;
  final values = context.allocateLocals(['pos']);
  final isContUnicode = identCont.isUnicode;
  final isStartUnicode = identStart.isUnicode;
  final sortedWords = reservedWords.toSet().toList();
  sortedWords.sort();
  final words = <List<String>>[];
  final firstChars = sortedWords.map((e) => e.codeUnitAt(0)).toSet().toList();
  for (final item in firstChars) {
    final selected =
        sortedWords.where((e) => e.codeUnitAt(0) == item).toList();
    words.add(selected);
  }

  values.addAll({
    'identCont': identCont.build(context, 'identCont', ['c']),
    'identStart': identStart.build(context, 'identStart', ['c']),
    'readCont': isContUnicode ? 'readRune(state)' : 'codeUnitAt(state.pos++)',
    'readStart':
        isStartUnicode ? 'readRune(state)' : 'codeUnitAt(state.pos++)',
    'words': helper.getAsCode(words),
  });
  return render2(fast, _templateFast, _template, values, [result]);
}