/// <summary> /// Parses a Block inside an open ReplSession /// </summary> /// <param name="expression">the Expression-Block that must be executed</param> /// <param name="replSession">the current repl-session</param> /// <returns>the result of the Execution-block</returns> public static object ParseBlock(string expression, IDisposable replSession) { if (replSession is InterpreterBuffer.RunnerItem rii) { ITVScriptingBaseVisitor <ScriptValue> visitor = InterpreterBuffer.GetInterpreter(rii); ITVScriptingParser.ProgramContext executor = GetProgramTree(expression); ScriptValue retVal = visitor.VisitProgram(executor); return(ScriptValueHelper.GetScriptValueResult <object>(retVal, false)); } return(ParseBlock(expression, replSession, null)); }
/// <summary> /// Reloads the definition of the program /// </summary> private void ReloadDefinition() { lock (runCounterLock) { executionWait.Reset(); while (currentRuns > 0) { Monitor.Wait(runCounterLock); } } try { AntlrInputStream astr = null; if (!isStatic) { astr = new AntlrFileStream(fileName, Encoding.Default); } else { using (var r = new StreamReader(file, Encoding.Default)) { astr = new AntlrInputStream(r); } } //SingletonPredictionContext. Lexer lex = new ITVScriptingLexer(astr); ITVScriptingParser parser = new ITVScriptingParser(new CommonTokenStream(lex)); ErrorListener listener = new ErrorListener(); parser.RemoveErrorListeners(); parser.AddErrorListener(listener); //parser.AddParseListener(new ScriptErrorHandler()); program = parser.program(); runnable = parser.NumberOfSyntaxErrors == 0; suspectLine = listener.SuspectLine; errors = listener.GetAllErrors(); lastCompilation = DateTime.Now; } finally { executionWait.Set(); } }