forked from jasder/antlr
Numerous small fixes
This commit is contained in:
parent
2a4de9bbf9
commit
c83d8fb109
|
@ -64,11 +64,11 @@ func NewATNConfig1(c *ATNConfig, state *ATNState, context *PredictionContext) *A
|
|||
func NewATNConfig(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) *ATNConfig {
|
||||
a := new(ATNConfig)
|
||||
|
||||
a.initATNConfig2(c, state, context, semanticContext)
|
||||
a.InitATNConfig2(c, state, context, semanticContext)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *ATNConfig) initATNConfig2(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) {
|
||||
func (a *ATNConfig) InitATNConfig2(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) {
|
||||
|
||||
a.state = state;
|
||||
a.alt = c.alt;
|
||||
|
@ -206,7 +206,7 @@ func NewLexerATNConfig( state *ATNState, alt int, context *PredictionContext) *L
|
|||
|
||||
this := new(LexerATNConfig)
|
||||
|
||||
this.initATNConfig(state, alt, context, SemanticContextNONE)
|
||||
this.InitATNConfig(state, alt, context, SemanticContextNONE)
|
||||
this.lexerActionExecutor = nil
|
||||
this.passedThroughNonGreedyDecision = false
|
||||
|
||||
|
|
|
@ -41,12 +41,12 @@ func NewATNConfigSet(fullCtx bool) *ATNConfigSet {
|
|||
|
||||
this := new(ATNConfigSet)
|
||||
|
||||
this.initATNConfigSet(fullCtx)
|
||||
this.InitATNConfigSet(fullCtx)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (a *ATNConfigSet) initATNConfigSet(fullCtx bool) {
|
||||
func (a *ATNConfigSet) InitATNConfigSet(fullCtx bool) {
|
||||
|
||||
// The reason that we need a.is because we don't want the hash map to use
|
||||
// the standard hash code and equals. We need all configurations with the
|
||||
|
@ -264,7 +264,7 @@ func NewOrderedATNConfigSet() *OrderedATNConfigSet {
|
|||
|
||||
this := new(OrderedATNConfigSet)
|
||||
|
||||
this.initATNConfigSet(false)
|
||||
this.InitATNConfigSet(false)
|
||||
this.configLookup = NewSet(nil, nil)
|
||||
|
||||
return this
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package antlr4
|
||||
import "strings"
|
||||
|
||||
// This is the earliest supported serialized UUID.
|
||||
// stick to serialized version for now, we don't need a UUID instance
|
||||
|
@ -13,17 +14,35 @@ var SERIALIZED_VERSION = 3
|
|||
// This is the current serialized UUID.
|
||||
var SERIALIZED_UUID = BASE_SERIALIZED_UUID
|
||||
|
||||
func initArray( length, value) {
|
||||
var tmp = []
|
||||
tmp[length-1] = value
|
||||
return tmp.map(function(i) {return value})
|
||||
func InitArray( length int, value interface{}) {
|
||||
var tmp = make([]interface{}, length)
|
||||
|
||||
for i := range tmp {
|
||||
tmp[i] = value
|
||||
}
|
||||
|
||||
return tmp
|
||||
}
|
||||
|
||||
func ATNDeserializer (options) {
|
||||
type ATNDeserializer struct {
|
||||
|
||||
if ( options== nil || options == nil ) {
|
||||
options = ATNDeserializationOptions.defaultOptions
|
||||
deserializationOptions ATNDeserializationOptions
|
||||
stateFactories
|
||||
actionFactories
|
||||
data []rune
|
||||
pos int
|
||||
uuid string
|
||||
|
||||
}
|
||||
|
||||
func NewATNDeserializer (options ATNDeserializationOptions) *ATNDeserializer {
|
||||
|
||||
if ( options== nil ) {
|
||||
options = ATNDeserializationOptionsdefaultOptions
|
||||
}
|
||||
|
||||
this := new(ATNDeserializer)
|
||||
|
||||
this.deserializationOptions = options
|
||||
this.stateFactories = nil
|
||||
this.actionFactories = nil
|
||||
|
@ -43,16 +62,26 @@ func ATNDeserializer (options) {
|
|||
// serialized ATN at or after the feature identified by {@code feature} was
|
||||
// introduced otherwise, {@code false}.
|
||||
|
||||
func (this *ATNDeserializer) isFeatureSupported(feature, actualUuid) {
|
||||
var idx1 = SUPPORTED_UUIDS.index(feature)
|
||||
func stringInSlice(a string, list []string) bool {
|
||||
for _, b := range list {
|
||||
if b == a {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) isFeatureSupported(feature, actualUuid string) bool {
|
||||
var idx1 = stringInSlice( feature, SUPPORTED_UUIDS )
|
||||
if (idx1<0) {
|
||||
return false
|
||||
}
|
||||
var idx2 = SUPPORTED_UUIDS.index(actualUuid)
|
||||
var idx2 = stringInSlice( actualUuid, SUPPORTED_UUIDS )
|
||||
return idx2 >= idx1
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) deserialize(data) {
|
||||
func (this *ATNDeserializer) deserialize(data []rune) *ATN {
|
||||
|
||||
this.reset(data)
|
||||
this.checkVersion()
|
||||
this.checkUUID()
|
||||
|
@ -72,16 +101,34 @@ func (this *ATNDeserializer) deserialize(data) {
|
|||
this.verifyATN(atn)
|
||||
}
|
||||
return atn
|
||||
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) reset(data) {
|
||||
var adjust = function(c) {
|
||||
var v = c.charCodeAt(0)
|
||||
return v>1 ? v-2 : -1
|
||||
}
|
||||
var temp = data.split("").map(adjust)
|
||||
// don't adjust the first value since that's the version number
|
||||
temp[0] = data.charCodeAt(0)
|
||||
func (this *ATNDeserializer) reset(data []rune) {
|
||||
|
||||
// TODO not sure the copy is necessary here
|
||||
temp := make([]rune, len(data))
|
||||
|
||||
for i, c := range data {
|
||||
// don't adjust the first value since that's the version number
|
||||
if (i == 0) {
|
||||
temp[i] = c
|
||||
} else if c > 1 {
|
||||
temp[i] = c-2
|
||||
} else {
|
||||
temp[i] = -1
|
||||
}
|
||||
}
|
||||
|
||||
// var adjust = func(c) {
|
||||
// var v = c.charCodeAt(0)
|
||||
// return v>1 ? v-2 : -1
|
||||
// }
|
||||
|
||||
// var temp = data.split("").map(adjust)
|
||||
// // don't adjust the first value since that's the version number
|
||||
// temp[0] = data.charCodeAt(0)
|
||||
|
||||
this.data = temp
|
||||
this.pos = 0
|
||||
}
|
||||
|
@ -95,25 +142,35 @@ func (this *ATNDeserializer) checkVersion() {
|
|||
|
||||
func (this *ATNDeserializer) checkUUID() {
|
||||
var uuid = this.readUUID()
|
||||
if (SUPPORTED_UUIDS.indexOf(uuid)<0) {
|
||||
panic ("Could not deserialize ATN with UUID: " + uuid +
|
||||
" (expected " + SERIALIZED_UUID + " or a legacy UUID).", uuid, SERIALIZED_UUID)
|
||||
if ( strings.Index(uuid, SUPPORTED_UUIDS )<0) {
|
||||
panic("Could not deserialize ATN with UUID: " + uuid + " (expected " + SERIALIZED_UUID + " or a legacy UUID).", uuid, SERIALIZED_UUID)
|
||||
}
|
||||
this.uuid = uuid
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readATN() {
|
||||
func (this *ATNDeserializer) readATN() *ATN {
|
||||
var grammarType = this.readInt()
|
||||
var maxTokenType = this.readInt()
|
||||
return NewATN(grammarType, maxTokenType)
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readStates(atn) {
|
||||
var j, pair, stateNumber
|
||||
var loopBackStateNumbers = []
|
||||
var endStateNumbers = []
|
||||
type LoopEndStateIntPair struct {
|
||||
item0 *LoopEndState
|
||||
item1 int
|
||||
}
|
||||
|
||||
type BlockStartStateIntPair struct {
|
||||
item0 *BlockStartState
|
||||
item1 int
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readStates(atn *ATN) {
|
||||
|
||||
var loopBackStateNumbers = make([]LoopEndStateIntPair)
|
||||
var endStateNumbers = make([]BlockStartStateIntPair)
|
||||
|
||||
var nstates = this.readInt()
|
||||
for(var i=0 i<nstates i++) {
|
||||
for i :=0; i<nstates; i++ {
|
||||
var stype = this.readInt()
|
||||
// ignore bad type of states
|
||||
if (stype==ATNStateInvalidType) {
|
||||
|
@ -127,46 +184,46 @@ func (this *ATNDeserializer) readStates(atn) {
|
|||
var s = this.stateFactory(stype, ruleIndex)
|
||||
if (stype == ATNStateLOOP_END) { // special case
|
||||
var loopBackStateNumber = this.readInt()
|
||||
loopBackStateNumbers.push([s, loopBackStateNumber])
|
||||
} else if_, ok := s.(BlockStartState); ok {
|
||||
loopBackStateNumbers = append( loopBackStateNumbers, LoopEndStateIntPair{s, loopBackStateNumber})
|
||||
} else if _, ok := s.(*BlockStartState); ok {
|
||||
var endStateNumber = this.readInt()
|
||||
endStateNumbers.push([s, endStateNumber])
|
||||
endStateNumbers = append( endStateNumbers BlockStartStateIntPair{s, endStateNumber})
|
||||
}
|
||||
atn.addState(s)
|
||||
}
|
||||
// delay the assignment of loop back and end states until we know all the
|
||||
// state instances have been initialized
|
||||
for (j=0 j<loopBackStateNumbers.length j++) {
|
||||
pair = loopBackStateNumbers[j]
|
||||
pair[0].loopBackState = atn.states[pair[1]]
|
||||
for j:=0; j<len(loopBackStateNumbers); j++ {
|
||||
pair := loopBackStateNumbers[j]
|
||||
pair.item0.loopBackState = atn.states[pair[1]]
|
||||
}
|
||||
|
||||
for (j=0 j<endStateNumbers.length j++) {
|
||||
pair = endStateNumbers[j]
|
||||
pair[0].endState = atn.states[pair[1]]
|
||||
for j:=0; j<len(endStateNumbers); j++ {
|
||||
pair := endStateNumbers[j]
|
||||
pair.item0.endState = atn.states[pair[1]]
|
||||
}
|
||||
|
||||
var numNonGreedyStates = this.readInt()
|
||||
for (j=0 j<numNonGreedyStates j++) {
|
||||
stateNumber = this.readInt()
|
||||
for j:=0; j<numNonGreedyStates; j++ {
|
||||
stateNumber := this.readInt()
|
||||
atn.states[stateNumber].nonGreedy = true
|
||||
}
|
||||
|
||||
var numPrecedenceStates = this.readInt()
|
||||
for (j=0 j<numPrecedenceStates j++) {
|
||||
stateNumber = this.readInt()
|
||||
for j:=0; j<numPrecedenceStates; j++ {
|
||||
stateNumber := this.readInt()
|
||||
atn.states[stateNumber].isPrecedenceRule = true
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readRules(atn) {
|
||||
var i
|
||||
func (this *ATNDeserializer) readRules(atn *ATN) {
|
||||
|
||||
var nrules = this.readInt()
|
||||
if (atn.grammarType == ATNTypeLexer ) {
|
||||
atn.ruleToTokenType = initArray(nrules, 0)
|
||||
atn.ruleToTokenType = InitArray(nrules, 0)
|
||||
}
|
||||
atn.ruleToStartState = initArray(nrules, 0)
|
||||
for (i=0 i<nrules i++) {
|
||||
atn.ruleToStartState = InitArray(nrules, 0)
|
||||
for i:=0; i<nrules; i++ {
|
||||
var s = this.readInt()
|
||||
var startState = atn.states[s]
|
||||
atn.ruleToStartState[i] = startState
|
||||
|
@ -178,10 +235,10 @@ func (this *ATNDeserializer) readRules(atn) {
|
|||
atn.ruleToTokenType[i] = tokenType
|
||||
}
|
||||
}
|
||||
atn.ruleToStopState = initArray(nrules, 0)
|
||||
for (i=0 i<atn.states.length i++) {
|
||||
atn.ruleToStopState = InitArray(nrules, 0)
|
||||
for i:=0; i<len(atn.states); i++ {
|
||||
var state = atn.states[i]
|
||||
if (!_, ok := state.(RuleStopState); ok) {
|
||||
if _, ok := state.(*RuleStopState); !ok {
|
||||
continue
|
||||
}
|
||||
atn.ruleToStopState[state.ruleIndex] = state
|
||||
|
@ -189,26 +246,26 @@ func (this *ATNDeserializer) readRules(atn) {
|
|||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readModes(atn) {
|
||||
func (this *ATNDeserializer) readModes(atn *ATN) {
|
||||
var nmodes = this.readInt()
|
||||
for (var i=0 i<nmodes i++) {
|
||||
for i:=0; i<nmodes; i++ {
|
||||
var s = this.readInt()
|
||||
atn.modeToStartState.push(atn.states[s])
|
||||
atn.modeToStartState = append(atn.modeToStartState, atn.states[s])
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readSets(atn) {
|
||||
var sets = []
|
||||
func (this *ATNDeserializer) readSets(atn *ATN) {
|
||||
var sets = make([]*IntervalSet)
|
||||
var m = this.readInt()
|
||||
for (var i=0 i<m i++) {
|
||||
for i:=0; i<m; i++ {
|
||||
var iset = NewIntervalSet()
|
||||
sets.push(iset)
|
||||
sets = append(sets, iset)
|
||||
var n = this.readInt()
|
||||
var containsEof = this.readInt()
|
||||
if (containsEof!=0) {
|
||||
iset.addOne(-1)
|
||||
}
|
||||
for (var j=0 j<n j++) {
|
||||
for j:=0; j<n; j++ {
|
||||
var i1 = this.readInt()
|
||||
var i2 = this.readInt()
|
||||
iset.addRange(i1, i2)
|
||||
|
@ -217,26 +274,26 @@ func (this *ATNDeserializer) readSets(atn) {
|
|||
return sets
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readEdges(atn, sets) {
|
||||
var i, j, state, trans, target
|
||||
func (this *ATNDeserializer) readEdges(atn *ATN, sets) {
|
||||
|
||||
var nedges = this.readInt()
|
||||
for (i=0 i<nedges i++) {
|
||||
for i:=0; i<nedges; i++ {
|
||||
var src = this.readInt()
|
||||
var trg = this.readInt()
|
||||
var ttype = this.readInt()
|
||||
var arg1 = this.readInt()
|
||||
var arg2 = this.readInt()
|
||||
var arg3 = this.readInt()
|
||||
trans = this.edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets)
|
||||
trans := this.edgeFactory(atn, ttype, src, trg, arg1, arg2, arg3, sets)
|
||||
var srcState = atn.states[src]
|
||||
srcState.addTransition(trans)
|
||||
srcState.addTransition(trans,-1)
|
||||
}
|
||||
// edges for rule stop states can be derived, so they aren't serialized
|
||||
for (i=0 i<atn.states.length i++) {
|
||||
state = atn.states[i]
|
||||
for (j=0 j<state.transitions.length j++) {
|
||||
var t = state.transitions[j]
|
||||
if (!_, ok := t.(RuleTransition); ok) {
|
||||
for i:=0; i<len(atn.states); i++ {
|
||||
state := atn.states[i]
|
||||
for j:=0; j<len(state.transitions); j++ {
|
||||
var t,ok = state.transitions[j].(*RuleTransition)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
var outermostPrecedenceReturn = -1
|
||||
|
@ -246,58 +303,58 @@ func (this *ATNDeserializer) readEdges(atn, sets) {
|
|||
}
|
||||
}
|
||||
|
||||
trans = NewEpsilonTransition(t.followState, outermostPrecedenceReturn)
|
||||
trans := NewEpsilonTransition(t.followState, outermostPrecedenceReturn)
|
||||
atn.ruleToStopState[t.target.ruleIndex].addTransition(trans)
|
||||
}
|
||||
}
|
||||
|
||||
for (i=0 i<atn.states.length i++) {
|
||||
state = atn.states[i]
|
||||
if _, ok := state.(BlockStartState); ok {
|
||||
for i:=0; i<len(atn.states); i++ {
|
||||
state := atn.states[i]
|
||||
if s2, ok := state.(*BlockStartState); ok {
|
||||
// we need to know the end state to set its start state
|
||||
if (state.endState == nil) {
|
||||
if (s2.endState == nil) {
|
||||
panic ("IllegalState")
|
||||
}
|
||||
// block end states can only be associated to a single block start
|
||||
// state
|
||||
if ( state.endState.startState != nil) {
|
||||
if ( s2.endState.startState != nil) {
|
||||
panic ("IllegalState")
|
||||
}
|
||||
state.endState.startState = state
|
||||
s2.endState.startState = state
|
||||
}
|
||||
if _, ok := state.(PlusLoopbackState); ok {
|
||||
for (j=0 j<state.transitions.length j++) {
|
||||
target = state.transitions[j].target
|
||||
if _, ok := target.(PlusBlockStartState); ok {
|
||||
target.loopBackState = state
|
||||
if _, ok := state.(*PlusLoopbackState); ok {
|
||||
for j:=0; j<len(state.transitions); j++ {
|
||||
target := state.transitions[j].target
|
||||
if t2, ok := target.(*PlusBlockStartState); ok {
|
||||
t2.loopBackState = state
|
||||
}
|
||||
}
|
||||
} else if _, ok := state.(StarLoopbackState); ok {
|
||||
for (j=0 j<state.transitions.length j++) {
|
||||
target = state.transitions[j].target
|
||||
if _, ok := target.(StarLoopEntryState); ok {
|
||||
target.loopBackState = state
|
||||
} else if _, ok := state.(*StarLoopbackState); ok {
|
||||
for j:=0; j<len(state.transitions); j++ {
|
||||
target := state.transitions[j].target
|
||||
if t2, ok := target.(*StarLoopEntryState); ok {
|
||||
t2.loopBackState = state
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readDecisions(atn) {
|
||||
func (this *ATNDeserializer) readDecisions(atn *ATN) {
|
||||
var ndecisions = this.readInt()
|
||||
for (var i=0 i<ndecisions i++) {
|
||||
for i:=0; i<ndecisions; i++ {
|
||||
var s = this.readInt()
|
||||
var decState = atn.states[s]
|
||||
atn.decisionToState.push(decState)
|
||||
var decState = atn.states[s].(*DecisionState)
|
||||
atn.decisionToState = append(atn.decisionToState, decState)
|
||||
decState.decision = i
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readLexerActions(atn) {
|
||||
func (this *ATNDeserializer) readLexerActions(atn *ATN) {
|
||||
if (atn.grammarType == ATNTypeLexer) {
|
||||
var count = this.readInt()
|
||||
atn.lexerActions = initArray(count, nil)
|
||||
for (var i=0 i<count i++) {
|
||||
atn.lexerActions = InitArray(count, nil)
|
||||
for i :=0; i<count; i++ {
|
||||
var actionType = this.readInt()
|
||||
var data1 = this.readInt()
|
||||
if (data1 == 0xFFFF) {
|
||||
|
@ -313,19 +370,18 @@ func (this *ATNDeserializer) readLexerActions(atn) {
|
|||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) generateRuleBypassTransitions(atn) {
|
||||
var i
|
||||
var count = atn.ruleToStartState.length
|
||||
for(i=0 i<count i++) {
|
||||
func (this *ATNDeserializer) generateRuleBypassTransitions(atn *ATN) {
|
||||
var count = len(atn.ruleToStartState)
|
||||
for i:=0; i<count; i++ {
|
||||
atn.ruleToTokenType[i] = atn.maxTokenType + i + 1
|
||||
}
|
||||
for(i=0 i<count i++) {
|
||||
for i:=0; i<count; i++ {
|
||||
this.generateRuleBypassTransition(atn, i)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) generateRuleBypassTransition(atn, idx) {
|
||||
var i, state
|
||||
func (this *ATNDeserializer) generateRuleBypassTransition(atn *ATN, idx int) {
|
||||
|
||||
var bypassStart = NewBasicBlockStartState()
|
||||
bypassStart.ruleIndex = idx
|
||||
atn.addState(bypassStart)
|
||||
|
@ -339,17 +395,17 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn, idx) {
|
|||
|
||||
bypassStop.startState = bypassStart
|
||||
|
||||
var excludeTransition = nil
|
||||
var endState = nil
|
||||
var excludeTransition *ATNState = nil
|
||||
var endState *Transition = nil
|
||||
|
||||
if (atn.ruleToStartState[idx].isPrecedenceRule) {
|
||||
// wrap from the beginning of the rule to the StarLoopEntryState
|
||||
endState = nil
|
||||
for(i=0 i<atn.states.length i++) {
|
||||
state = atn.states[i]
|
||||
for i:=0; i<len(atn.states); i++ {
|
||||
state := atn.states[i]
|
||||
if (this.stateIsEndStateFor(state, idx)) {
|
||||
endState = state
|
||||
excludeTransition = state.loopBackState.transitions[0]
|
||||
excludeTransition = state.(*StarLoopEntryState).loopBackState.transitions[0]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -362,9 +418,9 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn, idx) {
|
|||
|
||||
// all non-excluded transitions that currently target end state need to
|
||||
// target blockEnd instead
|
||||
for(i=0 i<atn.states.length i++) {
|
||||
state = atn.states[i]
|
||||
for(var j=0 j<state.transitions.length j++) {
|
||||
for i:=0; i< len(atn.states); i++ {
|
||||
state := atn.states[i]
|
||||
for j :=0; j<len(state.transitions); j++ {
|
||||
var transition = state.transitions[j]
|
||||
if (transition == excludeTransition) {
|
||||
continue
|
||||
|
@ -378,34 +434,36 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn, idx) {
|
|||
// all transitions leaving the rule start state need to leave blockStart
|
||||
// instead
|
||||
var ruleToStartState = atn.ruleToStartState[idx]
|
||||
var count = ruleToStartState.transitions.length
|
||||
var count = len(ruleToStartState.transitions)
|
||||
for ( count > 0) {
|
||||
bypassStart.addTransition(ruleToStartState.transitions[count-1])
|
||||
bypassStart.addTransition(ruleToStartState.transitions[count-1],-1)
|
||||
ruleToStartState.transitions = ruleToStartState.transitions.slice(-1)
|
||||
}
|
||||
// link the Newstates
|
||||
atn.ruleToStartState[idx].addTransition(NewEpsilonTransition(bypassStart))
|
||||
bypassStop.addTransition(NewEpsilonTransition(endState))
|
||||
atn.ruleToStartState[idx].addTransition(NewEpsilonTransition(bypassStart,-1))
|
||||
bypassStop.addTransition(NewEpsilonTransition(endState, -1), -1)
|
||||
|
||||
var matchState = NewBasicState()
|
||||
atn.addState(matchState)
|
||||
matchState.addTransition(NewAtomTransition(bypassStop, atn.ruleToTokenType[idx]))
|
||||
bypassStart.addTransition(NewEpsilonTransition(matchState))
|
||||
matchState.addTransition(NewAtomTransition(bypassStop, atn.ruleToTokenType[idx]), -1)
|
||||
bypassStart.addTransition(NewEpsilonTransition(matchState, -1), -1)
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) stateIsEndStateFor(state, idx) {
|
||||
func (this *ATNDeserializer) stateIsEndStateFor(state *ATNState, idx int) {
|
||||
if ( state.ruleIndex != idx) {
|
||||
return nil
|
||||
}
|
||||
if (!( state instanceof StarLoopEntryState)) {
|
||||
if _,ok := state.(*StarLoopEntryState); !ok {
|
||||
return nil
|
||||
}
|
||||
var maybeLoopEndState = state.transitions[state.transitions.length - 1].target
|
||||
if (!( maybeLoopEndState instanceof LoopEndState)) {
|
||||
var maybeLoopEndState = state.transitions[len(state.transitions) - 1].target
|
||||
if _,ok := maybeLoopEndState.(*LoopEndState); !ok {
|
||||
return nil
|
||||
}
|
||||
if (maybeLoopEndState.epsilonOnlyTransitions &&
|
||||
(maybeLoopEndState.transitions[0].target instanceof RuleStopState)) {
|
||||
|
||||
_,ok := maybeLoopEndState.transitions[0].target.(*RuleStopState)
|
||||
|
||||
if (maybeLoopEndState.epsilonOnlyTransitions && ok) {
|
||||
return state
|
||||
} else {
|
||||
return nil
|
||||
|
@ -419,10 +477,10 @@ func (this *ATNDeserializer) stateIsEndStateFor(state, idx) {
|
|||
//
|
||||
// @param atn The ATN.
|
||||
//
|
||||
func (this *ATNDeserializer) markPrecedenceDecisions(atn) {
|
||||
for(var i=0 i<atn.states.length i++) {
|
||||
func (this *ATNDeserializer) markPrecedenceDecisions(atn *ATN) {
|
||||
for i :=0; i< len(atn.states); i++ {
|
||||
var state = atn.states[i]
|
||||
if (!( state instanceof StarLoopEntryState)) {
|
||||
if _,ok := state.(*StarLoopEntryState); !ok {
|
||||
continue
|
||||
}
|
||||
// We analyze the ATN to determine if this ATN decision state is the
|
||||
|
@ -430,89 +488,104 @@ func (this *ATNDeserializer) markPrecedenceDecisions(atn) {
|
|||
// precedence rule should continue or complete.
|
||||
//
|
||||
if ( atn.ruleToStartState[state.ruleIndex].isPrecedenceRule) {
|
||||
var maybeLoopEndState = state.transitions[state.transitions.length - 1].target
|
||||
var maybeLoopEndState = state.transitions[len(state.transitions) - 1].target
|
||||
if _, ok := maybeLoopEndState.(LoopEndState); ok {
|
||||
if ( maybeLoopEndState.epsilonOnlyTransitions &&
|
||||
(maybeLoopEndState.transitions[0].target instanceof RuleStopState)) {
|
||||
state.precedenceRuleDecision = true
|
||||
s2,ok2 := maybeLoopEndState.transitions[0].target.(*RuleStopState)
|
||||
if ( maybeLoopEndState.epsilonOnlyTransitions && ok2) {
|
||||
s2.precedenceRuleDecision = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) verifyATN(atn) {
|
||||
func (this *ATNDeserializer) verifyATN(atn *ATN) {
|
||||
if (!this.deserializationOptions.verifyATN) {
|
||||
return
|
||||
}
|
||||
// verify assumptions
|
||||
for(var i=0 i<atn.states.length i++) {
|
||||
for i:=0; i<len(atn.states); i++ {
|
||||
|
||||
var state = atn.states[i]
|
||||
if (state == nil) {
|
||||
continue
|
||||
}
|
||||
this.checkCondition(state.epsilonOnlyTransitions || state.transitions.length <= 1)
|
||||
if _, ok := state.(PlusBlockStartState); ok {
|
||||
this.checkCondition(state.loopBackState != nil)
|
||||
} else if _, ok := state.(StarLoopEntryState); ok {
|
||||
this.checkCondition(state.loopBackState != nil)
|
||||
this.checkCondition(state.transitions.length == 2)
|
||||
if (state.transitions[0].target instanceof StarBlockStartState) {
|
||||
this.checkCondition(state.transitions[1].target instanceof LoopEndState)
|
||||
this.checkCondition(!state.nonGreedy)
|
||||
} else if (state.transitions[0].target instanceof LoopEndState) {
|
||||
this.checkCondition(state.transitions[1].target instanceof StarBlockStartState)
|
||||
this.checkCondition(state.nonGreedy)
|
||||
} else {
|
||||
panic("IllegalState")
|
||||
}
|
||||
} else if _, ok := state.(StarLoopbackState); ok {
|
||||
this.checkCondition(state.transitions.length == 1)
|
||||
this.checkCondition(state.transitions[0].target instanceof StarLoopEntryState)
|
||||
} else if _, ok := state.(LoopEndState); ok {
|
||||
this.checkCondition(state.loopBackState != nil)
|
||||
} else if _, ok := state.(RuleStartState); ok {
|
||||
this.checkCondition(state.stopState != nil)
|
||||
} else if _, ok := state.(BlockStartState); ok {
|
||||
this.checkCondition(state.endState != nil)
|
||||
} else if _, ok := state.(BlockEndState); ok {
|
||||
this.checkCondition(state.startState != nil)
|
||||
} else if _, ok := state.(DecisionState); ok {
|
||||
this.checkCondition(state.transitions.length <= 1 || state.decision >= 0)
|
||||
} else {
|
||||
this.checkCondition(state.transitions.length <= 1 || _, ok := state.(RuleStopState); ok)
|
||||
this.checkCondition(state.epsilonOnlyTransitions || len(state.transitions) <= 1, nil)
|
||||
|
||||
switch s2:= state.(type) {
|
||||
|
||||
case *PlusBlockStartState:
|
||||
this.checkCondition(s2.loopBackState != nil,nil)
|
||||
case *StarLoopEntryState:
|
||||
|
||||
this.checkCondition(s2.loopBackState != nil,nil)
|
||||
this.checkCondition(len(s2.transitions) == 2,nil)
|
||||
|
||||
switch _ := s2.(type) {
|
||||
case *StarBlockStartState:
|
||||
_,ok2 := s2.transitions[1].target.(*LoopEndState)
|
||||
this.checkCondition(ok2, nil)
|
||||
this.checkCondition(!s2.nonGreedy, nil)
|
||||
case *LoopEndState:
|
||||
_,ok2 := s2.transitions[1].target.(*StarBlockStartState)
|
||||
// this.checkCondition(state.transitions[1].target instanceof StarBlockStartState)
|
||||
this.checkCondition(ok2, nil)
|
||||
this.checkCondition(s2.nonGreedy, nil)
|
||||
default:
|
||||
panic("IllegalState")
|
||||
}
|
||||
|
||||
case *StarLoopbackState:
|
||||
this.checkCondition(len(state.transitions) == 1, nil)
|
||||
_,ok2 := state.transitions[0].target.(*StarLoopEntryState)
|
||||
this.checkCondition(ok2, nil)
|
||||
case *LoopEndState:
|
||||
this.checkCondition(s2.loopBackState != nil, nil)
|
||||
case *RuleStartState:
|
||||
this.checkCondition(s2.stopState != nil, nil)
|
||||
case *BlockStartState:
|
||||
this.checkCondition(s2.endState != nil, nil)
|
||||
case *BlockEndState:
|
||||
this.checkCondition(s2.startState != nil, nil)
|
||||
case *DecisionState:
|
||||
this.checkCondition(len(s2.transitions) <= 1 || s2.decision >= 0, nil)
|
||||
default:
|
||||
_, ok := s2.(*RuleStopState)
|
||||
this.checkCondition(len(s2.transitions) <= 1 || ok, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) checkCondition(condition, message) {
|
||||
func (this *ATNDeserializer) checkCondition(condition bool, message string) {
|
||||
if (!condition) {
|
||||
if (message == nil || message==nil) {
|
||||
if (message==nil) {
|
||||
message = "IllegalState"
|
||||
}
|
||||
panic (message)
|
||||
panic(message)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readInt() {
|
||||
return this.data[this.pos++]
|
||||
func (this *ATNDeserializer) readInt() int {
|
||||
v := this.data[this.pos]
|
||||
this.pos += 1
|
||||
return v
|
||||
}
|
||||
|
||||
ATNDeserializer.prototype.readInt32 = function() {
|
||||
func (this *ATNDeserializer) readInt32() int {
|
||||
var low = this.readInt()
|
||||
var high = this.readInt()
|
||||
return low | (high << 16)
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) readLong() {
|
||||
func (this *ATNDeserializer) readLong() int64 {
|
||||
var low = this.readInt32()
|
||||
var high = this.readInt32()
|
||||
return (low & 0x00000000FFFFFFFF) | (high << 32)
|
||||
}
|
||||
|
||||
type createByteToHex struct {
|
||||
func createByteToHex() {
|
||||
var bth = []
|
||||
for i := 0 i < 256 i++) {
|
||||
for i := 0; i < 256; i++ {
|
||||
bth[i] = (i + 0x100).toString(16).substr(1).toUpperCase()
|
||||
}
|
||||
return bth
|
||||
|
@ -520,7 +593,7 @@ type createByteToHex struct {
|
|||
|
||||
var byteToHex = createByteToHex()
|
||||
|
||||
func (this *ATNDeserializer) readUUID() {
|
||||
func (this *ATNDeserializer) readUUID() string {
|
||||
var bb = []
|
||||
for i:=7;i>=0;i-- {
|
||||
var int = this.readInt()
|
||||
|
@ -538,9 +611,9 @@ func (this *ATNDeserializer) readUUID() {
|
|||
byteToHex[bb[14]] + byteToHex[bb[15]]
|
||||
}
|
||||
|
||||
ATNDeserializer.prototype.edgeFactory = function(atn, type, src, trg, arg1, arg2, arg3, sets) {
|
||||
ATNDeserializer.prototypeIndex.edgeFactory = function(atn, typeIndex, src, trg, arg1, arg2, arg3, sets) {
|
||||
var target = atn.states[trg]
|
||||
switch(type) {
|
||||
switch(typeIndex) {
|
||||
case Transition.EPSILON:
|
||||
return NewEpsilonTransition(target)
|
||||
case Transition.RANGE:
|
||||
|
@ -562,11 +635,11 @@ ATNDeserializer.prototype.edgeFactory = function(atn, type, src, trg, arg1, arg2
|
|||
case Transition.WILDCARD:
|
||||
return NewWildcardTransition(target)
|
||||
default:
|
||||
panic "The specified transition type: " + type + " is not valid."
|
||||
panic "The specified transition typeIndex: " + typeIndex + " is not valid."
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ATNDeserializer) stateFactory(type, ruleIndex) {
|
||||
func (this *ATNDeserializer) stateFactory(typeIndex, ruleIndex) {
|
||||
if (this.stateFactories == nil) {
|
||||
var sf = []
|
||||
sf[ATNStateInvalidType] = nil
|
||||
|
@ -584,10 +657,10 @@ func (this *ATNDeserializer) stateFactory(type, ruleIndex) {
|
|||
sf[ATNStateLOOP_END] = function() { return NewLoopEndState() }
|
||||
this.stateFactories = sf
|
||||
}
|
||||
if (type>this.stateFactories.length || this.stateFactories[type] == nil) {
|
||||
panic("The specified state type " + type + " is not valid.")
|
||||
if (typeIndex>len(this.stateFactories) || this.stateFactories[typeIndex] == nil) {
|
||||
panic("The specified state typeIndex " + typeIndex + " is not valid.")
|
||||
} else {
|
||||
var s = this.stateFactories[type]()
|
||||
var s = this.stateFactories[typeIndex]()
|
||||
if (s!=nil) {
|
||||
s.ruleIndex = ruleIndex
|
||||
return s
|
||||
|
@ -595,7 +668,7 @@ func (this *ATNDeserializer) stateFactory(type, ruleIndex) {
|
|||
}
|
||||
}
|
||||
|
||||
ATNDeserializer.prototype.lexerActionFactory = function(type, data1, data2) {
|
||||
ATNDeserializer.prototypeIndex.lexerActionFactory = function(typeIndex, data1, data2) {
|
||||
if (this.actionFactories == nil) {
|
||||
var af = []
|
||||
af[LexerActionTypeCHANNEL] = function(data1, data2) { return NewLexerChannelAction(data1) }
|
||||
|
@ -608,10 +681,10 @@ ATNDeserializer.prototype.lexerActionFactory = function(type, data1, data2) {
|
|||
af[LexerActionTypeTYPE] = function(data1, data2) { return NewLexerTypeAction(data1) }
|
||||
this.actionFactories = af
|
||||
}
|
||||
if (type>this.actionFactories.length || this.actionFactories[type] == nil) {
|
||||
panic("The specified lexer action type " + type + " is not valid.")
|
||||
if (typeIndex>len(this.actionFactories) || this.actionFactories[typeIndex] == nil) {
|
||||
panic("The specified lexer action typeIndex " + typeIndex + " is not valid.")
|
||||
} else {
|
||||
return this.actionFactories[type](data1, data2)
|
||||
return this.actionFactories[typeIndex](data1, data2)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ type ATNSimulator struct {
|
|||
sharedContextCache *PredictionContextCache
|
||||
}
|
||||
|
||||
func ATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimulator {
|
||||
func NewATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimulator {
|
||||
|
||||
// The context cache maps all PredictionContext objects that are ==
|
||||
// to a single cached copy. This cache is shared across all contexts
|
||||
|
@ -29,14 +29,18 @@ func ATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimu
|
|||
|
||||
this := new(ATNSimulator)
|
||||
|
||||
this.atn = atn
|
||||
this.sharedContextCache = sharedContextCache
|
||||
this.InitATNSimulator(atn, sharedContextCache)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ATNSimulator) InitATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) {
|
||||
this.atn = atn
|
||||
this.sharedContextCache = sharedContextCache
|
||||
}
|
||||
|
||||
// Must distinguish between missing edge and edge we know leads nowhere///
|
||||
var ATNSimulatorERROR = NewDFAState(0x7FFFFFFF, NewATNConfigSet())
|
||||
var ATNSimulatorERROR = NewDFAState(0x7FFFFFFF, NewATNConfigSet(false))
|
||||
|
||||
func (this *ATNSimulator) getCachedContext(context *PredictionContext) *PredictionContext {
|
||||
if (this.sharedContextCache == nil) {
|
||||
|
|
|
@ -78,12 +78,12 @@ type ATNState struct {
|
|||
func NewATNState() *ATNState {
|
||||
|
||||
as := new(ATNState)
|
||||
as.initATNState()
|
||||
as.InitATNState()
|
||||
|
||||
return as
|
||||
}
|
||||
|
||||
func (as *ATNState) initATNState(){
|
||||
func (as *ATNState) InitATNState(){
|
||||
|
||||
// Which ATN are we in?
|
||||
as.atn = nil
|
||||
|
@ -167,7 +167,7 @@ type BasicState struct {
|
|||
|
||||
func NewBasicState() *BasicState {
|
||||
this := new(BasicState)
|
||||
this.initATNState()
|
||||
this.InitATNState()
|
||||
|
||||
this.stateType = ATNStateBASIC
|
||||
return this
|
||||
|
@ -184,13 +184,13 @@ func NewDecisionState() *DecisionState {
|
|||
|
||||
this := new(DecisionState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *DecisionState) initDecisionState() {
|
||||
func (this *DecisionState) InitDecisionState() {
|
||||
|
||||
this.decision = -1
|
||||
this.nonGreedy = false
|
||||
|
@ -208,13 +208,13 @@ func NewBlockStartState() *BlockStartState {
|
|||
|
||||
this := new(BlockStartState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *BlockStartState) initBlockStartState() {
|
||||
func (this *BlockStartState) InitBlockStartState() {
|
||||
|
||||
this.endState = nil
|
||||
|
||||
|
@ -228,9 +228,9 @@ func NewBasicBlockStartState() *BasicBlockStartState {
|
|||
|
||||
this := new(BasicBlockStartState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.initBlockStartState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
this.InitBlockStartState()
|
||||
|
||||
this.stateType = ATNStateBLOCK_START
|
||||
return this
|
||||
|
@ -247,7 +247,7 @@ func NewBlockEndState() *BlockEndState {
|
|||
|
||||
this := new(BlockEndState)
|
||||
|
||||
this.initATNState()
|
||||
this.InitATNState()
|
||||
this.stateType = ATNStateBLOCK_END
|
||||
this.startState = nil
|
||||
|
||||
|
@ -266,7 +266,7 @@ type RuleStopState struct {
|
|||
func NewRuleStopState() *RuleStopState {
|
||||
this := new(RuleStopState)
|
||||
|
||||
this.initATNState()
|
||||
this.InitATNState()
|
||||
this.stateType = ATNStateRULE_STOP
|
||||
return this
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func NewRuleStartState() *RuleStartState {
|
|||
|
||||
this := new(RuleStartState)
|
||||
|
||||
this.initATNState()
|
||||
this.InitATNState()
|
||||
this.stateType = ATNStateRULE_START
|
||||
this.stopState = nil
|
||||
this.isPrecedenceRule = false
|
||||
|
@ -301,9 +301,9 @@ func NewPlusLoopbackState() *PlusLoopbackState {
|
|||
|
||||
this := new(PlusLoopbackState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.initBlockStartState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
this.InitBlockStartState()
|
||||
|
||||
this.stateType = ATNStatePLUS_LOOP_BACK
|
||||
return this
|
||||
|
@ -324,9 +324,9 @@ func NewPlusBlockStartState() *PlusBlockStartState {
|
|||
|
||||
this := new(PlusBlockStartState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.initBlockStartState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
this.InitBlockStartState()
|
||||
|
||||
this.stateType = ATNStatePLUS_BLOCK_START
|
||||
this.loopBackState = nil
|
||||
|
@ -343,9 +343,9 @@ func NewStarBlockStartState() *StarBlockStartState {
|
|||
|
||||
this := new(StarBlockStartState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.initBlockStartState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
this.InitBlockStartState()
|
||||
|
||||
this.stateType = ATNStateSTAR_BLOCK_START
|
||||
|
||||
|
@ -361,7 +361,7 @@ func NewStarLoopbackState() *StarLoopbackState {
|
|||
|
||||
this := new(StarLoopbackState)
|
||||
|
||||
this.initATNState()
|
||||
this.InitATNState()
|
||||
|
||||
this.stateType = ATNStateSTAR_LOOP_BACK
|
||||
return this
|
||||
|
@ -379,8 +379,8 @@ func NewStarLoopEntryState() *StarLoopEntryState {
|
|||
|
||||
this := new(StarLoopEntryState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
|
||||
this.stateType = ATNStateSTAR_LOOP_ENTRY
|
||||
this.loopBackState = nil
|
||||
|
@ -402,7 +402,7 @@ func NewLoopEndState() *LoopEndState {
|
|||
|
||||
this := new(LoopEndState)
|
||||
|
||||
this.initATNState()
|
||||
this.InitATNState()
|
||||
|
||||
this.stateType = ATNStateLOOP_END
|
||||
this.loopBackState = nil
|
||||
|
@ -419,8 +419,8 @@ func NewTokensStartState() *TokensStartState {
|
|||
|
||||
this := new(TokensStartState)
|
||||
|
||||
this.initATNState()
|
||||
this.initDecisionState()
|
||||
this.InitATNState()
|
||||
this.InitDecisionState()
|
||||
|
||||
this.stateType = ATNStateTOKEN_START
|
||||
return this
|
||||
|
|
|
@ -25,6 +25,7 @@ type IntStream interface {
|
|||
|
||||
type TokenStream interface {
|
||||
IntStream
|
||||
|
||||
LT(k int) *Token
|
||||
get(index int) *Token
|
||||
getTokenSource() *TokenSource
|
||||
|
@ -168,13 +169,13 @@ func (bt *BufferedTokenStream) fetch(n int) int {
|
|||
}
|
||||
|
||||
// Get all tokens from start..stop inclusively///
|
||||
func (bt *BufferedTokenStream) getTokens(start int, stop int, types []int) []*Token {
|
||||
func (bt *BufferedTokenStream) getTokens(start int, stop int, types *IntervalSet) []*Token {
|
||||
|
||||
if (start < 0 || stop < 0) {
|
||||
return nil
|
||||
}
|
||||
bt.lazyInit()
|
||||
var subset = (make[]*Token)
|
||||
var subset = make([]*Token)
|
||||
if (stop >= len(bt.tokens)) {
|
||||
stop = len(bt.tokens) - 1
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ func NewDFASerializer(dfa *DFA, literalNames, symbolicNames []string) *DFASerial
|
|||
|
||||
this := new(DFASerializer)
|
||||
|
||||
this.initDFASerializer(dfa, literalNames, symbolicNames)
|
||||
this.InitDFASerializer(dfa, literalNames, symbolicNames)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *DFASerializer) initDFASerializer(dfa *DFA, literalNames, symbolicNames []string) {
|
||||
func (this *DFASerializer) InitDFASerializer(dfa *DFA, literalNames, symbolicNames []string) {
|
||||
this.dfa = dfa
|
||||
this.literalNames = literalNames
|
||||
this.symbolicNames = symbolicNames
|
||||
|
@ -105,7 +105,7 @@ func NewLexerDFASerializer(dfa *DFA) *LexerDFASerializer {
|
|||
|
||||
this := new(DFASerializer)
|
||||
|
||||
this.initDFASerializer(dfa, nil, nil)
|
||||
this.InitDFASerializer(dfa, nil, nil)
|
||||
|
||||
return this
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package antlr4
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type ErrorStrategy struct {
|
||||
|
@ -15,7 +16,7 @@ func (this *ErrorStrategy) reset(recognizer *Parser){
|
|||
func (this *ErrorStrategy) recoverInline(recognizer *Parser){
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) recover(recognizer *Parser, e *Error){
|
||||
func (this *ErrorStrategy) recover(recognizer *Parser, e *RecognitionException){
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) sync(recognizer *Parser){
|
||||
|
@ -35,12 +36,17 @@ type DefaultErrorStrategy struct {
|
|||
|
||||
errorRecoveryMode bool
|
||||
lastErrorIndex int
|
||||
lastErrorStates []int
|
||||
lastErrorStates *IntervalSet
|
||||
}
|
||||
|
||||
func DefaultErrorStrategy() *DefaultErrorStrategy {
|
||||
func NewDefaultErrorStrategy() *DefaultErrorStrategy {
|
||||
|
||||
d := new(DefaultErrorStrategy)
|
||||
d.InitDefaultErrorStrategy()
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *DefaultErrorStrategy) InitDefaultErrorStrategy() {
|
||||
|
||||
// Indicates whether the error strategy is currently "recovering from an
|
||||
// error". This is used to suppress reporting multiple error messages while
|
||||
|
@ -59,12 +65,8 @@ func DefaultErrorStrategy() *DefaultErrorStrategy {
|
|||
d.lastErrorIndex = -1
|
||||
d.lastErrorStates = nil
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
//DefaultErrorStrategy.prototype = Object.create(ErrorStrategy.prototype)
|
||||
//DefaultErrorStrategy.prototype.constructor = DefaultErrorStrategy
|
||||
|
||||
// <p>The default implementation simply calls {@link //endErrorCondition} to
|
||||
// ensure that the handler is not in error recovery mode.</p>
|
||||
func (this *DefaultErrorStrategy) reset(recognizer *Parser) {
|
||||
|
@ -125,7 +127,7 @@ func (this *DefaultErrorStrategy) reportMatch(recognizer *Parser) {
|
|||
// the exception</li>
|
||||
// </ul>
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) {
|
||||
func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *RecognitionException) {
|
||||
// if we've already reported an error and have not matched a token
|
||||
// yet successfully, don't report any errors.
|
||||
if(this.inErrorRecoveryMode(recognizer)) {
|
||||
|
@ -135,9 +137,9 @@ func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) {
|
|||
|
||||
switch e.(type) {
|
||||
default:
|
||||
fmt.Println("unknown recognition error type: " + e.constructor.name)
|
||||
fmt.Println(e.stack)
|
||||
recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e)
|
||||
fmt.Println("unknown recognition error type: " + reflect.TypeOf(e).Name())
|
||||
// fmt.Println(e.stack)
|
||||
recognizer.notifyErrorListeners(e.offendingToken, e.message, e)
|
||||
case NoViableAltException:
|
||||
this.reportNoViableAlternative(recognizer, e)
|
||||
case InputMismatchException:
|
||||
|
@ -146,6 +148,7 @@ func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) {
|
|||
this.reportFailedPredicate(recognizer, e)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// {@inheritDoc}
|
||||
//
|
||||
|
@ -154,19 +157,20 @@ func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) {
|
|||
// that can follow the current rule.</p>
|
||||
//
|
||||
func (this *DefaultErrorStrategy) recover(recognizer *Parser, e *RecognitionException) {
|
||||
if (this.lastErrorIndex==recognizer.getInputStream().index &&
|
||||
this.lastErrorStates != nil && this.lastErrorStates.indexOf(recognizer.state)>=0) {
|
||||
|
||||
if (this.lastErrorIndex==recognizer.getInputStream().index() &&
|
||||
this.lastErrorStates != nil && this.lastErrorStates.contains(recognizer.state)) {
|
||||
// uh oh, another error at same token index and previously-visited
|
||||
// state in ATN must be a case where LT(1) is in the recovery
|
||||
// token set so nothing got consumed. Consume a single token
|
||||
// at least to prevent an infinite loop this is a failsafe.
|
||||
recognizer.consume()
|
||||
}
|
||||
this.lastErrorIndex = recognizer._input.index
|
||||
this.lastErrorIndex = recognizer._input.index()
|
||||
if (this.lastErrorStates == nil) {
|
||||
this.lastErrorStates = []
|
||||
this.lastErrorStates = NewIntervalSet()
|
||||
}
|
||||
this.lastErrorStates.push(recognizer.state)
|
||||
this.lastErrorStates.addOne(recognizer.state)
|
||||
var followSet = this.getErrorRecoverySet(recognizer)
|
||||
this.consumeUntil(recognizer, followSet)
|
||||
}
|
||||
|
@ -224,7 +228,7 @@ func (this *DefaultErrorStrategy) sync(recognizer *Parser) {
|
|||
var s = recognizer._interp.atn.states[recognizer.state]
|
||||
var la = recognizer.getTokenStream().LA(1)
|
||||
// try cheaper subset first might get lucky. seems to shave a wee bit off
|
||||
if (la==TokenEOF || recognizer.atn.nextTokens(s).contains(la)) {
|
||||
if (la==TokenEOF || recognizer.getATN().nextTokens(s).contains(la)) {
|
||||
return
|
||||
}
|
||||
// Return but don't end recovery. only do that upon valid token match
|
||||
|
@ -264,14 +268,14 @@ func (this *DefaultErrorStrategy) sync(recognizer *Parser) {
|
|||
// @param recognizer the parser instance
|
||||
// @param e the recognition exception
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer *Parser, e *RecognitionException) {
|
||||
var tokens = recognizer.getTokenStream()
|
||||
var input
|
||||
func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer *Parser, e *NoViableAltException) {
|
||||
var tokens = recognizer.getTokenStream()
|
||||
var input string
|
||||
if(tokens != nil) {
|
||||
if (e.startToken.tokenType==TokenEOF) {
|
||||
input = "<EOF>"
|
||||
} else {
|
||||
input = tokens.getText(NewInterval(e.startToken, e.offendingToken))
|
||||
input = tokens.getTextFromInterval(NewInterval(e.startToken, e.offendingToken))
|
||||
}
|
||||
} else {
|
||||
input = "<unknown input>"
|
||||
|
@ -305,7 +309,7 @@ func (this *DefaultErrorStrategy) reportInputMismatch(recognizer *Parser, e *Rec
|
|||
// @param e the recognition exception
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportFailedPredicate(recognizer *Parser, e *RecognitionException) {
|
||||
var ruleName = recognizer.ruleNames[recognizer._ctx.ruleIndex]
|
||||
var ruleName = recognizer.getRuleNames()[recognizer._ctx.ruleIndex]
|
||||
var msg = "rule " + ruleName + " " + e.message
|
||||
recognizer.notifyErrorListeners(msg, e.offendingToken, e)
|
||||
}
|
||||
|
@ -336,7 +340,7 @@ func (this *DefaultErrorStrategy) reportUnwantedToken(recognizer *Parser) {
|
|||
var tokenName = this.getTokenErrorDisplay(t)
|
||||
var expecting = this.getExpectedTokens(recognizer)
|
||||
var msg = "extraneous input " + tokenName + " expecting " +
|
||||
expecting.toString(recognizer.literalNames, recognizer.symbolicNames)
|
||||
expecting.toStringVerbose(recognizer.literalNames, recognizer.symbolicNames, false)
|
||||
recognizer.notifyErrorListeners(msg, t, nil)
|
||||
}
|
||||
// This method is called to report a syntax error which requires the
|
||||
|
@ -362,7 +366,7 @@ func (this *DefaultErrorStrategy) reportMissingToken(recognizer *Parser) {
|
|||
this.beginErrorCondition(recognizer)
|
||||
var t = recognizer.getCurrentToken()
|
||||
var expecting = this.getExpectedTokens(recognizer)
|
||||
var msg = "missing " + expecting.toString(recognizer.literalNames, recognizer.symbolicNames) +
|
||||
var msg = "missing " + expecting.toStringVerbose(recognizer.literalNames, recognizer.symbolicNames, false) +
|
||||
" at " + this.getTokenErrorDisplay(t)
|
||||
recognizer.notifyErrorListeners(msg, t, nil)
|
||||
}
|
||||
|
@ -485,7 +489,7 @@ func (this *DefaultErrorStrategy) singleTokenInsertion(recognizer *Parser) {
|
|||
// deletion successfully recovers from the mismatched input, otherwise
|
||||
// {@code nil}
|
||||
//
|
||||
func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer *Parser) {
|
||||
func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer *Parser) Token {
|
||||
var nextTokenType = recognizer.getTokenStream().LA(2)
|
||||
var expecting = this.getExpectedTokens(recognizer)
|
||||
if (expecting.contains(nextTokenType)) {
|
||||
|
@ -526,8 +530,8 @@ func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer *Parser) {
|
|||
func (this *DefaultErrorStrategy) getMissingSymbol(recognizer *Parser) {
|
||||
var currentSymbol = recognizer.getCurrentToken()
|
||||
var expecting = this.getExpectedTokens(recognizer)
|
||||
var expectedTokenType = expecting.first() // get any element
|
||||
var tokenText
|
||||
var expectedTokenType = expecting.first()
|
||||
var tokenText string
|
||||
if (expectedTokenType==TokenEOF) {
|
||||
tokenText = "<missing EOF>"
|
||||
} else {
|
||||
|
@ -538,10 +542,12 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer *Parser) {
|
|||
if (current.tokenType==TokenEOF && lookback != nil) {
|
||||
current = lookback
|
||||
}
|
||||
return recognizer.getTokenFactory().create(current.source, expectedTokenType, tokenText, TokenDefaultChannel, -1, -1, current.line, current.column)
|
||||
|
||||
tf := recognizer.getTokenFactory()
|
||||
return tf.create(current.source, expectedTokenType, tokenText, TokenDefaultChannel, -1, -1, current.line, current.column)
|
||||
}
|
||||
|
||||
func (this *DefaultErrorStrategy) getExpectedTokens(recognizer *Parser) {
|
||||
func (this *DefaultErrorStrategy) getExpectedTokens(recognizer *Parser) *IntervalSet {
|
||||
return recognizer.getExpectedTokens()
|
||||
}
|
||||
|
||||
|
@ -675,7 +681,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer *Parser) *Inter
|
|||
// compute what follows who invoked us
|
||||
var invokingState = atn.states[ctx.invokingState]
|
||||
var rt = invokingState.transitions[0]
|
||||
var follow = atn.nextTokens(rt.followState)
|
||||
var follow = atn.nextTokens(rt.(*RuleTransition).followState, nil)
|
||||
recoverSet.addSet(follow)
|
||||
ctx = ctx.parentCtx
|
||||
}
|
||||
|
@ -684,7 +690,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer *Parser) *Inter
|
|||
}
|
||||
|
||||
// Consume tokens until one matches the given token set.//
|
||||
func (this *DefaultErrorStrategy) consumeUntil(recognizer *Parser, set) {
|
||||
func (this *DefaultErrorStrategy) consumeUntil(recognizer *Parser, set *IntervalSet) {
|
||||
var ttype = recognizer.getTokenStream().LA(1)
|
||||
for( ttype != TokenEOF && !set.contains(ttype)) {
|
||||
recognizer.consume()
|
||||
|
@ -719,14 +725,18 @@ func (this *DefaultErrorStrategy) consumeUntil(recognizer *Parser, set) {
|
|||
// {@code myparser.setErrorHandler(NewBailErrorStrategy())}</p>
|
||||
//
|
||||
// @see Parser//setErrorHandler(ANTLRErrorStrategy)
|
||||
//
|
||||
|
||||
type BailErrorStrategy struct {
|
||||
DefaultErrorStrategy.call(this)
|
||||
return this
|
||||
DefaultErrorStrategy
|
||||
}
|
||||
|
||||
//BailErrorStrategy.prototype = Object.create(DefaultErrorStrategy.prototype)
|
||||
//BailErrorStrategy.prototype.constructor = BailErrorStrategy
|
||||
func NewBailErrorStrategy() *BailErrorStrategy {
|
||||
|
||||
this := new(BailErrorStrategy)
|
||||
this.InitDefaultErrorStrategy()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
// Instead of recovering from exception {@code e}, re-panic it wrapped
|
||||
// in a {@link ParseCancellationException} so it is not caught by the
|
||||
|
@ -739,7 +749,7 @@ func (this *BailErrorStrategy) recover(recognizer *Parser, e *RecognitionExcepti
|
|||
context.exception = e
|
||||
context = context.parentCtx
|
||||
}
|
||||
panic(NewParseCancellationException(e))
|
||||
panic(NewParseCancellationException()) // TODO we don't emit e properly
|
||||
}
|
||||
|
||||
// Make sure we don't attempt to recover inline if the parser
|
||||
|
|
|
@ -33,12 +33,12 @@ func NewRecognitionException(message string, recognizer *Recognizer, input *Inpu
|
|||
// TODO may be able to use - "runtime" func Stack(buf []byte, all bool) int
|
||||
|
||||
t := new(RecognitionException)
|
||||
t.initRecognitionException(message, recognizer, input, ctx)
|
||||
t.InitRecognitionException(message, recognizer, input, ctx)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *RecognitionException) initRecognitionException(message string, recognizer *Recognizer, input *InputStream, ctx *RuleContext){
|
||||
func (t *RecognitionException) InitRecognitionException(message string, recognizer *Recognizer, input *InputStream, ctx *RuleContext){
|
||||
|
||||
t.message = message
|
||||
t.recognizer = recognizer
|
||||
|
@ -99,7 +99,7 @@ func NewLexerNoViableAltException(lexer *Lexer, input *InputStream, startIndex i
|
|||
|
||||
this := new (LexerNoViableAltException)
|
||||
|
||||
this.initRecognitionException("", lexer, input, nil)
|
||||
this.InitRecognitionException("", lexer, input, nil)
|
||||
|
||||
this.startIndex = startIndex
|
||||
this.deadEndConfigs = deadEndConfigs
|
||||
|
@ -152,7 +152,7 @@ func NoViableAltException(recognizer *Parser, input *InputStream, startToken *To
|
|||
}
|
||||
|
||||
this := new(NoViableAltException)
|
||||
this.initRecognitionException("", recognizer, input, ctx)
|
||||
this.InitRecognitionException("", recognizer, input, ctx)
|
||||
|
||||
// Which configurations did we try at input.index() that couldn't match
|
||||
// input.LT(1)?//
|
||||
|
@ -179,7 +179,7 @@ type InputMismatchException struct {
|
|||
func NewInputMismatchException(recognizer *Parser) *InputMismatchException {
|
||||
|
||||
this := new(InputMismatchException)
|
||||
this.initRecognitionException("", recognizer, recognizer.getInputStream(), recognizer._ctx)
|
||||
this.InitRecognitionException("", recognizer, recognizer.getInputStream(), recognizer._ctx)
|
||||
|
||||
this.offendingToken = recognizer.getCurrentToken()
|
||||
|
||||
|
@ -206,7 +206,7 @@ func NewFailedPredicateException(recognizer *Parser, predicate string, message s
|
|||
|
||||
this := new(FailedPredicateException)
|
||||
|
||||
this.initRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx)
|
||||
this.InitRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx)
|
||||
|
||||
var s = recognizer._interp.atn.states[recognizer.state]
|
||||
var trans = s.transitions[0]
|
||||
|
|
|
@ -51,8 +51,8 @@ func NewIntervalSet() *IntervalSet {
|
|||
return i
|
||||
}
|
||||
|
||||
func (i *IntervalSet) first(v int) int {
|
||||
if (i.intervals == nil || len(i.intervals)==0) {
|
||||
func (i *IntervalSet) first() int {
|
||||
if (len(i.intervals)==0) {
|
||||
return TokenInvalidType
|
||||
} else {
|
||||
return i.intervals[0].start
|
||||
|
|
|
@ -49,13 +49,13 @@ func NewLexer(input *InputStream) *Lexer {
|
|||
|
||||
lexer := new(Lexer)
|
||||
|
||||
lexer.initRecognizer()
|
||||
lexer.initLexer(input)
|
||||
lexer.InitRecognizer()
|
||||
lexer.InitLexer(input)
|
||||
|
||||
return lexer
|
||||
}
|
||||
|
||||
func (l *Lexer) initLexer(input *InputStream){
|
||||
func (l *Lexer) InitLexer(input *InputStream){
|
||||
|
||||
l._input = input
|
||||
l._factory = CommonTokenFactoryDEFAULT
|
||||
|
|
|
@ -38,6 +38,9 @@ type Parser struct {
|
|||
_tracer bool
|
||||
_parseListeners []*ParseTreeListener
|
||||
_syntaxErrors int
|
||||
|
||||
literalNames []string
|
||||
symbolicNames []string
|
||||
}
|
||||
|
||||
// p.is all the parsing support code essentially most of it is error
|
||||
|
@ -46,7 +49,7 @@ func NewParser(input *TokenStream) *Parser {
|
|||
|
||||
p := new(Parser)
|
||||
|
||||
p.initRecognizer()
|
||||
p.InitRecognizer()
|
||||
|
||||
// The input stream.
|
||||
p._input = nil
|
||||
|
@ -271,12 +274,12 @@ func (this *Parser) getATN() *ATN {
|
|||
return this.atn
|
||||
}
|
||||
|
||||
func (p *Parser) getTokenFactory() {
|
||||
func (p *Parser) getTokenFactory() *TokenFactory {
|
||||
return p._input.getTokenSource()._factory
|
||||
}
|
||||
|
||||
// Tell our token source and error strategy about a Newway to create tokens.//
|
||||
func (p *Parser) setTokenFactory(factory) {
|
||||
func (p *Parser) setTokenFactory(factory *TokenFactory) {
|
||||
p._input.getTokenSource()._factory = factory
|
||||
}
|
||||
|
||||
|
@ -590,14 +593,14 @@ func (p *Parser) isExpectedToken(symbol *Token) bool {
|
|||
//
|
||||
// @see ATN//getExpectedTokens(int, RuleContext)
|
||||
//
|
||||
func (p *Parser) getExpectedTokens() []*Token {
|
||||
func (p *Parser) getExpectedTokens() *IntervalSet {
|
||||
return p._interp.atn.getExpectedTokens(p.state, p._ctx)
|
||||
}
|
||||
|
||||
func (p *Parser) getExpectedTokensWithinCurrentRule() []*Token {
|
||||
func (p *Parser) getExpectedTokensWithinCurrentRule() *IntervalSet {
|
||||
var atn = p._interp.atn
|
||||
var s = atn.states[p.state]
|
||||
return atn.nextTokens(s)
|
||||
return atn.nextTokens(s,nil)
|
||||
}
|
||||
|
||||
// Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found.//
|
||||
|
@ -643,9 +646,9 @@ func (p *Parser) getDFAStrings() {
|
|||
// For debugging and other purposes.//
|
||||
func (p *Parser) dumpDFA() {
|
||||
var seenOne = false
|
||||
for i := 0; i < p._interp.decisionToDFA.length; i++) {
|
||||
for i := 0; i < p._interp.decisionToDFA.length; i++ {
|
||||
var dfa = p._interp.decisionToDFA[i]
|
||||
if (dfa.states.length > 0) {
|
||||
if ( len(dfa.states) > 0) {
|
||||
if (seenOne) {
|
||||
fmt.Println()
|
||||
}
|
||||
|
|
|
@ -232,38 +232,30 @@ import (
|
|||
// the input.</p>
|
||||
//
|
||||
|
||||
//var Utils = require('./../Utils')
|
||||
var Set = Utils.Set
|
||||
var BitSet = Utils.BitSet
|
||||
var DoubleDict = Utils.DoubleDict
|
||||
//var ATN = require('./ATN').ATN
|
||||
//var ATNConfig = require('./ATNConfig').ATNConfig
|
||||
//var ATNConfigSet = require('./ATNConfigSet').ATNConfigSet
|
||||
//var Token = require('./../Token').Token
|
||||
//var DFAState = require('./../dfa/DFAState').DFAState
|
||||
//var PredPrediction = require('./../dfa/DFAState').PredPrediction
|
||||
//var ATNSimulator = require('./ATNSimulator').ATNSimulator
|
||||
//var PredictionMode = require('./PredictionMode').PredictionMode
|
||||
//var RuleContext = require('./../RuleContext').RuleContext
|
||||
//var ParserRuleContext = require('./../ParserRuleContext').ParserRuleContext
|
||||
//var SemanticContext = require('./SemanticContext').SemanticContext
|
||||
//var StarLoopEntryState = require('./ATNState').StarLoopEntryState
|
||||
//var RuleStopState = require('./ATNState').RuleStopState
|
||||
//var PredictionContext = require('./../PredictionContext').PredictionContext
|
||||
//var Interval = require('./../IntervalSet').Interval
|
||||
//var Transitions = require('./Transition')
|
||||
var Transition = Transitions.Transition
|
||||
var SetTransition = Transitions.SetTransition
|
||||
var NotSetTransition = Transitions.NotSetTransition
|
||||
var RuleTransition = Transitions.RuleTransition
|
||||
var ActionTransition = Transitions.ActionTransition
|
||||
//var NoViableAltException = require('./../error/Errors').NoViableAltException
|
||||
type ParserATNSimulator struct {
|
||||
parser *Parser
|
||||
predictionMode int
|
||||
_input *TokenStream
|
||||
_startIndex int
|
||||
_dfa *DFA
|
||||
decisionToDFA []*DFA
|
||||
mergeCache DoubleDict
|
||||
_outerContext *ParserRuleContext
|
||||
}
|
||||
|
||||
//var SingletonPredictionContext = require('./../PredictionContext').SingletonPredictionContext
|
||||
//var predictionContextFromRuleContext = require('./../PredictionContext').predictionContextFromRuleContext
|
||||
func NewParserATNSimulator(parser *Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *ParserATNSimulator {
|
||||
|
||||
this := new(ParserATNSimulator)
|
||||
|
||||
this.InitParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) InitParserATNSimulator(parser *Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) {
|
||||
|
||||
this.InitATNSimulator(atn, sharedContextCache)
|
||||
|
||||
func ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) {
|
||||
ATNSimulator.call(this, atn, sharedContextCache)
|
||||
this.parser = parser
|
||||
this.decisionToDFA = decisionToDFA
|
||||
// SLL, LL, or LL + exact ambig detection?//
|
||||
|
@ -282,22 +274,19 @@ func ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) {
|
|||
// also be examined during cache lookup.
|
||||
//
|
||||
this.mergeCache = nil
|
||||
return this
|
||||
|
||||
}
|
||||
|
||||
//ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype)
|
||||
//ParserATNSimulator.prototype.constructor = ParserATNSimulator
|
||||
|
||||
ParserATNSimulator.prototype.debug = false
|
||||
ParserATNSimulator.prototype.debug_list_atn_decisions = false
|
||||
ParserATNSimulator.prototype.dfa_debug = false
|
||||
ParserATNSimulator.prototype.retry_debug = false
|
||||
var ParserATNSimulatorprototypedebug = false
|
||||
var ParserATNSimulatorprototypedebug_list_atn_decisions = false
|
||||
var ParserATNSimulatorprototypedfa_debug = false
|
||||
var ParserATNSimulatorprototyperetry_debug = false
|
||||
|
||||
func (this *ParserATNSimulator) reset() {
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) {
|
||||
if (this.debug || this.debug_list_atn_decisions) {
|
||||
func (this *ParserATNSimulator) adaptivePredict(input *TokenStream, decision int, outerContext *ParserRuleContext) int {
|
||||
if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) {
|
||||
fmt.Println("adaptivePredict decision " + decision +
|
||||
" exec LA(1)==" + this.getLookaheadName(input) +
|
||||
" line " + input.LT(1).line + ":" +
|
||||
|
@ -328,7 +317,7 @@ func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) {
|
|||
if (outerContext==nil) {
|
||||
outerContext = RuleContext.EMPTY
|
||||
}
|
||||
if (this.debug || this.debug_list_atn_decisions) {
|
||||
if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) {
|
||||
fmt.Println("predictATN decision " + dfa.decision +
|
||||
" exec LA(1)==" + this.getLookaheadName(input) +
|
||||
", outerContext=" + outerContext.toString(this.parser.ruleNames))
|
||||
|
@ -362,7 +351,7 @@ func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) {
|
|||
}
|
||||
}
|
||||
var alt = this.execATN(dfa, s0, input, index, outerContext)
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("DFA after predictATN: " + dfa.toString(this.parser.literalNames))
|
||||
}
|
||||
return alt
|
||||
|
@ -403,8 +392,8 @@ func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) {
|
|||
// conflict
|
||||
// conflict + preds
|
||||
//
|
||||
ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, outerContext ) {
|
||||
if (this.debug || this.debug_list_atn_decisions) {
|
||||
func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input *TokenStream, startIndex int, outerContext *ParserRuleContext ) int {
|
||||
if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) {
|
||||
fmt.Println("execATN decision " + dfa.decision +
|
||||
" exec LA(1)==" + this.getLookaheadName(input) +
|
||||
" line " + input.LT(1).line + ":" + input.LT(1).column)
|
||||
|
@ -412,16 +401,16 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
|
|||
var alt
|
||||
var previousD = s0
|
||||
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("s0 = " + s0)
|
||||
}
|
||||
var t = input.LA(1)
|
||||
while(true) { // while more work
|
||||
for(true) { // for more work
|
||||
var D = this.getExistingTargetState(previousD, t)
|
||||
if(D==nil) {
|
||||
D = this.computeTargetState(dfa, previousD, t)
|
||||
}
|
||||
if(D==ATNSimulator.ERROR) {
|
||||
if(D==ATNSimulatorERROR) {
|
||||
// if any configs in previous dipped into outer context, that
|
||||
// means that input up to t actually finished entry rule
|
||||
// at least for SLL decision. Full LL doesn't dip into outer
|
||||
|
@ -434,7 +423,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
|
|||
var e = this.noViableAlt(input, outerContext, previousD.configs, startIndex)
|
||||
input.seek(startIndex)
|
||||
alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD.configs, outerContext)
|
||||
if(alt!=ATN.INVALID_ALT_NUMBER) {
|
||||
if(alt!=ATNINVALID_ALT_NUMBER) {
|
||||
return alt
|
||||
} else {
|
||||
panic e
|
||||
|
@ -444,7 +433,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
|
|||
// IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
|
||||
var conflictingAlts = nil
|
||||
if (D.predicates!=nil) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("DFA state has preds in DFA sim LL failover")
|
||||
}
|
||||
var conflictIndex = input.index
|
||||
|
@ -452,8 +441,8 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
|
|||
input.seek(startIndex)
|
||||
}
|
||||
conflictingAlts = this.evalSemanticContext(D.predicates, outerContext, true)
|
||||
if (conflictingAlts.length==1) {
|
||||
if(this.debug) {
|
||||
if (len(conflictingAlts)==1) {
|
||||
if(ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("Full LL avoided")
|
||||
}
|
||||
return conflictingAlts.minValue()
|
||||
|
@ -480,9 +469,9 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute
|
|||
var stopIndex = input.index
|
||||
input.seek(startIndex)
|
||||
var alts = this.evalSemanticContext(D.predicates, outerContext, true)
|
||||
if (alts.length==0) {
|
||||
if (len(alts)==0) {
|
||||
panic this.noViableAlt(input, outerContext, D.configs, startIndex)
|
||||
} else if (alts.length==1) {
|
||||
} else if (len(alts)==1) {
|
||||
return alts.minValue()
|
||||
} else {
|
||||
// report ambiguity after predicate evaluation to make sure the correct set of ambig alts is reported.
|
||||
|
@ -532,15 +521,15 @@ func (this *ParserATNSimulator) getExistingTargetState(previousD, t) {
|
|||
func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) {
|
||||
var reach = this.computeReachSet(previousD.configs, t, false)
|
||||
if(reach==nil) {
|
||||
this.addDFAEdge(dfa, previousD, t, ATNSimulator.ERROR)
|
||||
return ATNSimulator.ERROR
|
||||
this.addDFAEdge(dfa, previousD, t, ATNSimulatorERROR)
|
||||
return ATNSimulatorERROR
|
||||
}
|
||||
// create Newtarget state we'll add to DFA after it's complete
|
||||
var D = NewDFAState(nil, reach)
|
||||
|
||||
var predictedAlt = this.getUniqueAlt(reach)
|
||||
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
var altSubSets = PredictionModegetConflictingAltSubsets(reach)
|
||||
fmt.Println("SLL altSubSets=" + Utils.arrayToString(altSubSets) +
|
||||
", previous=" + previousD.configs +
|
||||
|
@ -550,7 +539,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) {
|
|||
PredictionModeallSubsetsConflict(altSubSets) + ", conflictingAlts=" +
|
||||
this.getConflictingAlts(reach))
|
||||
}
|
||||
if (predictedAlt!=ATN.INVALID_ALT_NUMBER) {
|
||||
if (predictedAlt!=ATNINVALID_ALT_NUMBER) {
|
||||
// NO CONFLICT, UNIQUELY PREDICTED ALT
|
||||
D.isAcceptState = true
|
||||
D.configs.uniqueAlt = predictedAlt
|
||||
|
@ -566,7 +555,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) {
|
|||
if (D.isAcceptState && D.configs.hasSemanticContext) {
|
||||
this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision))
|
||||
if( D.predicates!=nil) {
|
||||
D.prediction = ATN.INVALID_ALT_NUMBER
|
||||
D.prediction = ATNINVALID_ALT_NUMBER
|
||||
}
|
||||
}
|
||||
// all adds to dfa are done after we've created full D state
|
||||
|
@ -577,14 +566,14 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) {
|
|||
func (this *ParserATNSimulator) predicateDFAState(dfaState, decisionState) {
|
||||
// We need to test all predicates, even in DFA states that
|
||||
// uniquely predict alternative.
|
||||
var nalts = decisionState.transitions.length
|
||||
var nalts = len(decisionState.transitions)
|
||||
// Update DFA so reach becomes accept state with (predicate,alt)
|
||||
// pairs if preds found for conflicting alts
|
||||
var altsToCollectPredsFrom = this.getConflictingAltsOrUniqueAlt(dfaState.configs)
|
||||
var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts)
|
||||
if (altToPred!=nil) {
|
||||
dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred)
|
||||
dfaState.prediction = ATN.INVALID_ALT_NUMBER // make sure we use preds
|
||||
dfaState.prediction = ATNINVALID_ALT_NUMBER // make sure we use preds
|
||||
} else {
|
||||
// There are preds in configs but they might go away
|
||||
// when OR'd together like {p}? || NONE == NONE. If neither
|
||||
|
@ -594,12 +583,12 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState, decisionState) {
|
|||
}
|
||||
|
||||
// comes back with reach.uniqueAlt set to a valid alt
|
||||
ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how far we got before failing over
|
||||
func execATNWithFullContext(dfa, D, // how far we got before failing over
|
||||
s0,
|
||||
input,
|
||||
startIndex,
|
||||
outerContext) {
|
||||
if (this.debug || this.debug_list_atn_decisions) {
|
||||
if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) {
|
||||
fmt.Println("execATNWithFullContext "+s0)
|
||||
}
|
||||
var fullCtx = true
|
||||
|
@ -609,7 +598,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
|
|||
input.seek(startIndex)
|
||||
var t = input.LA(1)
|
||||
var predictedAlt = -1
|
||||
for (true) { // while more work
|
||||
for (true) { // for more work
|
||||
reach = this.computeReachSet(previous, t, fullCtx)
|
||||
if (reach==nil) {
|
||||
// if any configs in previous dipped into outer context, that
|
||||
|
@ -624,26 +613,26 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
|
|||
var e = this.noViableAlt(input, outerContext, previous, startIndex)
|
||||
input.seek(startIndex)
|
||||
var alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext)
|
||||
if(alt!=ATN.INVALID_ALT_NUMBER) {
|
||||
if(alt!=ATNINVALID_ALT_NUMBER) {
|
||||
return alt
|
||||
} else {
|
||||
panic e
|
||||
}
|
||||
}
|
||||
var altSubSets = PredictionModegetConflictingAltSubsets(reach)
|
||||
if(this.debug) {
|
||||
if(ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("LL altSubSets=" + altSubSets + ", predict=" +
|
||||
PredictionModegetUniqueAlt(altSubSets) + ", resolvesToJustOneViableAlt=" +
|
||||
PredictionModeresolvesToJustOneViableAlt(altSubSets))
|
||||
}
|
||||
reach.uniqueAlt = this.getUniqueAlt(reach)
|
||||
// unique prediction?
|
||||
if(reach.uniqueAlt!=ATN.INVALID_ALT_NUMBER) {
|
||||
if(reach.uniqueAlt!=ATNINVALID_ALT_NUMBER) {
|
||||
predictedAlt = reach.uniqueAlt
|
||||
break
|
||||
} else if (this.predictionMode != PredictionModeLL_EXACT_AMBIG_DETECTION) {
|
||||
predictedAlt = PredictionModeresolvesToJustOneViableAlt(altSubSets)
|
||||
if(predictedAlt != ATN.INVALID_ALT_NUMBER) {
|
||||
if(predictedAlt != ATNINVALID_ALT_NUMBER) {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
|
@ -667,7 +656,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
|
|||
// If the configuration set uniquely predicts an alternative,
|
||||
// without conflict, then we know that it's a full LL decision
|
||||
// not SLL.
|
||||
if (reach.uniqueAlt != ATN.INVALID_ALT_NUMBER ) {
|
||||
if (reach.uniqueAlt != ATNINVALID_ALT_NUMBER ) {
|
||||
this.reportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.index)
|
||||
return predictedAlt
|
||||
}
|
||||
|
@ -704,7 +693,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa
|
|||
}
|
||||
|
||||
func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("in computeReachSet, starting closure: " + closure)
|
||||
}
|
||||
if( this.mergeCache==nil) {
|
||||
|
@ -727,7 +716,7 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
|
|||
// First figure out where we can reach on input t
|
||||
for i:=0; i<len(closure.items); i++ {
|
||||
var c = closure.items[i]
|
||||
if(this.debug) {
|
||||
if(ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("testing " + this.getTokenName(t) + " at " + c)
|
||||
}
|
||||
if (c.state instanceof RuleStopState) {
|
||||
|
@ -736,19 +725,19 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
|
|||
skippedStopStates = []
|
||||
}
|
||||
skippedStopStates.push(c)
|
||||
if(this.debug) {
|
||||
if(ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("added " + c + " to skippedStopStates")
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
for(var j=0j<c.state.transitions.lengthj++) {
|
||||
for j:=0; j<len(c.state.transitions); j++ {
|
||||
var trans = c.state.transitions[j]
|
||||
var target = this.getReachableTarget(trans, t)
|
||||
if (target!=nil) {
|
||||
var cfg = NewATNConfig({state:target}, c)
|
||||
intermediate.add(cfg, this.mergeCache)
|
||||
if(this.debug) {
|
||||
if(ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("added " + cfg + " to intermediate")
|
||||
}
|
||||
}
|
||||
|
@ -767,13 +756,13 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
|
|||
// withheld in skippedStopStates, or when the current symbol is EOF.
|
||||
//
|
||||
if (skippedStopStates==nil && t!=TokenEOF) {
|
||||
if (intermediate.items.length==1) {
|
||||
if (len(intermediate.items)==1) {
|
||||
// Don't pursue the closure if there is just one state.
|
||||
// It can only have one alternative just add to result
|
||||
// Also don't pursue the closure if there is unique alternative
|
||||
// among the configurations.
|
||||
reach = intermediate
|
||||
} else if (this.getUniqueAlt(intermediate)!=ATN.INVALID_ALT_NUMBER) {
|
||||
} else if (this.getUniqueAlt(intermediate)!=ATNINVALID_ALT_NUMBER) {
|
||||
// Also don't pursue the closure if there is unique alternative
|
||||
// among the configurations.
|
||||
reach = intermediate
|
||||
|
@ -786,7 +775,7 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
|
|||
reach = NewATNConfigSet(fullCtx)
|
||||
var closureBusy = NewSet()
|
||||
var treatEofAsEpsilon = t == TokenEOF
|
||||
for (var k=0 k<intermediate.items.lengthk++) {
|
||||
for (var k=0 k<len(intermediate.items)k++) {
|
||||
this.closure(intermediate.items[k], reach, closureBusy, false, fullCtx, treatEofAsEpsilon)
|
||||
}
|
||||
}
|
||||
|
@ -818,12 +807,12 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) {
|
|||
// chooses an alternative matching the longest overall sequence when
|
||||
// multiple alternatives are viable.
|
||||
//
|
||||
if (skippedStopStates!=nil && ( (! fullCtx) || (! PredictionModehasConfigInRuleStopState(reach)))) {
|
||||
for (var l=0 l<skippedStopStates.lengthl++) {
|
||||
if (skippedStopStates!=nil && ( (!fullCtx) || (! PredictionModehasConfigInRuleStopState(reach)))) {
|
||||
for l :=0 l<len(skippedStopStates); l++ {
|
||||
reach.add(skippedStopStates[l], this.mergeCache)
|
||||
}
|
||||
}
|
||||
if (reach.items.length==0) {
|
||||
if (len(reach.items)==0) {
|
||||
return nil
|
||||
} else {
|
||||
return reach
|
||||
|
@ -854,7 +843,7 @@ func (this *ParserATNSimulator) removeAllConfigsNotInRuleStopState(configs, look
|
|||
return configs
|
||||
}
|
||||
var result = NewATNConfigSet(configs.fullCtx)
|
||||
for(var i=0 i<configs.items.lengthi++) {
|
||||
for(var i=0 i<len(configs.items)i++) {
|
||||
var config = configs.items[i]
|
||||
if (config.state instanceof RuleStopState) {
|
||||
result.add(config, this.mergeCache)
|
||||
|
@ -875,7 +864,7 @@ func (this *ParserATNSimulator) computeStartState(p, ctx, fullCtx) {
|
|||
// always at least the implicit call to start rule
|
||||
var initialContext = predictionContextFromRuleContext(this.atn, ctx)
|
||||
var configs = NewATNConfigSet(fullCtx)
|
||||
for(var i=0i<p.transitions.lengthi++) {
|
||||
for i:=0; i<len(p.transitions); i++ {
|
||||
var target = p.transitions[i].target
|
||||
var c = NewATNConfig({ state:target, alt:i+1, context:initialContext }, nil)
|
||||
var closureBusy = NewSet()
|
||||
|
@ -944,7 +933,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs) {
|
|||
var config
|
||||
var statesFromAlt1 = []
|
||||
var configSet = NewATNConfigSet(configs.fullCtx)
|
||||
for(var i=0 i<configs.items.length i++) {
|
||||
for(var i=0 i<len(configs.items) i++) {
|
||||
config = configs.items[i]
|
||||
// handle alt 1 first
|
||||
if (config.alt != 1) {
|
||||
|
@ -962,7 +951,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs) {
|
|||
configSet.add(config, this.mergeCache)
|
||||
}
|
||||
}
|
||||
for(i=0 i<configs.items.length i++) {
|
||||
for(i=0 i<len(configs.items) i++) {
|
||||
config = configs.items[i]
|
||||
if (config.alt == 1) {
|
||||
// already handled
|
||||
|
@ -1005,7 +994,7 @@ func (this *ParserATNSimulator) getPredsForAmbigAlts(ambigAlts, configs, nalts)
|
|||
// From this, it is clear that NONE||anything==NONE.
|
||||
//
|
||||
var altToPred = []
|
||||
for(var i=0i<configs.items.lengthi++) {
|
||||
for i:=0; i<len(configs.items); i++ {
|
||||
var c = configs.items[i]
|
||||
if(ambigAlts.contains( c.alt )) {
|
||||
altToPred[c.alt] = SemanticContext.orContext(altToPred[c.alt] || nil, c.semanticContext)
|
||||
|
@ -1024,7 +1013,7 @@ func (this *ParserATNSimulator) getPredsForAmbigAlts(ambigAlts, configs, nalts)
|
|||
if (nPredAlts==0) {
|
||||
altToPred = nil
|
||||
}
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("getPredsForAmbigAlts result " + Utils.arrayToString(altToPred))
|
||||
}
|
||||
return altToPred
|
||||
|
@ -1033,7 +1022,7 @@ func (this *ParserATNSimulator) getPredsForAmbigAlts(ambigAlts, configs, nalts)
|
|||
func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts, altToPred) {
|
||||
var pairs = []
|
||||
var containsPredicate = false
|
||||
for (var i=1 i<altToPred.lengthi++) {
|
||||
for (var i=1 i<len(altToPred)i++) {
|
||||
var pred = altToPred[i]
|
||||
// unpredicated is indicated by SemanticContext.NONE
|
||||
if( ambigAlts!=nil && ambigAlts.contains( i )) {
|
||||
|
@ -1100,22 +1089,22 @@ func (this *ParserATNSimulator) getSynValidOrSemInvalidAltThatFinishedDecisionEn
|
|||
var semValidConfigs = cfgs[0]
|
||||
var semInvalidConfigs = cfgs[1]
|
||||
var alt = this.getAltThatFinishedDecisionEntryRule(semValidConfigs)
|
||||
if (alt!=ATN.INVALID_ALT_NUMBER) { // semantically/syntactically viable path exists
|
||||
if (alt!=ATNINVALID_ALT_NUMBER) { // semantically/syntactically viable path exists
|
||||
return alt
|
||||
}
|
||||
// Is there a syntactically valid path with a failed pred?
|
||||
if (semInvalidConfigs.items.length>0) {
|
||||
if (len(semInvalidConfigs.items)>0) {
|
||||
alt = this.getAltThatFinishedDecisionEntryRule(semInvalidConfigs)
|
||||
if (alt!=ATN.INVALID_ALT_NUMBER) { // syntactically viable path exists
|
||||
if (alt!=ATNINVALID_ALT_NUMBER) { // syntactically viable path exists
|
||||
return alt
|
||||
}
|
||||
}
|
||||
return ATN.INVALID_ALT_NUMBER
|
||||
return ATNINVALID_ALT_NUMBER
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) getAltThatFinishedDecisionEntryRule(configs) {
|
||||
var alts = []
|
||||
for(var i=0i<configs.items.length i++) {
|
||||
for i:=0; i<len(configs.items); i++ {
|
||||
var c = configs.items[i]
|
||||
if (c.reachesIntoOuterContext>0 || ((c.state instanceof RuleStopState) && c.context.hasEmptyPath())) {
|
||||
if(alts.indexOf(c.alt)<0) {
|
||||
|
@ -1123,8 +1112,8 @@ func (this *ParserATNSimulator) getAltThatFinishedDecisionEntryRule(configs) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (alts.length==0) {
|
||||
return ATN.INVALID_ALT_NUMBER
|
||||
if (len(alts)==0) {
|
||||
return ATNINVALID_ALT_NUMBER
|
||||
} else {
|
||||
return Math.min.apply(nil, alts)
|
||||
}
|
||||
|
@ -1141,7 +1130,7 @@ func (this *ParserATNSimulator) getAltThatFinishedDecisionEntryRule(configs) {
|
|||
func (this *ParserATNSimulator) splitAccordingToSemanticValidity( configs, outerContext) {
|
||||
var succeeded = NewATNConfigSet(configs.fullCtx)
|
||||
var failed = NewATNConfigSet(configs.fullCtx)
|
||||
for(var i=0i<configs.items.length i++) {
|
||||
for i:=0; i<len(configs.items); i++ {
|
||||
var c = configs.items[i]
|
||||
if (c.semanticContext != SemanticContext.NONE) {
|
||||
var predicateEvaluationResult = c.semanticContext.evaluate(this.parser, outerContext)
|
||||
|
@ -1165,7 +1154,7 @@ func (this *ParserATNSimulator) splitAccordingToSemanticValidity( configs, outer
|
|||
//
|
||||
func (this *ParserATNSimulator) evalSemanticContext(predPredictions, outerContext, complete) {
|
||||
var predictions = NewBitSet()
|
||||
for(var i=0i<predPredictions.lengthi++) {
|
||||
for i:=0; i<len(predPredictions); i++ {
|
||||
var pair = predPredictions[i]
|
||||
if (pair.pred == SemanticContext.NONE) {
|
||||
predictions.add(pair.alt)
|
||||
|
@ -1175,11 +1164,11 @@ func (this *ParserATNSimulator) evalSemanticContext(predPredictions, outerContex
|
|||
continue
|
||||
}
|
||||
var predicateEvaluationResult = pair.pred.evaluate(this.parser, outerContext)
|
||||
if (this.debug || this.dfa_debug) {
|
||||
if (ParserATNSimulatorprototypedebug || this.dfa_debug) {
|
||||
fmt.Println("eval pred " + pair + "=" + predicateEvaluationResult)
|
||||
}
|
||||
if (predicateEvaluationResult) {
|
||||
if (this.debug || this.dfa_debug) {
|
||||
if (ParserATNSimulatorprototypedebug || this.dfa_debug) {
|
||||
fmt.Println("PREDICT " + pair.alt)
|
||||
}
|
||||
predictions.add(pair.alt)
|
||||
|
@ -1206,25 +1195,25 @@ func (this *ParserATNSimulator) closure(config, configs, closureBusy, collectPre
|
|||
|
||||
|
||||
func (this *ParserATNSimulator) closureCheckingStopState(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("closure(" + config.toString(this.parser,true) + ")")
|
||||
fmt.Println("configs(" + configs.toString() + ")")
|
||||
if(config.reachesIntoOuterContext>50) {
|
||||
panic "problem"
|
||||
panic("problem")
|
||||
}
|
||||
}
|
||||
if (config.state instanceof RuleStopState) {
|
||||
// We hit rule end. If we have context info, use it
|
||||
// run thru all possible stack tops in ctx
|
||||
if (! config.context.isEmpty()) {
|
||||
for ( var i =0 i<config.context.length i++) {
|
||||
for ( var i =0 i<len(config.context) i++) {
|
||||
if (config.context.getReturnState(i) == PredictionContext.EMPTY_RETURN_STATE) {
|
||||
if (fullCtx) {
|
||||
configs.add(NewATNConfig({state:config.state, context:PredictionContext.EMPTY}, config), this.mergeCache)
|
||||
continue
|
||||
} else {
|
||||
// we have no context info, just chase follow links (if greedy)
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("FALLING off rule " + this.getRuleName(config.state.ruleIndex))
|
||||
}
|
||||
this.closure_(config, configs, closureBusy, collectPredicates,
|
||||
|
@ -1249,7 +1238,7 @@ func (this *ParserATNSimulator) closureCheckingStopState(config, configs, closur
|
|||
return
|
||||
} else {
|
||||
// else if we have no context info, just chase follow links (if greedy)
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("FALLING off rule " + this.getRuleName(config.state.ruleIndex))
|
||||
}
|
||||
}
|
||||
|
@ -1266,7 +1255,7 @@ func (this *ParserATNSimulator) closure_(config, configs, closureBusy, collectPr
|
|||
// make sure to not return here, because EOF transitions can act as
|
||||
// both epsilon transitions and non-epsilon transitions.
|
||||
}
|
||||
for(var i = 0i<p.transitions.length i++) {
|
||||
for i := 0; i<len(p.transitions); i++ {
|
||||
var t = p.transitions[i]
|
||||
var continueCollecting = collectPredicates && !_, ok := t.(ActionTransition); ok
|
||||
var c = this.getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon)
|
||||
|
@ -1297,7 +1286,7 @@ func (this *ParserATNSimulator) closure_(config, configs, closureBusy, collectPr
|
|||
c.reachesIntoOuterContext += 1
|
||||
configs.dipsIntoOuterContext = true // TODO: can remove? only care when we add to set per middle of this method
|
||||
newDepth -= 1
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("dips into outer ctx: " + c)
|
||||
}
|
||||
} else if _, ok := t.(RuleTransition); ok {
|
||||
|
@ -1321,19 +1310,19 @@ func (this *ParserATNSimulator) getRuleName( index) {
|
|||
|
||||
func (this *ParserATNSimulator) getEpsilonTarget(config, t, collectPredicates, inContext, fullCtx, treatEofAsEpsilon) {
|
||||
switch(t.serializationType) {
|
||||
case Transition.RULE:
|
||||
case TransitionRULE:
|
||||
return this.ruleTransition(config, t)
|
||||
case Transition.PRECEDENCE:
|
||||
case TransitionPRECEDENCE:
|
||||
return this.precedenceTransition(config, t, collectPredicates, inContext, fullCtx)
|
||||
case Transition.PREDICATE:
|
||||
case TransitionPREDICATE:
|
||||
return this.predTransition(config, t, collectPredicates, inContext, fullCtx)
|
||||
case Transition.ACTION:
|
||||
case TransitionACTION:
|
||||
return this.actionTransition(config, t)
|
||||
case Transition.EPSILON:
|
||||
case TransitionEPSILON:
|
||||
return NewATNConfig({state:t.target}, config)
|
||||
case Transition.ATOM:
|
||||
case Transition.RANGE:
|
||||
case Transition.SET:
|
||||
case TransitionATOM:
|
||||
case TransitionRANGE:
|
||||
case TransitionSET:
|
||||
// EOF transitions act like epsilon transitions after the first EOF
|
||||
// transition is traversed
|
||||
if (treatEofAsEpsilon) {
|
||||
|
@ -1348,14 +1337,14 @@ func (this *ParserATNSimulator) getEpsilonTarget(config, t, collectPredicates, i
|
|||
}
|
||||
|
||||
func (this *ParserATNSimulator) actionTransition(config, t) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("ACTION edge " + t.ruleIndex + ":" + t.actionIndex)
|
||||
}
|
||||
return NewATNConfig({state:t.target}, config)
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) precedenceTransition(config, pt, collectPredicates, inContext, fullCtx) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("PRED (collectPredicates=" + collectPredicates + ") " +
|
||||
pt.precedence + ">=_p, ctx dependent=true")
|
||||
if (this.parser!=nil) {
|
||||
|
@ -1383,14 +1372,14 @@ func (this *ParserATNSimulator) precedenceTransition(config, pt, collectPredica
|
|||
} else {
|
||||
c = NewATNConfig({state:pt.target}, config)
|
||||
}
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("config from pred transition=" + c)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) predTransition(config, pt, collectPredicates, inContext, fullCtx) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("PRED (collectPredicates=" + collectPredicates + ") " + pt.ruleIndex +
|
||||
":" + pt.predIndex + ", ctx dependent=" + pt.isCtxDependent)
|
||||
if (this.parser!=nil) {
|
||||
|
@ -1418,14 +1407,14 @@ func (this *ParserATNSimulator) predTransition(config, pt, collectPredicates, in
|
|||
} else {
|
||||
c = NewATNConfig({state:pt.target}, config)
|
||||
}
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("config from pred transition=" + c)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) ruleTransition(config, t) {
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("CALL rule " + this.getRuleName(t.target.ruleIndex) + ", ctx=" + config.context)
|
||||
}
|
||||
var returnState = t.followState
|
||||
|
@ -1476,7 +1465,7 @@ func (this *ParserATNSimulator) getConflictingAlts(configs) {
|
|||
|
||||
func (this *ParserATNSimulator) getConflictingAltsOrUniqueAlt(configs) {
|
||||
var conflictingAlts = nil
|
||||
if (configs.uniqueAlt!= ATN.INVALID_ALT_NUMBER) {
|
||||
if (configs.uniqueAlt!= ATNINVALID_ALT_NUMBER) {
|
||||
conflictingAlts = NewBitSet()
|
||||
conflictingAlts.add(configs.uniqueAlt)
|
||||
} else {
|
||||
|
@ -1490,7 +1479,7 @@ func (this *ParserATNSimulator) getTokenName( t) {
|
|||
return "EOF"
|
||||
}
|
||||
if( this.parser!=nil && this.parser.literalNames!=nil) {
|
||||
if (t >= this.parser.literalNames.length) {
|
||||
if (t >= len(this.parser.literalNames)) {
|
||||
fmt.Println("" + t + " ttype out of range: " + this.parser.literalNames)
|
||||
fmt.Println("" + this.parser.getInputStream().getTokens())
|
||||
} else {
|
||||
|
@ -1511,10 +1500,10 @@ func (this *ParserATNSimulator) getLookaheadName(input) {
|
|||
func (this *ParserATNSimulator) dumpDeadEndConfigs(nvae) {
|
||||
fmt.Println("dead end configs: ")
|
||||
var decs = nvae.getDeadEndConfigs()
|
||||
for(var i=0 i<decs.length i++) {
|
||||
for(var i=0 i<len(decs) i++) {
|
||||
var c = decs[i]
|
||||
var trans = "no edges"
|
||||
if (c.state.transitions.length>0) {
|
||||
if (len(c.state.transitions)>0) {
|
||||
var t = c.state.transitions[0]
|
||||
if _, ok := t.(AtomTransition); ok {
|
||||
trans = "Atom "+ this.getTokenName(t.label)
|
||||
|
@ -1532,13 +1521,13 @@ func (this *ParserATNSimulator) noViableAlt(input, outerContext, configs, startI
|
|||
}
|
||||
|
||||
func (this *ParserATNSimulator) getUniqueAlt(configs) {
|
||||
var alt = ATN.INVALID_ALT_NUMBER
|
||||
for(var i=0i<configs.items.lengthi++) {
|
||||
var alt = ATNINVALID_ALT_NUMBER
|
||||
for i:=0; i<len(configs.items); i++ {
|
||||
var c = configs.items[i]
|
||||
if (alt == ATN.INVALID_ALT_NUMBER) {
|
||||
if (alt == ATNINVALID_ALT_NUMBER) {
|
||||
alt = c.alt // found first alt
|
||||
} else if( c.alt!=alt) {
|
||||
return ATN.INVALID_ALT_NUMBER
|
||||
return ATNINVALID_ALT_NUMBER
|
||||
}
|
||||
}
|
||||
return alt
|
||||
|
@ -1565,7 +1554,7 @@ func (this *ParserATNSimulator) getUniqueAlt(configs) {
|
|||
// on {@code to}
|
||||
//
|
||||
func (this *ParserATNSimulator) addDFAEdge(dfa, from_, t, to) {
|
||||
if( this.debug) {
|
||||
if( ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("EDGE " + from_ + " -> " + to + " upon " + this.getTokenName(t))
|
||||
}
|
||||
if (to==nil) {
|
||||
|
@ -1580,7 +1569,7 @@ func (this *ParserATNSimulator) addDFAEdge(dfa, from_, t, to) {
|
|||
}
|
||||
from_.edges[t+1] = to // connect
|
||||
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
var names = this.parser==nil ? nil : this.parser.literalNames
|
||||
fmt.Println("DFA=\n" + dfa.toString(names))
|
||||
}
|
||||
|
@ -1602,7 +1591,7 @@ func (this *ParserATNSimulator) addDFAEdge(dfa, from_, t, to) {
|
|||
// state was not already present.
|
||||
//
|
||||
func (this *ParserATNSimulator) addDFAState(dfa, D) {
|
||||
if (D == ATNSimulator.ERROR) {
|
||||
if (D == ATNSimulatorERROR) {
|
||||
return D
|
||||
}
|
||||
var hash = D.hashString()
|
||||
|
@ -1610,20 +1599,20 @@ func (this *ParserATNSimulator) addDFAState(dfa, D) {
|
|||
if(existing!=nil) {
|
||||
return existing
|
||||
}
|
||||
D.stateNumber = dfa.states.length
|
||||
D.stateNumber = len(dfa.states)
|
||||
if (! D.configs.readOnly) {
|
||||
D.configs.optimizeConfigs(this)
|
||||
D.configs.setReadonly(true)
|
||||
}
|
||||
dfa.states[hash] = D
|
||||
if (this.debug) {
|
||||
if (ParserATNSimulatorprototypedebug) {
|
||||
fmt.Println("adding NewDFA state: " + D)
|
||||
}
|
||||
return D
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) reportAttemptingFullContext(dfa, conflictingAlts, configs, startIndex, stopIndex) {
|
||||
if (this.debug || this.retry_debug) {
|
||||
if (ParserATNSimulatorprototypedebug || this.retry_debug) {
|
||||
var interval = NewInterval(startIndex, stopIndex + 1)
|
||||
fmt.Println("reportAttemptingFullContext decision=" + dfa.decision + ":" + configs +
|
||||
", input=" + this.parser.getTokenStream().getText(interval))
|
||||
|
@ -1634,7 +1623,7 @@ func (this *ParserATNSimulator) reportAttemptingFullContext(dfa, conflictingAlts
|
|||
}
|
||||
|
||||
func (this *ParserATNSimulator) reportContextSensitivity(dfa, prediction, configs, startIndex, stopIndex) {
|
||||
if (this.debug || this.retry_debug) {
|
||||
if (ParserATNSimulatorprototypedebug || this.retry_debug) {
|
||||
var interval = NewInterval(startIndex, stopIndex + 1)
|
||||
fmt.Println("reportContextSensitivity decision=" + dfa.decision + ":" + configs +
|
||||
", input=" + this.parser.getTokenStream().getText(interval))
|
||||
|
@ -1647,7 +1636,7 @@ func (this *ParserATNSimulator) reportContextSensitivity(dfa, prediction, config
|
|||
// If context sensitive parsing, we know it's ambiguity not conflict//
|
||||
func (this *ParserATNSimulator) reportAmbiguity(dfa, D, startIndex, stopIndex,
|
||||
exact, ambigAlts, configs ) {
|
||||
if (this.debug || this.retry_debug) {
|
||||
if (ParserATNSimulatorprototypedebug || this.retry_debug) {
|
||||
var interval = NewInterval(startIndex, stopIndex + 1)
|
||||
fmt.Println("reportAmbiguity " + ambigAlts + ":" + configs +
|
||||
", input=" + this.parser.getTokenStream().getText(interval))
|
||||
|
|
|
@ -41,16 +41,16 @@ func NewParserRuleContext(parent *ParserRuleContext, invokingStateNumber int) *P
|
|||
|
||||
prc := new(ParserRuleContext)
|
||||
|
||||
prc.initRuleContext(parent, invokingStateNumber)
|
||||
prc.initParserRuleContext(parent, invokingStateNumber)
|
||||
prc.InitRuleContext(parent, invokingStateNumber)
|
||||
prc.InitParserRuleContext(parent, invokingStateNumber)
|
||||
|
||||
return prc
|
||||
|
||||
}
|
||||
|
||||
func (prc *ParserRuleContext) initParserRuleContext(parent *ParserRuleContext, invokingStateNumber int){
|
||||
func (prc *ParserRuleContext) InitParserRuleContext(parent *ParserRuleContext, invokingStateNumber int){
|
||||
|
||||
prc.initRuleContext(parent, invokingStateNumber)
|
||||
prc.InitRuleContext(parent, invokingStateNumber)
|
||||
|
||||
prc.ruleIndex = -1
|
||||
// * If we are debugging or building a parse tree for a visitor,
|
||||
|
@ -224,7 +224,7 @@ type InterpreterRuleContext struct {
|
|||
func NewInterpreterRuleContext(parent *InterpreterRuleContext, invokingStateNumber, ruleIndex int) {
|
||||
|
||||
prc := new(InterpreterRuleContext)
|
||||
prc.initParserRuleContext( parent, invokingStateNumber )
|
||||
prc.InitParserRuleContext( parent, invokingStateNumber )
|
||||
|
||||
prc.ruleIndex = ruleIndex
|
||||
|
||||
|
|
|
@ -712,8 +712,12 @@ func combineCommonParents(parents []*PredictionContext) {
|
|||
}
|
||||
}
|
||||
|
||||
//func getCachedPredictionContext(context *PredictionContext, contextCache *PredictionContextCache, visited) *PredictionContext {
|
||||
// if (context.isEmpty()) {
|
||||
func getCachedPredictionContext(context *PredictionContext, contextCache *PredictionContextCache, visited map[*PredictionContext]*PredictionContext) *PredictionContext {
|
||||
|
||||
panic("getCachedPredictionContext not implemented")
|
||||
|
||||
return nil
|
||||
// if (context.isEmpty()) {
|
||||
// return context
|
||||
// }
|
||||
// var existing = visited[context] || nil
|
||||
|
@ -758,7 +762,7 @@ func combineCommonParents(parents []*PredictionContext) {
|
|||
// visited[context] = updated
|
||||
//
|
||||
// return updated
|
||||
//}
|
||||
}
|
||||
|
||||
// ter's recursive version of Sam's getAllNodes()
|
||||
//func getAllContextNodes(context, nodes, visited) {
|
||||
|
|
|
@ -13,11 +13,11 @@ type Recognizer struct {
|
|||
|
||||
func NewRecognizer() *Recognizer {
|
||||
rec := new(Recognizer)
|
||||
rec.initRecognizer()
|
||||
rec.InitRecognizer()
|
||||
return rec
|
||||
}
|
||||
|
||||
func (rec *Recognizer) initRecognizer() {
|
||||
func (rec *Recognizer) InitRecognizer() {
|
||||
rec._listeners = []ParseTreeListener{ ConsoleErrorListenerINSTANCE }
|
||||
rec._interp = nil
|
||||
rec.state = -1
|
||||
|
|
|
@ -35,12 +35,12 @@ type RuleContext struct {
|
|||
func NewRuleContext(parent *RuleContext, invokingState int) *RuleContext {
|
||||
|
||||
rn := &RuleContext{RuleNode{}}
|
||||
rn.initRuleContext(parent, invokingState)
|
||||
rn.InitRuleContext(parent, invokingState)
|
||||
|
||||
return rn
|
||||
}
|
||||
|
||||
func (rn *RuleContext) initRuleContext(parent *RuleContext, invokingState int) {
|
||||
func (rn *RuleContext) InitRuleContext(parent *RuleContext, invokingState int) {
|
||||
|
||||
// What context invoked this rule?
|
||||
rn.parentCtx = parent
|
||||
|
|
|
@ -27,12 +27,12 @@ func Transition (target *ATNState) *Transition {
|
|||
}
|
||||
|
||||
t := new(Transition)
|
||||
t.initTransition(target)
|
||||
t.InitTransition(target)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *Transition) initTransition(target *ATNState) {
|
||||
func (t *Transition) InitTransition(target *ATNState) {
|
||||
t.target = target
|
||||
// Are we epsilon, action, sempred?
|
||||
t.isEpsilon = false
|
||||
|
@ -103,7 +103,7 @@ type AtomTransition struct {
|
|||
func NewAtomTransition ( target *ATNState, label int ) *AtomTransition {
|
||||
|
||||
t := new(AtomTransition)
|
||||
t.initTransition( target )
|
||||
t.InitTransition( target )
|
||||
|
||||
t.label_ = label // The token type or character value or, signifies special label.
|
||||
t.label = t.makeLabel()
|
||||
|
@ -134,7 +134,7 @@ type RuleTransition struct {
|
|||
func NewRuleTransition ( ruleStart *ATNState, ruleIndex, precedence, followState int ) *RuleTransition {
|
||||
|
||||
t := new(RuleTransition)
|
||||
t.initTransition( ruleStart )
|
||||
t.InitTransition( ruleStart )
|
||||
|
||||
t.ruleIndex = ruleIndex
|
||||
t.precedence = precedence
|
||||
|
@ -161,7 +161,7 @@ type EpsilonTransition struct {
|
|||
func NewEpsilonTransition ( target *ATNState, outermostPrecedenceReturn int ) *EpsilonTransition {
|
||||
|
||||
t := new(EpsilonTransition)
|
||||
t.initTransition( target )
|
||||
t.InitTransition( target )
|
||||
|
||||
t.serializationType = TransitionEPSILON
|
||||
t.isEpsilon = true
|
||||
|
@ -187,7 +187,7 @@ type RangeTransition struct {
|
|||
func NewRangeTransition ( target *ATNState, start, stop int ) *RangeTransition {
|
||||
|
||||
t := new(RangeTransition)
|
||||
t.initTransition( target )
|
||||
t.InitTransition( target )
|
||||
|
||||
t.serializationType = TransitionRANGE
|
||||
t.start = start
|
||||
|
@ -218,7 +218,7 @@ func (t *RangeTransition) toString() string {
|
|||
//func NewAbstractPredicateTransition ( target *ATNState ) *AbstractPredicateTransition {
|
||||
//
|
||||
// t := new(AbstractPredicateTransition)
|
||||
// t.initTransition( target )
|
||||
// t.InitTransition( target )
|
||||
//
|
||||
// return t
|
||||
//}
|
||||
|
@ -234,7 +234,7 @@ type PredicateTransition struct {
|
|||
func PredicateTransition ( target *ATNState, ruleIndex, predIndex int, isCtxDependent bool ) *PredicateTransition {
|
||||
|
||||
t := new(PredicateTransition)
|
||||
t.initTransition(target)
|
||||
t.InitTransition(target)
|
||||
|
||||
t.serializationType = TransitionPREDICATE
|
||||
t.ruleIndex = ruleIndex
|
||||
|
@ -267,7 +267,7 @@ type ActionTransition struct {
|
|||
func NewActionTransition ( target *ATNState, ruleIndex, actionIndex int, isCtxDependent bool ) *ActionTransition {
|
||||
|
||||
t := new(ActionTransition)
|
||||
t.initTransition( target )
|
||||
t.InitTransition( target )
|
||||
|
||||
t.serializationType = TransitionACTION
|
||||
t.ruleIndex = ruleIndex
|
||||
|
@ -297,13 +297,13 @@ type SetTransition struct {
|
|||
func NewSetTransition ( target *ATNState, set *IntervalSet ) *SetTransition {
|
||||
|
||||
t := new(SetTransition)
|
||||
t.initTransition( target )
|
||||
t.initSetTransition( set )
|
||||
t.InitTransition( target )
|
||||
t.InitSetTransition( set )
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *SetTransition) initSetTransition( set *IntervalSet ) {
|
||||
func (t *SetTransition) InitSetTransition( set *IntervalSet ) {
|
||||
|
||||
t.serializationType = TransitionSET
|
||||
if (set !=nil && set !=nil) {
|
||||
|
@ -333,8 +333,8 @@ type NotSetTransition struct {
|
|||
func NotSetTransition ( target *ATNState, set *IntervalSet) *NotSetTransition {
|
||||
|
||||
t := new(NotSetTransition)
|
||||
t.initTransition( target )
|
||||
t.initSetTransition( target )
|
||||
t.InitTransition( target )
|
||||
t.InitSetTransition( target )
|
||||
|
||||
t.serializationType = TransitionNOT_SET
|
||||
|
||||
|
@ -359,7 +359,7 @@ type WildcardTransition struct {
|
|||
func NewWildcardTransition ( target *ATNState ) *WildcardTransition {
|
||||
|
||||
t := new(WildcardTransition)
|
||||
t.initTransition( target )
|
||||
t.InitTransition( target )
|
||||
|
||||
t.serializationType = TransitionWILDCARD
|
||||
return t
|
||||
|
@ -383,7 +383,7 @@ type PrecedencePredicateTransition struct {
|
|||
func PrecedencePredicateTransition ( target *ATNState, precedence int ) *PrecedencePredicateTransition {
|
||||
|
||||
t := new(PrecedencePredicateTransition)
|
||||
t.initTransition( target )
|
||||
t.InitTransition( target )
|
||||
|
||||
t.serializationType = TransitionPRECEDENCE
|
||||
t.precedence = precedence
|
||||
|
|
|
@ -85,12 +85,12 @@ type TerminalNodeImpl struct {
|
|||
func NewTerminalNodeImpl(symbol *Token) *TerminalNodeImpl {
|
||||
tn := &TerminalNodeImpl{TerminalNode{}}
|
||||
|
||||
tn.initTerminalNodeImpl(symbol)
|
||||
tn.InitTerminalNodeImpl(symbol)
|
||||
|
||||
return tn
|
||||
}
|
||||
|
||||
func (this *TerminalNodeImpl) initTerminalNodeImpl(symbol *Token) {
|
||||
func (this *TerminalNodeImpl) InitTerminalNodeImpl(symbol *Token) {
|
||||
this.parentCtx = nil
|
||||
this.symbol = symbol
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ type ErrorNodeImpl struct {
|
|||
|
||||
func NewErrorNodeImpl(token *Token) *ErrorNodeImpl {
|
||||
en := new(ErrorNodeImpl)
|
||||
en.initTerminalNodeImpl(token)
|
||||
en.InitTerminalNodeImpl(token)
|
||||
return en
|
||||
}
|
||||
|
||||
|
|
|
@ -368,7 +368,7 @@ public class ATNDeserializer {
|
|||
int ndecisions = toInt(data[p++]);
|
||||
for (int i=1; i<=ndecisions; i++) {
|
||||
int s = toInt(data[p++]);
|
||||
DecisionState decState = (DecisionState)atn.states.get(s);
|
||||
DecisionState decState = atn.states.get(s);
|
||||
atn.decisionToState.add(decState);
|
||||
decState.decision = i-1;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ function IntervalSet() {
|
|||
this.readOnly = false;
|
||||
}
|
||||
|
||||
IntervalSet.prototype.first = function(v) {
|
||||
IntervalSet.prototype.first = function() {
|
||||
if (this.intervals === null || this.intervals.length===0) {
|
||||
return Token.INVALID_TYPE;
|
||||
} else {
|
||||
|
|
|
@ -106,10 +106,10 @@ func New<parser.name>(input) <parser.name> {
|
|||
|
||||
var deserializer = NewATNDeserializer()
|
||||
var deserializedAtn = deserializer.deserialize(serializedATN)
|
||||
var decisionToDFA = make([]dfa.DFA,len(deserializedAtn.decisionToState))
|
||||
var decisionToDFA = make([]DFA,len(deserializedAtn.decisionToState))
|
||||
|
||||
for index, ds := range deserializedAtn.decisionToState {
|
||||
decisionToDFA[index] = dfa.NewDFA(ds, index)
|
||||
decisionToDFA[index] = NewDFA(ds, index)
|
||||
}
|
||||
|
||||
var sharedContextCache = NewPredictionContextCache()
|
||||
|
@ -661,7 +661,7 @@ type <struct.name> struct {
|
|||
func New<struct.name>(parser *Parser, parent *ParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name>}>) <struct.name> {
|
||||
|
||||
var p = new(<struct.name>)
|
||||
p.initParserRuleContext( parent, invokingState )
|
||||
p.InitParserRuleContext( parent, invokingState )
|
||||
|
||||
p.parser = parser
|
||||
p.ruleIndex = <parser.name>RULE_<struct.derivedFromName>
|
||||
|
@ -738,7 +738,7 @@ func (s *<struct.name>) accept(visitor *ParseTreeVisitor) {
|
|||
|
||||
|
||||
|
||||
AttributeDecl(d) ::= "p.<d.name> = <if(d.initValue)><d.initValue><else>null<endif>"
|
||||
AttributeDecl(d) ::= "p.<d.name> = <if(d.InitValue)><d.InitValue><else>null<endif>"
|
||||
|
||||
/** If we don't know location of label def x, use this template */
|
||||
labelref(x) ::= "<if(!x.isLocal)>localctx.<endif><x.name>"
|
||||
|
@ -820,15 +820,15 @@ func New<lexer.name>(input *TokenStream) *<lexer.name> {
|
|||
var deserializer = NewATNDeserializer()
|
||||
var deserializedAtn = deserializer.deserialize(serializedATN)
|
||||
|
||||
var decisionToDFA = make([]dfa.DFA,len(deserializedAtn.decisionToState))
|
||||
var decisionToDFA = make([]DFA,len(deserializedAtn.decisionToState))
|
||||
|
||||
for index, ds := range deserializedAtn.decisionToState {
|
||||
decisionToDFA[index] = dfa.NewDFA(ds, index)
|
||||
decisionToDFA[index] = NewDFA(ds, index)
|
||||
}
|
||||
|
||||
lex := new(<lexer.name>)
|
||||
|
||||
initLexer(lex, input);
|
||||
this.InitLexer(lex, input);
|
||||
|
||||
lex._interp = NewLexerATNSimulator(lex, atn, decisionToDFA, NewPredictionContextCache())
|
||||
lex.modeNames = [...]string{ <lexer.modes:{m| "<m>"}; separator=", ", wrap, anchor> }
|
||||
|
@ -865,7 +865,7 @@ var serializedATN = strings.Join( [...]string{"<model.serialized; wrap={",<\n>
|
|||
/** Using a type to init value map, try to init a type; if not in table
|
||||
* must be an object, default value is "nil".
|
||||
*/
|
||||
initValue(typeName) ::= <<
|
||||
InitValue(typeName) ::= <<
|
||||
<javaTypeInitMap.(typeName)>
|
||||
>>
|
||||
|
||||
|
|
Loading…
Reference in New Issue