/// <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); }
/// <summary> /// Exit a parse tree produced by <see cref="CdeltaParser.codeFile"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitCodeFile([NotNull] CdeltaParser.CodeFileContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="CdeltaParser.codeFile"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitCodeFile([NotNull] CdeltaParser.CodeFileContext context) { return(VisitChildren(context)); }
public override object VisitCodeFile(CdeltaParser.CodeFileContext context) { contextWithStructure.Add(context, codeFile); return(base.VisitCodeFile(context)); }