// if includeevent is set, it must be there.. // demlimchars is normally space, but can be ") " if its inside a multi. public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ") { Fields = new List <ConditionEntry>(); InnerCondition = OuterCondition = LogicalCondition.Or; EventName = ""; Action = ""; ActionVars = new Variables(); if (includeevent) { string actionvarsstr; if ((EventName = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (Action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (actionvarsstr = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',')) { return("Incorrect format of EVENT data associated with condition"); } if (actionvarsstr.HasChars()) { ActionVars = new Variables(actionvarsstr, Variables.FromMode.MultiEntryComma); } } LogicalCondition?ic = null; while (true) { string var = sp.NextQuotedWord(delimchars); // always has para cond if (var == null) { return("Missing parameter (left side) of condition"); } string cond = sp.NextQuotedWord(delimchars); if (cond == null) { return("Missing condition operator"); } ConditionEntry.MatchType mt; if (!ConditionEntry.MatchTypeFromString(cond, out mt)) { return("Condition operator " + cond + " is not recognised"); } string value = ""; if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..) { if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase)) { return("Condition must preceed fixed result operator"); } var = "Condition"; // fix case.. } else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side { value = sp.NextQuotedWord(delimchars); if (value == null) { return("Missing value part (right side) of condition"); } } ConditionEntry ce = new ConditionEntry() { ItemName = var, MatchCondition = mt, MatchString = value }; Fields.Add(ce); if (sp.IsEOL || sp.PeekChar() == ')') // end is either ) or EOL { InnerCondition = (ic == null) ? LogicalCondition.Or : ic.Value; return(""); } else { LogicalCondition nic; string err = GetLogicalCondition(sp, delimchars, out nic); if (err.Length > 0) { return(err + " for inner condition"); } if (ic == null) { ic = nic; } else if (ic.Value != nic) { return("Cannot specify different inner conditions between expressions"); } } } }
private Dictionary <string, string> ReadFromString(BaseUtils.StringParser p, FromMode fm, Dictionary <string, string> altops = null) { Dictionary <string, string> newvars = new Dictionary <string, string>(); while (!p.IsEOL) { string varname = p.NextQuotedWord("= "); if (varname == null) { return(null); } if (altops != null) // with extended ops, the ops are returned in the altops function, one per variable found { // used only with let and set.. if (varname.EndsWith("$+")) { varname = varname.Substring(0, varname.Length - 2); altops[varname] = "$+="; } else if (varname.EndsWith("$")) { varname = varname.Substring(0, varname.Length - 1); altops[varname] = "$="; } else if (varname.EndsWith("+")) { varname = varname.Substring(0, varname.Length - 1); altops[varname] = "+="; } else { altops[varname] = "="; // varname is good, it ended with a = or space, default is = bool dollar = p.IsCharMoveOn('$'); // check for varname space $+ bool add = p.IsCharMoveOn('+'); if (dollar && add) { altops[varname] = "$+="; } else if (dollar) { altops[varname] = "$="; } else if (add) { altops[varname] = "+="; } } } if (!p.IsCharMoveOn('=')) { return(null); } string value = (fm == FromMode.OnePerLine) ? p.NextQuotedWordOrLine() : p.NextQuotedWord((fm == FromMode.MultiEntryComma) ? ", " : ",) "); if (value == null) { return(null); } newvars[varname] = value; if (fm == FromMode.MultiEntryCommaBracketEnds && p.PeekChar() == ')') // bracket, stop don't remove.. outer bit wants to check its there.. { return(newvars); } else if (fm == FromMode.OnePerLine && !p.IsEOL) // single entry, must be eol now { return(null); } else if (!p.IsEOL && !p.IsCharMoveOn(',')) // if not EOL, but not comma, incorrectly formed list { return(null); } } return(newvars); }
public string Read(BaseUtils.StringParser sp, bool includeevent = false, string delimchars = " ") // if includeevent is set, it must be there.. { // demlimchars is normally space, but can be ") " if its inside a multi. fields = new List <ConditionEntry>(); innercondition = outercondition = ConditionEntry.LogicalCondition.Or; eventname = ""; action = ""; actiondata = ""; if (includeevent) { if ((eventname = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (action = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',') || (actiondata = sp.NextQuotedWord(", ")) == null || !sp.IsCharMoveOn(',')) { return("Incorrect format of EVENT data associated with condition"); } } ConditionEntry.LogicalCondition?ic = null; while (true) { string var = sp.NextQuotedWord(delimchars); // always has para cond if (var == null) { return("Missing parameter (left side) of condition"); } string cond = sp.NextQuotedWord(delimchars); if (cond == null) { return("Missing condition operator"); } ConditionEntry.MatchType mt; if (!ConditionEntry.MatchTypeFromString(cond, out mt)) { return("Condition operator " + cond + " is not recognised"); } string value = ""; if (ConditionEntry.IsNullOperation(mt)) // null operators (Always..) { if (!var.Equals("Condition", StringComparison.InvariantCultureIgnoreCase)) { return("Condition must preceed fixed result operator"); } var = "Condition"; // fix case.. } else if (!ConditionEntry.IsUnaryOperation(mt)) // not unary, require right side { value = sp.NextQuotedWord(delimchars); if (value == null) { return("Missing value part (right side) of condition"); } } ConditionEntry ce = new ConditionEntry() { itemname = var, matchtype = mt, matchstring = value }; fields.Add(ce); if (sp.IsEOL || sp.PeekChar() == ')') // end is either ) or EOL { innercondition = (ic == null) ? ConditionEntry.LogicalCondition.Or : ic.Value; return(""); } else { ConditionEntry.LogicalCondition nic; string err = ConditionEntry.GetLogicalCondition(sp, delimchars, out nic); if (err.Length > 0) { return(err + " for inner condition"); } if (ic == null) { ic = nic; } else if (ic.Value != nic) { return("Cannot specify different inner conditions between expressions"); } } } }