Exemple #1
0
        internal static bool TryTakeEntityReference(RuleTokenKeeper tokenKeeper, out EntityReference clause)
        {
            var next = tokenKeeper.Next;

            if (next.TokenType == ApplyIfTokenType.Identifier)
            {
                var work   = new RuleTokenKeeper(tokenKeeper);
                var entity = work.Take().Text;

                if (work.Next.TokenType == ApplyIfTokenType.Period)
                {
                    work.Take();
                    if (work.Next.TokenType == ApplyIfTokenType.Identifier)
                    {
                        var field = work.Take().Text;
                        tokenKeeper.Swap(work);
                        clause = new EntityReference(entity, field);
                        return(true);
                    }
                }

                clause = null;
                return(false);
            }

            clause = null;
            return(false);
        }
        private static bool TryTakeMatch(RuleTokenKeeper tokenKeeper, out ApplyIfRuleClause clause)
        {
            var next = tokenKeeper.Next;

            if (next.TokenType == ApplyIfTokenType.Match)
            {
                var work = new RuleTokenKeeper(tokenKeeper);
                work.Take();

                if (work.Next.TokenType == ApplyIfTokenType.OpenParen)
                {
                    work.Take();

                    if (EntityReferenceParser.TryTakeEntityReference(work, out var entityReference))
                    {
                        if (work.Next.TokenType == ApplyIfTokenType.CloseParen)
                        {
                            work.Take();
                        }

                        tokenKeeper.Swap(work);
                        clause = new MatchClause(entityReference);
                        return(true);
                    }
                }
            }

            clause = null;
            return(false);
        }
        private static bool TryTakeRuleSequence(RuleTokenKeeper tokenKeeper, out ApplyIfRuleClause clause)
        {
            var work = new RuleTokenKeeper(tokenKeeper);

            if (TryTakeRuleClause(work, out var left))
            {
                if (work.Next.TokenType == ApplyIfTokenType.Comma)
                {
                    ApplyIfRuleClause right;
                    work.Take();
                    if (TryTakeRuleSequence(work, out right) || TryTakeRuleClause(work, out right))
                    {
                        if (work.Finished)
                        {
                            tokenKeeper.Swap(work);
                            clause = new RuleSequenceClause(left, right);
                            return(true);
                        }
                    }
                }
            }

            clause = null;
            return(false);
        }
        private static bool TryTakeFirstError(RuleTokenKeeper tokenKeeper, out ApplyIfRuleClause clause)
        {
            var next = tokenKeeper.Next;

            if (next.TokenType == ApplyIfTokenType.FirstError)
            {
                clause = new FirstErrorClause();
                tokenKeeper.Take();
                return(true);
            }

            clause = null;
            return(false);
        }
        private static bool TryTakeCleanInput(RuleTokenKeeper tokenKeeper, out ApplyIfRuleClause clause)
        {
            var next = tokenKeeper.Next;

            if (next.TokenType == ApplyIfTokenType.CleanInput)
            {
                clause = new CleanInputClause();
                tokenKeeper.Take();
                return(true);
            }

            clause = null;
            return(false);
        }