LexerATNSimulator type annotations

This commit is contained in:
Peter Boyer 2015-12-18 19:15:21 -05:00
parent cd2466a9d9
commit b0720b2f13
3 changed files with 107 additions and 93 deletions

View File

@ -45,8 +45,28 @@ func (this *SimState) reset() {
resetSimState(this) resetSimState(this)
} }
func LexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache) { type LexerATNSimulator struct {
ATNSimulator.call(this, atn, sharedContextCache) ATNSimulator
recog *Lexer
predictionMode int
decisionToDFA []*DFA
mergeCache DoubleDict
startIndex int
line int
column int
mode int
prevAccept *SimState
match_calls int
}
func LexerATNSimulator(recog *Lexer, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) {
this := new(LexerATNSimulator)
this.InitATNSimulator(atn, sharedContextCache)
this.decisionToDFA = decisionToDFA this.decisionToDFA = decisionToDFA
this.recog = recog this.recog = recog
// The current token's starting index into the character stream. // The current token's starting index into the character stream.
@ -67,39 +87,38 @@ func LexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache) {
return this return this
} }
//LexerATNSimulator.prototype = Object.create(ATNSimulator.prototype) var LexerATNSimulatordebug = false
//LexerATNSimulator.prototype.constructor = LexerATNSimulator var LexerATNSimulatordfa_debug = false
LexerATNSimulator.debug = false var LexerATNSimulatorMIN_DFA_EDGE = 0
LexerATNSimulator.dfa_debug = false var LexerATNSimulatorMAX_DFA_EDGE = 127 // forces unicode to stay in ATN
LexerATNSimulator.MIN_DFA_EDGE = 0 var LexerATNSimulatormatch_calls = 0
LexerATNSimulator.MAX_DFA_EDGE = 127 // forces unicode to stay in ATN
LexerATNSimulator.match_calls = 0 func (this *LexerATNSimulator) copyState(simulator *LexerATNSimulator) {
func (this *LexerATNSimulator) copyState(simulator) {
this.column = simulator.column this.column = simulator.column
this.line = simulator.line this.line = simulator.line
this.mode = simulator.mode this.mode = simulator.mode
this.startIndex = simulator.startIndex this.startIndex = simulator.startIndex
} }
func (this *LexerATNSimulator) match(input, mode) { func (this *LexerATNSimulator) match(input *InputStream, mode int) int {
this.match_calls += 1 this.match_calls += 1
this.mode = mode this.mode = mode
var mark = input.mark() var mark = input.mark()
try {
this.startIndex = input.index defer func(){
this.prevAccept.reset()
var dfa = this.decisionToDFA[mode]
if (dfa.s0 == nil) {
return this.matchATN(input)
} else {
return this.execATN(input, dfa.s0)
}
} finally {
input.release(mark) input.release(mark)
}()
this.startIndex = input.index
this.prevAccept.reset()
var dfa = this.decisionToDFA[mode]
if (dfa.s0 == nil) {
return this.matchATN(input)
} else {
return this.execATN(input, dfa.s0)
} }
} }
@ -111,10 +130,10 @@ func (this *LexerATNSimulator) reset() {
this.mode = LexerDefaultMode this.mode = LexerDefaultMode
} }
func (this *LexerATNSimulator) matchATN(input) { func (this *LexerATNSimulator) matchATN(input *InputStream) int {
var startState = this.atn.modeToStartState[this.mode] var startState = this.atn.modeToStartState[this.mode]
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("matchATN mode " + this.mode + " start: " + startState) fmt.Println("matchATN mode " + this.mode + " start: " + startState)
} }
var old_mode = this.mode var old_mode = this.mode
@ -123,20 +142,21 @@ func (this *LexerATNSimulator) matchATN(input) {
s0_closure.hasSemanticContext = false s0_closure.hasSemanticContext = false
var next = this.addDFAState(s0_closure) var next = this.addDFAState(s0_closure)
if (!suppressEdge) { if (!suppressEdge) {
this.decisionToDFA[this.mode].s0 = next this.decisionToDFA[this.mode].s0 = next
} }
var predict = this.execATN(input, next) var predict = this.execATN(input, next)
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("DFA after matchATN: " + this.decisionToDFA[old_mode].toLexerString()) fmt.Println("DFA after matchATN: " + this.decisionToDFA[old_mode].toLexerString())
} }
return predict return predict
} }
LexerATNSimulator.prototype.execATN = function(input, ds0) { func (this *LexerATNSimulator) execATN(input *InputStream, ds0 *DFAState) int {
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("start state closure=" + ds0.configs) fmt.Println("start state closure=" + ds0.configs)
} }
if (ds0.isAcceptState) { if (ds0.isAcceptState) {
@ -147,7 +167,7 @@ LexerATNSimulator.prototype.execATN = function(input, ds0) {
var s = ds0 // s is current/from DFA state var s = ds0 // s is current/from DFA state
for (true) { // while more work for (true) { // while more work
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("execATN loop starting closure: " + s.configs) fmt.Println("execATN loop starting closure: " + s.configs)
} }
@ -175,7 +195,7 @@ LexerATNSimulator.prototype.execATN = function(input, ds0) {
target = this.computeTargetState(input, s, t) target = this.computeTargetState(input, s, t)
// print("Computed:" + str(target)) // print("Computed:" + str(target))
} }
if (target == ATNSimulator.ERROR) { if (target == ATNSimulatorERROR) {
break break
} }
// If this is a consumable input element, make sure to consume before // If this is a consumable input element, make sure to consume before
@ -206,16 +226,16 @@ LexerATNSimulator.prototype.execATN = function(input, ds0) {
// @return The existing target DFA state for the given input symbol // @return The existing target DFA state for the given input symbol
// {@code t}, or {@code nil} if the target state for this edge is not // {@code t}, or {@code nil} if the target state for this edge is not
// already cached // already cached
func (this *LexerATNSimulator) getExistingTargetState(s, t) { func (this *LexerATNSimulator) getExistingTargetState(s *DFAState, t int) *DFAState {
if (s.edges == nil || t < LexerATNSimulator.MIN_DFA_EDGE || t > LexerATNSimulator.MAX_DFA_EDGE) { if (s.edges == nil || t < LexerATNSimulatorMIN_DFA_EDGE || t > LexerATNSimulatorMAX_DFA_EDGE) {
return nil return nil
} }
var target = s.edges[t - LexerATNSimulator.MIN_DFA_EDGE] var target = s.edges[t - LexerATNSimulatorMIN_DFA_EDGE]
if(target==nil) { if(target==nil) {
target = nil target = nil
} }
if (this.debug && target != nil) { if (LexerATNSimulatordebug && target != nil) {
fmt.Println("reuse state " + s.stateNumber + " edge to " + target.stateNumber) fmt.Println("reuse state " + s.stateNumber + " edge to " + target.stateNumber)
} }
return target return target
@ -231,26 +251,26 @@ func (this *LexerATNSimulator) getExistingTargetState(s, t) {
// @return The computed target DFA state for the given input symbol // @return The computed target DFA state for the given input symbol
// {@code t}. If {@code t} does not lead to a valid DFA state, this method // {@code t}. If {@code t} does not lead to a valid DFA state, this method
// returns {@link //ERROR}. // returns {@link //ERROR}.
func (this *LexerATNSimulator) computeTargetState(input, s, t) { func (this *LexerATNSimulator) computeTargetState(input *InputStream, s *DFAState, t int) *DFAState {
var reach = NewOrderedATNConfigSet() var reach = NewOrderedATNConfigSet()
// if we don't find an existing DFA state // if we don't find an existing DFA state
// Fill reach starting from closure, following t transitions // Fill reach starting from closure, following t transitions
this.getReachableConfigSet(input, s.configs, reach, t) this.getReachableConfigSet(input, s.configs, reach, t)
if (reach.items.length == 0) { // we got nowhere on t from s if (len( reach.configs) == 0) { // we got nowhere on t from s
if (!reach.hasSemanticContext) { if (!reach.hasSemanticContext) {
// we got nowhere on t, don't panic out this knowledge it'd // we got nowhere on t, don't panic out this knowledge it'd
// cause a failover from DFA later. // cause a failover from DFA later.
this.addDFAEdge(s, t, ATNSimulator.ERROR) this.addDFAEdge(s, t, ATNSimulatorERROR)
} }
// stop when we can't match any more char // stop when we can't match any more char
return ATNSimulator.ERROR return ATNSimulatorERROR
} }
// Add an edge from s to target DFA found/created for reach // Add an edge from s to target DFA found/created for reach
return this.addDFAEdge(s, t, nil, reach) return this.addDFAEdge(s, t, nil, reach)
} }
func (this *LexerATNSimulator) failOrAccept(prevAccept, input, reach, t) { func (this *LexerATNSimulator) failOrAccept(prevAccept *SimState, input *InputStream, reach *ATNConfigSet, t int) int {
if (this.prevAccept.dfaState != nil) { if (this.prevAccept.dfaState != nil) {
var lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor var lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor
this.accept(input, lexerActionExecutor, this.startIndex, this.accept(input, lexerActionExecutor, this.startIndex,
@ -268,18 +288,17 @@ func (this *LexerATNSimulator) failOrAccept(prevAccept, input, reach, t) {
// Given a starting configuration set, figure out all ATN configurations // Given a starting configuration set, figure out all ATN configurations
// we can reach upon input {@code t}. Parameter {@code reach} is a return // we can reach upon input {@code t}. Parameter {@code reach} is a return
// parameter. // parameter.
func (this *LexerATNSimulator) getReachableConfigSet(input, closure, func (this *LexerATNSimulator) getReachableConfigSet(input *InputStream, closure *ATNConfigSet, reach *ATNConfigSet, t int) {
reach, t) {
// this is used to skip processing for configs which have a lower priority // this is used to skip processing for configs which have a lower priority
// than a config that already reached an accept state for the same rule // than a config that already reached an accept state for the same rule
var skipAlt = ATN.INVALID_ALT_NUMBER var skipAlt = ATNINVALID_ALT_NUMBER
for i := 0; i < len(closure.items); i++ { for i := 0; i < len(closure.items); i++ {
var cfg = closure.items[i] var cfg = closure.items[i]
var currentAltReachedAcceptState = (cfg.alt == skipAlt) var currentAltReachedAcceptState = (cfg.alt == skipAlt)
if (currentAltReachedAcceptState && cfg.passedThroughNonGreedyDecision) { if (currentAltReachedAcceptState && cfg.passedThroughNonGreedyDecision) {
continue continue
} }
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("testing %s at %s\n", this.getTokenName(t), cfg fmt.Println("testing %s at %s\n", this.getTokenName(t), cfg
.toString(this.recog, true)) .toString(this.recog, true))
} }
@ -304,9 +323,8 @@ func (this *LexerATNSimulator) getReachableConfigSet(input, closure,
} }
} }
func (this *LexerATNSimulator) accept(input, lexerActionExecutor, func (this *LexerATNSimulator) accept(input *InputStream, lexerActionExecutor *LexerActionExecutor, startIndex, index, line, charPos int) {
startIndex, index, line, charPos) { if (LexerATNSimulatordebug) {
if (this.debug) {
fmt.Println("ACTION %s\n", lexerActionExecutor) fmt.Println("ACTION %s\n", lexerActionExecutor)
} }
// seek to after last char in token // seek to after last char in token
@ -318,7 +336,7 @@ func (this *LexerATNSimulator) accept(input, lexerActionExecutor,
} }
} }
func (this *LexerATNSimulator) getReachableTarget(trans, t) { func (this *LexerATNSimulator) getReachableTarget(trans *Transition, t int) *ATNState {
if (trans.matches(t, 0, 0xFFFE)) { if (trans.matches(t, 0, 0xFFFE)) {
return trans.target return trans.target
} else { } else {
@ -326,8 +344,8 @@ func (this *LexerATNSimulator) getReachableTarget(trans, t) {
} }
} }
func (this *LexerATNSimulator) computeStartState(input, p) { func (this *LexerATNSimulator) computeStartState(input *InputStream, p *ATNState ) {
var initialContext = PredictionContext.EMPTY var initialContext = PredictionContextEMPTY
var configs = NewOrderedATNConfigSet() var configs = NewOrderedATNConfigSet()
for i := 0; i < len(p.transitions); i++ { for i := 0; i < len(p.transitions); i++ {
var target = p.transitions[i].target var target = p.transitions[i].target
@ -345,13 +363,14 @@ func (this *LexerATNSimulator) computeStartState(input, p) {
// //
// @return {@code true} if an accept state is reached, otherwise // @return {@code true} if an accept state is reached, otherwise
// {@code false}. // {@code false}.
func (this *LexerATNSimulator) closure(input, config, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon) { func (this *LexerATNSimulator) closure(input *InputStream, config *LexerATNConfig, configs *ATNConfigSet,
var cfg = nil currentAltReachedAcceptState, speculative, treatEofAsEpsilon bool) bool {
if (this.debug) {
if (LexerATNSimulatordebug) {
fmt.Println("closure(" + config.toString(this.recog, true) + ")") fmt.Println("closure(" + config.toString(this.recog, true) + ")")
} }
if (config.state instanceof RuleStopState) { if (config.state instanceof RuleStopState) {
if (this.debug) { if (LexerATNSimulatordebug) {
if (this.recog != nil) { if (this.recog != nil) {
fmt.Println("closure at %s rule stop %s\n", this.recog.getRuleNames()[config.state.ruleIndex], config) fmt.Println("closure at %s rule stop %s\n", this.recog.getRuleNames()[config.state.ruleIndex], config)
} else { } else {
@ -363,13 +382,13 @@ func (this *LexerATNSimulator) closure(input, config, configs, currentAltReached
configs.add(config) configs.add(config)
return true return true
} else { } else {
configs.add(NewLexerATNConfig({ state:config.state, context:PredictionContext.EMPTY}, config)) configs.add(NewLexerATNConfig({ state:config.state, context:PredictionContextEMPTY}, config))
currentAltReachedAcceptState = true currentAltReachedAcceptState = true
} }
} }
if (config.context != nil && !config.context.isEmpty()) { if (config.context != nil && !config.context.isEmpty()) {
for i := 0; i < len(config.context); i++ { for i := 0; i < len(config.context); i++ {
if (config.context.getReturnState(i) != PredictionContext.EMPTY_RETURN_STATE) { if (config.context.getReturnState(i) != PredictionContextEMPTY_RETURN_STATE) {
var newContext = config.context.getParent(i) // "pop" return state var newContext = config.context.getParent(i) // "pop" return state
var returnState = this.atn.states[config.context.getReturnState(i)] var returnState = this.atn.states[config.context.getReturnState(i)]
cfg = NewLexerATNConfig({ state:returnState, context:newContext }, config) cfg = NewLexerATNConfig({ state:returnState, context:newContext }, config)
@ -399,15 +418,15 @@ func (this *LexerATNSimulator) closure(input, config, configs, currentAltReached
} }
// side-effect: can alter configs.hasSemanticContext // side-effect: can alter configs.hasSemanticContext
func (this *LexerATNSimulator) getEpsilonTarget(input, config, trans, func (this *LexerATNSimulator) getEpsilonTarget(input *InputStream, config *LexerATNConfig, trans *Transition,
configs, speculative, treatEofAsEpsilon) { configs *ATNConfigSet, speculative, treatEofAsEpsilon bool) *LexerATNConfig {
var cfg = nil
if (trans.serializationType == Transition.RULE) { if (trans.serializationType == TransitionRULE) {
var newContext = SingletonPredictionContext.create(config.context, trans.followState.stateNumber) var newContext = SingletonPredictionContext.create(config.context, trans.followState.stateNumber)
cfg = NewLexerATNConfig( { state:trans.target, context:newContext}, config) cfg = NewLexerATNConfig( { state:trans.target, context:newContext}, config)
} else if (trans.serializationType == Transition.PRECEDENCE) { } else if (trans.serializationType == TransitionPRECEDENCE) {
panic "Precedence predicates are not supported in lexers." panic "Precedence predicates are not supported in lexers."
} else if (trans.serializationType == Transition.PREDICATE) { } else if (trans.serializationType == TransitionPREDICATE) {
// Track traversing semantic predicates. If we traverse, // Track traversing semantic predicates. If we traverse,
// we cannot add a DFA state for this "reach" computation // we cannot add a DFA state for this "reach" computation
// because the DFA would not test the predicate again in the // because the DFA would not test the predicate again in the
@ -426,14 +445,14 @@ func (this *LexerATNSimulator) getEpsilonTarget(input, config, trans,
// states reached by traversing predicates. Since this is when we // states reached by traversing predicates. Since this is when we
// test them, we cannot cash the DFA state target of ID. // test them, we cannot cash the DFA state target of ID.
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("EVAL rule " + trans.ruleIndex + ":" + trans.predIndex) fmt.Println("EVAL rule " + trans.ruleIndex + ":" + trans.predIndex)
} }
configs.hasSemanticContext = true configs.hasSemanticContext = true
if (this.evaluatePredicate(input, trans.ruleIndex, trans.predIndex, speculative)) { if (this.evaluatePredicate(input, trans.ruleIndex, trans.predIndex, speculative)) {
cfg = NewLexerATNConfig({ state:trans.target}, config) cfg = NewLexerATNConfig({ state:trans.target}, config)
} }
} else if (trans.serializationType == Transition.ACTION) { } else if (trans.serializationType == TransitionACTION) {
if (config.context == nil || config.context.hasEmptyPath()) { if (config.context == nil || config.context.hasEmptyPath()) {
// execute actions anywhere in the start rule for a token. // execute actions anywhere in the start rule for a token.
// //
@ -454,11 +473,11 @@ func (this *LexerATNSimulator) getEpsilonTarget(input, config, trans,
// ignore actions in referenced rules // ignore actions in referenced rules
cfg = NewLexerATNConfig( { state:trans.target}, config) cfg = NewLexerATNConfig( { state:trans.target}, config)
} }
} else if (trans.serializationType == Transition.EPSILON) { } else if (trans.serializationType == TransitionEPSILON) {
cfg = NewLexerATNConfig({ state:trans.target}, config) cfg = NewLexerATNConfig({ state:trans.target}, config)
} else if (trans.serializationType == Transition.ATOM || } else if (trans.serializationType == TransitionATOM ||
trans.serializationType == Transition.RANGE || trans.serializationType == TransitionRANGE ||
trans.serializationType == Transition.SET) { trans.serializationType == TransitionSET) {
if (treatEofAsEpsilon) { if (treatEofAsEpsilon) {
if (trans.matches(TokenEOF, 0, 0xFFFF)) { if (trans.matches(TokenEOF, 0, 0xFFFF)) {
cfg = NewLexerATNConfig( { state:trans.target }, config) cfg = NewLexerATNConfig( { state:trans.target }, config)
@ -488,8 +507,7 @@ func (this *LexerATNSimulator) getEpsilonTarget(input, config, trans,
// @return {@code true} if the specified predicate evaluates to // @return {@code true} if the specified predicate evaluates to
// {@code true}. // {@code true}.
// / // /
func (this *LexerATNSimulator) evaluatePredicate(input, ruleIndex, func (this *LexerATNSimulator) evaluatePredicate(input *InputStream, ruleIndex, predIndex int, speculative bool) bool {
predIndex, speculative) {
// assume true if no recognizer was provided // assume true if no recognizer was provided
if (this.recog == nil) { if (this.recog == nil) {
return true return true
@ -501,31 +519,26 @@ func (this *LexerATNSimulator) evaluatePredicate(input, ruleIndex,
var savedLine = this.line var savedLine = this.line
var index = input.index var index = input.index
var marker = input.mark() var marker = input.mark()
try {
this.consume(input) defer func(){
return this.recog.sempred(nil, ruleIndex, predIndex)
} finally {
this.column = savedcolumn this.column = savedcolumn
this.line = savedLine this.line = savedLine
input.seek(index) input.seek(index)
input.release(marker) input.release(marker)
} }()
this.consume(input)
return this.recog.sempred(nil, ruleIndex, predIndex)
} }
func (this *LexerATNSimulator) captureSimState(settings, input, dfaState) { func (this *LexerATNSimulator) captureSimState(settings *SimState, input *InputStream, dfaState *DFAState) {
settings.index = input.index settings.index = input.index
settings.line = this.line settings.line = this.line
settings.column = this.column settings.column = this.column
settings.dfaState = dfaState settings.dfaState = dfaState
} }
func (this *LexerATNSimulator) addDFAEdge(from_, tk, to, cfgs) { func (this *LexerATNSimulator) addDFAEdge(from_ *DFAState, tk int, to *DFAState , cfgs *ATNConfigSet) {
if (to == nil) {
to = nil
}
if (cfgs == nil) {
cfgs = nil
}
if (to == nil && cfgs != nil) { if (to == nil && cfgs != nil) {
// leading to this call, ATNConfigSet.hasSemanticContext is used as a // leading to this call, ATNConfigSet.hasSemanticContext is used as a
// marker indicating dynamic predicate evaluation makes this edge // marker indicating dynamic predicate evaluation makes this edge
@ -548,18 +561,18 @@ func (this *LexerATNSimulator) addDFAEdge(from_, tk, to, cfgs) {
} }
} }
// add the edge // add the edge
if (tk < LexerATNSimulator.MIN_DFA_EDGE || tk > LexerATNSimulator.MAX_DFA_EDGE) { if (tk < LexerATNSimulatorMIN_DFA_EDGE || tk > LexerATNSimulatorMAX_DFA_EDGE) {
// Only track edges within the DFA bounds // Only track edges within the DFA bounds
return to return to
} }
if (this.debug) { if (LexerATNSimulatordebug) {
fmt.Println("EDGE " + from_ + " -> " + to + " upon " + tk) fmt.Println("EDGE " + from_ + " -> " + to + " upon " + tk)
} }
if (from_.edges == nil) { if (from_.edges == nil) {
// make room for tokens 1..n and -1 masquerading as index 0 // make room for tokens 1..n and -1 masquerading as index 0
from_.edges = [] from_.edges = []
} }
from_.edges[tk - LexerATNSimulator.MIN_DFA_EDGE] = to // connect from_.edges[tk - LexerATNSimulatorMIN_DFA_EDGE] = to // connect
return to return to
} }
@ -568,7 +581,8 @@ func (this *LexerATNSimulator) addDFAEdge(from_, tk, to, cfgs) {
// configurations already. This method also detects the first // configurations already. This method also detects the first
// configuration containing an ATN rule stop state. Later, when // configuration containing an ATN rule stop state. Later, when
// traversing the DFA, we will know which rule to accept. // traversing the DFA, we will know which rule to accept.
func (this *LexerATNSimulator) addDFAState(configs) { func (this *LexerATNSimulator) addDFAState(configs *ATNConfigSet) *DFAState {
var proposed = NewDFAState(nil, configs) var proposed = NewDFAState(nil, configs)
var firstConfigWithRuleStopState = nil var firstConfigWithRuleStopState = nil
for i := 0; i < len(configs.items); i++ { for i := 0; i < len(configs.items); i++ {
@ -597,19 +611,19 @@ func (this *LexerATNSimulator) addDFAState(configs) {
return newState return newState
} }
func (this *LexerATNSimulator) getDFA(mode) { func (this *LexerATNSimulator) getDFA(mode int) *DFA {
return this.decisionToDFA[mode] return this.decisionToDFA[mode]
} }
// Get the text matched so far for the current token. // Get the text matched so far for the current token.
func (this *LexerATNSimulator) getText(input) { func (this *LexerATNSimulator) getText(input *InputStream) string {
// index is first lookahead char, don't include. // index is first lookahead char, don't include.
return input.getText(this.startIndex, input.index - 1) return input.getText(this.startIndex, input.index - 1)
} }
func (this *LexerATNSimulator) consume(input) { func (this *LexerATNSimulator) consume(input *InputStream) {
var curChar = input.LA(1) var curChar = input.LA(1)
if (curChar == "\n".charCodeAt(0)) { if (curChar == rune('\n')) {
this.line += 1 this.line += 1
this.column = 0 this.column = 0
} else { } else {
@ -618,11 +632,11 @@ func (this *LexerATNSimulator) consume(input) {
input.consume() input.consume()
} }
func (this *LexerATNSimulator) getTokenName(tt) { func (this *LexerATNSimulator) getTokenName(tt int) {
if (tt == -1) { if (tt == -1) {
return "EOF" return "EOF"
} else { } else {
return "'" + String.fromCharCode(tt) + "'" return "'" + string(tt) + "'"
} }
} }

View File

@ -18,7 +18,7 @@ type ParserATNSimulator struct {
func NewParserATNSimulator(parser *Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *ParserATNSimulator { func NewParserATNSimulator(parser *Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *ParserATNSimulator {
this := new(ParserATNSimulator)s this := new(ParserATNSimulator)
this.InitParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) this.InitParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache)

View File

@ -570,7 +570,7 @@ public class ParserATNSimulator extends ATNSimulator {
* {@code t}, or {@code null} if the target state for this edge is not * {@code t}, or {@code null} if the target state for this edge is not
* already cached * already cached
*/ */
protected DFAState getExistingTargetState(DFAState previousD, int t) { protected DFAState getExistingTargetState( previousD, int t) {
DFAState[] edges = previousD.edges; DFAState[] edges = previousD.edges;
if (edges == null || t + 1 < 0 || t + 1 >= edges.length) { if (edges == null || t + 1 < 0 || t + 1 >= edges.length) {
return null; return null;