private bool GetRuleConditions(Rule rule, ref string temp) { if (!temp.StartsWith("AK", StringComparison.OrdinalIgnoreCase)) { Output.AppendText($"ERROR: Chyba podmienka pre pravidlo '{rule.Name}'.{Environment.NewLine}"); return(false); } temp = temp.Substring(2).TrimStart(); if (temp[0] != '(') { Output.AppendText( $"ERROR: Za slovom AK sa nenachadza '(' v pravidle '{rule.Name}'.{Environment.NewLine}"); return(false); } var level = 1; var index = 1; for (var start = 0; level > 0; index++) { if (temp[index] == '(') { ++level; if (level > 2) { /*Output.AppendText( * $"ERROR: V podmienke pre pravidlo '{rule.Name}' je trojite vnorenie zatvoriek.{Environment.NewLine}"); * return false;*/ } else { start = index + 1; } continue; } if (temp[index] == ')') { --level; if (level == 1) { rule.AddCondition(temp.Substring(start, index - start)); } continue; } if (level == 1) { if (!char.IsWhiteSpace(temp[index])) { Output.AppendText( $"ERROR: Chyba v pravidle '{rule.Name}'. Medzi podmienkami nemoze byt text.{Environment.NewLine}"); return(false); } } } if (temp.Length <= index) { Output.AppendText($"ERROR: V pravidle '{rule.Name}' sa nenachadza akcia.{Environment.NewLine}"); return(false); } temp = temp.Substring(index).TrimStart(); return(true); }
private bool GetRuleActions(Rule rule, ref string temp) { if (!temp.StartsWith("POTOM", StringComparison.OrdinalIgnoreCase)) { Output.AppendText($"ERROR: Chyba Akcia pre pravidlo '{rule.Name}'.{Environment.NewLine}"); return(false); } temp = temp.Substring(5).TrimStart(); if (temp[0] != '(') { Output.AppendText( $"ERROR: Za slovom POTOM sa nenachadza '(' v pravidle '{rule.Name}'.{Environment.NewLine}"); return(false); } var level = 1; var index = 1; for (var start = 0; level > 0; index++) { if (temp[index] == '(') { ++level; if (level > 2) { /*Output.AppendText( * $"ERROR: V akcii pre pravidlo '{rule.Name}' je trojite vnorenie zatvoriek.{Environment.NewLine}"); * return false;*/ } else { start = index + 1; } continue; } if (temp[index] == ')') { --level; if (level == 1) { var actionText = temp.Substring(start, index - start); var action = GetAction(actionText); if (action == null) { Output.AppendText( $"ERROR: Neznama akcia:{Environment.NewLine}{actionText}{Environment.NewLine}"); return(false); } rule.Actions.Add(action); } continue; } if (level == 1) { if (!char.IsWhiteSpace(temp[index])) { Output.AppendText( $"ERROR: Chyba v pravidle '{rule.Name}'. Medzi akciami nemoze byt text.{Environment.NewLine}"); return(false); } } } temp = temp.Length <= index ? "" : temp.Substring(index).TrimStart(); return(true); }