FixOffsetBeforeMatch() публичный Метод

Creates a LexerActionExecutor which encodes the current offset for position-dependent lexer actions.

Normally, when the executor encounters lexer actions where ILexerAction.IsPositionDependent() returns , it calls Antlr4.Runtime.IIntStream.Seek(int) on the input Antlr4.Runtime.ICharStream to set the input position to the end of the current token. This behavior provides for efficient DFA representation of lexer actions which appear at the end of a lexer rule, even when the lexer rule matches a variable number of characters.

Prior to traversing a match transition in the ATN, the current offset from the token start index is assigned to all position-dependent lexer actions which have not already been assigned a fixed offset. By storing the offsets relative to the token start index, the DFA representation of lexer actions which appear in the middle of tokens remains efficient due to sharing among tokens of the same length, regardless of their absolute position in the input stream.

If the current executor already has offsets assigned to all position-dependent lexer actions, the method returns this .

public FixOffsetBeforeMatch ( int offset ) : Antlr4.Runtime.Atn.LexerActionExecutor
offset int /// The current offset to assign to all position-dependent /// lexer actions which do not already have offsets assigned. ///
Результат Antlr4.Runtime.Atn.LexerActionExecutor
Пример #1
0
        /** Given a starting configuration set, figure out all ATN configurations
         *  we can reach upon input {@code t}. Parameter {@code reach} is a return
         *  parameter.
         */
        protected void GetReachableConfigSet(ICharStream input, ATNConfigSet closure, ATNConfigSet reach, int t)
        {
            // this is used to skip processing for configs which have a lower priority
            // than a config that already reached an accept state for the same rule
            int skipAlt = ATN.INVALID_ALT_NUMBER;

            foreach (ATNConfig c in closure.configs)
            {
                bool currentAltReachedAcceptState = c.alt == skipAlt;
                if (currentAltReachedAcceptState && ((LexerATNConfig)c).hasPassedThroughNonGreedyDecision())
                {
                    continue;
                }

                if (debug)
                {
                    ConsoleWriteLine("testing " + GetTokenName(t) + " at " + c.ToString(recog, true));
                }

                int n = c.state.NumberOfTransitions;
                for (int ti = 0; ti < n; ti++)
                {                               // for each transition
                    Transition trans  = c.state.Transition(ti);
                    ATNState   target = GetReachableTarget(trans, t);
                    if (target != null)
                    {
                        LexerActionExecutor lexerActionExecutor = ((LexerATNConfig)c).getLexerActionExecutor();
                        if (lexerActionExecutor != null)
                        {
                            lexerActionExecutor = lexerActionExecutor.FixOffsetBeforeMatch(input.Index - startIndex);
                        }

                        bool treatEofAsEpsilon = t == IntStreamConstants.EOF;
                        if (Closure(input, new LexerATNConfig((LexerATNConfig)c, target, lexerActionExecutor), reach, currentAltReachedAcceptState, true, treatEofAsEpsilon))
                        {
                            // any remaining configs for this alt have a lower priority than
                            // the one that just reached an accept state.
                            skipAlt = c.alt;
                            break;
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Given a starting configuration set, figure out all ATN configurations
        /// we can reach upon input
        /// <paramref name="t"/>
        /// . Parameter
        /// <paramref name="reach"/>
        /// is a return
        /// parameter.
        /// </summary>
        protected internal virtual void GetReachableConfigSet(ICharStream input, ATNConfigSet closure, ATNConfigSet reach, int t)
        {
            // this is used to skip processing for configs which have a lower priority
            // than a config that already reached an accept state for the same rule
            int skipAlt = ATN.InvalidAltNumber;

            foreach (ATNConfig c in closure)
            {
                bool currentAltReachedAcceptState = c.Alt == skipAlt;
                if (currentAltReachedAcceptState && c.PassedThroughNonGreedyDecision)
                {
                    continue;
                }
                int n = c.State.NumberOfOptimizedTransitions;
                for (int ti = 0; ti < n; ti++)
                {
                    // for each optimized transition
                    Transition trans  = c.State.GetOptimizedTransition(ti);
                    ATNState   target = GetReachableTarget(trans, t);
                    if (target != null)
                    {
                        LexerActionExecutor lexerActionExecutor = c.ActionExecutor;
                        if (lexerActionExecutor != null)
                        {
                            lexerActionExecutor = lexerActionExecutor.FixOffsetBeforeMatch(input.Index - startIndex);
                        }
                        bool treatEofAsEpsilon = t == IntStreamConstants.Eof;
                        if (Closure(input, c.Transform(target, lexerActionExecutor, true), reach, currentAltReachedAcceptState, true, treatEofAsEpsilon))
                        {
                            // any remaining configs for this alt have a lower priority than
                            // the one that just reached an accept state.
                            skipAlt = c.Alt;
                            break;
                        }
                    }
                }
            }
        }