Exemplo n.º 1
0
        /// <summary>
        /// Tries to parse a range node to obtain the corresponding range of constants.
        /// </summary>
        /// <param name="range">The range to parse.</param>
        /// <param name="result">The constant range upon return if successful.</param>
        /// <param name="error">The error in case of failure.</param>
        public static bool TryParseRange(IRange range, out IConstantRange result, out IError error)
        {
            result = null;

            IOrderedLanguageConstant LeftExpressionConstant;
            IOrderedLanguageConstant RightExpressionConstant;

            if (!LanguageConstant.TryParseExpression((IExpression)range.LeftExpression, out LeftExpressionConstant, out error))
            {
                return(false);
            }

            if (!range.RightExpression.IsAssigned)
            {
                RightExpressionConstant = LeftExpressionConstant;
            }
            else if (!LanguageConstant.TryParseExpression((IExpression)range.RightExpression.Item, out RightExpressionConstant, out error))
            {
                return(false);
            }

            if (!LeftExpressionConstant.IsCompatibleWith(RightExpressionConstant))
            {
                error = new ErrorIncompatibleRangeBounds(range);
                return(false);
            }

            result = new ConstantRange(LeftExpressionConstant, RightExpressionConstant);
            error  = null;
            return(true);
        }
        /// <summary>
        /// Checks for errors before applying a rule.
        /// </summary>
        /// <param name="node">The node instance to check.</param>
        /// <param name="dataList">Optional data collected during inspection of sources.</param>
        /// <param name="data">Private data to give to Apply() upon return.</param>
        /// <returns>True if an error occured.</returns>
        public override bool CheckConsistency(IRange node, IDictionary <ISourceTemplate, object> dataList, out object data)
        {
            data = null;
            bool Success = true;

            if (!ConstantRange.TryParseRange(node, out IConstantRange Result, out IError Error))
            {
                AddSourceError(Error);
                Success = false;
            }