private void ExecuteExpression() { if (string.IsNullOrEmpty(Code)) { return; } AddHistoricalCode(); var tokens = new AphidLexer(Code + " ").GetTokens(); if (!tokens.Any(x => x.TokenType == AphidTokenType.EndOfStatement)) { tokens.Add(new AphidToken(AphidTokenType.EndOfStatement, "", 0)); } List<Components.Aphid.Parser.AphidExpression> ast = null; try { ast = new AphidParser(tokens).Parse(); } catch (AphidParserException ex) { InvokeDispatcher(() => _codeViewer.AppendParserException(Code, ex)); return; } if (ast.Count != 1) { throw new InvalidOperationException(); } var exp = ast.First(); var unary = exp as UnaryOperatorExpression; if (unary == null || unary.Operator != AphidTokenType.retKeyword) { ast.Clear(); ast.Add(new UnaryOperatorExpression( AphidTokenType.retKeyword, exp)); } try { _interpreter.Interpret(ast); } catch (AphidRuntimeException ex) { InvokeDispatcher(() => _codeViewer.AppendException(Code, "Runtime error", ex)); return; } catch (AphidParserException ex) { InvokeDispatcher(() => _codeViewer.AppendParserException(Code, ex)); return; } var retVal = _interpreter.GetReturnValue(); var serializer = new AphidSerializer() { IgnoreFunctions = false }; InvokeDispatcher(() => _codeViewer.AppendOutput(Code, serializer.Serialize(retVal))); UpdateVariables(); ExecuteWatchExpressions(); }
private void ExecuteWatchExpression(ExpressionViewModel vm) { try { _interpreter.Interpret("ret " + vm.Expression + ";"); } catch (AphidRuntimeException e) { InvokeDispatcher(() => vm.Value = "Runtime exception: " + e.Message); return; } catch (AphidParserException e) { InvokeDispatcher(() => vm.Value = "Parser exception: " + e.Message); return; } var retVal = new AphidSerializer() { IgnoreFunctions = false } .Serialize(_interpreter.GetReturnValue()); InvokeDispatcher(() => vm.Value = retVal); }
public static void Dump(AphidInterpreter interpreter, AphidObject obj) { AphidObject vmObj; interpreter.CurrentScope.TryResolve(ViewModelName, out vmObj); var vm = (AphidReplViewModel)vmObj.Value; var serializer = new AphidSerializer() { IgnoreFunctions = false }; vm._codeViewer.Dispatcher.Invoke(() => { if (obj != null) { vm._codeViewer.AppendCode(serializer.Serialize(obj)); } else { throw new InvalidOperationException(); } }); }