generate method

  1. @override
void generate(
  1. StringBuffer buffer,
  2. GrammarInformation grammarData,
  3. FirstFollowResult firstFollow, [
  4. bool generateProductions = false,
])
override

Generates data into a StringBuffer, that is the result of grammar productions and a first-follow sets

Implementation

@override
void generate(
  StringBuffer buffer,
  GrammarInformation grammarData,
  FirstFollowResult firstFollow, [
  bool generateProductions = false,
]) {
  buffer.write(_buildClassDeclaration());

  for (final entry in grammarData.extraDefinitions.entries) {
    buffer.write(
      '\tstatic const ${sanitizeName(entry.key)} = ${stringifyTerminal(entry.value, CHAR_SINGLE_QUOTE)};\n',
    );
  }

  _buildMapSet('\tstatic const firstSet', buffer, firstFollow.firstList);
  buffer.write(';\n');
  _buildMapSet('\tstatic const followSet', buffer, firstFollow.followList);
  if (!generateProductions) {
    buffer.write(';\n');
    _buildMapProductions(buffer, grammarData.productions);
  }
  buffer.write(';');

  buffer.write(_buildClassEnd());
}