forked from jasder/antlr
Add the StateType and TransitionType enumerations; more properties
This commit is contained in:
parent
a47fde57b2
commit
e0044cc4dd
|
@ -82,8 +82,10 @@
|
|||
<Compile Include="Atn\StarBlockStartState.cs" />
|
||||
<Compile Include="Atn\StarLoopbackState.cs" />
|
||||
<Compile Include="Atn\StarLoopEntryState.cs" />
|
||||
<Compile Include="Atn\StateType.cs" />
|
||||
<Compile Include="Atn\TokensStartState.cs" />
|
||||
<Compile Include="Atn\Transition.cs" />
|
||||
<Compile Include="Atn\TransitionType.cs" />
|
||||
<Compile Include="Atn\WildcardTransition.cs" />
|
||||
<Compile Include="BailErrorStrategy.cs" />
|
||||
<Compile Include="BaseErrorListener.cs" />
|
||||
|
|
|
@ -109,16 +109,16 @@ namespace Antlr4.Runtime.Atn
|
|||
int nstates = ToInt(data[p++]);
|
||||
for (int i_1 = 1; i_1 <= nstates; i_1++)
|
||||
{
|
||||
int stype = ToInt(data[p++]);
|
||||
StateType stype = StateType.Values()[ToInt(data[p++])];
|
||||
// ignore bad type of states
|
||||
if (stype == ATNState.InvalidType)
|
||||
if (stype == StateType.InvalidType)
|
||||
{
|
||||
atn.AddState(null);
|
||||
continue;
|
||||
}
|
||||
int ruleIndex = ToInt(data[p++]);
|
||||
ATNState s = StateFactory(stype, ruleIndex);
|
||||
if (stype == ATNState.LoopEnd)
|
||||
if (stype == StateType.LoopEnd)
|
||||
{
|
||||
// special case
|
||||
int loopBackStateNumber = ToInt(data[p++]);
|
||||
|
@ -234,7 +234,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
int src = ToInt(data[p]);
|
||||
int trg = ToInt(data[p + 1]);
|
||||
int ttype = ToInt(data[p + 2]);
|
||||
TransitionType ttype = TransitionType.Values()[ToInt(data[p + 2])];
|
||||
int arg1 = ToInt(data[p + 3]);
|
||||
int arg2 = ToInt(data[p + 4]);
|
||||
int arg3 = ToInt(data[p + 5]);
|
||||
|
@ -252,7 +252,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
bool returningToLeftFactored = state_1.ruleIndex >= 0 && atn.ruleToStartState[state_1
|
||||
.ruleIndex].leftFactored;
|
||||
for (int i_10 = 0; i_10 < state_1.GetNumberOfTransitions(); i_10++)
|
||||
for (int i_10 = 0; i_10 < state_1.NumberOfTransitions; i_10++)
|
||||
{
|
||||
Transition t = state_1.Transition(i_10);
|
||||
if (!(t is RuleTransition))
|
||||
|
@ -289,7 +289,7 @@ namespace Antlr4.Runtime.Atn
|
|||
if (state_2 is PlusLoopbackState)
|
||||
{
|
||||
PlusLoopbackState loopbackState = (PlusLoopbackState)state_2;
|
||||
for (int i_10 = 0; i_10 < loopbackState.GetNumberOfTransitions(); i_10++)
|
||||
for (int i_10 = 0; i_10 < loopbackState.NumberOfTransitions; i_10++)
|
||||
{
|
||||
ATNState target = loopbackState.Transition(i_10).target;
|
||||
if (target is PlusBlockStartState)
|
||||
|
@ -303,7 +303,7 @@ namespace Antlr4.Runtime.Atn
|
|||
if (state_2 is StarLoopbackState)
|
||||
{
|
||||
StarLoopbackState loopbackState = (StarLoopbackState)state_2;
|
||||
for (int i_10 = 0; i_10 < loopbackState.GetNumberOfTransitions(); i_10++)
|
||||
for (int i_10 = 0; i_10 < loopbackState.NumberOfTransitions; i_10++)
|
||||
{
|
||||
ATNState target = loopbackState.Transition(i_10).target;
|
||||
if (target is StarLoopEntryState)
|
||||
|
@ -359,8 +359,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
continue;
|
||||
}
|
||||
CheckCondition(state.OnlyHasEpsilonTransitions() || state.GetNumberOfTransitions(
|
||||
) <= 1);
|
||||
CheckCondition(state.OnlyHasEpsilonTransitions || state.NumberOfTransitions <= 1);
|
||||
if (state is PlusBlockStartState)
|
||||
{
|
||||
CheckCondition(((PlusBlockStartState)state).loopBackState != null);
|
||||
|
@ -369,7 +368,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
StarLoopEntryState starLoopEntryState = (StarLoopEntryState)state;
|
||||
CheckCondition(starLoopEntryState.loopBackState != null);
|
||||
CheckCondition(starLoopEntryState.GetNumberOfTransitions() == 2);
|
||||
CheckCondition(starLoopEntryState.NumberOfTransitions == 2);
|
||||
if (starLoopEntryState.Transition(0).target is StarBlockStartState)
|
||||
{
|
||||
CheckCondition(starLoopEntryState.Transition(1).target is LoopEndState);
|
||||
|
@ -390,7 +389,7 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
if (state is StarLoopbackState)
|
||||
{
|
||||
CheckCondition(state.GetNumberOfTransitions() == 1);
|
||||
CheckCondition(state.NumberOfTransitions == 1);
|
||||
CheckCondition(state.Transition(0).target is StarLoopEntryState);
|
||||
}
|
||||
if (state is LoopEndState)
|
||||
|
@ -412,12 +411,12 @@ namespace Antlr4.Runtime.Atn
|
|||
if (state is DecisionState)
|
||||
{
|
||||
DecisionState decisionState = (DecisionState)state;
|
||||
CheckCondition(decisionState.GetNumberOfTransitions() <= 1 || decisionState.decision
|
||||
>= 0);
|
||||
CheckCondition(decisionState.NumberOfTransitions <= 1 || decisionState.decision >=
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckCondition(state.GetNumberOfTransitions() <= 1 || state is RuleStopState);
|
||||
CheckCondition(state.NumberOfTransitions <= 1 || state is RuleStopState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -444,36 +443,36 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
RuleStartState startState = atn.ruleToStartState[i];
|
||||
ATNState middleState = startState;
|
||||
while (middleState.OnlyHasEpsilonTransitions() && middleState.GetNumberOfOptimizedTransitions
|
||||
() == 1 && middleState.GetOptimizedTransition(0).SerializationType == Transition
|
||||
while (middleState.OnlyHasEpsilonTransitions && middleState.NumberOfOptimizedTransitions
|
||||
== 1 && middleState.GetOptimizedTransition(0).TransitionType == TransitionType
|
||||
.Epsilon)
|
||||
{
|
||||
middleState = middleState.GetOptimizedTransition(0).target;
|
||||
}
|
||||
if (middleState.GetNumberOfOptimizedTransitions() != 1)
|
||||
if (middleState.NumberOfOptimizedTransitions != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Transition matchTransition = middleState.GetOptimizedTransition(0);
|
||||
ATNState matchTarget = matchTransition.target;
|
||||
if (matchTransition.IsEpsilon || !matchTarget.OnlyHasEpsilonTransitions() || matchTarget
|
||||
.GetNumberOfOptimizedTransitions() != 1 || !(matchTarget.GetOptimizedTransition
|
||||
(0).target is RuleStopState))
|
||||
if (matchTransition.IsEpsilon || !matchTarget.OnlyHasEpsilonTransitions || matchTarget
|
||||
.NumberOfOptimizedTransitions != 1 || !(matchTarget.GetOptimizedTransition(0)
|
||||
.target is RuleStopState))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
switch (matchTransition.SerializationType)
|
||||
switch (matchTransition.TransitionType)
|
||||
{
|
||||
case Transition.Atom:
|
||||
case Transition.Range:
|
||||
case Transition.Set:
|
||||
case TransitionType.Atom:
|
||||
case TransitionType.Range:
|
||||
case TransitionType.Set:
|
||||
{
|
||||
ruleToInlineTransition[i] = matchTransition;
|
||||
break;
|
||||
}
|
||||
|
||||
case Transition.NotSet:
|
||||
case Transition.Wildcard:
|
||||
case TransitionType.NotSet:
|
||||
case TransitionType.Wildcard:
|
||||
{
|
||||
// not implemented yet
|
||||
continue;
|
||||
|
@ -495,7 +494,7 @@ namespace Antlr4.Runtime.Atn
|
|||
continue;
|
||||
}
|
||||
IList<Transition> optimizedTransitions = null;
|
||||
for (int i_1 = 0; i_1 < state.GetNumberOfOptimizedTransitions(); i_1++)
|
||||
for (int i_1 = 0; i_1 < state.NumberOfOptimizedTransitions; i_1++)
|
||||
{
|
||||
Transition transition = state.GetOptimizedTransition(i_1);
|
||||
if (!(transition is RuleTransition))
|
||||
|
@ -530,23 +529,23 @@ namespace Antlr4.Runtime.Atn
|
|||
intermediateState.SetRuleIndex(target.ruleIndex);
|
||||
atn.AddState(intermediateState);
|
||||
optimizedTransitions.AddItem(new EpsilonTransition(intermediateState));
|
||||
switch (effective.SerializationType)
|
||||
switch (effective.TransitionType)
|
||||
{
|
||||
case Transition.Atom:
|
||||
case TransitionType.Atom:
|
||||
{
|
||||
intermediateState.AddTransition(new AtomTransition(target, ((AtomTransition)effective
|
||||
).label));
|
||||
break;
|
||||
}
|
||||
|
||||
case Transition.Range:
|
||||
case TransitionType.Range:
|
||||
{
|
||||
intermediateState.AddTransition(new RangeTransition(target, ((RangeTransition)effective
|
||||
).from, ((RangeTransition)effective).to));
|
||||
break;
|
||||
}
|
||||
|
||||
case Transition.Set:
|
||||
case TransitionType.Set:
|
||||
{
|
||||
intermediateState.AddTransition(new SetTransition(target, effective.Label));
|
||||
break;
|
||||
|
@ -560,11 +559,11 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
if (optimizedTransitions != null)
|
||||
{
|
||||
if (state.IsOptimized())
|
||||
if (state.IsOptimized)
|
||||
{
|
||||
while (state.GetNumberOfOptimizedTransitions() > 0)
|
||||
while (state.NumberOfOptimizedTransitions > 0)
|
||||
{
|
||||
state.RemoveOptimizedTransition(state.GetNumberOfOptimizedTransitions() - 1);
|
||||
state.RemoveOptimizedTransition(state.NumberOfOptimizedTransitions - 1);
|
||||
}
|
||||
}
|
||||
foreach (Transition transition in optimizedTransitions)
|
||||
|
@ -581,17 +580,17 @@ namespace Antlr4.Runtime.Atn
|
|||
int removedEdges = 0;
|
||||
foreach (ATNState state in atn.states)
|
||||
{
|
||||
if (!state.OnlyHasEpsilonTransitions() || state is RuleStopState)
|
||||
if (!state.OnlyHasEpsilonTransitions || state is RuleStopState)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IList<Transition> optimizedTransitions = null;
|
||||
for (int i = 0; i < state.GetNumberOfOptimizedTransitions(); i++)
|
||||
for (int i = 0; i < state.NumberOfOptimizedTransitions; i++)
|
||||
{
|
||||
Transition transition = state.GetOptimizedTransition(i);
|
||||
ATNState intermediate = transition.target;
|
||||
if (transition.SerializationType != Transition.Epsilon || intermediate.GetStateType
|
||||
() != ATNState.Basic || !intermediate.OnlyHasEpsilonTransitions())
|
||||
if (transition.TransitionType != TransitionType.Epsilon || intermediate.StateType
|
||||
!= StateType.Basic || !intermediate.OnlyHasEpsilonTransitions)
|
||||
{
|
||||
if (optimizedTransitions != null)
|
||||
{
|
||||
|
@ -599,9 +598,9 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
goto nextTransition_continue;
|
||||
}
|
||||
for (int j = 0; j < intermediate.GetNumberOfOptimizedTransitions(); j++)
|
||||
for (int j = 0; j < intermediate.NumberOfOptimizedTransitions; j++)
|
||||
{
|
||||
if (intermediate.GetOptimizedTransition(j).SerializationType != Transition.Epsilon)
|
||||
if (intermediate.GetOptimizedTransition(j).TransitionType != TransitionType.Epsilon)
|
||||
{
|
||||
if (optimizedTransitions != null)
|
||||
{
|
||||
|
@ -619,7 +618,7 @@ namespace Antlr4.Runtime.Atn
|
|||
optimizedTransitions.AddItem(state.GetOptimizedTransition(j_1));
|
||||
}
|
||||
}
|
||||
for (int j_2 = 0; j_2 < intermediate.GetNumberOfOptimizedTransitions(); j_2++)
|
||||
for (int j_2 = 0; j_2 < intermediate.NumberOfOptimizedTransitions; j_2++)
|
||||
{
|
||||
ATNState target = intermediate.GetOptimizedTransition(j_2).target;
|
||||
optimizedTransitions.AddItem(new EpsilonTransition(target));
|
||||
|
@ -629,11 +628,11 @@ nextTransition_continue: ;
|
|||
nextTransition_break: ;
|
||||
if (optimizedTransitions != null)
|
||||
{
|
||||
if (state.IsOptimized())
|
||||
if (state.IsOptimized)
|
||||
{
|
||||
while (state.GetNumberOfOptimizedTransitions() > 0)
|
||||
while (state.NumberOfOptimizedTransitions > 0)
|
||||
{
|
||||
state.RemoveOptimizedTransition(state.GetNumberOfOptimizedTransitions() - 1);
|
||||
state.RemoveOptimizedTransition(state.NumberOfOptimizedTransitions - 1);
|
||||
}
|
||||
}
|
||||
foreach (Transition transition in optimizedTransitions)
|
||||
|
@ -658,14 +657,14 @@ nextState_break: ;
|
|||
foreach (DecisionState decision in decisions)
|
||||
{
|
||||
IntervalSet setTransitions = new IntervalSet();
|
||||
for (int i = 0; i < decision.GetNumberOfOptimizedTransitions(); i++)
|
||||
for (int i = 0; i < decision.NumberOfOptimizedTransitions; i++)
|
||||
{
|
||||
Transition epsTransition = decision.GetOptimizedTransition(i);
|
||||
if (!(epsTransition is EpsilonTransition))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (epsTransition.target.GetNumberOfOptimizedTransitions() != 1)
|
||||
if (epsTransition.target.NumberOfOptimizedTransitions != 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -690,7 +689,7 @@ nextState_break: ;
|
|||
continue;
|
||||
}
|
||||
IList<Transition> optimizedTransitions = new List<Transition>();
|
||||
for (int i_1 = 0; i_1 < decision.GetNumberOfOptimizedTransitions(); i_1++)
|
||||
for (int i_1 = 0; i_1 < decision.NumberOfOptimizedTransitions; i_1++)
|
||||
{
|
||||
if (!setTransitions.Contains(i_1))
|
||||
{
|
||||
|
@ -740,14 +739,12 @@ nextState_break: ;
|
|||
atn.AddState(setOptimizedState);
|
||||
setOptimizedState.AddTransition(newTransition);
|
||||
optimizedTransitions.AddItem(new EpsilonTransition(setOptimizedState));
|
||||
removedPaths += decision.GetNumberOfOptimizedTransitions() - optimizedTransitions
|
||||
.Count;
|
||||
if (decision.IsOptimized())
|
||||
removedPaths += decision.NumberOfOptimizedTransitions - optimizedTransitions.Count;
|
||||
if (decision.IsOptimized)
|
||||
{
|
||||
while (decision.GetNumberOfOptimizedTransitions() > 0)
|
||||
while (decision.NumberOfOptimizedTransitions > 0)
|
||||
{
|
||||
decision.RemoveOptimizedTransition(decision.GetNumberOfOptimizedTransitions() - 1
|
||||
);
|
||||
decision.RemoveOptimizedTransition(decision.NumberOfOptimizedTransitions - 1);
|
||||
}
|
||||
}
|
||||
foreach (Transition transition_1 in optimizedTransitions)
|
||||
|
@ -772,7 +769,7 @@ nextState_break: ;
|
|||
ruleTransition.tailCall = TestTailCall(atn, ruleTransition, false);
|
||||
ruleTransition.optimizedTailCall = TestTailCall(atn, ruleTransition, true);
|
||||
}
|
||||
if (!state.IsOptimized())
|
||||
if (!state.IsOptimized)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -814,7 +811,7 @@ nextState_break: ;
|
|||
{
|
||||
continue;
|
||||
}
|
||||
if (!state.OnlyHasEpsilonTransitions())
|
||||
if (!state.OnlyHasEpsilonTransitions)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -822,7 +819,7 @@ nextState_break: ;
|
|||
.transitions;
|
||||
foreach (Transition t in transitions)
|
||||
{
|
||||
if (t.SerializationType != Transition.Epsilon)
|
||||
if (t.TransitionType != TransitionType.Epsilon)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -838,62 +835,62 @@ nextState_break: ;
|
|||
}
|
||||
|
||||
[NotNull]
|
||||
public static Transition EdgeFactory(ATN atn, int type, int src, int trg, int arg1
|
||||
, int arg2, int arg3, IList<IntervalSet> sets)
|
||||
public static Transition EdgeFactory(ATN atn, TransitionType type, int src, int trg
|
||||
, int arg1, int arg2, int arg3, IList<IntervalSet> sets)
|
||||
{
|
||||
ATNState target = atn.states[trg];
|
||||
switch (type)
|
||||
{
|
||||
case Transition.Epsilon:
|
||||
case TransitionType.Epsilon:
|
||||
{
|
||||
return new EpsilonTransition(target);
|
||||
}
|
||||
|
||||
case Transition.Range:
|
||||
case TransitionType.Range:
|
||||
{
|
||||
return new RangeTransition(target, arg1, arg2);
|
||||
}
|
||||
|
||||
case Transition.Rule:
|
||||
case TransitionType.Rule:
|
||||
{
|
||||
RuleTransition rt = new RuleTransition((RuleStartState)atn.states[arg1], arg2, arg3
|
||||
, target);
|
||||
return rt;
|
||||
}
|
||||
|
||||
case Transition.Predicate:
|
||||
case TransitionType.Predicate:
|
||||
{
|
||||
PredicateTransition pt = new PredicateTransition(target, arg1, arg2, arg3 != 0);
|
||||
return pt;
|
||||
}
|
||||
|
||||
case Transition.Precedence:
|
||||
case TransitionType.Precedence:
|
||||
{
|
||||
return new PrecedencePredicateTransition(target, arg1);
|
||||
}
|
||||
|
||||
case Transition.Atom:
|
||||
case TransitionType.Atom:
|
||||
{
|
||||
return new AtomTransition(target, arg1);
|
||||
}
|
||||
|
||||
case Transition.Action:
|
||||
case TransitionType.Action:
|
||||
{
|
||||
ActionTransition a = new ActionTransition(target, arg1, arg2, arg3 != 0);
|
||||
return a;
|
||||
}
|
||||
|
||||
case Transition.Set:
|
||||
case TransitionType.Set:
|
||||
{
|
||||
return new SetTransition(target, sets[arg1]);
|
||||
}
|
||||
|
||||
case Transition.NotSet:
|
||||
case TransitionType.NotSet:
|
||||
{
|
||||
return new NotSetTransition(target, sets[arg1]);
|
||||
}
|
||||
|
||||
case Transition.Wildcard:
|
||||
case TransitionType.Wildcard:
|
||||
{
|
||||
return new WildcardTransition(target);
|
||||
}
|
||||
|
@ -901,83 +898,83 @@ nextState_break: ;
|
|||
throw new ArgumentException("The specified transition type is not valid.");
|
||||
}
|
||||
|
||||
public static ATNState StateFactory(int type, int ruleIndex)
|
||||
public static ATNState StateFactory(StateType type, int ruleIndex)
|
||||
{
|
||||
ATNState s;
|
||||
switch (type)
|
||||
{
|
||||
case ATNState.InvalidType:
|
||||
case StateType.InvalidType:
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
case ATNState.Basic:
|
||||
case StateType.Basic:
|
||||
{
|
||||
s = new BasicState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.RuleStart:
|
||||
case StateType.RuleStart:
|
||||
{
|
||||
s = new RuleStartState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.BlockStart:
|
||||
case StateType.BlockStart:
|
||||
{
|
||||
s = new BasicBlockStartState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.PlusBlockStart:
|
||||
case StateType.PlusBlockStart:
|
||||
{
|
||||
s = new PlusBlockStartState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.StarBlockStart:
|
||||
case StateType.StarBlockStart:
|
||||
{
|
||||
s = new StarBlockStartState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.TokenStart:
|
||||
case StateType.TokenStart:
|
||||
{
|
||||
s = new TokensStartState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.RuleStop:
|
||||
case StateType.RuleStop:
|
||||
{
|
||||
s = new RuleStopState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.BlockEnd:
|
||||
case StateType.BlockEnd:
|
||||
{
|
||||
s = new BlockEndState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.StarLoopBack:
|
||||
case StateType.StarLoopBack:
|
||||
{
|
||||
s = new StarLoopbackState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.StarLoopEntry:
|
||||
case StateType.StarLoopEntry:
|
||||
{
|
||||
s = new StarLoopEntryState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.PlusLoopBack:
|
||||
case StateType.PlusLoopBack:
|
||||
{
|
||||
s = new PlusLoopbackState();
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.LoopEnd:
|
||||
case StateType.LoopEnd:
|
||||
{
|
||||
s = new LoopEndState();
|
||||
break;
|
||||
|
|
|
@ -94,32 +94,6 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
public const int InitialNumTransitions = 4;
|
||||
|
||||
public const int InvalidType = 0;
|
||||
|
||||
public const int Basic = 1;
|
||||
|
||||
public const int RuleStart = 2;
|
||||
|
||||
public const int BlockStart = 3;
|
||||
|
||||
public const int PlusBlockStart = 4;
|
||||
|
||||
public const int StarBlockStart = 5;
|
||||
|
||||
public const int TokenStart = 6;
|
||||
|
||||
public const int RuleStop = 7;
|
||||
|
||||
public const int BlockEnd = 8;
|
||||
|
||||
public const int StarLoopBack = 9;
|
||||
|
||||
public const int StarLoopEntry = 10;
|
||||
|
||||
public const int PlusLoopBack = 11;
|
||||
|
||||
public const int LoopEnd = 12;
|
||||
|
||||
public static readonly IList<string> serializationNames = Sharpen.Collections.UnmodifiableList
|
||||
(Arrays.AsList("INVALID", "BASIC", "RULE_START", "BLOCK_START", "PLUS_BLOCK_START"
|
||||
, "STAR_BLOCK_START", "TOKEN_START", "RULE_STOP", "BLOCK_END", "STAR_LOOP_BACK"
|
||||
|
@ -146,14 +120,16 @@ namespace Antlr4.Runtime.Atn
|
|||
/// <summary>Used to cache lookahead during parsing, not used during construction</summary>
|
||||
public IntervalSet nextTokenWithinRule;
|
||||
|
||||
// constants for serialization
|
||||
// at runtime, we don't have Rule objects
|
||||
/// <summary>Gets the state number.</summary>
|
||||
/// <remarks>Gets the state number.</remarks>
|
||||
/// <returns>the state number</returns>
|
||||
public int GetStateNumber()
|
||||
public int StateNumber
|
||||
{
|
||||
return stateNumber;
|
||||
get
|
||||
{
|
||||
// at runtime, we don't have Rule objects
|
||||
return stateNumber;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -167,9 +143,12 @@ namespace Antlr4.Runtime.Atn
|
|||
/// <see cref="RuleStopState">RuleStopState</see>
|
||||
/// , otherwise the state number
|
||||
/// </returns>
|
||||
public virtual int GetNonStopStateNumber()
|
||||
public virtual int NonStopStateNumber
|
||||
{
|
||||
return GetStateNumber();
|
||||
get
|
||||
{
|
||||
return StateNumber;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
@ -187,9 +166,12 @@ namespace Antlr4.Runtime.Atn
|
|||
return false;
|
||||
}
|
||||
|
||||
public virtual bool IsNonGreedyExitState()
|
||||
public virtual bool IsNonGreedyExitState
|
||||
{
|
||||
return false;
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
@ -203,9 +185,12 @@ namespace Antlr4.Runtime.Atn
|
|||
[transitions.Count]);
|
||||
}
|
||||
|
||||
public virtual int GetNumberOfTransitions()
|
||||
public virtual int NumberOfTransitions
|
||||
{
|
||||
return transitions.Count;
|
||||
get
|
||||
{
|
||||
return transitions.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void AddTransition(Antlr4.Runtime.Atn.Transition e)
|
||||
|
@ -241,11 +226,17 @@ namespace Antlr4.Runtime.Atn
|
|||
return transitions.Remove(index);
|
||||
}
|
||||
|
||||
public abstract int GetStateType();
|
||||
|
||||
public bool OnlyHasEpsilonTransitions()
|
||||
public abstract Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return epsilonOnlyTransitions;
|
||||
get;
|
||||
}
|
||||
|
||||
public bool OnlyHasEpsilonTransitions
|
||||
{
|
||||
get
|
||||
{
|
||||
return epsilonOnlyTransitions;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetRuleIndex(int ruleIndex)
|
||||
|
@ -253,14 +244,20 @@ namespace Antlr4.Runtime.Atn
|
|||
this.ruleIndex = ruleIndex;
|
||||
}
|
||||
|
||||
public virtual bool IsOptimized()
|
||||
public virtual bool IsOptimized
|
||||
{
|
||||
return optimizedTransitions != transitions;
|
||||
get
|
||||
{
|
||||
return optimizedTransitions != transitions;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int GetNumberOfOptimizedTransitions()
|
||||
public virtual int NumberOfOptimizedTransitions
|
||||
{
|
||||
return optimizedTransitions.Count;
|
||||
get
|
||||
{
|
||||
return optimizedTransitions.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Antlr4.Runtime.Atn.Transition GetOptimizedTransition(int i)
|
||||
|
@ -270,7 +267,7 @@ namespace Antlr4.Runtime.Atn
|
|||
|
||||
public virtual void AddOptimizedTransition(Antlr4.Runtime.Atn.Transition e)
|
||||
{
|
||||
if (!IsOptimized())
|
||||
if (!IsOptimized)
|
||||
{
|
||||
optimizedTransitions = new List<Antlr4.Runtime.Atn.Transition>();
|
||||
}
|
||||
|
@ -280,7 +277,7 @@ namespace Antlr4.Runtime.Atn
|
|||
public virtual void SetOptimizedTransition(int i, Antlr4.Runtime.Atn.Transition e
|
||||
)
|
||||
{
|
||||
if (!IsOptimized())
|
||||
if (!IsOptimized)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
@ -289,7 +286,7 @@ namespace Antlr4.Runtime.Atn
|
|||
|
||||
public virtual void RemoveOptimizedTransition(int i)
|
||||
{
|
||||
if (!IsOptimized())
|
||||
if (!IsOptimized)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
|
|
@ -54,11 +54,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.isCtxDependent = isCtxDependent;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Action;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Action;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.label = label;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Atom;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Atom;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,12 @@ namespace Antlr4.Runtime.Atn
|
|||
/// <author>Sam Harwell</author>
|
||||
public sealed class BasicBlockStartState : BlockStartState
|
||||
{
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return BlockStart;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.BlockStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,9 +35,12 @@ namespace Antlr4.Runtime.Atn
|
|||
/// <author>Sam Harwell</author>
|
||||
public sealed class BasicState : ATNState
|
||||
{
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return Basic;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.Basic;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,12 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
public BlockStartState startState;
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return BlockEnd;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.BlockEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,11 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Epsilon;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Epsilon;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,8 +70,8 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
return null;
|
||||
}
|
||||
IntervalSet[] look = new IntervalSet[s.GetNumberOfTransitions() + 1];
|
||||
for (int alt = 1; alt <= s.GetNumberOfTransitions(); alt++)
|
||||
IntervalSet[] look = new IntervalSet[s.NumberOfTransitions + 1];
|
||||
for (int alt = 1; alt <= s.NumberOfTransitions; alt++)
|
||||
{
|
||||
look[alt] = new IntervalSet();
|
||||
ICollection<ATNConfig> lookBusy = new HashSet<ATNConfig>();
|
||||
|
@ -175,7 +175,7 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
}
|
||||
}
|
||||
int n = s.GetNumberOfTransitions();
|
||||
int n = s.NumberOfTransitions;
|
||||
for (int i_1 = 0; i_1 < n; i_1++)
|
||||
{
|
||||
Transition t = s.Transition(i_1);
|
||||
|
|
|
@ -311,7 +311,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
continue;
|
||||
}
|
||||
int n = c.GetState().GetNumberOfOptimizedTransitions();
|
||||
int n = c.GetState().NumberOfOptimizedTransitions;
|
||||
for (int ti = 0; ti < n; ti++)
|
||||
{
|
||||
// for each optimized transition
|
||||
|
@ -364,7 +364,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
PredictionContext initialContext = PredictionContext.EmptyFull;
|
||||
ATNConfigSet configs = new OrderedATNConfigSet();
|
||||
for (int i = 0; i < p.GetNumberOfTransitions(); i++)
|
||||
for (int i = 0; i < p.NumberOfTransitions; i++)
|
||||
{
|
||||
ATNState target = p.Transition(i).target;
|
||||
ATNConfig c = ATNConfig.Create(target, i + 1, initialContext);
|
||||
|
@ -432,12 +432,12 @@ namespace Antlr4.Runtime.Atn
|
|||
return false;
|
||||
}
|
||||
// optimization
|
||||
if (!config.GetState().OnlyHasEpsilonTransitions())
|
||||
if (!config.GetState().OnlyHasEpsilonTransitions)
|
||||
{
|
||||
configs.AddItem(config);
|
||||
}
|
||||
ATNState p = config.GetState();
|
||||
for (int i_1 = 0; i_1 < p.GetNumberOfOptimizedTransitions(); i_1++)
|
||||
for (int i_1 = 0; i_1 < p.NumberOfOptimizedTransitions; i_1++)
|
||||
{
|
||||
Transition t = p.GetOptimizedTransition(i_1);
|
||||
ATNConfig c = GetEpsilonTarget(input, config, t, configs, speculative);
|
||||
|
@ -458,9 +458,9 @@ namespace Antlr4.Runtime.Atn
|
|||
t, ATNConfigSet configs, bool speculative)
|
||||
{
|
||||
ATNConfig c;
|
||||
switch (t.SerializationType)
|
||||
switch (t.TransitionType)
|
||||
{
|
||||
case Transition.Rule:
|
||||
case TransitionType.Rule:
|
||||
{
|
||||
RuleTransition ruleTransition = (RuleTransition)t;
|
||||
if (optimize_tail_calls && ruleTransition.optimizedTailCall && !config.GetContext
|
||||
|
@ -477,13 +477,13 @@ namespace Antlr4.Runtime.Atn
|
|||
break;
|
||||
}
|
||||
|
||||
case Transition.Precedence:
|
||||
case TransitionType.Precedence:
|
||||
{
|
||||
throw new NotSupportedException("Precedence predicates are not supported in lexers."
|
||||
);
|
||||
}
|
||||
|
||||
case Transition.Predicate:
|
||||
case TransitionType.Predicate:
|
||||
{
|
||||
PredicateTransition pt = (PredicateTransition)t;
|
||||
configs.MarkExplicitSemanticContext();
|
||||
|
@ -498,14 +498,14 @@ namespace Antlr4.Runtime.Atn
|
|||
break;
|
||||
}
|
||||
|
||||
case Transition.Action:
|
||||
case TransitionType.Action:
|
||||
{
|
||||
// ignore actions; just exec one per rule upon accept
|
||||
c = config.Transform(t.target, ((ActionTransition)t).actionIndex);
|
||||
break;
|
||||
}
|
||||
|
||||
case Transition.Epsilon:
|
||||
case TransitionType.Epsilon:
|
||||
{
|
||||
c = config.Transform(t.target);
|
||||
break;
|
||||
|
|
|
@ -38,9 +38,12 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
public ATNState loopBackState;
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return LoopEnd;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.LoopEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,11 +39,11 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return NotSet;
|
||||
return Antlr4.Runtime.Atn.TransitionType.NotSet;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -717,7 +717,7 @@ namespace Antlr4.Runtime.Atn
|
|||
System.Diagnostics.Debug.Assert(D.isAcceptState);
|
||||
if (D.configs.HasSemanticContext())
|
||||
{
|
||||
int nalts = decState.GetNumberOfTransitions();
|
||||
int nalts = decState.NumberOfTransitions;
|
||||
DFAState.PredPrediction[] predPredictions = D.predicates;
|
||||
if (predPredictions != null)
|
||||
{
|
||||
|
@ -883,7 +883,7 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
continue;
|
||||
}
|
||||
int n = c.GetState().GetNumberOfOptimizedTransitions();
|
||||
int n = c.GetState().NumberOfOptimizedTransitions;
|
||||
for (int ti = 0; ti < n; ti++)
|
||||
{
|
||||
// for each optimized transition
|
||||
|
@ -1068,7 +1068,7 @@ namespace Antlr4.Runtime.Atn
|
|||
while (true)
|
||||
{
|
||||
ATNConfigSet reachIntermediate = new ATNConfigSet();
|
||||
int n = p.GetNumberOfTransitions();
|
||||
int n = p.NumberOfTransitions;
|
||||
for (int ti = 0; ti < n; ti++)
|
||||
{
|
||||
// for each transition
|
||||
|
@ -1364,11 +1364,11 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
ATNState p = config.GetState();
|
||||
// optimization
|
||||
if (!p.OnlyHasEpsilonTransitions())
|
||||
if (!p.OnlyHasEpsilonTransitions)
|
||||
{
|
||||
configs.Add(config, contextCache);
|
||||
}
|
||||
for (int i_1 = 0; i_1 < p.GetNumberOfOptimizedTransitions(); i_1++)
|
||||
for (int i_1 = 0; i_1 < p.NumberOfOptimizedTransitions; i_1++)
|
||||
{
|
||||
Transition t = p.GetOptimizedTransition(i_1);
|
||||
bool continueCollecting = !(t is Antlr4.Runtime.Atn.ActionTransition) && collectPredicates;
|
||||
|
@ -1387,23 +1387,23 @@ namespace Antlr4.Runtime.Atn
|
|||
if (optimize_closure_busy)
|
||||
{
|
||||
bool checkClosure = false;
|
||||
switch (c.GetState().GetStateType())
|
||||
switch (c.GetState().StateType)
|
||||
{
|
||||
case ATNState.StarLoopEntry:
|
||||
case ATNState.BlockEnd:
|
||||
case ATNState.LoopEnd:
|
||||
case StateType.StarLoopEntry:
|
||||
case StateType.BlockEnd:
|
||||
case StateType.LoopEnd:
|
||||
{
|
||||
checkClosure = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.PlusBlockStart:
|
||||
case StateType.PlusBlockStart:
|
||||
{
|
||||
checkClosure = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case ATNState.RuleStop:
|
||||
case StateType.RuleStop:
|
||||
{
|
||||
checkClosure = c.GetContext().IsEmpty;
|
||||
break;
|
||||
|
@ -1484,31 +1484,31 @@ namespace Antlr4.Runtime.Atn
|
|||
public virtual ATNConfig GetEpsilonTarget(ATNConfig config, Transition t, bool collectPredicates
|
||||
, bool inContext, PredictionContextCache contextCache)
|
||||
{
|
||||
switch (t.SerializationType)
|
||||
switch (t.TransitionType)
|
||||
{
|
||||
case Transition.Rule:
|
||||
case TransitionType.Rule:
|
||||
{
|
||||
return RuleTransition(config, (Antlr4.Runtime.Atn.RuleTransition)t, contextCache);
|
||||
}
|
||||
|
||||
case Transition.Precedence:
|
||||
case TransitionType.Precedence:
|
||||
{
|
||||
return PrecedenceTransition(config, (PrecedencePredicateTransition)t, collectPredicates
|
||||
, inContext);
|
||||
}
|
||||
|
||||
case Transition.Predicate:
|
||||
case TransitionType.Predicate:
|
||||
{
|
||||
return PredTransition(config, (PredicateTransition)t, collectPredicates, inContext
|
||||
);
|
||||
}
|
||||
|
||||
case Transition.Action:
|
||||
case TransitionType.Action:
|
||||
{
|
||||
return ActionTransition(config, (Antlr4.Runtime.Atn.ActionTransition)t);
|
||||
}
|
||||
|
||||
case Transition.Epsilon:
|
||||
case TransitionType.Epsilon:
|
||||
{
|
||||
return config.Transform(t.target);
|
||||
}
|
||||
|
@ -1597,8 +1597,7 @@ namespace Antlr4.Runtime.Atn
|
|||
|
||||
public int Compare(ATNConfig o1, ATNConfig o2)
|
||||
{
|
||||
int diff = o1.GetState().GetNonStopStateNumber() - o2.GetState().GetNonStopStateNumber
|
||||
();
|
||||
int diff = o1.GetState().NonStopStateNumber - o2.GetState().NonStopStateNumber;
|
||||
if (diff != 0)
|
||||
{
|
||||
return diff;
|
||||
|
@ -1632,11 +1631,11 @@ namespace Antlr4.Runtime.Atn
|
|||
// quick check 1 & 2 => if we assume #1 holds and check #2 against the
|
||||
// minAlt from the first state, #2 will fail if the assumption was
|
||||
// incorrect
|
||||
int currentState = configs[0].GetState().GetNonStopStateNumber();
|
||||
int currentState = configs[0].GetState().NonStopStateNumber;
|
||||
for (int i = 0; i < configs.Count; i++)
|
||||
{
|
||||
ATNConfig config = configs[i];
|
||||
int stateNumber = config.GetState().GetNonStopStateNumber();
|
||||
int stateNumber = config.GetState().NonStopStateNumber;
|
||||
if (stateNumber != currentState)
|
||||
{
|
||||
if (config.GetAlt() != minAlt)
|
||||
|
@ -1649,14 +1648,14 @@ namespace Antlr4.Runtime.Atn
|
|||
BitArray representedAlts = null;
|
||||
if (exact)
|
||||
{
|
||||
currentState = configs[0].GetState().GetNonStopStateNumber();
|
||||
currentState = configs[0].GetState().NonStopStateNumber;
|
||||
// get the represented alternatives of the first state
|
||||
representedAlts = new BitArray();
|
||||
int maxAlt = minAlt;
|
||||
for (int i_1 = 0; i_1 < configs.Count; i_1++)
|
||||
{
|
||||
ATNConfig config = configs[i_1];
|
||||
if (config.GetState().GetNonStopStateNumber() != currentState)
|
||||
if (config.GetState().NonStopStateNumber != currentState)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1665,12 +1664,12 @@ namespace Antlr4.Runtime.Atn
|
|||
maxAlt = alt;
|
||||
}
|
||||
// quick check #3:
|
||||
currentState = configs[0].GetState().GetNonStopStateNumber();
|
||||
currentState = configs[0].GetState().NonStopStateNumber;
|
||||
int currentAlt = minAlt;
|
||||
for (int i_2 = 0; i_2 < configs.Count; i_2++)
|
||||
{
|
||||
ATNConfig config = configs[i_2];
|
||||
int stateNumber = config.GetState().GetNonStopStateNumber();
|
||||
int stateNumber = config.GetState().NonStopStateNumber;
|
||||
int alt = config.GetAlt();
|
||||
if (stateNumber != currentState)
|
||||
{
|
||||
|
@ -1694,7 +1693,7 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
}
|
||||
}
|
||||
currentState = configs[0].GetState().GetNonStopStateNumber();
|
||||
currentState = configs[0].GetState().NonStopStateNumber;
|
||||
int firstIndexCurrentState = 0;
|
||||
int lastIndexCurrentStateMinAlt = 0;
|
||||
PredictionContext joinedCheckContext = configs[0].GetContext();
|
||||
|
@ -1705,7 +1704,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
break;
|
||||
}
|
||||
if (config.GetState().GetNonStopStateNumber() != currentState)
|
||||
if (config.GetState().NonStopStateNumber != currentState)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1718,9 +1717,9 @@ namespace Antlr4.Runtime.Atn
|
|||
ATNConfig config = configs[i_4];
|
||||
ATNState state = config.GetState();
|
||||
alts.Set(config.GetAlt());
|
||||
if (state.GetNonStopStateNumber() != currentState)
|
||||
if (state.NonStopStateNumber != currentState)
|
||||
{
|
||||
currentState = state.GetNonStopStateNumber();
|
||||
currentState = state.NonStopStateNumber;
|
||||
firstIndexCurrentState = i_4;
|
||||
lastIndexCurrentStateMinAlt = i_4;
|
||||
joinedCheckContext = config.GetContext();
|
||||
|
@ -1731,7 +1730,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
break;
|
||||
}
|
||||
if (config2.GetState().GetNonStopStateNumber() != currentState)
|
||||
if (config2.GetState().NonStopStateNumber != currentState)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1751,7 +1750,7 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
break;
|
||||
}
|
||||
if (config2.GetState().GetNonStopStateNumber() != currentState)
|
||||
if (config2.GetState().NonStopStateNumber != currentState)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -1859,7 +1858,7 @@ namespace Antlr4.Runtime.Atn
|
|||
foreach (ATNConfig c in nvae.GetDeadEndConfigs())
|
||||
{
|
||||
string trans = "no edges";
|
||||
if (c.GetState().GetNumberOfOptimizedTransitions() > 0)
|
||||
if (c.GetState().NumberOfOptimizedTransitions > 0)
|
||||
{
|
||||
Transition t = c.GetState().GetOptimizedTransition(0);
|
||||
if (t is AtomTransition)
|
||||
|
@ -2054,7 +2053,7 @@ namespace Antlr4.Runtime.Atn
|
|||
}
|
||||
if (newState.isAcceptState && configs.HasSemanticContext())
|
||||
{
|
||||
PredicateDFAState(newState, configs, decisionState.GetNumberOfTransitions());
|
||||
PredicateDFAState(newState, configs, decisionState.NumberOfTransitions);
|
||||
}
|
||||
DFAState added = dfa.AddState(newState);
|
||||
if (debug && added == newState)
|
||||
|
@ -2168,8 +2167,8 @@ namespace Antlr4.Runtime.Atn
|
|||
while (!context.IsEmpty())
|
||||
{
|
||||
ATNState state = atn.states[context.invokingState];
|
||||
System.Diagnostics.Debug.Assert(state.GetNumberOfTransitions() == 1 && state.Transition
|
||||
(0).SerializationType == Transition.Rule);
|
||||
System.Diagnostics.Debug.Assert(state.NumberOfTransitions == 1 && state.Transition
|
||||
(0).TransitionType == TransitionType.Rule);
|
||||
Antlr4.Runtime.Atn.RuleTransition transition = (Antlr4.Runtime.Atn.RuleTransition
|
||||
)state.Transition(0);
|
||||
if (!transition.tailCall)
|
||||
|
|
|
@ -48,9 +48,12 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
public PlusLoopbackState loopBackState;
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return PlusBlockStart;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.PlusBlockStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,9 +42,12 @@ namespace Antlr4.Runtime.Atn
|
|||
/// </summary>
|
||||
public sealed class PlusLoopbackState : DecisionState
|
||||
{
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return PlusLoopBack;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.PlusLoopBack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,11 +43,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.precedence = precedence;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Precedence;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Precedence;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,11 +61,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.isCtxDependent = isCtxDependent;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Predicate;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Predicate;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,11 +45,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.to = to;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Range;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Range;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,12 @@ namespace Antlr4.Runtime.Atn
|
|||
|
||||
public bool leftFactored;
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return RuleStart;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.RuleStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,14 +42,20 @@ namespace Antlr4.Runtime.Atn
|
|||
/// </remarks>
|
||||
public sealed class RuleStopState : ATNState
|
||||
{
|
||||
public override int GetNonStopStateNumber()
|
||||
public override int NonStopStateNumber
|
||||
{
|
||||
return -1;
|
||||
get
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return RuleStop;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.RuleStop;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,11 +57,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.followState = followState;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Rule;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Rule;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,11 +51,11 @@ namespace Antlr4.Runtime.Atn
|
|||
this.set = set;
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Set;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Set;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,12 @@ namespace Antlr4.Runtime.Atn
|
|||
/// <remarks>The block that begins a closure loop.</remarks>
|
||||
public sealed class StarBlockStartState : BlockStartState
|
||||
{
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return StarBlockStart;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.StarBlockStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,9 +36,12 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
public StarLoopbackState loopBackState;
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return StarLoopEntry;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.StarLoopEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,12 @@ namespace Antlr4.Runtime.Atn
|
|||
return (StarLoopEntryState)Transition(0).target;
|
||||
}
|
||||
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return StarLoopBack;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.StarLoopBack;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Sam Harwell
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
using Antlr4.Runtime.Atn;
|
||||
using Sharpen;
|
||||
|
||||
namespace Antlr4.Runtime.Atn
|
||||
{
|
||||
public enum StateType
|
||||
{
|
||||
InvalidType,
|
||||
Basic,
|
||||
RuleStart,
|
||||
BlockStart,
|
||||
PlusBlockStart,
|
||||
StarBlockStart,
|
||||
TokenStart,
|
||||
RuleStop,
|
||||
BlockEnd,
|
||||
StarLoopBack,
|
||||
StarLoopEntry,
|
||||
PlusLoopBack,
|
||||
LoopEnd
|
||||
}
|
||||
}
|
|
@ -35,9 +35,12 @@ namespace Antlr4.Runtime.Atn
|
|||
/// <summary>The Tokens rule start state linking to each lexer rule start state</summary>
|
||||
public sealed class TokensStartState : DecisionState
|
||||
{
|
||||
public override int GetStateType()
|
||||
public override Antlr4.Runtime.Atn.StateType StateType
|
||||
{
|
||||
return TokenStart;
|
||||
get
|
||||
{
|
||||
return Antlr4.Runtime.Atn.StateType.TokenStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,55 +51,34 @@ namespace Antlr4.Runtime.Atn
|
|||
/// </remarks>
|
||||
public abstract class Transition
|
||||
{
|
||||
public const int Epsilon = 1;
|
||||
|
||||
public const int Range = 2;
|
||||
|
||||
public const int Rule = 3;
|
||||
|
||||
public const int Predicate = 4;
|
||||
|
||||
public const int Atom = 5;
|
||||
|
||||
public const int Action = 6;
|
||||
|
||||
public const int Set = 7;
|
||||
|
||||
public const int NotSet = 8;
|
||||
|
||||
public const int Wildcard = 9;
|
||||
|
||||
public const int Precedence = 10;
|
||||
|
||||
public static readonly IList<string> serializationNames = Sharpen.Collections.UnmodifiableList
|
||||
(Arrays.AsList("INVALID", "EPSILON", "RANGE", "RULE", "PREDICATE", "ATOM", "ACTION"
|
||||
, "SET", "NOT_SET", "WILDCARD", "PRECEDENCE"));
|
||||
|
||||
private sealed class _Dictionary_86 : Dictionary<Type, int>
|
||||
private sealed class _Dictionary_74 : Dictionary<Type, Antlr4.Runtime.Atn.TransitionType
|
||||
>
|
||||
{
|
||||
public _Dictionary_86()
|
||||
public _Dictionary_74()
|
||||
{
|
||||
{
|
||||
// constants for serialization
|
||||
// e.g., {isType(input.LT(1))}?
|
||||
// ~(A|B) or ~atom, wildcard, which convert to next 2
|
||||
this.Put(typeof(EpsilonTransition), Antlr4.Runtime.Atn.Transition.Epsilon);
|
||||
this.Put(typeof(RangeTransition), Antlr4.Runtime.Atn.Transition.Range);
|
||||
this.Put(typeof(RuleTransition), Antlr4.Runtime.Atn.Transition.Rule);
|
||||
this.Put(typeof(PredicateTransition), Antlr4.Runtime.Atn.Transition.Predicate);
|
||||
this.Put(typeof(AtomTransition), Antlr4.Runtime.Atn.Transition.Atom);
|
||||
this.Put(typeof(ActionTransition), Antlr4.Runtime.Atn.Transition.Action);
|
||||
this.Put(typeof(SetTransition), Antlr4.Runtime.Atn.Transition.Set);
|
||||
this.Put(typeof(NotSetTransition), Antlr4.Runtime.Atn.Transition.NotSet);
|
||||
this.Put(typeof(WildcardTransition), Antlr4.Runtime.Atn.Transition.Wildcard);
|
||||
this.Put(typeof(PrecedencePredicateTransition), Antlr4.Runtime.Atn.Transition.Precedence
|
||||
this.Put(typeof(EpsilonTransition), Antlr4.Runtime.Atn.TransitionType.Epsilon);
|
||||
this.Put(typeof(RangeTransition), Antlr4.Runtime.Atn.TransitionType.Range);
|
||||
this.Put(typeof(RuleTransition), Antlr4.Runtime.Atn.TransitionType.Rule);
|
||||
this.Put(typeof(PredicateTransition), Antlr4.Runtime.Atn.TransitionType.Predicate
|
||||
);
|
||||
this.Put(typeof(AtomTransition), Antlr4.Runtime.Atn.TransitionType.Atom);
|
||||
this.Put(typeof(ActionTransition), Antlr4.Runtime.Atn.TransitionType.Action);
|
||||
this.Put(typeof(SetTransition), Antlr4.Runtime.Atn.TransitionType.Set);
|
||||
this.Put(typeof(NotSetTransition), Antlr4.Runtime.Atn.TransitionType.NotSet);
|
||||
this.Put(typeof(WildcardTransition), Antlr4.Runtime.Atn.TransitionType.Wildcard);
|
||||
this.Put(typeof(PrecedencePredicateTransition), Antlr4.Runtime.Atn.TransitionType
|
||||
.Precedence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static readonly IDictionary<Type, int> serializationTypes = Sharpen.Collections
|
||||
.UnmodifiableMap(new _Dictionary_86());
|
||||
public static readonly IDictionary<Type, Antlr4.Runtime.Atn.TransitionType> serializationTypes
|
||||
= Sharpen.Collections.UnmodifiableMap(new _Dictionary_74());
|
||||
|
||||
/// <summary>The target of this transition.</summary>
|
||||
/// <remarks>The target of this transition.</remarks>
|
||||
|
@ -115,7 +94,7 @@ namespace Antlr4.Runtime.Atn
|
|||
this.target = target;
|
||||
}
|
||||
|
||||
public abstract int SerializationType
|
||||
public abstract Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* [The "BSD license"]
|
||||
* Copyright (c) 2013 Terence Parr
|
||||
* Copyright (c) 2013 Sam Harwell
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
using Antlr4.Runtime.Atn;
|
||||
using Sharpen;
|
||||
|
||||
namespace Antlr4.Runtime.Atn
|
||||
{
|
||||
public enum TransitionType
|
||||
{
|
||||
Invalid,
|
||||
Epsilon,
|
||||
Range,
|
||||
Rule,
|
||||
Predicate,
|
||||
Atom,
|
||||
Action,
|
||||
Set,
|
||||
NotSet,
|
||||
Wildcard,
|
||||
Precedence
|
||||
}
|
||||
}
|
|
@ -39,11 +39,11 @@ namespace Antlr4.Runtime.Atn
|
|||
{
|
||||
}
|
||||
|
||||
public override int SerializationType
|
||||
public override Antlr4.Runtime.Atn.TransitionType TransitionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return Wildcard;
|
||||
return Antlr4.Runtime.Atn.TransitionType.Wildcard;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -205,12 +205,12 @@ namespace Antlr4.Runtime
|
|||
{
|
||||
return;
|
||||
}
|
||||
switch (s.GetStateType())
|
||||
switch (s.StateType)
|
||||
{
|
||||
case ATNState.BlockStart:
|
||||
case ATNState.StarBlockStart:
|
||||
case ATNState.PlusBlockStart:
|
||||
case ATNState.StarLoopEntry:
|
||||
case StateType.BlockStart:
|
||||
case StateType.StarBlockStart:
|
||||
case StateType.PlusBlockStart:
|
||||
case StateType.StarLoopEntry:
|
||||
{
|
||||
// report error and recover if possible
|
||||
if (SingleTokenDeletion(recognizer) != null)
|
||||
|
@ -220,8 +220,8 @@ namespace Antlr4.Runtime
|
|||
throw new InputMismatchException(recognizer);
|
||||
}
|
||||
|
||||
case ATNState.PlusLoopBack:
|
||||
case ATNState.StarLoopBack:
|
||||
case StateType.PlusLoopBack:
|
||||
case StateType.StarLoopBack:
|
||||
{
|
||||
// System.err.println("at loop back: "+s.getClass().getSimpleName());
|
||||
ReportUnwantedToken(recognizer);
|
||||
|
|
|
@ -744,7 +744,7 @@ namespace Antlr4.Runtime.Misc
|
|||
}
|
||||
foreach (Transition transition in state.GetTransitions())
|
||||
{
|
||||
if (transition.SerializationType != Transition.Rule)
|
||||
if (transition.TransitionType != TransitionType.Rule)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 15c7bc6a2623747ddfb9e19d923d1119e9af538f
|
||||
Subproject commit 5cda16588918c8873c62abdeb9ce88e600e5d045
|
Loading…
Reference in New Issue