fastBuild function
Implementation
Future<void> fastBuild(Context context, List<Named> parsers, String filename,
{bool addErrorMessageProcessor = true,
String? footer,
bool format = true,
String? header,
String? partOf,
Map<String, Named> publish = const {}}) async {
for (var i = 0; i < 2; i++) {
context.pass = i;
context.globalDeclarations.clear();
context.globalAllocator = context.globalAllocator.clone();
for (final parser in parsers) {
context.localAllocator = context.localAllocator.clone();
final result = context.getResult(parser, true);
parser.build(context, result);
}
}
final declarations = context.globalDeclarations;
for (final entry in publish.entries) {
final code = _publish(entry.key, entry.value);
declarations.insert(0, code);
}
if (addErrorMessageProcessor) {
declarations.add(ParseRuntime.getErrorMessageProcessor());
}
declarations.addAll(ParseRuntime.getClasses());
var code = declarations.join('\n\n');
if (partOf != null) {
code = 'part of \'$partOf\';\n\n' + code;
}
if (header != null) {
code = header + code;
}
if (footer != null) {
code += footer;
}
File(filename).writeAsStringSync(code);
if (format) {
final process =
await Process.start(Platform.executable, ['format', filename]);
process.stdout.transform(utf8.decoder).forEach(print);
process.stderr.transform(utf8.decoder).forEach(print);
}
}