/** * Builds LHS pathElement and validates to specification */ protected ModifierSpec(string rawJsonKey, OpMode opMode) { string prefix = rawJsonKey.Substring(0, 1); string suffix = rawJsonKey.Length > 1 ? rawJsonKey.Substring(rawJsonKey.Length - 1) : null; if (OpMode.IsValid(prefix)) { _opMode = OpMode.From(prefix); rawJsonKey = rawJsonKey.Substring(1); } else { _opMode = opMode; } if (suffix == "?" && !rawJsonKey.EndsWith("\\?")) { _checkValue = true; rawJsonKey = rawJsonKey.Substring(0, rawJsonKey.Length - 1); } else { _checkValue = false; } _pathElement = PathElementBuilder.BuildMatchablePathElement(rawJsonKey); if (!(_pathElement is IStarPathElement) && !(_pathElement is LiteralPathElement) && !(_pathElement is ArrayPathElement)) { throw new SpecException(opMode.GetName() + " cannot have " + _pathElement.GetType().Name + " RHS"); } }
/** * Create a path element and ensures it is a Matchable Path Element */ public static IMatchablePathElement BuildMatchablePathElement(string rawJsonKey) { IPathElement pe = PathElementBuilder.ParseSingleKeyLHS(rawJsonKey); if (!(pe is IMatchablePathElement mpe)) { throw new SpecException("Spec LHS key=" + rawJsonKey + " is not a valid LHS key."); } return((IMatchablePathElement)mpe); }
public PathEvaluatingTraversal(string dotNotation) { if ((dotNotation.Contains("*") && !dotNotation.Contains("\\*")) || (dotNotation.Contains("$") && !dotNotation.Contains("\\$"))) { throw new SpecException("DotNotation (write key) can not contain '*' or '$' : write key: " + dotNotation); } List <IPathElement> paths; Traversr trav; if (!String.IsNullOrWhiteSpace(dotNotation)) { // Compute the path elements. paths = PathElementBuilder.ParseDotNotationRHS(dotNotation); // Use the canonical versions of the path elements to create the Traversr var traversrPaths = new List <string>(paths.Count); foreach (IPathElement pe in paths) { traversrPaths.Add(pe.GetCanonicalForm()); } trav = CreateTraversr(traversrPaths); } else { paths = new List <IPathElement>(); trav = CreateTraversr(new List <string>(new[] { "" })); } var evalPaths = new List <IEvaluatablePathElement>(paths.Count); foreach (IPathElement pe in paths) { if (!(pe is IEvaluatablePathElement epe)) { throw new SpecException("RHS key=" + pe.RawKey + " is not a valid RHS key."); } evalPaths.Add(epe); } _elements = evalPaths.AsReadOnly(); _traversr = trav; }
public ShiftrSpec(string rawJsonKey) { _pathElement = PathElementBuilder.BuildMatchablePathElement(rawJsonKey); }