Class LexerATNSimulator


  • public class LexerATNSimulator
    extends ATNSimulator
    "dup" of ParserInterpreter
    • Field Detail

      • recog

        protected final Lexer recog
      • startIndex

        protected int startIndex
        The current token's starting index into the character stream. Shared across DFA to ATN simulation in case the ATN fails and the DFA did not have a previous accept state. In this case, we use the ATN-generated exception object.
      • line

        protected int line
        line number 1..n within the input
      • charPositionInLine

        protected int charPositionInLine
        The index of the character relative to the beginning of the line 0..n-1
      • decisionToDFA

        public final DFA[] decisionToDFA
      • mode

        protected int mode
      • prevAccept

        protected final LexerATNSimulator.SimState prevAccept
        Used during DFA/ATN exec to record the most recent accept configuration info
    • Method Detail

      • match

        public int match​(CharStream input,
                         int mode)
      • clearDFA

        public void clearDFA()
        Description copied from class: ATNSimulator
        Clear the DFA cache used by the current instance. Since the DFA cache may be shared by multiple ATN simulators, this method may affect the performance (but not accuracy) of other parsers which are being used concurrently.
        Overrides:
        clearDFA in class ATNSimulator
      • matchATN

        protected int matchATN​(CharStream input)
      • getExistingTargetState

        protected DFAState getExistingTargetState​(DFAState s,
                                                  int t)
        Get an existing target state for an edge in the DFA. If the target state for the edge has not yet been computed or is otherwise not available, this method returns null.
        Parameters:
        s - The current DFA state
        t - The next input symbol
        Returns:
        The existing target DFA state for the given input symbol t, or null if the target state for this edge is not already cached
      • computeTargetState

        protected DFAState computeTargetState​(CharStream input,
                                              DFAState s,
                                              int t)
        Compute a target state for an edge in the DFA, and attempt to add the computed state and corresponding edge to the DFA.
        Parameters:
        input - The input stream
        s - The current DFA state
        t - The next input symbol
        Returns:
        The computed target DFA state for the given input symbol t. If t does not lead to a valid DFA state, this method returns ATNSimulator.ERROR.
      • getReachableConfigSet

        protected void getReachableConfigSet​(CharStream input,
                                             ATNConfigSet closure,
                                             ATNConfigSet reach,
                                             int t)
        Given a starting configuration set, figure out all ATN configurations we can reach upon input t. Parameter reach is a return parameter.
      • accept

        protected void accept​(CharStream input,
                              LexerActionExecutor lexerActionExecutor,
                              int startIndex,
                              int index,
                              int line,
                              int charPos)
      • getReachableTarget

        protected ATNState getReachableTarget​(Transition trans,
                                              int t)
      • closure

        protected boolean closure​(CharStream input,
                                  LexerATNConfig config,
                                  ATNConfigSet configs,
                                  boolean currentAltReachedAcceptState,
                                  boolean speculative,
                                  boolean treatEofAsEpsilon)
        Since the alternatives within any lexer decision are ordered by preference, this method stops pursuing the closure as soon as an accept state is reached. After the first accept state is reached by depth-first search from config, all other (potentially reachable) states for this rule would have a lower priority.
        Returns:
        true if an accept state is reached, otherwise false.
      • evaluatePredicate

        protected boolean evaluatePredicate​(CharStream input,
                                            int ruleIndex,
                                            int predIndex,
                                            boolean speculative)
        Evaluate a predicate specified in the lexer.

        If speculative is true, this method was called before consume(org.antlr.v4.runtime.CharStream) for the matched character. This method should call consume(org.antlr.v4.runtime.CharStream) before evaluating the predicate to ensure position sensitive values, including Lexer.getText(), Lexer.getLine(), and Lexer.getCharPositionInLine(), properly reflect the current lexer state. This method should restore input and the simulator to the original state before returning (i.e. undo the actions made by the call to consume(org.antlr.v4.runtime.CharStream).

        Parameters:
        input - The input stream.
        ruleIndex - The rule containing the predicate.
        predIndex - The index of the predicate within the rule.
        speculative - true if the current index in input is one character before the predicate's location.
        Returns:
        true if the specified predicate evaluates to true.
      • addDFAState

        protected DFAState addDFAState​(ATNConfigSet configs)
        Add a new DFA state if there isn't one with this set of configurations already. This method also detects the first configuration containing an ATN rule stop state. Later, when traversing the DFA, we will know which rule to accept.
      • getDFA

        public final DFA getDFA​(int mode)
      • getText

        public String getText​(CharStream input)
        Get the text matched so far for the current token.
      • getLine

        public int getLine()
      • setLine

        public void setLine​(int line)
      • getCharPositionInLine

        public int getCharPositionInLine()
      • setCharPositionInLine

        public void setCharPositionInLine​(int charPositionInLine)
      • consume

        public void consume​(CharStream input)
      • getTokenName

        public String getTokenName​(int t)