/// <summary> /// Generates the parser for the input files of this compiler (.gram files) /// </summary> /// <returns>The number of errors (should be 0)</returns> private static int GenerateCDParser() { Stream stream = typeof(CompilationTask).Assembly.GetManifestResourceStream("Hime.SDK.Sources.Input.HimeGrammar.gram"); CompilationTask task = new CompilationTask(); task.Mode = Mode.Source; task.AddInputRaw(stream); task.GrammarName = "HimeGrammar"; task.Namespace = "Hime.SDK.Input"; task.CodeAccess = Modifier.Internal; task.Method = ParsingMethod.LALR1; Report report = task.Execute(); return(report.Errors.Count); }
/// <summary> /// Builds the fixture parser /// </summary> /// <returns>The fixture parser assembly</returns> private static AssemblyReflection BuildFixtureParser() { Stream stream1 = typeof(Program).Assembly.GetManifestResourceStream("Hime.Tests.Driver.Resources.Fixture.gram"); Stream stream2 = typeof(CompilationTask).Assembly.GetManifestResourceStream("Hime.SDK.Sources.Input.HimeGrammar.gram"); CompilationTask task = new CompilationTask(); task.AddInputRaw(stream1); task.AddInputRaw(stream2); task.GrammarName = "Fixture"; task.CodeAccess = Modifier.Public; task.Method = ParsingMethod.LALR1; task.Mode = Mode.Assembly; task.Namespace = "Hime.Tests.Driver"; task.Execute(); return(new AssemblyReflection("Fixture.dll")); }
public override bool Execute() { if (string.IsNullOrEmpty(GrammarFile)) { Log.LogError("The grammar file name is not set"); return(false); } if (string.IsNullOrEmpty(Namespace)) { Log.LogError("The namespace is not set"); return(false); } if (string.IsNullOrEmpty(GrammarName)) { Log.LogError("The grammar name is not set"); return(false); } if (string.IsNullOrEmpty(OutputPath)) { Log.LogError("The output assembly path is not set"); return(false); } Mode outputMode; switch (OutputMode) { case "Assembly": case "assembly": outputMode = Mode.Assembly; break; case "Source": case "source": outputMode = Mode.Source; break; case "SourceAndAssembly": case "source-and-assembly": outputMode = Mode.SourceAndAssembly; break; default: Log.LogError("The output mode is incorrect, it should be Assembly, Source or SourceAndAssembly"); return(false); } Modifier codeAccess; switch (CodeAccess) { case "Public": case "public": codeAccess = Modifier.Public; break; case "Internal": case "internal": codeAccess = Modifier.Public; break; default: Log.LogError("The code access mode is incorrect, it should be either Public or Internal"); return(false); } CompilationTask task = new CompilationTask(); task.AddInputFile(GrammarFile); task.CodeAccess = codeAccess; task.GrammarName = GrammarName; task.Mode = outputMode; task.OutputPath = OutputPath; task.Namespace = Namespace; Report report = task.Execute(); if (report.Errors.Count == 0) { Log.LogMessage($"Grammar {GrammarName} compiled succesfully"); return(true); } Log.LogMessage($"Grammar {GrammarName} compilation failed"); for (int i = 0; i < report.Errors.Count; i++) { Log.LogError($"Error in {GrammarFile} : {report.Errors[i].ToString()}"); } return(false); }