public ConstraintDescription Parse(string constraint) { state = ConstraintParserState.firstChar; word.Clear(); prototype = new ConstraintDescription(); prototype.Terms = new List <ConstraintSegment>(); errorMessage = null; hasLeadNumber = false; eqRelationDefined = false; int charNumber = 0; foreach (var ch in constraint.Append('\0')) { if (char.IsWhiteSpace(ch)) { charNumber++; continue; } state = stateTable[state](state, ch); if (state == ConstraintParserState.syntaxError) { throw new SyntaxErrorException($"{errorMessage} at char {charNumber}"); } charNumber++; } if (!prototype.Terms.Any(x => x.OwnerId != null)) { throw new SemanticErrorException($"parsed expression does not contains anchors"); } if (state != ConstraintParserState.done) { throw new InternalErrorException($"parser ended work in invalid state: {state}"); } return(prototype); }
public ConstraintPrototype(XmlElement node) : base(node) { Strength = node.HasAttribute("strength") ? GetStrength(node.GetAttribute("strength")) : ClStrength.Default; Constraint = new ConstraintParser().Parse(node.InnerText.Trim(" \n\r\t".ToCharArray())); }