Matches() public abstract method

public abstract Matches ( int symbol, int minVocabSymbol, int maxVocabSymbol ) : bool
symbol int
minVocabSymbol int
maxVocabSymbol int
return bool
Example #1
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;
                }
                goto case TransitionType.Epsilon;
            }

            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);
        }
Example #2
0
        protected ATNConfig GetEpsilonTarget(ATNConfig config,
										  Transition t,
										  bool collectPredicates,
										  bool inContext,
										  bool fullCtx,
										  bool treatEofAsEpsilon)
        {
            switch (t.TransitionType)
            {
                case TransitionType.RULE:
                    return RuleTransition(config, (RuleTransition)t);

                case TransitionType.PRECEDENCE:
                    return PrecedenceTransition(config, (PrecedencePredicateTransition)t, collectPredicates, inContext, fullCtx);

                case TransitionType.PREDICATE:
                    return PredTransition(config, (PredicateTransition)t,
                                          collectPredicates,
                                          inContext,
                                          fullCtx);

                case TransitionType.ACTION:
                    return ActionTransition(config, (ActionTransition)t);

                case TransitionType.EPSILON:
                    return new ATNConfig(config, t.target);

                case TransitionType.ATOM:
                case TransitionType.RANGE:
                case TransitionType.SET:
                    // EOF transitions act like epsilon transitions after the first EOF
                    // transition is traversed
                    if (treatEofAsEpsilon)
                    {
                        if (t.Matches(TokenConstants.EOF, 0, 1))
                        {
                            return new ATNConfig(config, t.target);
                        }
                    }

                    return null;

                default:
                    return null;
            }
        }
Example #3
0
        protected ATNState GetReachableTarget(Transition trans, int ttype)
        {
            if (trans.Matches(ttype, 0, atn.maxTokenType))
            {
                return trans.target;
            }

            return null;
        }
Example #4
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:
                {
                    /*  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;
        }
Example #5
0
 protected internal virtual ATNState GetReachableTarget(Transition trans, int t)
 {
     if (trans.Matches(t, char.MinValue, char.MaxValue))
     {
         return trans.target;
     }
     return null;
 }
Example #6
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);
        }
Example #7
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)
                {
                    Console.WriteLine("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);
        }
Example #8
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)
                    {
                        Console.WriteLine("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, char.MinValue, char.MaxValue))
                        {
                            c = new LexerATNConfig(config, t.target);
                            break;
                        }
                    }

                    break;
            }

            return c;
        }
Example #9
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;
        }
 public virtual ATNState GetReachableTarget(Transition trans, int t)
 {
     if (trans.Matches(t, Lexer.MinCharValue, Lexer.MaxCharValue))
     {
         return trans.target;
     }
     return null;
 }