Represents an executor for a sequence of lexer actions which traversed during the matching operation of a lexer rule (token).
Represents an executor for a sequence of lexer actions which traversed during the matching operation of a lexer rule (token).

The executor tracks position information for position-dependent lexer actions efficiently, ensuring that actions appearing only at the end of the rule do not cause bloating of the Antlr4.Runtime.Dfa.DFA created for the lexer.

예제 #1
0
        protected internal virtual DFAState AddDFAState(ATNConfigSet configs)
        {
            System.Diagnostics.Debug.Assert(!configs.HasSemanticContext);

            DFAState proposed = new DFAState(atn.modeToDFA[mode], configs);
            DFAState existing;

            if (atn.modeToDFA[mode].states.TryGetValue(proposed, out existing))
            {
                return(existing);
            }
            configs.OptimizeConfigs(this);
            DFAState  newState = new DFAState(atn.modeToDFA[mode], configs.Clone(true));
            ATNConfig firstConfigWithRuleStopState = null;

            foreach (ATNConfig c in configs)
            {
                if (c.State is RuleStopState)
                {
                    firstConfigWithRuleStopState = c;
                    break;
                }
            }
            if (firstConfigWithRuleStopState != null)
            {
                int prediction = atn.ruleToTokenType[firstConfigWithRuleStopState.State.ruleIndex];
                LexerActionExecutor lexerActionExecutor = firstConfigWithRuleStopState.ActionExecutor;
                newState.AcceptStateInfo = new AcceptStateInfo(prediction, lexerActionExecutor);
            }
            return(atn.modeToDFA[mode].AddState(newState));
        }
예제 #2
0
 public LexerATNConfig(LexerATNConfig c, ATNState state,
                       PredictionContext context)
     : base(c, state, context, c.semanticContext)
 {
     this.lexerActionExecutor            = c.lexerActionExecutor;
     this.passedThroughNonGreedyDecision = checkNonGreedyDecision(c, state);
 }
예제 #3
0
 public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor)
 {
     if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
     {
         if (lexerActionExecutor != null)
         {
             return new ATNConfig.ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, state, alt, context, false);
         }
         else
         {
             return new ATNConfig.SemanticContextATNConfig(semanticContext, state, alt, context);
         }
     }
     else
     {
         if (lexerActionExecutor != null)
         {
             return new ATNConfig.ActionATNConfig(lexerActionExecutor, state, alt, context, false);
         }
         else
         {
             return new Antlr4.Runtime.Atn.ATNConfig(state, alt, context);
         }
     }
 }
예제 #4
0
 public LexerATNConfig(ATNState state,
                       int alt,
                       PredictionContext context)
     : base(state, alt, context /*, SemanticContext.NONE*/)                    // TODO
 {
     this.passedThroughNonGreedyDecision = false;
     this.lexerActionExecutor            = null;
 }
예제 #5
0
 public LexerATNConfig(ATNState state,
                       int alt,
                       PredictionContext context,
                       LexerActionExecutor lexerActionExecutor)
     : base(state, alt, context, SemanticContext.NONE)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = false;
 }
예제 #6
0
 protected internal ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNConfig c, ATNState state, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(c, state, context)
 {
     if (c.SemanticContext != SemanticContext.None)
     {
         throw new NotSupportedException();
     }
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #7
0
        public static Antlr4.Runtime.Atn.LexerActionExecutor Append(Antlr4.Runtime.Atn.LexerActionExecutor lexerActionExecutor, ILexerAction lexerAction)
        {
            if (lexerActionExecutor == null)
            {
                return(new Antlr4.Runtime.Atn.LexerActionExecutor(new ILexerAction[] { lexerAction }));
            }
            ILexerAction[] lexerActions = Arrays.CopyOf(lexerActionExecutor.lexerActions, lexerActionExecutor.lexerActions.Length + 1);

            lexerActions[lexerActions.Length - 1] = lexerAction;
            return(new Antlr4.Runtime.Atn.LexerActionExecutor(lexerActions));
        }
예제 #8
0
 protected internal virtual void Accept(ICharStream input, LexerActionExecutor lexerActionExecutor, int startIndex, int index, int line, int charPos)
 {
     // seek to after last char in token
     input.Seek(index);
     this._line = line;
     this.charPositionInLine = charPos;
     if (lexerActionExecutor != null && recog != null)
     {
         lexerActionExecutor.Execute(recog, input, startIndex);
     }
 }
예제 #9
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     else
     {
         if (!(obj is Antlr4.Runtime.Atn.LexerActionExecutor))
         {
             return(false);
         }
     }
     Antlr4.Runtime.Atn.LexerActionExecutor other = (Antlr4.Runtime.Atn.LexerActionExecutor)obj;
     return(hashCode == other.hashCode && Arrays.Equals(lexerActions, other.lexerActions));
 }
