private Parser GetParser() { if (_parser == null) { using (var options = new CompilerOptions()) { var sourceItems = new SourceItem[]{ new TextItem() { Name = "GdlGrammer", ContentType = TextItemType.MGrammar, Reader = new StringReader(Language) } }; options.AddSourceItems(sourceItems); CompilationResults results = Compiler.Compile(options); if (results.HasErrors) { //TODO: show meaningful error message throw new Exception("Failed to compile GDL ...."); } else { foreach (var parserFactory in results.ParserFactories) { //TODO: Why inside foreach loop!!! _parser = parserFactory.Value.Create(); } } } } return _parser; }
internal static Parser GetParser() { using (var options = new CompilerOptions()) { var sourceItems = new SourceItem[]{ new TextItem() { Name = "GdlGrammar", ContentType = TextItemType.MGrammar, Reader = new StringReader(GDL) } }; options.AddSourceItems(sourceItems); CompilationResults results = null; results = Compiler.Compile(options); if (results.HasErrors) { throw new Exception("Failed to compile GDL ...." + Environment.NewLine + results.Errors[0]); } else { foreach (var parserFactory in results.ParserFactories) { return parserFactory.Value.Create(); } } } return null; }