forked from jasder/antlr
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
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "action_"+ruleIndex+":"+actionIndex;
|
return "action_"+ruleIndex+":"+actionIndex;
|
||||||
|
|
|
@ -51,6 +51,11 @@ public final class AtomTransition extends Transition {
|
||||||
@NotNull
|
@NotNull
|
||||||
public IntervalSet label() { return IntervalSet.of(label); }
|
public IntervalSet label() { return IntervalSet.of(label); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return label == symbol;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -42,6 +42,11 @@ public final class EpsilonTransition extends Transition {
|
||||||
@Override
|
@Override
|
||||||
public boolean isEpsilon() { return true; }
|
public boolean isEpsilon() { return true; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -491,66 +491,11 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ATNState getReachableTarget(Transition trans, int t) {
|
public ATNState getReachableTarget(Transition trans, int t) {
|
||||||
switch (trans.getSerializationType()) {
|
if (trans.matches(t, Lexer.MIN_CHAR_VALUE, Lexer.MAX_CHAR_VALUE)) {
|
||||||
case Transition.ATOM:
|
return trans.target;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -43,6 +43,13 @@ public final class NotSetTransition extends SetTransition {
|
||||||
return NOT_SET;
|
return NOT_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return symbol >= minVocabSymbol
|
||||||
|
&& symbol <= maxVocabSymbol
|
||||||
|
&& !super.matches(symbol, minVocabSymbol, maxVocabSymbol);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return '~'+super.toString();
|
return '~'+super.toString();
|
||||||
|
|
|
@ -913,44 +913,11 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ATNState getReachableTarget(@NotNull Transition trans, int ttype) {
|
public ATNState getReachableTarget(@NotNull Transition trans, int ttype) {
|
||||||
switch (trans.getSerializationType()) {
|
if (trans.matches(ttype, 0, atn.maxTokenType)) {
|
||||||
case Transition.ATOM:
|
return trans.target;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SemanticContext[] getPredsForAmbigAlts(@NotNull BitSet ambigAlts,
|
public SemanticContext[] getPredsForAmbigAlts(@NotNull BitSet ambigAlts,
|
||||||
|
|
|
@ -57,6 +57,11 @@ public final class PredicateTransition extends Transition {
|
||||||
@Override
|
@Override
|
||||||
public boolean isEpsilon() { return true; }
|
public boolean isEpsilon() { return true; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public SemanticContext.Predicate getPredicate() {
|
public SemanticContext.Predicate getPredicate() {
|
||||||
return new SemanticContext.Predicate(ruleIndex, predIndex, isCtxDependent);
|
return new SemanticContext.Predicate(ruleIndex, predIndex, isCtxDependent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,11 @@ public final class RangeTransition extends Transition {
|
||||||
@NotNull
|
@NotNull
|
||||||
public IntervalSet label() { return IntervalSet.of(from, to); }
|
public IntervalSet label() { return IntervalSet.of(from, to); }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return symbol >= from && symbol <= to;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -56,4 +56,9 @@ public final class RuleTransition extends Transition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEpsilon() { return true; }
|
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
|
@NotNull
|
||||||
public IntervalSet label() { return set; }
|
public IntervalSet label() { return set; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return set.contains(symbol);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
|
@ -110,4 +110,6 @@ public abstract class Transition {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public IntervalSet label() { return null; }
|
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;
|
return WILDCARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(int symbol, int minVocabSymbol, int maxVocabSymbol) {
|
||||||
|
return symbol >= minVocabSymbol && symbol <= maxVocabSymbol;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
Loading…
Reference in New Issue