codegen function
Implementation
String codegen(String clazz, String contents) {
CandidLexer.checkVersion();
CandidParser.checkVersion();
final input = InputStream.fromString(contents);
final lexer = CandidLexer(input);
final tokens = CommonTokenStream(lexer);
final parser = CandidParser(tokens);
parser.addErrorListener(DiagnosticErrorListener());
parser.buildParseTree = true;
final prog = parser.prog();
final typeDef = TypeDefParser();
ParseTreeWalker.DEFAULT.walk(typeDef, prog);
final classDef = ClassDefParser(typeDef.typeDefs, typeDef.primIdlMap);
ParseTreeWalker.DEFAULT.walk(classDef, prog);
final idl = IDLParser(
clazz,
typeDef.typeDefs,
typeDef.primIdlMap,
classDef.tupleTypes,
);
ParseTreeWalker.DEFAULT.walk(idl, prog);
final formatter = DartFormatter();
final code = formatter.format(Template(
fileTpl,
htmlEscapeValues: false,
).renderString({
'idl': idl.idlCodes,
'classes': classDef.classCodes,
}));
return code;
}