예제 #10
0
 protected internal virtual int FailOrAccept(LexerATNSimulator.SimState prevAccept, ICharStream input, ATNConfigSet reach, int t)
 {
     if (prevAccept.dfaState != null)
     {
         LexerActionExecutor lexerActionExecutor = prevAccept.dfaState.LexerActionExecutor;
         Accept(input, lexerActionExecutor, startIndex, prevAccept.index, prevAccept.line, prevAccept.charPos);
         return(prevAccept.dfaState.Prediction);
     }
     else
     {
         // if no accept and EOF is first char, return EOF
         if (t == IntStreamConstants.Eof && input.Index == startIndex)
         {
             return(TokenConstants.Eof);
         }
         throw new LexerNoViableAltException(recog, input, startIndex, reach);
     }
 }
예제 #11
0
        protected void Accept(ICharStream input, LexerActionExecutor lexerActionExecutor,
                              int startIndex, int index, int line, int charPos)
        {
            if (debug)
            {
                ConsoleWriteLine("ACTION " + lexerActionExecutor);
            }

            // seek to after last char in token
            input.Seek(index);
            this.thisLine           = line;
            this.charPositionInLine = charPos;

            if (lexerActionExecutor != null && recog != null)
            {
                lexerActionExecutor.Execute(recog, input, startIndex);
            }
        }
예제 #12
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;
                        }
                    }
                }
            }
        }
예제 #13
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;
                        }
                    }
                }
            }
        }
예제 #14
0
        private Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext, bool checkNonGreedy, LexerActionExecutor lexerActionExecutor)
        {
            bool passedThroughNonGreedy = checkNonGreedy && CheckNonGreedyDecision(this, state);

            if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
            {
                if (lexerActionExecutor != null || passedThroughNonGreedy)
                {
                    return(new ATNConfig.ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, this, state, context, passedThroughNonGreedy));
                }
                else
                {
                    return(new ATNConfig.SemanticContextATNConfig(semanticContext, this, state, context));
                }
            }
            else
            {
                if (lexerActionExecutor != null || passedThroughNonGreedy)
                {
                    return(new ATNConfig.ActionATNConfig(lexerActionExecutor, this, state, context, passedThroughNonGreedy));
                }
                else
                {
                    return(new Antlr4.Runtime.Atn.ATNConfig(this, state, context));
                }
            }
        }
예제 #15
0
 public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, LexerActionExecutor lexerActionExecutor, bool checkNonGreedy)
 {
     return(Transform(state, context, this.SemanticContext, checkNonGreedy, lexerActionExecutor));
 }
예제 #16
0
 private Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext, bool checkNonGreedy, LexerActionExecutor lexerActionExecutor)
 {
     bool passedThroughNonGreedy = checkNonGreedy && CheckNonGreedyDecision(this, state);
     if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
     {
         if (lexerActionExecutor != null || passedThroughNonGreedy)
         {
             return new ATNConfig.ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, this, state, context, passedThroughNonGreedy);
         }
         else
         {
             return new ATNConfig.SemanticContextATNConfig(semanticContext, this, state, context);
         }
     }
     else
     {
         if (lexerActionExecutor != null || passedThroughNonGreedy)
         {
             return new ATNConfig.ActionATNConfig(lexerActionExecutor, this, state, context, passedThroughNonGreedy);
         }
         else
         {
             return new Antlr4.Runtime.Atn.ATNConfig(this, state, context);
         }
     }
 }
