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