Esempio n. 1
0
        internal bool RunCode(string code, bool fastFail = false, bool onlyErrors = false)
        {
            if (link == null)
            {
                var bo = new BuildOptionsManager(App);
                link = new ElaIncrementalLinker(bo.CreateLinkerOptions(),
                                                bo.CreateCompilerOptions());
            }

            link.SetSource(code.Trim('\0'));
            var lr = link.Build();

            if (!lr.Success && fastFail)
            {
                return(false);
            }

            foreach (var m in lr.Messages)
            {
                if (m.Type == Ela.MessageType.Error || !onlyErrors)
                {
                    var tag = m.Type == Ela.MessageType.Error ? "``!!!" :
                              m.Type == Ela.MessageType.Warning ? "``|||" :
                              "``???";
                    Con.PrintLine(String.Format("{0}{1} ({2},{3}): {4} ELA{5}: {6}", tag, m.File.Name, m.Line, m.Column, m.Type, m.Code, m.Message));
                }
            }

            if (lr.Success)
            {
                var th = new Thread(() => ExecuteInput(lr.Assembly));
                Con.SetExecControl(th);
                App.GetService <IStatusBarService>().SetStatusString(StatusType.Information, "Executing code in Interactive...");
                th.Start();
                return(true);
            }
            else
            {
                Con.PrintLine();
                Con.Print(Con.Prompt + ">");
                Con.ScrollToCaret();
                return(false);
            }
        }
Esempio n. 2
0
        private static int InterpretString(string source)
        {
            if (linker == null)
            {
                linker = new ElaIncrementalLinker(CreateLinkerOptions(), CreateCompilerOptions());

                if (opt.Arguments.Count > 0)
                {
                    CompileArguments(linker);
                }
            }

            linker.SetSource(source);
            var res = linker.Build();

            helper.PrintErrors(res.Messages);

            if (!res.Success)
            {
                if (res.Assembly != null)
                {
                    var r = res.Assembly.GetRootModule();

                    if (r != null)
                    {
                        lastOffset = r.Ops.Count;
                    }
                }

                return(R_ERR);
            }
            else
            {
                return(Execute(res.Assembly, true));
            }
        }
Esempio n. 3
0
        private void WalkLines(IEnumerable <DocLine> lines, StringBuilder toc, StringBuilder sb)
        {
            int tocId = 0;

            WalkLines(lines,
                      (str, type) =>
            {
                if (type == LineType.CodeItem)
                {
                    GenerateCodeItem(str, sb);
                }
                else if (type == LineType.Table)
                {
                    str      = HttpUtility.HtmlEncode(str);
                    var rows = str.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

                    sb.Append("<table class='textTable'>");

                    foreach (var r in rows)
                    {
                        var cells  = new List <String>();
                        var buffer = r.ToCharArray();
                        var pos    = 0;
                        var l      = '\0';

                        for (var i = 0; i < buffer.Length; i++)
                        {
                            var c    = buffer[i];
                            var last = i == buffer.Length - 1;

                            if ((l == ' ' && c == '|') || last)
                            {
                                cells.Add(new String(buffer, pos, i - pos + (last ? 1 : 0)));
                                pos = i + 1;
                            }

                            l = c;
                        }

                        sb.Append("<tr>");

                        foreach (var c in cells)
                        {
                            sb.AppendFormat("<td class='textTd'>{0}</td>",
                                            MarkupParser.Parse(c));
                        }

                        sb.Append("</tr>");
                    }

                    sb.Append("</table>");
                }
                else if (type == LineType.ElaCode || type == LineType.EvalCode)
                {
                    if (type == LineType.EvalCode)
                    {
                        lnk.SetSource(str);
                        var res = lnk.Build();

                        if (res.Success)
                        {
                            if (vm == null)
                            {
                                vm = new ElaMachine(res.Assembly);
                            }
                            else
                            {
                                vm.RefreshState();
                            }

                            try
                            {
                                var rv = vm.Resume();

                                if (!rv.ReturnValue.Is <ElaUnit>())
                                {
                                    var val = vm.PrintValue(rv.ReturnValue);

                                    if (val.Contains('\r') || val.Length > 30)
                                    {
                                        str += "\r\n/*\r\nThe result is:\r\n" + val + "\r\n*/";
                                    }
                                    else
                                    {
                                        str += " //The result is: " + val;
                                    }
                                }
                            }
                            catch (ElaCodeException ex)
                            {
                                Error(ex.Message);
                            }
                        }
                        else
                        {
                            res.Messages.ToList().ForEach(m => Console.Write("\r\n" + m.ToString()));
                        }
                    }

                    sb.AppendFormat(ELACODE, Lex(str));
                }
                else if (type == LineType.Code)
                {
                    str = HttpUtility.HtmlEncode(str);
                    sb.AppendFormat(CODE, str);
                }
                else if (type == LineType.Header1)
                {
                    str    = HttpUtility.HtmlEncode(str);
                    var id = (tocId++).ToString();
                    sb.AppendFormat("<a name=\"{0}\"></a>", id);
                    sb.AppendFormat(H1, str);
                    toc.Append("<b>");
                    toc.AppendFormat(A, id, str);
                    toc.Append("</b><br/>");
                }
                else if (type == LineType.Header2)
                {
                    str    = HttpUtility.HtmlEncode(str);
                    var id = (tocId++).ToString();
                    sb.AppendFormat("<a name=\"{0}\"></a>", id);
                    sb.AppendFormat(H2, str);
                    toc.Append("&nbsp;&nbsp;&nbsp;&nbsp;");
                    toc.AppendFormat(A, id, str);
                    toc.Append("<br/>");
                }
                else if (type == LineType.Header3)
                {
                    str = HttpUtility.HtmlEncode(str);
                    sb.AppendFormat(H3, str);
                }
                else if (type == LineType.List)
                {
                    str = HttpUtility.HtmlEncode(str);
                    sb.Append("<ul>");
                    var split = str.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    split.ToList().ForEach(s => sb.AppendFormat(LI, MarkupParser.Parse(s)));
                    sb.Append("</ul>");
                }
                else
                {
                    str = HttpUtility.HtmlEncode(str);
                    sb.AppendFormat(TEXT, MarkupParser.Parse(str));
                }
            });
        }