Пример #1
0
        public static IEnumerable <Expression> Iterate(Expression expressionToIterate)
        {
            BinaryConcat binaryConcat = expressionToIterate.As <BinaryConcat>();

            if (binaryConcat != null)
            {
                foreach (Expression expression in Iterate(binaryConcat.Left.AsSequence().Concat(binaryConcat.Right)))
                {
                    yield return(expression);
                }

                yield break;
            }

            Concat concat = expressionToIterate.As <Concat>();

            if (concat != null)
            {
                foreach (Expression expression in Iterate(concat.Expressions))
                {
                    yield return(expression);
                }

                yield break;
            }

            yield return(expressionToIterate);
        }
Пример #2
0
        internal override GrammarExpressionTuple GenerateGrammar(GrammarType grammarType, int grammarNumber,
                                                                 ref int index, ref int additionalGrammarNumber, Action <GrammarPostReport> onIterate, params GrammarExpressionWithOriginal[] dependencies)
        {
            CheckDependencies(dependencies);

            if (IterationCount == 0)
            {
                return(Empty.Instance.GenerateGrammar(grammarType, grammarNumber, ref index, ref additionalGrammarNumber, onIterate));
            }

            GrammarExpressionTuple original = dependencies[0].GrammarExpression;

            if (IterationCount == 1)
            {
                GrammarExpressionTuple grammarExpressionTuple = new GrammarExpressionTuple(this, original.Grammar, grammarNumber);

                if (onIterate != null)
                {
                    onIterate(new GrammarPostReport(grammarExpressionTuple, new GrammarExpressionWithOriginal(original).AsSequence()));
                }

                return(grammarExpressionTuple);
            }

            GrammarExpressionTuple dependency1 = original;

            for (int i = 1; i < IterationCount; i++)
            {
                GrammarExpressionTuple dependency2 = Mirror(original, ref index, ref additionalGrammarNumber);

                int number;

                if (i == IterationCount - 1)
                {
                    number = grammarNumber;
                }
                else
                {
                    number = additionalGrammarNumber++;
                }

                GrammarExpressionTuple expressionTuple =
                    new BinaryConcat(dependency1.Expression, dependency2.Expression).
                    GenerateGrammar(grammarType, number, ref index, ref additionalGrammarNumber, onIterate, new GrammarExpressionWithOriginal(dependency1), new GrammarExpressionWithOriginal(dependency2, original));

                dependency1 = expressionTuple;
            }

            return(dependency1);
        }
Пример #3
0
        internal override StateMachineExpressionTuple GenerateStateMachine(int stateMachineNumber, ref int index, ref int additionalStateMachineNumber, Action <StateMachinePostReport> onIterate, params StateMachineExpressionWithOriginal[] dependencies)
        {
            CheckDependencies(dependencies);

            if (IterationCount == 0)
            {
                return(Empty.Instance.GenerateStateMachine(stateMachineNumber, ref index, ref additionalStateMachineNumber, onIterate));
            }

            StateMachineExpressionTuple original = dependencies[0].StateMachineExpression;

            if (IterationCount == 1)
            {
                StateMachineExpressionTuple stateMachineExpressionTuple = new StateMachineExpressionTuple(this, original.StateMachine, stateMachineNumber);

                if (onIterate != null)
                {
                    onIterate(new StateMachinePostReport(stateMachineExpressionTuple, new StateMachineExpressionWithOriginal(original).AsSequence()));
                }

                return(stateMachineExpressionTuple);
            }

            StateMachineExpressionTuple dependency1 = original;

            for (int i = 1; i < IterationCount; i++)
            {
                StateMachineExpressionTuple dependency2 = Mirror(original, ref index, ref additionalStateMachineNumber);

                int number;

                if (i == IterationCount - 1)
                {
                    number = stateMachineNumber;
                }
                else
                {
                    number = additionalStateMachineNumber++;
                }

                StateMachineExpressionTuple expressionTuple =
                    new BinaryConcat(dependency1.Expression, dependency2.Expression).
                    GenerateStateMachine(number, ref index, ref additionalStateMachineNumber, onIterate, new StateMachineExpressionWithOriginal(dependency1), new StateMachineExpressionWithOriginal(dependency2, original));

                dependency1 = expressionTuple;
            }

            return(dependency1);
        }
Пример #4
0
        public override Expression ToRegExp()
        {
            Entity     prev       = null;
            Expression expression = null;

            foreach (Entity entity in EntityCollection)
            {
                if (prev == null)
                {
                    expression = entity.ToRegExp();
                }
                else
                {
                    expression = new RegExpBinaryConcat(expression, entity.ToRegExp());
                }

                prev = entity;
            }

            return(expression);
        }