// Is run every thime the content of the multiline is evaluated
        public void Evaluate()
        {
            if (!string.IsNullOrEmpty(input.Buffer.Text))
            {
                if (input.Buffer.Text.Length == 0)
                {
                    output.Text = "No Input!";
                    return;
                }

                eval.Parse(input.Buffer.Text);

                var res = eval.Evaluate();

                // Resets the graph, should it be used, in case it is no longer used
                drawView.xList.Clear();
                drawView.xList.Clear();
                drawView.Hide();

                string outputstring = String.Empty;

                output.Text = string.Empty; // Clears output before adding new text

                if (!(res is Null || res is Error))
                {
                    outputstring = res.ToString() + "\n";
                }

                foreach (var data in eval.SideEffects)
                {
                    if (data is PrintData)
                    {
                        outputstring += data.ToString() + "\n";
                    }
                    else if (data is ErrorData)
                    {
                        outputstring += data.ToString() + "\n";
                    }
                    else if (data is DebugData && eval.GetBool("debug"))
                    {
                        outputstring += data.ToString() + "\n";
                    }
                    else if (data is PlotData)
                    {
                        drawView.Plot(data as PlotData);
                    }
                }

                output.Text = outputstring;
            }
        }
Exemple #2
0
    public void EvaluateInput()
    {
        Expression res;
        TextIter   insertIter = Buffer.StartIter;

        if (InputView.Buffer.Text.Length == 0)
        {
            Buffer.InsertWithTagsByName(ref insertIter, "No input\n", "error");
            return;
        }

        Eval.Parse(InputView.Buffer.Text);

        res = Eval.Evaluate();

        if (res is Error)
        {
            Eval.SideEffects.Add(new ErrorData(res as Error));
        }
        else if (!(res is Null))
        {
            Buffer.Insert(ref insertIter, "ret: " + res.ToString() + "\n");
        }

        foreach (var data in Eval.SideEffects)
        {
            if (data is PrintData)
            {
                Buffer.Insert(ref insertIter, data.ToString() + "\n");
            }
            else if (data is ErrorData)
            {
                Buffer.InsertWithTagsByName(ref insertIter, data.ToString() + "\n", "error");
            }
            else if (data is DebugData && Eval.GetBool("debug"))
            {
                Buffer.InsertWithTagsByName(ref insertIter, data.ToString() + "\n", "debug");
            }
            else if (data is PlotData)
            {
                DrawView.Plot(data as PlotData);
                DrawView.Show();
            }
            else if (data is WidgetData)
            {
                WidgetView.AddWidget(data as WidgetData);
                WidgetView.Show();
            }
        }
    }