private void run(string query) { richTextBox.Document.Blocks.Clear(); RegAnalisator ra = new RegAnalisator(); List <string> listVars = new List <string>(); List <string> listTypes = new List <string>(); InfoAboutError inf = ra.checkQuery(query, listVars, listTypes); richTextBox.AppendText("Ошибка: " + ((inf.error) ? "Да" : "Нет")); if (inf.error) { richTextBox.AppendText(Environment.NewLine + "Строка: " + inf.positionLineError); richTextBox.AppendText(Environment.NewLine + "Позиция: " + inf.positionError); if (inf.message == "") { richTextBox.AppendText(Environment.NewLine + "Неверный символ: " + inf.errorChar); } else if (inf.typeMessage == "Отсутствует символ") { richTextBox.AppendText(Environment.NewLine + "Отсутствует символ: " + inf.message); } else if (inf.typeMessage == "Дубликат переменной") { richTextBox.AppendText(Environment.NewLine + "Дубликат переменной: " + inf.message); } else if (inf.typeMessage == "Неверное имя переменной") { richTextBox.AppendText(Environment.NewLine + "Неверное имя переменной: " + inf.message); } } }
public InfoAboutError checkQuery(string query, List <string> listVars, List <string> listTypes) { RegAnalisator ra = new RegAnalisator(); InfoAboutError inf = new InfoAboutError(); deleteSymbols(ref query); string queryForFindPosition = query; ra.formatString(ref query); string[] masStr = query.Split(';'); int countString = masStr.Length; if (masStr[masStr.Length - 1] == "") { countString--; } for (int i = 0; i < countString; i++) { string q = masStr[i]; if (i == countString - 1) { if (query.ToCharArray()[query.Length - 1] == ';') { q += ";"; } } else { q += ";"; } inf = ra.checkString(q, listVars, listTypes); if (inf.error) { inf.indexLineError = i; inf.trueQuery += inf.str; InfoAboutError inf3 = inf.Clone(); InfoAboutError inf4 = inf.Clone(); findRealPositionError(ref inf, queryForFindPosition); findDuplicateVariable(ref inf3, listVars); if (inf3.error) { inf3.indexLineError = i; findRealPositionError(ref inf3, queryForFindPosition); if ((inf3.positionLineError < inf.positionLineError) || (inf3.error && !inf.error)) { inf = inf3; } else if ((inf3.positionError < inf.positionError) || (inf3.error && !inf.error)) { inf = inf3; } for (int k = listVars.Count - 1; k >= 0; k--) { if (listVars[k] == inf.message) { listVars.RemoveAt(k); break; } } findDuplicateVariable(ref inf, listVars); if (inf.error) { inf.indexLineError = i; findRealPositionError(ref inf, queryForFindPosition); } } // inf3 = inf.Clone(); findBadVariable(ref inf4, listVars); if (inf4.error) { inf4.indexLineError = i; findRealPositionError(ref inf4, queryForFindPosition); } InfoAboutError[] masError2 = new InfoAboutError[3]; masError2[0] = inf; masError2[1] = inf3; masError2[2] = inf4; inf = getFirstPositionError(masError2); break; } inf.trueQuery += q; InfoAboutError[] masError = new InfoAboutError[3]; masError[2] = inf.Clone(); masError[1] = inf.Clone(); masError[0] = inf.Clone(); findRealPositionError(ref masError[2], queryForFindPosition); findDuplicateVariable(ref masError[0], listVars); if (masError[0].error) { masError[0].indexLineError = i; findRealPositionError(ref masError[0], queryForFindPosition); for (int k = listVars.Count - 1; k >= 0; k--) { if (listVars[k] == masError[0].message) { listVars.RemoveAt(k); break; } } findDuplicateVariable(ref masError[0], listVars); if (masError[0].error) { masError[0].indexLineError = i; findRealPositionError(ref masError[0], queryForFindPosition); } } findBadVariable(ref masError[1], listVars); if (masError[1].error) { masError[1].indexLineError = i; findRealPositionError(ref masError[1], queryForFindPosition); } bool hasError = false; foreach (InfoAboutError iar in masError) { if (iar.error) { hasError = true; break; } } if (hasError) { inf = getFirstPositionError(masError); break; } } char[] masCharForQuery = queryForFindPosition.ToCharArray(); for (int i = masCharForQuery.Length - 1; i >= 0; i--) { if (masCharForQuery[i] != ' ' && masCharForQuery[i] != '\t') { if (masCharForQuery[i] != ';') { inf.typeMessage = "Отсутствует символ"; inf.message = ";"; } break; } } return(inf); }