예제 #1
0
        private bool CompileScript()
        {
            string[] lines = richTextBox1.Lines;
            Body   = new MSC.Script.Body();
            Logger = new MSC.Logger();
            Logger.OnMessageReceived += Logger_OnMessageReceived;
            richTextBox1.Clear();
            richTextBox2.Clear();
            treeView1.Nodes.Clear();
            try
            {
                Body.Initialize(lines);
                foreach (MSC.Script.Method method in Body.Methods)
                {
                    List <TreeNode> nodes = new List <TreeNode>();
                    foreach (MSC.Script.Instruction inst in method.Instructions)
                    {
                        TreeNode node = new TreeNode(inst.ToString());
                        nodes.Add(node);
                    }
                    TreeNode trnode = new TreeNode(method.IndexPous + "- " + method.Type + "(" + method.Instructions.Count + ")", nodes.ToArray());
                    treeView1.Nodes.Add(trnode);
                }
                richTextBox1.Lines = lines;
                return(true);
            }catch (Exception ex)
            {
                Logger.AddMessage(ex.Message, Log.Type.Error);
                if (ex.Message.Contains("Error >"))
                {
                    int errorline = int.Parse(ex.Message.Split(':')[1]);
                    int i         = 1;
                    foreach (string item in lines)
                    {
                        if (i == errorline)
                        {
                            richTextBox1.SelectionStart  = richTextBox1.TextLength;
                            richTextBox1.SelectionLength = 0;
                            Color temp = richTextBox1.SelectionBackColor;

                            richTextBox1.SelectionBackColor = Color.Red;
                            if (i != lines.Length)
                            {
                                richTextBox1.AppendText(item + "\n");
                            }
                            else
                            {
                                richTextBox1.AppendText(item);
                            }
                            richTextBox1.SelectionBackColor = temp;
                        }
                        else
                        {
                            if (i != lines.Length)
                            {
                                richTextBox1.AppendText(item + "\n");
                            }
                            else
                            {
                                richTextBox1.AppendText(item);
                            }
                        }
                        i++;
                    }
                }
                return(false);
            }
        }