Ejemplo n.º 1
0
        private void executeButton_Click(object sender, EventArgs e)
        {
            Interpreter interpreter = new Interpreter();

            interpreter.DoScript(scriptRichTextBox.Text);
            string permuts = "Следующие замены будут добавлены: " + Environment.NewLine;

            permuts = Interpreter.Output.Aggregate(permuts, (temp, x) => temp + $"{x.Key} ->{(x.Final ? "." : string.Empty)} {x.Value}" + Environment.NewLine);
            MessageBox.Show(permuts);
            StartForm.AddPermutsFromScript(Interpreter.Output);
            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 2
0
        public static string DoWork(StartForm form, List <Triple <string, string, bool> > permuts)
        {
            int step = 1;

            Stop = false;
            string text  = form.inputTextBox.Text;
            int    i     = 0;
            int    pos   = -1;
            bool   found = false;

            while (!Stop)
            {
                var x = permuts[i];
                do
                {
                    if (Stop)
                    {
                        break;
                    }
                    pos = StringFind(text, x.Key);
                    if (pos != -1)
                    {
                        string before = text;
                        if (x.Value == string.Empty)
                        {
                            text = text.Remove(pos, x.Key.Length);
                        }
                        else if (x.Key == string.Empty)
                        {
                            text = text.Insert(pos, x.Value);
                        }
                        else
                        {
                            text = text.Remove(pos, x.Key.Length).Insert(pos, x.Value);
                        }
                        form.Invoke(new InvokeWork(() =>
                        {
                            form.stepsDataGridView.Rows.Add(new object[] { step, before, text });
                        }));
                        step++;
                        if (x.Final)
                        {
                            Stop = true;
                        }
                        found = true;
                        if (x.Key == string.Empty)
                        {
                            break;
                        }
                    }
                }while (pos != -1);
                if (!found)
                {
                    i = (i + 1) % permuts.Count;
                }
                else
                {
                    i = 0;
                }
                if ((i == 0) && (!found))
                {
                    Stop = true;
                }
                else
                {
                    found = false;
                }
            }
            return(text);
        }
Ejemplo n.º 3
0
 public StartForm()
 {
     InitializeComponent();
     LastInstance = this;
 }