public static Flexpression Create(
     IFlexpression content,
     long min,
     long max)
 {
     return(new QuantifierFlexpression(content, min, max));
 }
        public static bool Satisfies(this IFlexpression source, IFlexpressionSpecification flexpressionSpecification)
        {
            var visitor   = new SpecificationToVisitorAdapter(flexpressionSpecification);
            var satisfied = source.AcceptVisitor(visitor);

            return(satisfied);
        }
        public QuantifierFlexpression(IFlexpression content, long min, long max)
        {
            Content = content ?? throw new ArgumentNullException(nameof(content));


            if (Content is QuantifierFlexpression quantifier)
            {
                Content = quantifier.Content;
                min     = quantifier.Min * Min;
                max     = quantifier.Max * Max;
            }

            if (min < 0)
            {
                throw new ArgumentException($"Min value {min} is smaller than 0.", nameof(min));
            }

            if (max < 0)
            {
                throw new ArgumentException($"Max value {max} is smaller than 0.", nameof(max));
            }

            if (max < min)
            {
                throw new ArgumentException($"Max value {max} is smaller than min value {min}.", nameof(max));
            }

            Min = min;
            Max = max;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GotoWrapper" /> class.
        /// </summary>
        /// <param name="flexpression">The flexpression to retrieve the list of <see cref="LabelTarget"/>s from.</param>
        /// <param name="labelName">The name of the label.</param>
        /// <exception cref="ArgumentNullException">When the <paramref name="flexpression"/> is null, the exception is thrown.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="labelName"/> is null, empty, or just whitespace, the exception is thrown.</exception>
        public GotoWrapper(IFlexpression flexpression, string labelName)
        {
            Debug.Assert((flexpression != null), "The flexpression argument cannot be null.");
            Debug.Assert(!string.IsNullOrWhiteSpace(labelName), "The labelName argument cannot be null, empty, or just whitespace.");

            this.flexpression = flexpression;
            this.labelName    = labelName;
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GotoWrapper" /> class.
        /// </summary>
        /// <param name="flexpression">The flexpression to retrieve the list of <see cref="LabelTarget"/>s from.</param>
        /// <param name="labelName">The name of the label.</param>
        /// <exception cref="ArgumentNullException">When the <paramref name="flexpression"/> is null, the exception is thrown.</exception>
        /// <exception cref="ArgumentException">When the <paramref name="labelName"/> is null, empty, or just whitespace, the exception is thrown.</exception>
        public GotoWrapper(IFlexpression flexpression, string labelName)
        {
            Debug.Assert((flexpression != null), "The flexpression argument cannot be null.");
            Debug.Assert(!string.IsNullOrWhiteSpace(labelName), "The labelName argument cannot be null, empty, or just whitespace.");

            this.flexpression = flexpression;
            this.labelName = labelName;
        }
Пример #6
0
        /// <summary>
        /// Creates a new instance of the <see cref="Block&lt;TParent&gt;"/>.
        /// </summary>
        /// <param name="parent">The parent to return to once the block has been ended.</param>
        /// <param name="lookupParent">The lookup parent is used to have the <see cref="Block&lt;TParent&gt;"/> return to <paramref name="parent"/>, but pull its lookups from another (used to improve fluent syntax).</param>
        /// <param name="allowRethrow">Indicates whether or not this block allows rethrow.</param>
        /// <param name="implicitVariables">A collection of implicit variables to be used as valid, when looking for variables.</param>
        /// <exception cref="ArgumentNullException">When the <paramref name="parent"/> is null, the exception is thrown.</exception>
        internal Block(TParent parent, IFlexpression lookupParent = null, bool allowRethrow = false, IEnumerable <ParameterExpression> implicitVariables = null)
        {
            Debug.Assert((parent != null), "The parent argument cannot be null.");

            this.parent            = parent;
            this.lookupParent      = lookupParent ?? parent;
            this.allowRethrow      = allowRethrow;
            this.implicitVariables = implicitVariables;
            this.lstExpressions    = new List <IExpressionWrapper>();
            this.variables         = new List <ParameterExpression>();
            this.Variables         = variables.AsReadOnly();
        }
Пример #7
0
        /// <summary>
        /// Creates an else if block of the if block.
        /// </summary>
        /// <param name="test">The test to perform for the else if block.</param>
        /// <returns>The <see cref="Block&lt;TParent&gt;"/> of the new else if block.</returns>
        /// <exception cref="InvalidOperationException">When an else/else if was already set for this block, the exception is thrown.</exception>
        private Block <If <TParent> > ElseIfSafe(Expression test)
        {
            if (this.expressionFalse != null)
            {
                throw new InvalidOperationException("An else statement already exists for the current context.");
            }

            var elseIf = new If <TParent>(this.parent, test);

            this.expressionFalse = elseIf;

            return(elseIf.expressionTrue);
        }
Пример #8
0
        public Flexpression DefineGroup(string groupName, IFlexpression content)
        {
            var group = _groupsDefinitionsByName.GetExistingValueOrNew(
                groupName,
                pName => new GroupFlexpressionDefinition(pName, AutoFreezingValue.CreateUndefined <IFlexpression>()));

            if (content != null)
            {
                group.ContentContainer.Set(content);
            }

            return(group);
        }
Пример #9
0
        public void AssignDefaultBody(IFlexpression defaultBody)
        {
            if (defaultBody == null)
            {
                throw new ArgumentNullException("defaultBody");
            }
            if (this.defaultBody != null)
            {
                throw new InvalidOperationException("Only one default statement is allowed per switch statement.");
            }

            this.defaultBody = defaultBody;
        }
Пример #10
0
        public virtual bool Equals(IFlexpression other)
        {
            if (other is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return(LocalId.Equals(other.LocalId));
        }
Пример #11
0
        public static Flexpression Create(
            OverloadableCodeBinarySymmetricOperator binaryOperator, IFlexpression leftArgument, IFlexpression rightArgument)
        {
            if (leftArgument is BinaryOperatorFlexpression binOperator && binOperator.BinaryOperator == binaryOperator)
            {
                return(new MultiArgBinaryOperatorFlexpression(binaryOperator, new[] { binOperator.LeftArgument, binOperator.RightArgument, rightArgument }));
            }

            if (leftArgument is MultiArgBinaryOperatorFlexpression multiBinOperator && multiBinOperator.BinaryOperator == binaryOperator)
            {
                var leftArgs = multiBinOperator.Arguments;
                var args     = new IFlexpression[leftArgs.Count + 1];

                for (var idx = leftArgs.Count - 1; idx >= 0; --idx)
                {
                    args[idx] = leftArgs[idx];
                }

                args[^ 1] = rightArgument;
Пример #12
0
 public static UnaryOperatorFlexpression Create(OverloadableCodeUnarySymmetricOperator unaryOperator,
                                                IFlexpression argument)
 {
     return(new UnaryOperatorFlexpression(unaryOperator, argument));
 }
Пример #13
0
 public UnaryOperatorFlexpression(OverloadableCodeUnarySymmetricOperator unaryOperator, IFlexpression argument)
 {
     UnaryOperator = unaryOperator;
     Argument      = argument;
 }
 public static Flexpression Create(
     IFlexpression content,
     long count)
 {
     return(new QuantifierFlexpression(content, count, count));
 }
 public bool VisitCustom(IFlexpression customFlexpression)
 {
     return(_specification.IsSatisfiedByCustom(customFlexpression));
 }
        public static bool IsSatisfiedBy(this IFlexpressionSpecification flexpressionSpecification, IFlexpression flexpression)
        {
            var visitor   = new SpecificationToVisitorAdapter(flexpressionSpecification);
            var satisfied = flexpression.AcceptVisitor(visitor);

            return(satisfied);
        }