Пример #1
0
 public LexerATNConfig(LexerATNConfig c, ATNState state,
                       PredictionContext context)
     : base(c, state, context, c.semanticContext)
 {
     this.lexerActionExecutor            = c.lexerActionExecutor;
     this.passedThroughNonGreedyDecision = checkNonGreedyDecision(c, state);
 }
Пример #2
0
 public LexerATNConfig(ATNState state,
                       int alt,
                       PredictionContext context)
     : base(state, alt, context /*, SemanticContext.NONE*/)                    // TODO
 {
     this.passedThroughNonGreedyDecision = false;
     this.lexerActionExecutor            = null;
 }
Пример #3
0
 public LexerATNConfig(ATNState state,
                       int alt,
                       PredictionContext context,
                       LexerActionExecutor lexerActionExecutor)
     : base(state, alt, context, SemanticContext.NONE)
 {
     this.lexerActionExecutor            = lexerActionExecutor;
     this.passedThroughNonGreedyDecision = false;
 }
Пример #4
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     else
     {
         if (!(obj is erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor))
         {
             return(false);
         }
     }
     erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor other = (erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor)obj;
     return(hashCode == other.hashCode && Arrays.Equals(lexerActions, other.lexerActions));
 }
Пример #5
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);
            }
        }
Пример #6
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;
                        }
                    }
                }
            }
        }
Пример #7
0
        protected int FailOrAccept(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);
            }
        }
Пример #8
0
        public static erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor Append(erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor lexerActionExecutor, ILexerAction lexerAction)
        {
            if (lexerActionExecutor == null)
            {
                return(new erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor(new ILexerAction[] { lexerAction }));
            }
            ILexerAction[] lexerActions = Arrays.CopyOf(lexerActionExecutor.lexerActions, lexerActionExecutor.lexerActions.Length + 1);

            lexerActions[lexerActions.Length - 1] = lexerAction;
            return(new erl.Oracle.TnsNames.Antlr4.Runtime.Atn.LexerActionExecutor(lexerActions));
        }
Пример #9
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);
        }