Exemple #1
0
        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);
        }
Exemple #2
0
        private static string GetCriteriaType(Match match, out object criteria)
        {
            string type           = "String";
            string stringCriteria = match.Groups["stringCriteria"].Value;

            if (!string.IsNullOrEmpty(stringCriteria))
            {
                type     = ExprItem.GetTypeValue(stringCriteria);
                criteria = stringCriteria;

                return(type);
            }
            else
            {
                string intCriteria = match.Groups["intCriteria"].Value;
                if (!string.IsNullOrEmpty(intCriteria))
                {
                    type = "Integer";
                    int intValue = int.MinValue;
                    if (!int.TryParse(intCriteria, out intValue))
                    {
                        throw new ApplicationException(intValue + " is not a valid integer.");
                    }
                    criteria = intValue;

                    return(type);
                }

                string doubleCriteria = match.Groups["doubleCriteria"].Value;
                if (!string.IsNullOrEmpty(doubleCriteria))
                {
                    type = "Double";
                    double doubleValue = double.MinValue;
                    if (!double.TryParse(doubleCriteria, out doubleValue))
                    {
                        throw new ApplicationException(doubleCriteria + " is not a valid double value.");
                    }
                    criteria = doubleValue;

                    return(type);
                }

                string boolCriteria = match.Groups["boolCriteria"].Value;
                if (!string.IsNullOrEmpty(boolCriteria))
                {
                    type = "Boolean";
                    bool boolValue = true;
                    if (!bool.TryParse(boolCriteria.ToString(), out boolValue))
                    {
                        throw new ApplicationException(boolCriteria + " is not a valid boolean value.");
                    }
                    criteria = boolValue;
                    return(type);
                }

                criteria = stringCriteria;

                return(type);
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
 List<ExprItem> regulars = new List<ExprItem>(); /* Opcionális kifejezés kezdete-> o:: */
 /* ***************************************** */
 public Section(string sname,bool opt,List<string> rules)
 {
   SectName = sname;
   optional = opt;
   foreach (string s in rules)
   {
     Regex r = new Regex(@"^(?<opti>o[r]?::)?(?<other>.+)$");
     Match m = r.Match(s);
     ExprItem eItem = new ExprItem();
     eItem.expr = m.Groups["other"].Value;
     eItem.optional = m.Groups["opti"].Value.ToString() == "o::";
     regulars.Add(eItem);
   }
 }
Exemple #6
0
        private static TlaExpr TranslateToTlaExpr(this exprSeq expr, AutomatonParsingContext ctx)
        {
            if (expr.exprItems.Length != expr.boolOperators.Length + 1)
            {
                throw new ApplicationException();
            }

            var items = new ExprItem[expr.exprItems.Length + expr.boolOperators.Length];

            items[0] = new ExprItem(expr.exprItems[0].Translate(ctx));
            for (int i = 0, j = 1; i < expr.boolOperators.Length; i++, j += 2)
            {
                items[j + 0] = new ExprItem(_opsByStr[expr.boolOperators[i].strings.First()]);
                items[j + 1] = new ExprItem(expr.exprItems[i + 1].Translate(ctx));
            }

            return(TranslateExprPart(items, 0, items.Length));
        }
Exemple #7
0
 protected void ValidateBase(ExprItem exprItem)
 {
     Invariant(!string.IsNullOrEmpty(exprItem.Type), string.Format(
                   CommonStrings.XMustNotBeNull, "ExprItem.Type"));
 }
Exemple #8
0
        protected void Validate(ExprItem exprItem)
        {
            if (exprItem == null)
            {
                throw new ArgumentNullException(string.Format(
                                                    CommonStrings.XMustNotBeNull, "exprItem"));
            }

            const string methodName = "Validate";

            try
            {
                System.Reflection.MethodInfo method = this.GetType().GetMethod(methodName,
                                                                               System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic
                                                                               | System.Reflection.BindingFlags.Instance, Type.DefaultBinder,
                                                                               new Type[] { exprItem.GetType() },
                                                                               new System.Reflection.ParameterModifier[0]);

                if (method != null)
                {
                    if (method != lastExprItemMethodRead || exprItem != lastExprItem)
                    {
                        lastExprItemMethodRead = method;
                        lastExprItem           = exprItem;

                        method.Invoke(this, new Object[] { exprItem });
                    }
                    else
                    {
                        string message = string.Format(CommonStrings.LoopingMethodTerminated,
                                                       methodName, exprItem.GetType().ToString());
                        System.Diagnostics.Debug.WriteLine(message);
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY,
                                                   methodName, exprItem.GetType().ToString());
                    System.Diagnostics.Debug.WriteLine(message);
                    throw new ApplicationException(message);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    if (ex.InnerException is ApplicationException && ex.InnerException.InnerException != null &&
                        ex.InnerException.Message == ex.InnerException.InnerException.Message)
                    {
                        throw new ApplicationException(ex.InnerException.Message, ex.InnerException.InnerException);
                    }
                    else
                    {
                        throw new ApplicationException(ex.InnerException.Message, ex.InnerException);
                    }
                }
                else
                {
                    throw new ApplicationException(ex.Message, ex);
                }
            }
        }