internal Variable ProcessTry(ParsingScript script) { int startTryCondition = script.Pointer - 1; int currentStackLevel = ParserFunction.GetCurrentStackLevel(); Exception exception = null; Variable result = null; try { result = ProcessBlock(script); } catch (Exception exc) { exception = exc; } if (exception != null || result.IsReturn || result.Type == Variable.VarType.BREAK || result.Type == Variable.VarType.CONTINUE) { // We are here from the middle of the try-block either because // an exception was thrown or because of a Break/Continue. Skip it. script.Pointer = startTryCondition; SkipBlock(script); } string catchToken = Utils.GetNextToken(script); script.Forward(); // skip opening parenthesis // The next token after the try block must be a catch. if (!Constants.CATCH_LIST.Contains(catchToken)) { throw new ArgumentException("Expecting a 'catch()' but got [" + catchToken + "]"); } string exceptionName = Utils.GetNextToken(script); script.Forward(); // skip closing parenthesis if (exception != null) { string excStack = CreateExceptionStack(exceptionName,currentStackLevel); ParserFunction.InvalidateStacksAfterLevel(currentStackLevel); GetVarFunction excMsgFunc = new GetVarFunction(new Variable(exception.Message)); ParserFunction.AddGlobalOrLocalVariable(exceptionName,excMsgFunc); GetVarFunction excStackFunc = new GetVarFunction(new Variable(excStack)); ParserFunction.AddGlobalOrLocalVariable(exceptionName + ".Stack",excStackFunc); result = ProcessBlock(script); ParserFunction.PopLocalVariable(exceptionName); } else { SkipBlock(script); } SkipRestBlocks(script); return(result); }
private static void ProcessScript(string script, string filename = "") { s_PrintingCompleted = false; string errorMsg = null; Variable result = null; try { if (!string.IsNullOrWhiteSpace(filename)) { result = System.Threading.Tasks.Task.Run(() => Interpreter.Instance.ProcessFileAsync(filename, true)).Result; //Interpreter.Instance.ProcessFile(filename, true)).Result; } else { result = System.Threading.Tasks.Task.Run(() => //Interpreter.Instance.ProcessAsync(script, filename)).Result; Interpreter.Instance.Process(script, filename, true)).Result; } } catch (Exception exc) { errorMsg = exc.InnerException != null ? exc.InnerException.Message : exc.Message; ParserFunction.InvalidateStacksAfterLevel(0); } if (!s_PrintingCompleted) { string output = Interpreter.Instance.Output; if (!string.IsNullOrWhiteSpace(output)) { Console.WriteLine(output); } else if (result != null) { output = result.AsString(false, false); if (!string.IsNullOrWhiteSpace(output)) { Console.WriteLine(output); } } } if (!string.IsNullOrWhiteSpace(errorMsg)) { Utils.PrintColor(errorMsg + Environment.NewLine, ConsoleColor.Red); errorMsg = string.Empty; } }
private static void ProcessScript(string script) { string error; Variable result; try { result = Interpreter.Instance.Process(script); // Console.WriteLine(result); } catch (Exception exc) { error = exc.Message; ParserFunction.InvalidateStacksAfterLevel(0); } }
private static void ProcessScript(string script) { s_PrintingCompleted = false; string errorMsg = null; Variable result = null; try { result = Interpreter.Instance.Process(script); } catch (Exception exc) { errorMsg = exc.Message; ParserFunction.InvalidateStacksAfterLevel(0); } if (!s_PrintingCompleted) { string output = Interpreter.Instance.Output; if (!string.IsNullOrWhiteSpace(output)) { Console.WriteLine(output); } else if (result != null) { output = result.AsString(false, false); if (!string.IsNullOrWhiteSpace(output)) { Console.WriteLine(output); } } } if (!string.IsNullOrWhiteSpace(errorMsg)) { Utils.PrintColor(errorMsg + Environment.NewLine, ConsoleColor.Red); errorMsg = string.Empty; } }
public static void ProcessException(ParsingScript script, ParsingException exc) { Debugger debugger = script != null && script.Debugger != null ? script.Debugger : MainInstance; if (debugger == null) { return; } if (debugger.ReplMode) { string replResult = DebuggerUtils.ResponseMainToken(DebuggerUtils.DebugAction.REPL) + "Exception thrown: " + exc.Message + "\n"; debugger.SendBack(replResult, false); debugger.LastResult = null; ParserFunction.InvalidateStacksAfterLevel(0); return; } string stack = exc.ExceptionStack; string vars = debugger.GetAllVariables(script); int varsCount = vars.Split('\n').Length; string result = "exc\n" + exc.Message + "\n"; //result += exc. + "\n"; result += varsCount + "\n"; result += vars + "\n"; result += stack + "\n"; debugger.SendBack(result, !debugger.ReplMode); debugger.LastResult = null; ParserFunction.InvalidateStacksAfterLevel(0); }
public static void ProcessException(ParsingScript script, ParsingException exc) { Debugger debugger = script.Debugger != null ? script.Debugger : MainInstance; if (debugger == null) { return; } string stack = exc.ExceptionStack; string vars = debugger.GetAllVariables(script); int varsCount = vars.Split('\n').Length; string result = "exc\n" + exc.Message + "\n"; result += varsCount + "\n"; result += vars + "\n"; result += stack + "\n"; debugger.SendBack(result); debugger.LastResult = null; ParserFunction.InvalidateStacksAfterLevel(0); }