public IEnumerable<CompileError> GetDiagnostics(string programText) { ScriptEngine py = null; SourceUnit src = null; LanguageContext pythonLanguageContext = null; CompilerContext cc = null; IronPython.PythonOptions pyOptions; IronPython.Compiler.Parser pyParser = null; IEnumerable<CompileError> errorList = Enumerable.Empty<CompileError>(); try { py = IronPython.Hosting.Python.CreateEngine(); src = HostingHelpers.GetSourceUnit(py.CreateScriptSourceFromString(programText)); pythonLanguageContext = HostingHelpers.GetLanguageContext(py); cc = new CompilerContext(src, pythonLanguageContext.GetCompilerOptions(), ErrorSink.Default); pyOptions = pythonLanguageContext.Options as IronPython.PythonOptions; pyParser = Parser.CreateParser(cc, pyOptions); pyParser.ParseFile(true); } catch (Microsoft.Scripting.SyntaxErrorException e) { CompileError syntaxError = new CompileError(e.Message, new FileSpan(e.RawSpan.Start.Line, e.RawSpan.Start.Column, e.RawSpan.End.Line, e.RawSpan.End.Column)); errorList = errorList.Concat(new[] { syntaxError }); } finally { pyParser?.Dispose(); } return errorList; }
public IEnumerable <CompileError> GetDiagnostics(string programText) { SyntaxTree tree = CSharpSyntaxTree.ParseText(programText); var diagnostics = tree.GetDiagnostics(); var errorList = new List <CompileError>(); foreach (var diagnostic in diagnostics) { var span = diagnostic.Location.GetMappedLineSpan(); var errorLocation = new FileSpan(span); var error = new CompileError(diagnostic.GetMessage(), errorLocation); errorList.Add(error); } return(errorList); }
public virtual void AddError(CompileError err) { m_errors.Add(err); }