/// <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); }
private void AddValueToList(IConstantRange range) { if (LanguageConstant.TryParseInt(range.Minimum, out int IntMinimum) && LanguageConstant.TryParseInt(range.Maximum, out int IntMaximum)) { ConstantList.Add(range.Minimum); if (IntMinimum < IntMaximum) { for (int i = IntMinimum + 1; i < IntMaximum; i++) { ConstantList.Add(new NumberLanguageConstant(new Number(i))); } ConstantList.Add(range.Maximum); } } else if (range.Minimum is DiscreteLanguageConstant AsDiscreteMinimum && AsDiscreteMinimum.IsValueKnown && range.Maximum is DiscreteLanguageConstant AsDiscreteMaximum && AsDiscreteMaximum.IsValueKnown) { ConstantList.Add(AsDiscreteMinimum); if (AsDiscreteMaximum.IsConstantGreater(AsDiscreteMinimum)) { IClass EmbeddingClass = AsDiscreteMinimum.Discrete.EmbeddingClass; int DiscreteMinimumIndex = EmbeddingClass.DiscreteList.IndexOf(AsDiscreteMinimum.Discrete); int DiscreteMaximumIndex = EmbeddingClass.DiscreteList.IndexOf(AsDiscreteMaximum.Discrete); if (DiscreteMinimumIndex >= 0 && DiscreteMaximumIndex >= 0) { for (int Index = DiscreteMinimumIndex + 1; Index < DiscreteMaximumIndex; Index++) { IDiscrete MiddleDiscrete = EmbeddingClass.DiscreteList[Index]; DiscreteLanguageConstant MiddleConstant = new DiscreteLanguageConstant(MiddleDiscrete); ConstantList.Add(MiddleConstant); } } } } }