internal SkryptParser.ProgramContext ParseProgram(string source, ParserOptions options) { ErrorHandler.Source = source; var errorHandler = new CompileErrorHandler(this, source) { Tolerant = options.Tolerant }; var errorListener = new ErrorListener(this, errorHandler); var inputStream = new AntlrInputStream(source); var skryptLexer = new SkryptLexer(inputStream) { Engine = this, CompileErrorHandler = errorHandler }; skryptLexer.RemoveErrorListeners(); skryptLexer.AddErrorListener(errorListener); var commonTokenStream = new CommonTokenStream(skryptLexer); Parser = new SkryptParser(commonTokenStream) { Engine = this, TokenStream = commonTokenStream, CompileErrorHandler = errorHandler }; Parser.RemoveErrorListeners(); Parser.AddErrorListener(errorListener); Parser.GlobalEnvironment = GlobalEnvironment; var program = Parser.program(); Parser.LinkLexicalEnvironments(program, GlobalEnvironment); if (errorHandler.Errors.Count > 0 && options.ReportErrors) { var sorted = errorHandler.Errors.OrderBy(x => x.File).ThenBy(x => x.Line).ThenBy(x => x.Column); foreach (var err in sorted) { ErrorHandler.ReportError(err); } } return(program); }
public ErrorListener(SkryptEngine engine, CompileErrorHandler compileErrorHandler) { _engine = engine; _compileErrorHandler = compileErrorHandler; }