private void _AddCurveBrackets(ref int i, ref int start)
        {
            string offset = Line.GetOffset(lines[i]);

            string[] parts = new string[3];
            parts[0] = lines[i];
            parts[1] = offset + "{";
            i++;
            start    = i;
            parts[2] = offset + "\t" + Line.TrimmedLine(lines[i]);
            Split.Remove(ref lines, i);

            Split.InsertInsteadOf(i - 1, ref lines, parts);

            i++;
            int IF_Without_ELSE = 0;

            Word[] words = Split.SeparateLine(Line.TrimmedLine(lines[i]));
            while (Word.IsBlock(words))
            {
                if (Word.FirstNotEmptyWord(words).Text == Data.IF.Text)
                {
                    IF_Without_ELSE++;
                }
                if (IsSingleLineBlock(i))
                {
                    i++;
                }
                else
                {
                    i = Brackets.GetCloseCurveBracketIndex(lines, i + 1);
                }
                words = Split.SeparateLine(Line.TrimmedLine(lines[i]));
            }
            bool wasSingleLine_ELSE = false;

            for (; IF_Without_ELSE > 0; IF_Without_ELSE--)
            {
                if (Line.TrimmedLine(lines[i + 1]) == Data.ELSE.Text)
                {
                    if (IsSingleLineBlock(i))
                    {
                        i++;
                        wasSingleLine_ELSE = true;
                    }
                    else
                    {
                        i = Brackets.GetCloseCurveBracketIndex(lines, i + 1);
                        wasSingleLine_ELSE = false;
                    }
                }
            }
            if (wasSingleLine_ELSE)
            {
                i++;
            }
            parts[0] = lines[i];
            parts[1] = offset + "}";
            parts[2] = lines[i + 1];
            Split.Remove(ref lines, i + 1);
            Split.InsertInsteadOf(i, ref lines, parts);
            i = start;
        }
 private void CASE_ToSingleLine()
 {
     for (int i = 0; i < lines.Length; i++)
     {
         Word[] words = Split.SeparateLine(lines[i]);
         Word.TrimWords(ref words);
         if (words.Length == 0)
         {
             continue;
         }
         int  nested_SWITCH   = 0;
         bool wasNestedSwitch = false;
         if (Line.TrimmedLine(Word.FirstNotEmptyWord(words).Text) == Data.SWITCH.Text)
         {
             i++;
             int SWITCH_End = Brackets.GetCloseCurveBracketIndex(lines, i);
             for (int j = i + 1; j < SWITCH_End; j++)
             {
                 words = Split.SeparateLine(lines[j]);
                 string firstWord;
                 try
                 {
                     firstWord = Line.TrimmedLine(Word.FirstNotEmptyWord(words).Text);
                 }
                 catch (Exception)
                 {
                     continue;
                 }
                 if (firstWord == Data.CASE.Text)
                 {
                     if (Word.IndexOfFirst(words, Data.CASE) == words.Length - 1)
                     {
                         CombineLines(ref j);
                         break;
                     }
                     else
                     {
                         Split_CASE_Or_DEFAULT(words, j);
                     }
                 }
                 else if (firstWord == Data.DEFAULT.Text)
                 {
                     if (Word.IndexOfFirst(words, Data.DEFAULT) == words.Length - 1)
                     {
                         CombineLines(ref j);
                         break;
                     }
                     else
                     {
                         Split_CASE_Or_DEFAULT(words, j);
                     }
                 }
                 else if (firstWord == Data.DEFAULT_WithColon.Text)
                 {
                     if (Word.IndexOfFirst(words, Data.DEFAULT_WithColon) == words.Length - 1)
                     {
                         CombineLines(ref j);
                         break;
                     }
                     else
                     {
                         Split_CASE_Or_DEFAULT(words, j);
                     }
                 }
                 else if ((firstWord == Data.SWITCH.Text || firstWord.Contains(Data.SWITCH_WithBracket.Text)) && !wasNestedSwitch)
                 {
                     nested_SWITCH   = j;
                     wasNestedSwitch = true;
                 }
             }
             i = SWITCH_End;
             if (wasNestedSwitch)
             {
                 i = nested_SWITCH;
             }
         }
     }
 }
        private void CarryFromConditionToNewLine()
        {
            for (int i = 0; i < lines.Length; i++)
            {
                string offset = "";
                if (i != 0)
                {
                    offset = Line.GetOffset(lines[i - 1]);
                }

                Word[] words = Split.SeparateLine(Line.TrimmedLine(lines[i]));
                Word.TrimWords(ref words);
                if (words.Length == 0)
                {
                    continue;
                }
                if (Word.Contains(words, Data.DO))
                {
                    string[] parts       = new string[2];
                    int      DO_Position = Word.IndexOfFirst(words, Data.DO);
                    parts[0] = offset + Word.ToLine(words, 0, DO_Position);
                    parts[1] = Word.ToLine(words, DO_Position + 1);
                    if (Line.TrimmedLine(parts[1]) == "")
                    {
                        Array.Resize(ref parts, 1);
                    }
                    Split.InsertInsteadOf(i, ref lines, parts);
                }
                else if (Word.ContainsBlockOperator(words))
                {
                    if (words[0].Text == Data.WHILE.Text)
                    {
                        int closeRoundBracket = Brackets.GetCloseBracketPosition(words, '(');
                        if (closeRoundBracket != words.Length - 1 && words[closeRoundBracket + 1].Text == ";")
                        {
                            continue;
                        }
                    }
                    int      closeBracketPosition = Brackets.GetCloseBracketPosition(words, '(');
                    string[] parts = new string[2];
                    parts[0] = offset + Word.ToLine(words, 0, closeBracketPosition);
                    parts[1] = offset + "\t" + Word.ToLine(words, closeBracketPosition + 1);
                    if (Line.TrimmedLine(parts[1]) == "")
                    {
                        continue;
                    }
                    Split.InsertInsteadOf(i, ref lines, parts);
                }
                else if (words[0].Text == Data.ELSE.Text)
                {
                    string[] parts = new string[2];
                    parts[0] = offset + Data.ELSE.Text;
                    parts[1] = offset + "\t" + Word.ToLine(words, 1);
                    if (Line.TrimmedLine(parts[1]) == "")
                    {
                        continue;
                    }
                    Split.InsertInsteadOf(i, ref lines, parts);
                }
            }
        }
Esempio n. 4
0
 public Operand(Word name, Location location) : base(name, location)
 {
 }
Esempio n. 5
0
 public Operand(Word name, int lineIndex, int wordIndex) : base(name, new Location(lineIndex, wordIndex))
 {
 }
Esempio n. 6
0
 public CodeElement(Word name, int lineIndex, int wordIndex) : this(name, new Location(lineIndex, wordIndex))
 {
 }