예제 #17
0
 public ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNState state, int alt, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(state, alt, context)
 {
     this.lexerActionExecutor = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #18
0
 protected internal ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNConfig c, ATNState state, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(c, state, context)
 {
     if (c.SemanticContext != SemanticContext.None)
     {
         throw new NotSupportedException();
     }
     this.lexerActionExecutor = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #19
0
 public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(semanticContext, c, state, context)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #20
0
 public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, SemanticContext semanticContext, ATNConfig c, ATNState state, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(semanticContext, c, state, context)
 {
     this.lexerActionExecutor = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #21
0
        protected void Accept(ICharStream input, LexerActionExecutor lexerActionExecutor,
							  int startIndex, int index, int line, int charPos)
        {
            if (debug)
            {
                Console.WriteLine("ACTION " + lexerActionExecutor);
            }

            // seek to after last char in token
            input.Seek(index);
            this.thisLine = line;
            this.charPositionInLine = charPos;

            if (lexerActionExecutor != null && recog != null)
            {
                lexerActionExecutor.Execute(recog, input, startIndex);
            }
        }
예제 #22
0
        protected internal virtual ATNConfig GetEpsilonTarget([NotNull] ICharStream input, [NotNull] ATNConfig config, [NotNull] Transition t, [NotNull] ATNConfigSet configs, bool speculative, bool treatEofAsEpsilon)
        {
            ATNConfig c;

            switch (t.TransitionType)
            {
            case TransitionType.Rule:
            {
                RuleTransition ruleTransition = (RuleTransition)t;
                if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.Context.HasEmpty)
                {
                    c = config.Transform(t.target, true);
                }
                else
                {
                    PredictionContext newContext = config.Context.GetChild(ruleTransition.followState.stateNumber);
                    c = config.Transform(t.target, newContext, true);
                }
                break;
            }

            case TransitionType.Precedence:
            {
                throw new NotSupportedException("Precedence predicates are not supported in lexers.");
            }

            case TransitionType.Predicate:
            {
                /*  Track traversing semantic predicates. If we traverse,
                 *  we cannot add a DFA state for this "reach" computation
                 *      because the DFA would not test the predicate again in the
                 *      future. Rather than creating collections of semantic predicates
                 *      like v3 and testing them on prediction, v4 will test them on the
                 *      fly all the time using the ATN not the DFA. This is slower but
                 *      semantically it's not used that often. One of the key elements to
                 *      this predicate mechanism is not adding DFA states that see
                 *      predicates immediately afterwards in the ATN. For example,
                 *
                 *      a : ID {p1}? | ID {p2}? ;
                 *
                 *      should create the start state for rule 'a' (to save start state
                 *      competition), but should not create target of ID state. The
                 *      collection of ATN states the following ID references includes
                 *      states reached by traversing predicates. Since this is when we
                 *      test them, we cannot cash the DFA state target of ID.
                 */
                PredicateTransition pt = (PredicateTransition)t;
                configs.MarkExplicitSemanticContext();
                if (EvaluatePredicate(input, pt.ruleIndex, pt.predIndex, speculative))
                {
                    c = config.Transform(t.target, true);
                }
                else
                {
                    c = null;
                }
                break;
            }

            case TransitionType.Action:
            {
                if (config.Context.HasEmpty)
                {
                    // execute actions anywhere in the start rule for a token.
                    //
                    // TODO: if the entry rule is invoked recursively, some
                    // actions may be executed during the recursive call. The
                    // problem can appear when hasEmpty() is true but
                    // isEmpty() is false. In this case, the config needs to be
                    // split into two contexts - one with just the empty path
                    // and another with everything but the empty path.
                    // Unfortunately, the current algorithm does not allow
                    // getEpsilonTarget to return two configurations, so
                    // additional modifications are needed before we can support
                    // the split operation.
                    LexerActionExecutor lexerActionExecutor = LexerActionExecutor.Append(config.ActionExecutor, atn.lexerActions[((ActionTransition)t).actionIndex]);
                    c = config.Transform(t.target, lexerActionExecutor, true);
                    break;
                }
                else
                {
                    // ignore actions in referenced rules
                    c = config.Transform(t.target, true);
                    break;
                }
            }

            case TransitionType.Epsilon:
            {
                c = config.Transform(t.target, true);
                break;
            }

            case TransitionType.Atom:
            case TransitionType.Range:
            case TransitionType.Set:
            {
                if (treatEofAsEpsilon)
                {
                    if (t.Matches(IntStreamConstants.Eof, char.MinValue, char.MaxValue))
                    {
                        c = config.Transform(t.target, false);
                        break;
                    }
                }
                c = null;
                break;
            }

            default:
            {
                c = null;
                break;
            }
            }
            return(c);
        }
예제 #23
0
        protected internal virtual ATNConfig GetEpsilonTarget(ICharStream input, ATNConfig config, Transition t, ATNConfigSet configs, bool speculative, bool treatEofAsEpsilon)
        {
            ATNConfig c;

            switch (t.TransitionType)
            {
            case TransitionType.Rule:
            {
                RuleTransition ruleTransition = (RuleTransition)t;
                if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.Context.HasEmpty)
                {
                    c = config.Transform(t.target, true);
                }
                else
                {
                    PredictionContext newContext = config.Context.GetChild(ruleTransition.followState.stateNumber);
                    c = config.Transform(t.target, newContext, true);
                }
                break;
            }

            case TransitionType.Precedence:
            {
                throw new NotSupportedException("Precedence predicates are not supported in lexers.");
            }

            case TransitionType.Predicate:
            {
                PredicateTransition pt = (PredicateTransition)t;
                configs.MarkExplicitSemanticContext();
                if (EvaluatePredicate(input, pt.ruleIndex, pt.predIndex, speculative))
                {
                    c = config.Transform(t.target, true);
                }
                else
                {
                    c = null;
                }
                break;
            }

            case TransitionType.Action:
            {
                if (config.Context.HasEmpty)
                {
                    // execute actions anywhere in the start rule for a token.
                    //
                    // TODO: if the entry rule is invoked recursively, some
                    // actions may be executed during the recursive call. The
                    // problem can appear when hasEmpty() is true but
                    // isEmpty() is false. In this case, the config needs to be
                    // split into two contexts - one with just the empty path
                    // and another with everything but the empty path.
                    // Unfortunately, the current algorithm does not allow
                    // getEpsilonTarget to return two configurations, so
                    // additional modifications are needed before we can support
                    // the split operation.
                    LexerActionExecutor lexerActionExecutor = LexerActionExecutor.Append(config.ActionExecutor, atn.lexerActions[((ActionTransition)t).actionIndex]);
                    c = config.Transform(t.target, lexerActionExecutor, true);
                    break;
                }
                else
                {
                    // ignore actions in referenced rules
                    c = config.Transform(t.target, true);
                    break;
                }
            }

            case TransitionType.Epsilon:
            {
                c = config.Transform(t.target, true);
                break;
            }

            case TransitionType.Atom:
            case TransitionType.Range:
            case TransitionType.Set:
            {
                if (treatEofAsEpsilon)
                {
                    if (t.Matches(IntStreamConstants.Eof, char.MinValue, char.MaxValue))
                    {
                        c = config.Transform(t.target, false);
                        break;
                    }
                }
                c = null;
                break;
            }

            default:
            {
                c = null;
                break;
            }
            }
            return(c);
        }
예제 #24
0
 protected internal virtual void Accept(ICharStream input, LexerActionExecutor lexerActionExecutor, int startIndex, int index, int line, int charPos)
 {
     // seek to after last char in token
     input.Seek(index);
     this.line = line;
     this.charPositionInLine = charPos;
     if (lexerActionExecutor != null && recog != null)
     {
         lexerActionExecutor.Execute(recog, input, startIndex);
     }
 }
예제 #25
0
 public ActionATNConfig(LexerActionExecutor lexerActionExecutor, ATNState state, int alt, PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(state, alt, context)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }
예제 #26
0
 public Antlr4.Runtime.Atn.ATNConfig Transform(ATNState state, LexerActionExecutor lexerActionExecutor, bool checkNonGreedy)
 {
     return Transform(state, context, this.SemanticContext, checkNonGreedy, lexerActionExecutor);
 }
예제 #27
0
        // side-effect: can alter configs.hasSemanticContext

        protected LexerATNConfig GetEpsilonTarget(ICharStream input,
                                                  LexerATNConfig config,
                                                  Transition t,
                                                  ATNConfigSet configs,
                                                  bool speculative,
                                                  bool treatEofAsEpsilon)
        {
            LexerATNConfig c = null;

            switch (t.TransitionType)
            {
            case TransitionType.RULE:
                RuleTransition    ruleTransition = (RuleTransition)t;
                PredictionContext newContext     = new SingletonPredictionContext(config.context, ruleTransition.followState.stateNumber);
                c = new LexerATNConfig(config, t.target, newContext);
                break;

            case TransitionType.PRECEDENCE:
                throw new Exception("Precedence predicates are not supported in lexers.");

            case TransitionType.PREDICATE:
                /*  Track traversing semantic predicates. If we traverse,
                 * we cannot add a DFA state for this "reach" computation
                 * because the DFA would not test the predicate again in the
                 * future. Rather than creating collections of semantic predicates
                 * like v3 and testing them on prediction, v4 will test them on the
                 * fly all the time using the ATN not the DFA. This is slower but
                 * semantically it's not used that often. One of the key elements to
                 * this predicate mechanism is not adding DFA states that see
                 * predicates immediately afterwards in the ATN. For example,
                 *
                 * a : ID {p1}? | ID {p2}? ;
                 *
                 * should create the start state for rule 'a' (to save start state
                 * competition), but should not create target of ID state. The
                 * collection of ATN states the following ID references includes
                 * states reached by traversing predicates. Since this is when we
                 * test them, we cannot cash the DFA state target of ID.
                 */
                PredicateTransition pt = (PredicateTransition)t;
                if (debug)
                {
                    ConsoleWriteLine("EVAL rule " + pt.ruleIndex + ":" + pt.predIndex);
                }
                configs.hasSemanticContext = true;
                if (EvaluatePredicate(input, pt.ruleIndex, pt.predIndex, speculative))
                {
                    c = new LexerATNConfig(config, t.target);
                }
                break;

            case TransitionType.ACTION:
                if (config.context == null || config.context.HasEmptyPath)
                {
                    // execute actions anywhere in the start rule for a token.
                    //
                    // TODO: if the entry rule is invoked recursively, some
                    // actions may be executed during the recursive call. The
                    // problem can appear when hasEmptyPath() is true but
                    // isEmpty() is false. In this case, the config needs to be
                    // split into two contexts - one with just the empty path
                    // and another with everything but the empty path.
                    // Unfortunately, the current algorithm does not allow
                    // getEpsilonTarget to return two configurations, so
                    // additional modifications are needed before we can support
                    // the split operation.
                    LexerActionExecutor lexerActionExecutor = LexerActionExecutor.Append(config.getLexerActionExecutor(), atn.lexerActions[((ActionTransition)t).actionIndex]);
                    c = new LexerATNConfig(config, t.target, lexerActionExecutor);
                    break;
                }
                else
                {
                    // ignore actions in referenced rules
                    c = new LexerATNConfig(config, t.target);
                    break;
                }

            case TransitionType.EPSILON:
                c = new LexerATNConfig(config, t.target);
                break;

            case TransitionType.ATOM:
            case TransitionType.RANGE:
            case TransitionType.SET:
                if (treatEofAsEpsilon)
                {
                    if (t.Matches(IntStreamConstants.EOF, Lexer.MinCharValue, Lexer.MaxCharValue))
                    {
                        c = new LexerATNConfig(config, t.target);
                        break;
                    }
                }

                break;
            }

            return(c);
        }
예제 #28
0
 public static Antlr4.Runtime.Atn.ATNConfig Create(ATNState state, int alt, PredictionContext context, Antlr4.Runtime.Atn.SemanticContext semanticContext, LexerActionExecutor lexerActionExecutor)
 {
     if (semanticContext != Antlr4.Runtime.Atn.SemanticContext.None)
     {
         if (lexerActionExecutor != null)
         {
             return(new ATNConfig.ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, state, alt, context, false));
         }
         else
         {
             return(new ATNConfig.SemanticContextATNConfig(semanticContext, state, alt, context));
         }
     }
     else
     {
         if (lexerActionExecutor != null)
         {
             return(new ATNConfig.ActionATNConfig(lexerActionExecutor, state, alt, context, false));
         }
         else
         {
             return(new Antlr4.Runtime.Atn.ATNConfig(state, alt, context));
         }
     }
 }
예제 #29
0
 public ActionSemanticContextATNConfig(LexerActionExecutor lexerActionExecutor, [NotNull] SemanticContext semanticContext, [NotNull] ATNState state, int alt, [Nullable] PredictionContext context, bool passedThroughNonGreedyDecision)
     : base(semanticContext, state, alt, context)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision;
 }