public static Grammar LoadGrammar(string grammarFile, IReadOnlyList <CompilerReference> assemblyReferences) { if (DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(grammarFile), References = assemblyReferences }).HasErrors) { WriteColored(ConsoleColor.Magenta, DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(grammarFile), References = assemblyReferences }).TraceDiagnostics); return(null); } if (DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(grammarFile), References = assemblyReferences }).Diagnostics.Count > 0) { WriteColored(ConsoleColor.Yellow, DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(grammarFile), References = assemblyReferences }).TraceDiagnostics); } return(DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(grammarFile), References = assemblyReferences }).Value); }
public static Grammar LoadGrammar(string grammarFile, params string[] prerequisiteGrammars) { foreach (string prerequisite in prerequisiteGrammars) { var options = new CompilerOptions { InputGrammar = prerequisite, Output = Path.GetFileNameWithoutExtension(prerequisite) + ".Language.dll", Verbosity = Verbosity.Normal }; var buildResult = DSLCompiler.Compile(options); if (!buildResult.HasErrors) { continue; } WriteColored(ConsoleColor.Magenta, buildResult.TraceDiagnostics); return(null); } var compilationResult = DSLCompiler.ParseGrammarFromFile(grammarFile); if (compilationResult.HasErrors) { WriteColored(ConsoleColor.Magenta, compilationResult.TraceDiagnostics); return(null); } if (compilationResult.Diagnostics.Count > 0) { WriteColored(ConsoleColor.Yellow, compilationResult.TraceDiagnostics); } return(compilationResult.Value); }
public static Grammar LoadGrammar(string pathGrammarFile, bool verbose = false, params Type[] types) { var assemblies = new Assembly[types.Length]; for (int i = 0; i < types.Length; ++i) { assemblies[i] = types[i].GetTypeInfo().Assembly; } var compilationResult = DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(pathGrammarFile), References = CompilerReference.FromAssemblyFiles(assemblies) }); if (verbose) { if (compilationResult.HasErrors) { Console.WriteLine("Compilation HasErrors! Trace: "); compilationResult.TraceDiagnostics(); Console.WriteLine("------------------------------------------"); } else { Console.WriteLine("No Errors in Compilation. Trace: "); compilationResult.TraceDiagnostics(); Console.WriteLine("------------------------------------------"); } } return(compilationResult.HasErrors ? null : compilationResult.Value); }
public static Grammar LoadGrammar(string grammarFile, params string[] prerequisiteGrammars) { foreach (string prerequisite in prerequisiteGrammars) { var buildResult = DSLCompiler.Compile(prerequisite, $"{prerequisite}.xml"); if (buildResult.HasErrors) { WriteColored(ConsoleColor.Magenta, buildResult.TraceDiagnostics); return(null); } } var compilationResult = DSLCompiler.LoadGrammarFromFile(grammarFile); if (compilationResult.HasErrors) { WriteColored(ConsoleColor.Magenta, compilationResult.TraceDiagnostics); return(null); } if (compilationResult.Diagnostics.Count > 0) { WriteColored(ConsoleColor.Yellow, compilationResult.TraceDiagnostics); } return(compilationResult.Value); }
private static Result <Grammar> CompileGrammar() { return(DSLCompiler.Compile(new CompilerOptions { InputGrammarText = File.ReadAllText(GrammarPath), References = CompilerReference.FromAssemblyFiles(typeof(Semantics).GetTypeInfo().Assembly) })); }
private LanguageGrammar() { var options = new CompilerOptions { InputGrammarText = GrammarContent, References = CompilerReference.FromAssemblyFiles( typeof(Semantics).GetTypeInfo().Assembly, typeof(Microsoft.ProgramSynthesis.Wrangling.Tree.Node).GetTypeInfo().Assembly) }; Result <Grammar> compile = DSLCompiler.Compile(options); Grammar = compile.Value; }
static Grammar getGrammar() { var g = DSLCompiler.Compile(new CompilerOptions { InputGrammarText = File.ReadAllText("SExp.grammar"), References = CompilerReference.FromAssemblyFiles( typeof(SExpProgram).GetTypeInfo().Assembly, typeof(Semantics.SExp).GetTypeInfo().Assembly, typeof(Semantics.Semantics).GetTypeInfo().Assembly, typeof(Learning.RankingScore).GetTypeInfo().Assembly) }); return(g.Value); }
private static Grammar LoadGrammar(string file, IReadOnlyList <CompilerReference> assemblyReferences) { var compilationResult = DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(file), References = assemblyReferences }); if (compilationResult.HasErrors) { compilationResult.TraceDiagnostics(); return(null); } return(compilationResult.Value); }
public TransformationsController() { const string grammarFileName = @"Prose/Transformations.grammar"; var reader = new StreamReader(PathToFiles + grammarFileName); var grammar = reader.ReadToEnd(); _grammar = DSLCompiler.Compile( new CompilerOptions() { InputGrammarText = grammar, References = CompilerReference.FromAssemblyFiles( typeof(List <int>).GetTypeInfo().Assembly, typeof(Semantics).GetTypeInfo().Assembly, typeof(Node).GetTypeInfo().Assembly) } ); }
public static Grammar LoadGrammar(string grammarFile, IReadOnlyList <CompilerReference> assemblyReferences) { var compilationResult = DSLCompiler.Compile(new CompilerOptions() { InputGrammarText = File.ReadAllText(ResolveFilename(grammarFile)), References = assemblyReferences }); if (compilationResult.HasErrors) { WriteColored(ConsoleColor.Magenta, compilationResult.TraceDiagnostics); return(null); } if (compilationResult.Diagnostics.Count > 0) { WriteColored(ConsoleColor.Yellow, compilationResult.TraceDiagnostics); } return(compilationResult.Value); }