private void RunImpl() { Console.Title = Title; Console.CancelKeyPress += OnCancelKeyPress; Console.WriteLine(Greeting); string input; while (true) { Console.ForegroundColor = ConsoleColor.White; string prompt = (Interpreter.Status == InterpreterStatus.WaitingMoreInput ? PromptMoreInput : Prompt); Console.Write(prompt); var result = ReadInput(out input); //Check the result type - it may be the response to "Abort?" question, not a script to execute. switch (result) { case ReadResult.AbortYes: return; //exit case ReadResult.AbortNo: continue; //while loop case ReadResult.Script: break; //do nothing, continue to evaluate script } Interpreter.ClearOutputBuffer(); Interpreter.EvaluateAsync(input); while (Interpreter.IsBusy()) { Thread.Sleep(50); } switch (Interpreter.Status) { case InterpreterStatus.Ready: //success Console.WriteLine(Interpreter.GetOutput()); break; case InterpreterStatus.SyntaxError: Console.WriteLine(Interpreter.GetOutput()); //write all output we have Console.ForegroundColor = ConsoleColor.Red; foreach (var err in Interpreter.ParsedScript.ParserMessages) { Console.WriteLine(string.Empty.PadRight(prompt.Length + err.Location.Column) + "^"); //show err location Console.WriteLine(err.Message); //print message } break; case InterpreterStatus.RuntimeError: ReportException(); break; default: break; } //switch } } //Run method
//This method allows custom implementation of running a sample in Grammar Explorer // By default it evaluates a parse tree using default interpreter public virtual string RunSample(ParseTree parsedSample) { var interpreter = new ScriptInterpreter(this); interpreter.Evaluate(parsedSample); return interpreter.GetOutput(); }