Ejemplo n.º 1
0
        /// <summary>
        /// Loops until token pattern match succeeds.
        /// This method matches using the same primary token filter as the parent match.
        /// Keeps state machine if match was found on the first token that follows the match
        /// </summary>
        public static FSMI LoopUntilAfterMatch <TToken>(this LazyFSMState <TToken> state,
                                                        params LazyFSMPredicate <TToken>[] predicates
                                                        ) where TToken : Token
        {
            if (state.m_SkipCount > 0)
            {
                state.m_SkipCount--;
                if (state.m_SkipCount == 0)
                {
                    return(FSMI.Advance);
                }
                return(FSMI.Loop);
            }

            var stream = state.Tokens;

            if (state.m_CurrentTokenIndex > 0)
            {
                stream = stream.Skip(state.m_CurrentTokenIndex);
            }

            LazyFSMState <TToken> subState = new LazyFSMState <TToken>();

            if (stream.LazyFSM(state.m_OnlyPrimary, ref subState, predicates) != null)
            {
                return(state.Skip(subState.m_PatternTokenLength - 1));
            }

            return(FSMI.Loop);
        }