/// <inheritdoc/> public void Execute(GeneratorExecutionContext context) { foreach (var file in GetCdeltaFiles(context)) { var input = file.GetText()?.ToString(); if (input == null) { continue; } var inputStream = new AntlrInputStream(input); var lexer = new CdeltaLexer(inputStream); var tokenStream = new CommonTokenStream(lexer); var parser = new CdeltaParser(tokenStream); CdeltaParser.CodeFileContext parsed = parser.codeFile(); var visitor = new CdeltaGrammarVisitor(); var result = visitor.Visit(parsed); var code = result.First().ToCode(); context.AddSource($"{Path.GetFileName(file.Path)}.cs", code); } using var stream = typeof(CdeltaGenerator).Assembly.GetManifestResourceStream("Cdelta.IAutomaton.cs"); using var reader = new StreamReader(stream); context.AddSource("IAutomaton.cs", reader.ReadToEnd()); }
private static CodeFile BuildStructure(AntlrInputStream inputStream) { if (inputStream == null) { throw new ArgumentNullException(nameof(inputStream)); } CdeltaLexer lexer = new CdeltaLexer(inputStream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); CdeltaParser parser = new CdeltaParser(tokenStream); CdeltaParser.CodeFileContext result = parser.codeFile(); CodeFile codeFile = new CodeFile(); CdeltaGrammarVisitor visitor = new CdeltaGrammarVisitor(inputStream.ToString(), ref codeFile); visitor.Visit(result); codeFile.Finish(); codeFile.Verify(); return(codeFile); }