internal string GetPredicateFullPath(ExprItem exprItem) { ExprLeaf leaf = exprItem as ExprLeaf; if (leaf != null) { if (leaf.ReferenceType.IndexOf("path", StringComparison.InvariantCultureIgnoreCase) >= 0) { return(leaf.Item.ToString()); } } ExprUnaryOperator unarayOperand = exprItem as ExprUnaryOperator; if (unarayOperand != null) { ExprItem operand = unarayOperand.Operand; return(GetPredicateFullPath(operand)); } PathExpr pathExpr = exprItem as PathExpr; if (pathExpr != null) { return(pathExpr.Path); } return(null); }
protected void Validate(ExprLeaf exprLeaf) { this.ValidateBase((ExprItem)exprLeaf); Invariant(exprLeaf.Item != null, string.Format(CommonStrings.XMustNotBeNull, "ExprLeaf.Item")); Invariant(exprLeaf.ReferenceType != null, string.Format(CommonStrings.XMustNotBeNull, "ExprLeaf.ReferenceType")); }
private static ExprBinaryOperator ProcessMatchesExpr(Match match) { string matches = match.Groups["matchesExpr"].Value; if (string.IsNullOrEmpty(matches)) { throw new ApplicationException("matches must not be null or empty."); } string leftPath = match.Groups["predicate_path"].Value; ExprLeaf leftOperand = null; if (string.IsNullOrEmpty(leftPath)) { leftOperand = new ExprLeaf("/archetype_node_id", "String", "path"); } else { leftOperand = new ExprLeaf(leftPath, "String", "path"); } OperatorKind operatorKind = new OperatorKind(OperatorKind.op_matches); string pattern = match.Groups["regex_pattern"].Value; if (string.IsNullOrEmpty(pattern)) { throw new ApplicationException("pattern must not be null or empty."); } ExprLeaf rightOperand = new ExprLeaf(pattern, "String", "pattern"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, rightOperand.Type, operatorKind, false); return(binaryOperator); }
private static ExprBinaryOperator ProcessStandardPredicateExpr(Match match) { string standardExpr = match.Groups["predicate_expre"].Value; if (string.IsNullOrEmpty(standardExpr)) { throw new ApplicationException("standardExpr must not be null or empty."); } string path = match.Groups["predicate_path"].Value; if (string.IsNullOrEmpty(path)) { throw new ApplicationException("predicate_path must not be null or empty"); } ExprLeaf lefOperand = new ExprLeaf(path, "String", "Path"); string standardExprOperator = match.Groups["predicate_path_operator"].Value; OperatorKind operatorKind = new OperatorKind(OperatorKind.GetOperatorKind(standardExprOperator)); // default value object criteriaValue = null; string type = GetCriteriaType(match, out criteriaValue); ExprLeaf rightOperand = new ExprLeaf(criteriaValue, type, "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(lefOperand, rightOperand, type, operatorKind, false); return(binaryOperator); }
private static ExprBinaryOperator ProcessPredicateWithFullPath(Match match) { string fullPath = match.Groups["fullPath"].Value; if (string.IsNullOrEmpty(fullPath)) { throw new ApplicationException("fullPath must not be null or empty."); } PathExpr pathExpr = ToPathExpr(fullPath); string standardExprOperator = match.Groups["predicate_path_operator"].Value; OperatorKind operatorKind = new OperatorKind(OperatorKind.GetOperatorKind(standardExprOperator)); string predicateCriteria = match.Groups["predicate_criteria"].Value; if (string.IsNullOrEmpty(predicateCriteria)) { throw new ApplicationException("predicateCriteria must not be null or empty."); } object criteriaValue = null; string type = GetCriteriaType(match, out criteriaValue); ExprLeaf rightOperand = new ExprLeaf(criteriaValue, type, "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(pathExpr, rightOperand, type, operatorKind, false); return(binaryOperator); }
internal static ExprItem ExprItem(string typeName) { DesignByContract.Check.Require(!string.IsNullOrEmpty(typeName), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "typeName")); ExprItem exprItem = null; switch (typeName) { case "EXPR_LEAF": exprItem = new ExprLeaf(); break; case "EXPR_UNARY_OPERATOR": exprItem = new ExprUnaryOperator(); break; case "EXPR_BINARY_OPERATOR": exprItem = new ExprBinaryOperator(); break; default: throw new NotSupportedException("type not supported: " + typeName); } DesignByContract.Check.Ensure(exprItem != null, "exprItem must not be null."); return(exprItem); }
internal static string AssertionRegExPattern(Assertion assertion) { Check.Require(assertion != null, "assertion must not be null."); string assertionRegex = string.Empty; ExprBinaryOperator expression = assertion.Expression as ExprBinaryOperator; if (expression != null) { ExprLeaf rightExpression = expression.RightOperand as ExprLeaf; if (rightExpression != null) { CString stringConstraint = rightExpression.Item as CString; Check.Assert(stringConstraint != null); Check.Assert(!string.IsNullOrEmpty(stringConstraint.Pattern)); Check.Assert(!(stringConstraint.Pattern.StartsWith("/") && stringConstraint.Pattern.EndsWith("/")), "Regex is enclosed in forward slashes, as with the C_STRING produced by old version of the ADL Parser."); // Cleanse regex of fullstops which are not either preceded by a backslash (\.) or followed by a star (.*) assertionRegex = stringConstraint.Pattern .Replace(".*", " * ") .Replace(@"\.", @" \ ") .Replace(".", @"\.") .Replace(@" \ ", @"\.") .Replace(" * ", ".*"); } } return assertionRegex; }
internal string GetValueCriteriaByPath(ExprItem exprItem, string requiredPath) { ExprLeaf leaf = exprItem as ExprLeaf; ExprBinaryOperator binary = exprItem as ExprBinaryOperator; if (binary != null) { switch (binary.Operator.Value) { case OperatorKind.op_eq: case OperatorKind.op_ne: { string path = GetPredicateFullPath(binary.LeftOperand); if (path != null && path.EndsWith(requiredPath, StringComparison.InvariantCultureIgnoreCase)) { ExprLeaf rightOperand = binary.RightOperand as ExprLeaf; if (rightOperand == null) { throw new ApplicationException("rightOperand must be typeof ExprLeaf when the leftOperand is name/value path."); } if (!rightOperand.ReferenceType.Equals("constraint")) { throw new NotSupportedException(rightOperand.ReferenceType + "rightOperand.ReferenceType is not supported."); } return(rightOperand.Item.ToString()); } return(null); } case OperatorKind.op_or: case OperatorKind.op_and: case OperatorKind.op_not: ExprItem left = binary.LeftOperand; ExprItem right = binary.RightOperand; string nameValue = GetValueCriteriaByPath(right, requiredPath); if (nameValue != null) { return(nameValue); } nameValue = GetValueCriteriaByPath(left, requiredPath); return(nameValue); default: return(null); } } return(null); }
private static ExprBinaryOperator ProcessArchetypeNodeIdExpr(Match match) { string archetypeNodeId = match.Groups["archetype_node_id"].Value; if (string.IsNullOrEmpty(archetypeNodeId)) { throw new ApplicationException("archetypeNodeId must not be null or empty."); } ExprLeaf leftOperand = new ExprLeaf("/archetype_node_id", "String", "path"); ExprLeaf rightOperand = new ExprLeaf(archetypeNodeId, "String", "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, "String", new OperatorKind(OperatorKind.op_eq), false); return(binaryOperator); }
private static ExprBinaryOperator ProcessShortCutName(Match match) { string shortCutNameExpr = match.Groups["shortCutName"].Value; if (string.IsNullOrEmpty(shortCutNameExpr)) { throw new ApplicationException("shortCutNameExpr must not be null or empty."); } string nameValue = match.Groups["stringCriteria"].Value; ExprLeaf leftOperand = new ExprLeaf("/name/value", "String", "path"); ExprLeaf rightOperand = new ExprLeaf(nameValue, "String", "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(leftOperand, rightOperand, "String", new OperatorKind(OperatorKind.op_eq), false); return(binaryOperator); }
private static ExprBinaryOperator ProcessPositionExpr(Match match) { string positionString = match.Groups["position"].Value; if (string.IsNullOrEmpty(positionString)) { throw new ApplicationException("positionString must not be null or empty."); } int position = int.Parse(positionString); if (position <= 0) { throw new ApplicationException("Position specified within openehr path must not <= 0."); } FunctionCall functionCall = new FunctionCall("position", null, null); ExprLeaf rightOperand = new ExprLeaf(position, "Integer", "constraint"); ExprBinaryOperator binaryOperator = new ExprBinaryOperator(functionCall, rightOperand, rightOperand.Type, new OperatorKind(OperatorKind.op_eq), false); return(binaryOperator); }