compileHoneyTalk function

CompilationResult compileHoneyTalk(
  1. String script
)

Implementation

CompilationResult compileHoneyTalk(String script) {
  final scriptLc = script.replaceAllMapped(strRegex, (match) {
    final value = match.group(0)!;
    return value.startsWith('"') ? value : value.toLowerCase();
  });

  final chars = InputStream.fromString(scriptLc);
  final lexer = HoneyTalkLexer(chars);
  final tokens = CommonTokenStream(lexer);
  final parser = HoneyTalkParser(tokens);

  CompilationResult? error;
  parser.removeErrorListeners();
  parser.addErrorListener(HoneyErrorListener((e) {
    error = e;
  }));

  final statements = parser.script().accept(ScriptVisitor())!;

  return error ?? CompilationResult(statements: statements);
}