Merge branch 'get-reachable-target' of git://github.com/sharwell/antlr4
This commit is contained in:
commit
4f918f75bc
|
@ -57,6 +57,11 @@ public final class ActionTransition extends Transition {
|
|||
return true; // we are to be ignored by analysis 'cept for predicates
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "action_"+ruleIndex+":"+actionIndex;
|
||||
|
|
|
@ -51,6 +51,11 @@ public final class AtomTransition extends Transition {
|
|||
@NotNull
|
||||
public IntervalSet label() { return IntervalSet.of(label); }
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return label == symbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
|
|
@ -42,6 +42,11 @@ public final class EpsilonTransition extends Transition {
|
|||
@Override
|
||||
public boolean isEpsilon() { return true; }
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
|
|
@ -491,66 +491,11 @@ public class LexerATNSimulator extends ATNSimulator {
|
|||
|
||||
@Nullable
|
||||
public ATNState getReachableTarget(Transition trans, int t) {
|
||||
switch (trans.getSerializationType()) {
|
||||
case Transition.ATOM:
|
||||
AtomTransition at = (AtomTransition)trans;
|
||||
if ( at.label == t ) {
|
||||
if ( debug ) {
|
||||
System.out.format("match %s\n", getTokenName(at.label));
|
||||
}
|
||||
|
||||
return at.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
case Transition.RANGE:
|
||||
RangeTransition rt = (RangeTransition)trans;
|
||||
if ( t>=rt.from && t<=rt.to ) {
|
||||
if ( debug ) {
|
||||
System.out.format("match range %s\n", rt);
|
||||
}
|
||||
|
||||
return rt.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
case Transition.SET:
|
||||
SetTransition st = (SetTransition)trans;
|
||||
if ( st.set.contains(t) ) {
|
||||
if ( debug ) {
|
||||
System.out.format("match set %s\n", st.set.toString(true));
|
||||
}
|
||||
|
||||
return st.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
case Transition.NOT_SET:
|
||||
NotSetTransition nst = (NotSetTransition)trans;
|
||||
if (!nst.set.contains(t) && t!=IntStream.EOF) // ~set doesn't not match EOF
|
||||
{
|
||||
if ( debug ) {
|
||||
System.out.format("match ~set %s\n", nst.set.toString(true));
|
||||
}
|
||||
|
||||
return nst.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
case Transition.WILDCARD:
|
||||
if (t != IntStream.EOF) {
|
||||
return trans.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
if (trans.matches(t, Lexer.MIN_CHAR_VALUE, Lexer.MAX_CHAR_VALUE)) {
|
||||
return trans.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
|
|
@ -43,6 +43,13 @@ public final class NotSetTransition extends SetTransition {
|
|||
return NOT_SET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return symbol >= minVocabSymbol
|
||||
&& symbol <= maxVocabSymbol
|
||||
&& !super.matches(symbol, minVocabSymbol, maxVocabSymbol);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return '~'+super.toString();
|
||||
|
|
|
@ -913,44 +913,11 @@ public class ParserATNSimulator extends ATNSimulator {
|
|||
|
||||
@Nullable
|
||||
public ATNState getReachableTarget(@NotNull Transition trans, int ttype) {
|
||||
switch (trans.getSerializationType()) {
|
||||
case Transition.ATOM:
|
||||
AtomTransition at = (AtomTransition)trans;
|
||||
if ( at.label == ttype ) {
|
||||
return at.target;
|
||||
}
|
||||
return null;
|
||||
|
||||
case Transition.SET:
|
||||
SetTransition st = (SetTransition)trans;
|
||||
if ( st.set.contains(ttype) ) {
|
||||
return st.target;
|
||||
}
|
||||
return null;
|
||||
|
||||
case Transition.NOT_SET:
|
||||
NotSetTransition nst = (NotSetTransition)trans;
|
||||
if ( !nst.set.contains(ttype) ) {
|
||||
return nst.target;
|
||||
}
|
||||
return null;
|
||||
|
||||
case Transition.RANGE:
|
||||
RangeTransition rt = (RangeTransition)trans;
|
||||
if ( ttype>=rt.from && ttype<=rt.to ) {
|
||||
return rt.target;
|
||||
}
|
||||
return null;
|
||||
|
||||
case Transition.WILDCARD:
|
||||
if (ttype != Token.EOF) {
|
||||
return trans.target;
|
||||
}
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
if (trans.matches(ttype, 0, atn.maxTokenType)) {
|
||||
return trans.target;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public SemanticContext[] getPredsForAmbigAlts(@NotNull BitSet ambigAlts,
|
||||
|
|
|
@ -57,6 +57,11 @@ public final class PredicateTransition extends Transition {
|
|||
@Override
|
||||
public boolean isEpsilon() { return true; }
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public SemanticContext.Predicate getPredicate() {
|
||||
return new SemanticContext.Predicate(ruleIndex, predIndex, isCtxDependent);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,11 @@ public final class RangeTransition extends Transition {
|
|||
@NotNull
|
||||
public IntervalSet label() { return IntervalSet.of(from, to); }
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return symbol >= from && symbol <= to;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
|
|
@ -56,4 +56,9 @@ public final class RuleTransition extends Transition {
|
|||
|
||||
@Override
|
||||
public boolean isEpsilon() { return true; }
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,11 @@ public class SetTransition extends Transition {
|
|||
@NotNull
|
||||
public IntervalSet label() { return set; }
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return set.contains(symbol);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
|
|
@ -110,4 +110,6 @@ public abstract class Transition {
|
|||
|
||||
@Nullable
|
||||
public IntervalSet label() { return null; }
|
||||
|
||||
public abstract boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,11 @@ public final class WildcardTransition extends Transition {
|
|||
return WILDCARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String toString() {
|
||||
|
|
Loading…
Reference in New Issue