private async Task DumpFormatAsync(ExpressionViewModel vm, string msg) => //if () //{ // return ; //} //var retVal = SerializingFormatter.Format( // Interpreter, // true, // Interpreter.GetReturnValue(), // ignoreNull: false, // ignoreClrObj: false, // scopes: AphidObject.GetScopeAncestors(Interpreter.CurrentScope)); //return CodeViewer.Run(() => vm.Value = retVal); await CodeViewer.Run( x => vm.Value = x, await(msg != null ? (Func <Task <string> >)(() => Task.FromResult(msg)) : (() => Task.Run( () => SerializingFormatter.Format( Interpreter, true, Interpreter.GetReturnValue(), ignoreNull: false, ignoreClrObj: false, scopes: AphidObject .GetScopeAncestors(Interpreter.CurrentScope)))))());
public static void Dump(AphidInterpreter interpreter, object obj) => SerializingFormatter .Format(interpreter, obj) .Then(CodeViewer.HighlightAsync) .ContinueWith(x => interpreter.CurrentScope .Resolve(interpreter, ViewModelName) .Get <AphidReplViewModel>() .CodeViewer .AppendColoredOutput(x.Result)) .Do(DumpTasks.Add);
public static void DumpValue( AphidInterpreter interpreter, object value, bool ignoreNull = true, bool ignoreClrObj = true) => WriteLineHighlighted( SerializingFormatter.Format( interpreter, value, ignoreNull, ignoreClrObj));
public static AphidObject EvalExpression(AphidInterpreter interpreter, string code) { AphidObject result = null; void action() { if (code.Trim()?.Length == 0) { return; } var lexer = new AphidLexer(code); var tokens = lexer.GetTokens(); var exp = AphidParser.ParseExpression(tokens, code); var retExp = new UnaryOperatorExpression(AphidTokenType.retKeyword, exp); //new AphidCodeVisitor(code).VisitExpression(retExp); interpreter.Interpret(retExp); result = interpreter.GetReturnValue(true); if (result != null && (result.Value != null || result.Any())) { WriteLineHighlighted( SerializingFormatter.Format( interpreter, result, ignoreNull: false, ignoreClrObj: false)); } } if (AphidErrorHandling.HandleErrors) { TryAction(interpreter, code, action); } else { action(); } return(result); }
public static void DumpStackTrace(AphidInterpreter interpreter, AphidFrame[] trace) { var cfg = AphidConfig.Current; var frameNum = 0; if (!Console.IsOutputRedirected) { WriteSubheader(StackTraceHead, "~|Blue~~White~"); } else { WriteErrorMessage(StackTraceHead); } foreach (var frame in trace) { var frameStr = FrameFormatter.FormatFrame(frameNum++, in frame); WriteLineOut(frameStr); if (cfg.StackTraceParams) { var args = frame.Arguments .Select((x, y) => string.Format( "{0} $args[{1}] = {2}", GetAphidObjectTypeName(x), y, SerializingFormatter.Format( interpreter, x, ignoreNull: false, ignoreClrObj: false))); if (cfg.StackTraceParamsMax >= 0) { var h = cfg.StackTraceParamsMax / 2f; int first = (int)Math.Ceiling(h), last = (int)Math.Floor(h); var count = frame.Arguments.Count(); var skip = Math.Max(0, count - first - last); if (skip != 0) { args = args .Where((_, i) => i < first || i >= skip + first) .Append(string.Format("/* Skipped {0:n0} args /*", skip)) .Skip(skip); } } var argStr = args.JoinLines(); if (argStr.Length > 0) { WriteLineOut(Format(argStr.Indent(" "))); } //var locals = frame.Scope // .Select(x => string.Format( // "{0} {1} = {2}", // x.Key, // GetAphidObjectTypeName(x.Value), // DumpValue(interpreter, serializer, x.Value))) // .JoinLines(); //if (locals.Length > 0) //{ // WriteLineOut(Highlight(StyleEscape(locals.Indent(" ")))); //} } } WriteLineOut(""); if (cfg.ShowErrorExpression || cfg.ShowErrorStatement) { ShowErrorNodes(interpreter, cfg, trace); } if (cfg.ShowErrorFrameExcerpts) { var dumpCount = 0; foreach (var t in trace) { if (DumpFirstExcerpt( t.Expression, string.Format( "Frame {0:x4} Excerpt", Array.IndexOf(trace, t))) && ++dumpCount == cfg.FrameExcerptsMax) { break; } } } //if(dumpCount == 0) //{ // foreach(var pair in ctxPairs) // { // DumpFirstExcerpt( // pair.Item2, // string.Format("Current {0} Excerpt", pair.Item1)); // } //} var headerPrinted = false; var statement = interpreter.CurrentStatement; var exp = interpreter.CurrentExpression; var file = interpreter.GetScriptFilename(); var stmtFile = statement?.Filename; var expFile = exp?.Filename; if (cfg.ShowErrorFileList) { foreach (var s in new (string, string, Func <List <AphidExpression> >)[]