From c83d8fb109585b7003b96bd8f0fcbf58e3cd7a4e Mon Sep 17 00:00:00 2001 From: Peter Boyer Date: Fri, 18 Dec 2015 14:09:06 -0500 Subject: [PATCH] Numerous small fixes --- runtime/Go/src/antlr4/ATNConfig.go | 6 +- runtime/Go/src/antlr4/ATNConfigSet.go | 6 +- runtime/Go/src/antlr4/ATNDeserializer.go | 429 ++++++++++-------- runtime/Go/src/antlr4/ATNSimulator.go | 12 +- runtime/Go/src/antlr4/ATNState.go | 60 +-- runtime/Go/src/antlr4/BufferedTokenStream.go | 5 +- runtime/Go/src/antlr4/DFASerializer.go | 6 +- runtime/Go/src/antlr4/ErrorStrategy.go | 84 ++-- runtime/Go/src/antlr4/Errors.go | 12 +- runtime/Go/src/antlr4/IntervalSet.go | 4 +- runtime/Go/src/antlr4/Lexer.go | 6 +- runtime/Go/src/antlr4/Parser.go | 19 +- runtime/Go/src/antlr4/ParserATNSimulator.go | 257 +++++------ runtime/Go/src/antlr4/ParserRuleContext.go | 10 +- runtime/Go/src/antlr4/PredictionContext.go | 10 +- runtime/Go/src/antlr4/Recognizer.go | 4 +- runtime/Go/src/antlr4/RuleContext.go | 4 +- runtime/Go/src/antlr4/Transition.go | 32 +- runtime/Go/src/antlr4/Tree.go | 6 +- .../antlr/v4/runtime/atn/ATNDeserializer.java | 2 +- runtime/JavaScript/src/antlr4/IntervalSet.js | 2 +- .../antlr/v4/tool/templates/codegen/Go/Go.stg | 16 +- 22 files changed, 538 insertions(+), 454 deletions(-) diff --git a/runtime/Go/src/antlr4/ATNConfig.go b/runtime/Go/src/antlr4/ATNConfig.go index a32df8e12..7abb494f2 100644 --- a/runtime/Go/src/antlr4/ATNConfig.go +++ b/runtime/Go/src/antlr4/ATNConfig.go @@ -64,11 +64,11 @@ func NewATNConfig1(c *ATNConfig, state *ATNState, context *PredictionContext) *A func NewATNConfig(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) *ATNConfig { a := new(ATNConfig) - a.initATNConfig2(c, state, context, semanticContext) + a.InitATNConfig2(c, state, context, semanticContext) return a } -func (a *ATNConfig) initATNConfig2(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) { +func (a *ATNConfig) InitATNConfig2(c *ATNConfig, state *ATNState, context *PredictionContext, semanticContext *SemanticContext) { a.state = state; a.alt = c.alt; @@ -206,7 +206,7 @@ func NewLexerATNConfig( state *ATNState, alt int, context *PredictionContext) *L this := new(LexerATNConfig) - this.initATNConfig(state, alt, context, SemanticContextNONE) + this.InitATNConfig(state, alt, context, SemanticContextNONE) this.lexerActionExecutor = nil this.passedThroughNonGreedyDecision = false diff --git a/runtime/Go/src/antlr4/ATNConfigSet.go b/runtime/Go/src/antlr4/ATNConfigSet.go index b9ac75be9..5663a781d 100644 --- a/runtime/Go/src/antlr4/ATNConfigSet.go +++ b/runtime/Go/src/antlr4/ATNConfigSet.go @@ -41,12 +41,12 @@ func NewATNConfigSet(fullCtx bool) *ATNConfigSet { this := new(ATNConfigSet) - this.initATNConfigSet(fullCtx) + this.InitATNConfigSet(fullCtx) return this } -func (a *ATNConfigSet) initATNConfigSet(fullCtx bool) { +func (a *ATNConfigSet) InitATNConfigSet(fullCtx bool) { // The reason that we need a.is because we don't want the hash map to use // the standard hash code and equals. We need all configurations with the @@ -264,7 +264,7 @@ func NewOrderedATNConfigSet() *OrderedATNConfigSet { this := new(OrderedATNConfigSet) - this.initATNConfigSet(false) + this.InitATNConfigSet(false) this.configLookup = NewSet(nil, nil) return this diff --git a/runtime/Go/src/antlr4/ATNDeserializer.go b/runtime/Go/src/antlr4/ATNDeserializer.go index 14568cc73..0f17f23cc 100644 --- a/runtime/Go/src/antlr4/ATNDeserializer.go +++ b/runtime/Go/src/antlr4/ATNDeserializer.go @@ -1,4 +1,5 @@ package antlr4 +import "strings" // This is the earliest supported serialized UUID. // stick to serialized version for now, we don't need a UUID instance @@ -13,17 +14,35 @@ var SERIALIZED_VERSION = 3 // This is the current serialized UUID. var SERIALIZED_UUID = BASE_SERIALIZED_UUID -func initArray( length, value) { - var tmp = [] - tmp[length-1] = value - return tmp.map(function(i) {return value}) +func InitArray( length int, value interface{}) { + var tmp = make([]interface{}, length) + + for i := range tmp { + tmp[i] = value + } + + return tmp } -func ATNDeserializer (options) { +type ATNDeserializer struct { + + deserializationOptions ATNDeserializationOptions + stateFactories + actionFactories + data []rune + pos int + uuid string + +} + +func NewATNDeserializer (options ATNDeserializationOptions) *ATNDeserializer { - if ( options== nil || options == nil ) { - options = ATNDeserializationOptions.defaultOptions + if ( options== nil ) { + options = ATNDeserializationOptionsdefaultOptions } + + this := new(ATNDeserializer) + this.deserializationOptions = options this.stateFactories = nil this.actionFactories = nil @@ -43,16 +62,26 @@ func ATNDeserializer (options) { // serialized ATN at or after the feature identified by {@code feature} was // introduced otherwise, {@code false}. -func (this *ATNDeserializer) isFeatureSupported(feature, actualUuid) { - var idx1 = SUPPORTED_UUIDS.index(feature) +func stringInSlice(a string, list []string) bool { + for _, b := range list { + if b == a { + return true + } + } + return false +} + +func (this *ATNDeserializer) isFeatureSupported(feature, actualUuid string) bool { + var idx1 = stringInSlice( feature, SUPPORTED_UUIDS ) if (idx1<0) { return false } - var idx2 = SUPPORTED_UUIDS.index(actualUuid) + var idx2 = stringInSlice( actualUuid, SUPPORTED_UUIDS ) return idx2 >= idx1 } -func (this *ATNDeserializer) deserialize(data) { +func (this *ATNDeserializer) deserialize(data []rune) *ATN { + this.reset(data) this.checkVersion() this.checkUUID() @@ -72,16 +101,34 @@ func (this *ATNDeserializer) deserialize(data) { this.verifyATN(atn) } return atn + } -func (this *ATNDeserializer) reset(data) { - var adjust = function(c) { - var v = c.charCodeAt(0) - return v>1 ? v-2 : -1 - } - var temp = data.split("").map(adjust) - // don't adjust the first value since that's the version number - temp[0] = data.charCodeAt(0) +func (this *ATNDeserializer) reset(data []rune) { + + // TODO not sure the copy is necessary here + temp := make([]rune, len(data)) + + for i, c := range data { + // don't adjust the first value since that's the version number + if (i == 0) { + temp[i] = c + } else if c > 1 { + temp[i] = c-2 + } else { + temp[i] = -1 + } + } + +// var adjust = func(c) { +// var v = c.charCodeAt(0) +// return v>1 ? v-2 : -1 +// } + +// var temp = data.split("").map(adjust) +// // don't adjust the first value since that's the version number +// temp[0] = data.charCodeAt(0) + this.data = temp this.pos = 0 } @@ -95,25 +142,35 @@ func (this *ATNDeserializer) checkVersion() { func (this *ATNDeserializer) checkUUID() { var uuid = this.readUUID() - if (SUPPORTED_UUIDS.indexOf(uuid)<0) { - panic ("Could not deserialize ATN with UUID: " + uuid + - " (expected " + SERIALIZED_UUID + " or a legacy UUID).", uuid, SERIALIZED_UUID) + if ( strings.Index(uuid, SUPPORTED_UUIDS )<0) { + panic("Could not deserialize ATN with UUID: " + uuid + " (expected " + SERIALIZED_UUID + " or a legacy UUID).", uuid, SERIALIZED_UUID) } this.uuid = uuid } -func (this *ATNDeserializer) readATN() { +func (this *ATNDeserializer) readATN() *ATN { var grammarType = this.readInt() var maxTokenType = this.readInt() return NewATN(grammarType, maxTokenType) } -func (this *ATNDeserializer) readStates(atn) { - var j, pair, stateNumber - var loopBackStateNumbers = [] - var endStateNumbers = [] +type LoopEndStateIntPair struct { + item0 *LoopEndState + item1 int +} + +type BlockStartStateIntPair struct { + item0 *BlockStartState + item1 int +} + +func (this *ATNDeserializer) readStates(atn *ATN) { + + var loopBackStateNumbers = make([]LoopEndStateIntPair) + var endStateNumbers = make([]BlockStartStateIntPair) + var nstates = this.readInt() - for(var i=0 i 0) { - bypassStart.addTransition(ruleToStartState.transitions[count-1]) + bypassStart.addTransition(ruleToStartState.transitions[count-1],-1) ruleToStartState.transitions = ruleToStartState.transitions.slice(-1) } // link the Newstates - atn.ruleToStartState[idx].addTransition(NewEpsilonTransition(bypassStart)) - bypassStop.addTransition(NewEpsilonTransition(endState)) + atn.ruleToStartState[idx].addTransition(NewEpsilonTransition(bypassStart,-1)) + bypassStop.addTransition(NewEpsilonTransition(endState, -1), -1) var matchState = NewBasicState() atn.addState(matchState) - matchState.addTransition(NewAtomTransition(bypassStop, atn.ruleToTokenType[idx])) - bypassStart.addTransition(NewEpsilonTransition(matchState)) + matchState.addTransition(NewAtomTransition(bypassStop, atn.ruleToTokenType[idx]), -1) + bypassStart.addTransition(NewEpsilonTransition(matchState, -1), -1) } -func (this *ATNDeserializer) stateIsEndStateFor(state, idx) { +func (this *ATNDeserializer) stateIsEndStateFor(state *ATNState, idx int) { if ( state.ruleIndex != idx) { return nil } - if (!( state instanceof StarLoopEntryState)) { + if _,ok := state.(*StarLoopEntryState); !ok { return nil } - var maybeLoopEndState = state.transitions[state.transitions.length - 1].target - if (!( maybeLoopEndState instanceof LoopEndState)) { + var maybeLoopEndState = state.transitions[len(state.transitions) - 1].target + if _,ok := maybeLoopEndState.(*LoopEndState); !ok { return nil } - if (maybeLoopEndState.epsilonOnlyTransitions && - (maybeLoopEndState.transitions[0].target instanceof RuleStopState)) { + + _,ok := maybeLoopEndState.transitions[0].target.(*RuleStopState) + + if (maybeLoopEndState.epsilonOnlyTransitions && ok) { return state } else { return nil @@ -419,10 +477,10 @@ func (this *ATNDeserializer) stateIsEndStateFor(state, idx) { // // @param atn The ATN. // -func (this *ATNDeserializer) markPrecedenceDecisions(atn) { - for(var i=0 i= 0) - } else { - this.checkCondition(state.transitions.length <= 1 || _, ok := state.(RuleStopState); ok) + this.checkCondition(state.epsilonOnlyTransitions || len(state.transitions) <= 1, nil) + + switch s2:= state.(type) { + + case *PlusBlockStartState: + this.checkCondition(s2.loopBackState != nil,nil) + case *StarLoopEntryState: + + this.checkCondition(s2.loopBackState != nil,nil) + this.checkCondition(len(s2.transitions) == 2,nil) + + switch _ := s2.(type) { + case *StarBlockStartState: + _,ok2 := s2.transitions[1].target.(*LoopEndState) + this.checkCondition(ok2, nil) + this.checkCondition(!s2.nonGreedy, nil) + case *LoopEndState: + _,ok2 := s2.transitions[1].target.(*StarBlockStartState) + // this.checkCondition(state.transitions[1].target instanceof StarBlockStartState) + this.checkCondition(ok2, nil) + this.checkCondition(s2.nonGreedy, nil) + default: + panic("IllegalState") + } + + case *StarLoopbackState: + this.checkCondition(len(state.transitions) == 1, nil) + _,ok2 := state.transitions[0].target.(*StarLoopEntryState) + this.checkCondition(ok2, nil) + case *LoopEndState: + this.checkCondition(s2.loopBackState != nil, nil) + case *RuleStartState: + this.checkCondition(s2.stopState != nil, nil) + case *BlockStartState: + this.checkCondition(s2.endState != nil, nil) + case *BlockEndState: + this.checkCondition(s2.startState != nil, nil) + case *DecisionState: + this.checkCondition(len(s2.transitions) <= 1 || s2.decision >= 0, nil) + default: + _, ok := s2.(*RuleStopState) + this.checkCondition(len(s2.transitions) <= 1 || ok, nil) } } } -func (this *ATNDeserializer) checkCondition(condition, message) { +func (this *ATNDeserializer) checkCondition(condition bool, message string) { if (!condition) { - if (message == nil || message==nil) { + if (message==nil) { message = "IllegalState" } - panic (message) + panic(message) } } -func (this *ATNDeserializer) readInt() { - return this.data[this.pos++] +func (this *ATNDeserializer) readInt() int { + v := this.data[this.pos] + this.pos += 1 + return v } -ATNDeserializer.prototype.readInt32 = function() { +func (this *ATNDeserializer) readInt32() int { var low = this.readInt() var high = this.readInt() return low | (high << 16) } -func (this *ATNDeserializer) readLong() { +func (this *ATNDeserializer) readLong() int64 { var low = this.readInt32() var high = this.readInt32() return (low & 0x00000000FFFFFFFF) | (high << 32) } -type createByteToHex struct { +func createByteToHex() { var bth = [] - for i := 0 i < 256 i++) { + for i := 0; i < 256; i++ { bth[i] = (i + 0x100).toString(16).substr(1).toUpperCase() } return bth @@ -520,7 +593,7 @@ type createByteToHex struct { var byteToHex = createByteToHex() -func (this *ATNDeserializer) readUUID() { +func (this *ATNDeserializer) readUUID() string { var bb = [] for i:=7;i>=0;i-- { var int = this.readInt() @@ -538,9 +611,9 @@ func (this *ATNDeserializer) readUUID() { byteToHex[bb[14]] + byteToHex[bb[15]] } -ATNDeserializer.prototype.edgeFactory = function(atn, type, src, trg, arg1, arg2, arg3, sets) { +ATNDeserializer.prototypeIndex.edgeFactory = function(atn, typeIndex, src, trg, arg1, arg2, arg3, sets) { var target = atn.states[trg] - switch(type) { + switch(typeIndex) { case Transition.EPSILON: return NewEpsilonTransition(target) case Transition.RANGE: @@ -562,11 +635,11 @@ ATNDeserializer.prototype.edgeFactory = function(atn, type, src, trg, arg1, arg2 case Transition.WILDCARD: return NewWildcardTransition(target) default: - panic "The specified transition type: " + type + " is not valid." + panic "The specified transition typeIndex: " + typeIndex + " is not valid." } } -func (this *ATNDeserializer) stateFactory(type, ruleIndex) { +func (this *ATNDeserializer) stateFactory(typeIndex, ruleIndex) { if (this.stateFactories == nil) { var sf = [] sf[ATNStateInvalidType] = nil @@ -584,10 +657,10 @@ func (this *ATNDeserializer) stateFactory(type, ruleIndex) { sf[ATNStateLOOP_END] = function() { return NewLoopEndState() } this.stateFactories = sf } - if (type>this.stateFactories.length || this.stateFactories[type] == nil) { - panic("The specified state type " + type + " is not valid.") + if (typeIndex>len(this.stateFactories) || this.stateFactories[typeIndex] == nil) { + panic("The specified state typeIndex " + typeIndex + " is not valid.") } else { - var s = this.stateFactories[type]() + var s = this.stateFactories[typeIndex]() if (s!=nil) { s.ruleIndex = ruleIndex return s @@ -595,7 +668,7 @@ func (this *ATNDeserializer) stateFactory(type, ruleIndex) { } } -ATNDeserializer.prototype.lexerActionFactory = function(type, data1, data2) { +ATNDeserializer.prototypeIndex.lexerActionFactory = function(typeIndex, data1, data2) { if (this.actionFactories == nil) { var af = [] af[LexerActionTypeCHANNEL] = function(data1, data2) { return NewLexerChannelAction(data1) } @@ -608,10 +681,10 @@ ATNDeserializer.prototype.lexerActionFactory = function(type, data1, data2) { af[LexerActionTypeTYPE] = function(data1, data2) { return NewLexerTypeAction(data1) } this.actionFactories = af } - if (type>this.actionFactories.length || this.actionFactories[type] == nil) { - panic("The specified lexer action type " + type + " is not valid.") + if (typeIndex>len(this.actionFactories) || this.actionFactories[typeIndex] == nil) { + panic("The specified lexer action typeIndex " + typeIndex + " is not valid.") } else { - return this.actionFactories[type](data1, data2) + return this.actionFactories[typeIndex](data1, data2) } } diff --git a/runtime/Go/src/antlr4/ATNSimulator.go b/runtime/Go/src/antlr4/ATNSimulator.go index 76f88c7ab..84312d748 100644 --- a/runtime/Go/src/antlr4/ATNSimulator.go +++ b/runtime/Go/src/antlr4/ATNSimulator.go @@ -5,7 +5,7 @@ type ATNSimulator struct { sharedContextCache *PredictionContextCache } -func ATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimulator { +func NewATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimulator { // The context cache maps all PredictionContext objects that are == // to a single cached copy. This cache is shared across all contexts @@ -29,14 +29,18 @@ func ATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimu this := new(ATNSimulator) - this.atn = atn - this.sharedContextCache = sharedContextCache + this.InitATNSimulator(atn, sharedContextCache) return this } +func (this *ATNSimulator) InitATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) { + this.atn = atn + this.sharedContextCache = sharedContextCache +} + // Must distinguish between missing edge and edge we know leads nowhere/// -var ATNSimulatorERROR = NewDFAState(0x7FFFFFFF, NewATNConfigSet()) +var ATNSimulatorERROR = NewDFAState(0x7FFFFFFF, NewATNConfigSet(false)) func (this *ATNSimulator) getCachedContext(context *PredictionContext) *PredictionContext { if (this.sharedContextCache == nil) { diff --git a/runtime/Go/src/antlr4/ATNState.go b/runtime/Go/src/antlr4/ATNState.go index 424831af9..e77c7c7f7 100644 --- a/runtime/Go/src/antlr4/ATNState.go +++ b/runtime/Go/src/antlr4/ATNState.go @@ -78,12 +78,12 @@ type ATNState struct { func NewATNState() *ATNState { as := new(ATNState) - as.initATNState() + as.InitATNState() return as } -func (as *ATNState) initATNState(){ +func (as *ATNState) InitATNState(){ // Which ATN are we in? as.atn = nil @@ -167,7 +167,7 @@ type BasicState struct { func NewBasicState() *BasicState { this := new(BasicState) - this.initATNState() + this.InitATNState() this.stateType = ATNStateBASIC return this @@ -184,13 +184,13 @@ func NewDecisionState() *DecisionState { this := new(DecisionState) - this.initATNState() - this.initDecisionState() + this.InitATNState() + this.InitDecisionState() return this } -func (this *DecisionState) initDecisionState() { +func (this *DecisionState) InitDecisionState() { this.decision = -1 this.nonGreedy = false @@ -208,13 +208,13 @@ func NewBlockStartState() *BlockStartState { this := new(BlockStartState) - this.initATNState() - this.initDecisionState() + this.InitATNState() + this.InitDecisionState() return this } -func (this *BlockStartState) initBlockStartState() { +func (this *BlockStartState) InitBlockStartState() { this.endState = nil @@ -228,9 +228,9 @@ func NewBasicBlockStartState() *BasicBlockStartState { this := new(BasicBlockStartState) - this.initATNState() - this.initDecisionState() - this.initBlockStartState() + this.InitATNState() + this.InitDecisionState() + this.InitBlockStartState() this.stateType = ATNStateBLOCK_START return this @@ -247,7 +247,7 @@ func NewBlockEndState() *BlockEndState { this := new(BlockEndState) - this.initATNState() + this.InitATNState() this.stateType = ATNStateBLOCK_END this.startState = nil @@ -266,7 +266,7 @@ type RuleStopState struct { func NewRuleStopState() *RuleStopState { this := new(RuleStopState) - this.initATNState() + this.InitATNState() this.stateType = ATNStateRULE_STOP return this } @@ -282,7 +282,7 @@ func NewRuleStartState() *RuleStartState { this := new(RuleStartState) - this.initATNState() + this.InitATNState() this.stateType = ATNStateRULE_START this.stopState = nil this.isPrecedenceRule = false @@ -301,9 +301,9 @@ func NewPlusLoopbackState() *PlusLoopbackState { this := new(PlusLoopbackState) - this.initATNState() - this.initDecisionState() - this.initBlockStartState() + this.InitATNState() + this.InitDecisionState() + this.InitBlockStartState() this.stateType = ATNStatePLUS_LOOP_BACK return this @@ -324,9 +324,9 @@ func NewPlusBlockStartState() *PlusBlockStartState { this := new(PlusBlockStartState) - this.initATNState() - this.initDecisionState() - this.initBlockStartState() + this.InitATNState() + this.InitDecisionState() + this.InitBlockStartState() this.stateType = ATNStatePLUS_BLOCK_START this.loopBackState = nil @@ -343,9 +343,9 @@ func NewStarBlockStartState() *StarBlockStartState { this := new(StarBlockStartState) - this.initATNState() - this.initDecisionState() - this.initBlockStartState() + this.InitATNState() + this.InitDecisionState() + this.InitBlockStartState() this.stateType = ATNStateSTAR_BLOCK_START @@ -361,7 +361,7 @@ func NewStarLoopbackState() *StarLoopbackState { this := new(StarLoopbackState) - this.initATNState() + this.InitATNState() this.stateType = ATNStateSTAR_LOOP_BACK return this @@ -379,8 +379,8 @@ func NewStarLoopEntryState() *StarLoopEntryState { this := new(StarLoopEntryState) - this.initATNState() - this.initDecisionState() + this.InitATNState() + this.InitDecisionState() this.stateType = ATNStateSTAR_LOOP_ENTRY this.loopBackState = nil @@ -402,7 +402,7 @@ func NewLoopEndState() *LoopEndState { this := new(LoopEndState) - this.initATNState() + this.InitATNState() this.stateType = ATNStateLOOP_END this.loopBackState = nil @@ -419,8 +419,8 @@ func NewTokensStartState() *TokensStartState { this := new(TokensStartState) - this.initATNState() - this.initDecisionState() + this.InitATNState() + this.InitDecisionState() this.stateType = ATNStateTOKEN_START return this diff --git a/runtime/Go/src/antlr4/BufferedTokenStream.go b/runtime/Go/src/antlr4/BufferedTokenStream.go index 25350c064..6f429ae0c 100644 --- a/runtime/Go/src/antlr4/BufferedTokenStream.go +++ b/runtime/Go/src/antlr4/BufferedTokenStream.go @@ -25,6 +25,7 @@ type IntStream interface { type TokenStream interface { IntStream + LT(k int) *Token get(index int) *Token getTokenSource() *TokenSource @@ -168,13 +169,13 @@ func (bt *BufferedTokenStream) fetch(n int) int { } // Get all tokens from start..stop inclusively/// -func (bt *BufferedTokenStream) getTokens(start int, stop int, types []int) []*Token { +func (bt *BufferedTokenStream) getTokens(start int, stop int, types *IntervalSet) []*Token { if (start < 0 || stop < 0) { return nil } bt.lazyInit() - var subset = (make[]*Token) + var subset = make([]*Token) if (stop >= len(bt.tokens)) { stop = len(bt.tokens) - 1 } diff --git a/runtime/Go/src/antlr4/DFASerializer.go b/runtime/Go/src/antlr4/DFASerializer.go index 8b601d714..2778eb67e 100644 --- a/runtime/Go/src/antlr4/DFASerializer.go +++ b/runtime/Go/src/antlr4/DFASerializer.go @@ -21,12 +21,12 @@ func NewDFASerializer(dfa *DFA, literalNames, symbolicNames []string) *DFASerial this := new(DFASerializer) - this.initDFASerializer(dfa, literalNames, symbolicNames) + this.InitDFASerializer(dfa, literalNames, symbolicNames) return this } -func (this *DFASerializer) initDFASerializer(dfa *DFA, literalNames, symbolicNames []string) { +func (this *DFASerializer) InitDFASerializer(dfa *DFA, literalNames, symbolicNames []string) { this.dfa = dfa this.literalNames = literalNames this.symbolicNames = symbolicNames @@ -105,7 +105,7 @@ func NewLexerDFASerializer(dfa *DFA) *LexerDFASerializer { this := new(DFASerializer) - this.initDFASerializer(dfa, nil, nil) + this.InitDFASerializer(dfa, nil, nil) return this } diff --git a/runtime/Go/src/antlr4/ErrorStrategy.go b/runtime/Go/src/antlr4/ErrorStrategy.go index 9378085e2..73237a20a 100644 --- a/runtime/Go/src/antlr4/ErrorStrategy.go +++ b/runtime/Go/src/antlr4/ErrorStrategy.go @@ -3,6 +3,7 @@ package antlr4 import ( "fmt" "strings" + "reflect" ) type ErrorStrategy struct { @@ -15,7 +16,7 @@ func (this *ErrorStrategy) reset(recognizer *Parser){ func (this *ErrorStrategy) recoverInline(recognizer *Parser){ } -func (this *ErrorStrategy) recover(recognizer *Parser, e *Error){ +func (this *ErrorStrategy) recover(recognizer *Parser, e *RecognitionException){ } func (this *ErrorStrategy) sync(recognizer *Parser){ @@ -35,12 +36,17 @@ type DefaultErrorStrategy struct { errorRecoveryMode bool lastErrorIndex int - lastErrorStates []int + lastErrorStates *IntervalSet } -func DefaultErrorStrategy() *DefaultErrorStrategy { +func NewDefaultErrorStrategy() *DefaultErrorStrategy { d := new(DefaultErrorStrategy) + d.InitDefaultErrorStrategy() + return d +} + +func (d *DefaultErrorStrategy) InitDefaultErrorStrategy() { // Indicates whether the error strategy is currently "recovering from an // error". This is used to suppress reporting multiple error messages while @@ -59,12 +65,8 @@ func DefaultErrorStrategy() *DefaultErrorStrategy { d.lastErrorIndex = -1 d.lastErrorStates = nil - return d } -//DefaultErrorStrategy.prototype = Object.create(ErrorStrategy.prototype) -//DefaultErrorStrategy.prototype.constructor = DefaultErrorStrategy - //

The default implementation simply calls {@link //endErrorCondition} to // ensure that the handler is not in error recovery mode.

func (this *DefaultErrorStrategy) reset(recognizer *Parser) { @@ -125,7 +127,7 @@ func (this *DefaultErrorStrategy) reportMatch(recognizer *Parser) { // the exception // // -func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) { +func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *RecognitionException) { // if we've already reported an error and have not matched a token // yet successfully, don't report any errors. if(this.inErrorRecoveryMode(recognizer)) { @@ -135,9 +137,9 @@ func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) { switch e.(type) { default: - fmt.Println("unknown recognition error type: " + e.constructor.name) - fmt.Println(e.stack) - recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e) + fmt.Println("unknown recognition error type: " + reflect.TypeOf(e).Name()) +// fmt.Println(e.stack) + recognizer.notifyErrorListeners(e.offendingToken, e.message, e) case NoViableAltException: this.reportNoViableAlternative(recognizer, e) case InputMismatchException: @@ -146,6 +148,7 @@ func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) { this.reportFailedPredicate(recognizer, e) } } + // // {@inheritDoc} // @@ -154,19 +157,20 @@ func (this *DefaultErrorStrategy) reportError(recognizer *Parser, e *) { // that can follow the current rule.

// func (this *DefaultErrorStrategy) recover(recognizer *Parser, e *RecognitionException) { - if (this.lastErrorIndex==recognizer.getInputStream().index && - this.lastErrorStates != nil && this.lastErrorStates.indexOf(recognizer.state)>=0) { + + if (this.lastErrorIndex==recognizer.getInputStream().index() && + this.lastErrorStates != nil && this.lastErrorStates.contains(recognizer.state)) { // uh oh, another error at same token index and previously-visited // state in ATN must be a case where LT(1) is in the recovery // token set so nothing got consumed. Consume a single token // at least to prevent an infinite loop this is a failsafe. recognizer.consume() } - this.lastErrorIndex = recognizer._input.index + this.lastErrorIndex = recognizer._input.index() if (this.lastErrorStates == nil) { - this.lastErrorStates = [] + this.lastErrorStates = NewIntervalSet() } - this.lastErrorStates.push(recognizer.state) + this.lastErrorStates.addOne(recognizer.state) var followSet = this.getErrorRecoverySet(recognizer) this.consumeUntil(recognizer, followSet) } @@ -224,7 +228,7 @@ func (this *DefaultErrorStrategy) sync(recognizer *Parser) { var s = recognizer._interp.atn.states[recognizer.state] var la = recognizer.getTokenStream().LA(1) // try cheaper subset first might get lucky. seems to shave a wee bit off - if (la==TokenEOF || recognizer.atn.nextTokens(s).contains(la)) { + if (la==TokenEOF || recognizer.getATN().nextTokens(s).contains(la)) { return } // Return but don't end recovery. only do that upon valid token match @@ -264,14 +268,14 @@ func (this *DefaultErrorStrategy) sync(recognizer *Parser) { // @param recognizer the parser instance // @param e the recognition exception // -func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer *Parser, e *RecognitionException) { - var tokens = recognizer.getTokenStream() - var input +func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer *Parser, e *NoViableAltException) { + var tokens = recognizer.getTokenStream() + var input string if(tokens != nil) { if (e.startToken.tokenType==TokenEOF) { input = "" } else { - input = tokens.getText(NewInterval(e.startToken, e.offendingToken)) + input = tokens.getTextFromInterval(NewInterval(e.startToken, e.offendingToken)) } } else { input = "" @@ -305,7 +309,7 @@ func (this *DefaultErrorStrategy) reportInputMismatch(recognizer *Parser, e *Rec // @param e the recognition exception // func (this *DefaultErrorStrategy) reportFailedPredicate(recognizer *Parser, e *RecognitionException) { - var ruleName = recognizer.ruleNames[recognizer._ctx.ruleIndex] + var ruleName = recognizer.getRuleNames()[recognizer._ctx.ruleIndex] var msg = "rule " + ruleName + " " + e.message recognizer.notifyErrorListeners(msg, e.offendingToken, e) } @@ -336,7 +340,7 @@ func (this *DefaultErrorStrategy) reportUnwantedToken(recognizer *Parser) { var tokenName = this.getTokenErrorDisplay(t) var expecting = this.getExpectedTokens(recognizer) var msg = "extraneous input " + tokenName + " expecting " + - expecting.toString(recognizer.literalNames, recognizer.symbolicNames) + expecting.toStringVerbose(recognizer.literalNames, recognizer.symbolicNames, false) recognizer.notifyErrorListeners(msg, t, nil) } // This method is called to report a syntax error which requires the @@ -362,7 +366,7 @@ func (this *DefaultErrorStrategy) reportMissingToken(recognizer *Parser) { this.beginErrorCondition(recognizer) var t = recognizer.getCurrentToken() var expecting = this.getExpectedTokens(recognizer) - var msg = "missing " + expecting.toString(recognizer.literalNames, recognizer.symbolicNames) + + var msg = "missing " + expecting.toStringVerbose(recognizer.literalNames, recognizer.symbolicNames, false) + " at " + this.getTokenErrorDisplay(t) recognizer.notifyErrorListeners(msg, t, nil) } @@ -485,7 +489,7 @@ func (this *DefaultErrorStrategy) singleTokenInsertion(recognizer *Parser) { // deletion successfully recovers from the mismatched input, otherwise // {@code nil} // -func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer *Parser) { +func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer *Parser) Token { var nextTokenType = recognizer.getTokenStream().LA(2) var expecting = this.getExpectedTokens(recognizer) if (expecting.contains(nextTokenType)) { @@ -526,8 +530,8 @@ func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer *Parser) { func (this *DefaultErrorStrategy) getMissingSymbol(recognizer *Parser) { var currentSymbol = recognizer.getCurrentToken() var expecting = this.getExpectedTokens(recognizer) - var expectedTokenType = expecting.first() // get any element - var tokenText + var expectedTokenType = expecting.first() + var tokenText string if (expectedTokenType==TokenEOF) { tokenText = "" } else { @@ -538,10 +542,12 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer *Parser) { if (current.tokenType==TokenEOF && lookback != nil) { current = lookback } - return recognizer.getTokenFactory().create(current.source, expectedTokenType, tokenText, TokenDefaultChannel, -1, -1, current.line, current.column) + + tf := recognizer.getTokenFactory() + return tf.create(current.source, expectedTokenType, tokenText, TokenDefaultChannel, -1, -1, current.line, current.column) } -func (this *DefaultErrorStrategy) getExpectedTokens(recognizer *Parser) { +func (this *DefaultErrorStrategy) getExpectedTokens(recognizer *Parser) *IntervalSet { return recognizer.getExpectedTokens() } @@ -675,7 +681,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer *Parser) *Inter // compute what follows who invoked us var invokingState = atn.states[ctx.invokingState] var rt = invokingState.transitions[0] - var follow = atn.nextTokens(rt.followState) + var follow = atn.nextTokens(rt.(*RuleTransition).followState, nil) recoverSet.addSet(follow) ctx = ctx.parentCtx } @@ -684,7 +690,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer *Parser) *Inter } // Consume tokens until one matches the given token set.// -func (this *DefaultErrorStrategy) consumeUntil(recognizer *Parser, set) { +func (this *DefaultErrorStrategy) consumeUntil(recognizer *Parser, set *IntervalSet) { var ttype = recognizer.getTokenStream().LA(1) for( ttype != TokenEOF && !set.contains(ttype)) { recognizer.consume() @@ -719,14 +725,18 @@ func (this *DefaultErrorStrategy) consumeUntil(recognizer *Parser, set) { // {@code myparser.setErrorHandler(NewBailErrorStrategy())}

// // @see Parser//setErrorHandler(ANTLRErrorStrategy) -// + type BailErrorStrategy struct { - DefaultErrorStrategy.call(this) - return this + DefaultErrorStrategy } -//BailErrorStrategy.prototype = Object.create(DefaultErrorStrategy.prototype) -//BailErrorStrategy.prototype.constructor = BailErrorStrategy +func NewBailErrorStrategy() *BailErrorStrategy { + + this := new(BailErrorStrategy) + this.InitDefaultErrorStrategy() + + return this +} // Instead of recovering from exception {@code e}, re-panic it wrapped // in a {@link ParseCancellationException} so it is not caught by the @@ -739,7 +749,7 @@ func (this *BailErrorStrategy) recover(recognizer *Parser, e *RecognitionExcepti context.exception = e context = context.parentCtx } - panic(NewParseCancellationException(e)) + panic(NewParseCancellationException()) // TODO we don't emit e properly } // Make sure we don't attempt to recover inline if the parser diff --git a/runtime/Go/src/antlr4/Errors.go b/runtime/Go/src/antlr4/Errors.go index bfe797edf..555080117 100644 --- a/runtime/Go/src/antlr4/Errors.go +++ b/runtime/Go/src/antlr4/Errors.go @@ -33,12 +33,12 @@ func NewRecognitionException(message string, recognizer *Recognizer, input *Inpu // TODO may be able to use - "runtime" func Stack(buf []byte, all bool) int t := new(RecognitionException) - t.initRecognitionException(message, recognizer, input, ctx) + t.InitRecognitionException(message, recognizer, input, ctx) return t } -func (t *RecognitionException) initRecognitionException(message string, recognizer *Recognizer, input *InputStream, ctx *RuleContext){ +func (t *RecognitionException) InitRecognitionException(message string, recognizer *Recognizer, input *InputStream, ctx *RuleContext){ t.message = message t.recognizer = recognizer @@ -99,7 +99,7 @@ func NewLexerNoViableAltException(lexer *Lexer, input *InputStream, startIndex i this := new (LexerNoViableAltException) - this.initRecognitionException("", lexer, input, nil) + this.InitRecognitionException("", lexer, input, nil) this.startIndex = startIndex this.deadEndConfigs = deadEndConfigs @@ -152,7 +152,7 @@ func NoViableAltException(recognizer *Parser, input *InputStream, startToken *To } this := new(NoViableAltException) - this.initRecognitionException("", recognizer, input, ctx) + this.InitRecognitionException("", recognizer, input, ctx) // Which configurations did we try at input.index() that couldn't match // input.LT(1)?// @@ -179,7 +179,7 @@ type InputMismatchException struct { func NewInputMismatchException(recognizer *Parser) *InputMismatchException { this := new(InputMismatchException) - this.initRecognitionException("", recognizer, recognizer.getInputStream(), recognizer._ctx) + this.InitRecognitionException("", recognizer, recognizer.getInputStream(), recognizer._ctx) this.offendingToken = recognizer.getCurrentToken() @@ -206,7 +206,7 @@ func NewFailedPredicateException(recognizer *Parser, predicate string, message s this := new(FailedPredicateException) - this.initRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx) + this.InitRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx) var s = recognizer._interp.atn.states[recognizer.state] var trans = s.transitions[0] diff --git a/runtime/Go/src/antlr4/IntervalSet.go b/runtime/Go/src/antlr4/IntervalSet.go index 4c010eb36..5c6066e8d 100644 --- a/runtime/Go/src/antlr4/IntervalSet.go +++ b/runtime/Go/src/antlr4/IntervalSet.go @@ -51,8 +51,8 @@ func NewIntervalSet() *IntervalSet { return i } -func (i *IntervalSet) first(v int) int { - if (i.intervals == nil || len(i.intervals)==0) { +func (i *IntervalSet) first() int { + if (len(i.intervals)==0) { return TokenInvalidType } else { return i.intervals[0].start diff --git a/runtime/Go/src/antlr4/Lexer.go b/runtime/Go/src/antlr4/Lexer.go index c211a8117..ab4862a26 100644 --- a/runtime/Go/src/antlr4/Lexer.go +++ b/runtime/Go/src/antlr4/Lexer.go @@ -49,13 +49,13 @@ func NewLexer(input *InputStream) *Lexer { lexer := new(Lexer) - lexer.initRecognizer() - lexer.initLexer(input) + lexer.InitRecognizer() + lexer.InitLexer(input) return lexer } -func (l *Lexer) initLexer(input *InputStream){ +func (l *Lexer) InitLexer(input *InputStream){ l._input = input l._factory = CommonTokenFactoryDEFAULT diff --git a/runtime/Go/src/antlr4/Parser.go b/runtime/Go/src/antlr4/Parser.go index bfdceee3c..0644a385c 100644 --- a/runtime/Go/src/antlr4/Parser.go +++ b/runtime/Go/src/antlr4/Parser.go @@ -38,6 +38,9 @@ type Parser struct { _tracer bool _parseListeners []*ParseTreeListener _syntaxErrors int + + literalNames []string + symbolicNames []string } // p.is all the parsing support code essentially most of it is error @@ -46,7 +49,7 @@ func NewParser(input *TokenStream) *Parser { p := new(Parser) - p.initRecognizer() + p.InitRecognizer() // The input stream. p._input = nil @@ -271,12 +274,12 @@ func (this *Parser) getATN() *ATN { return this.atn } -func (p *Parser) getTokenFactory() { +func (p *Parser) getTokenFactory() *TokenFactory { return p._input.getTokenSource()._factory } // Tell our token source and error strategy about a Newway to create tokens.// -func (p *Parser) setTokenFactory(factory) { +func (p *Parser) setTokenFactory(factory *TokenFactory) { p._input.getTokenSource()._factory = factory } @@ -590,14 +593,14 @@ func (p *Parser) isExpectedToken(symbol *Token) bool { // // @see ATN//getExpectedTokens(int, RuleContext) // -func (p *Parser) getExpectedTokens() []*Token { +func (p *Parser) getExpectedTokens() *IntervalSet { return p._interp.atn.getExpectedTokens(p.state, p._ctx) } -func (p *Parser) getExpectedTokensWithinCurrentRule() []*Token { +func (p *Parser) getExpectedTokensWithinCurrentRule() *IntervalSet { var atn = p._interp.atn var s = atn.states[p.state] - return atn.nextTokens(s) + return atn.nextTokens(s,nil) } // Get a rule's index (i.e., {@code RULE_ruleName} field) or -1 if not found.// @@ -643,9 +646,9 @@ func (p *Parser) getDFAStrings() { // For debugging and other purposes.// func (p *Parser) dumpDFA() { var seenOne = false - for i := 0; i < p._interp.decisionToDFA.length; i++) { + for i := 0; i < p._interp.decisionToDFA.length; i++ { var dfa = p._interp.decisionToDFA[i] - if (dfa.states.length > 0) { + if ( len(dfa.states) > 0) { if (seenOne) { fmt.Println() } diff --git a/runtime/Go/src/antlr4/ParserATNSimulator.go b/runtime/Go/src/antlr4/ParserATNSimulator.go index f50654afa..c0e5d9801 100644 --- a/runtime/Go/src/antlr4/ParserATNSimulator.go +++ b/runtime/Go/src/antlr4/ParserATNSimulator.go @@ -232,38 +232,30 @@ import ( // the input.

// -//var Utils = require('./../Utils') -var Set = Utils.Set -var BitSet = Utils.BitSet -var DoubleDict = Utils.DoubleDict -//var ATN = require('./ATN').ATN -//var ATNConfig = require('./ATNConfig').ATNConfig -//var ATNConfigSet = require('./ATNConfigSet').ATNConfigSet -//var Token = require('./../Token').Token -//var DFAState = require('./../dfa/DFAState').DFAState -//var PredPrediction = require('./../dfa/DFAState').PredPrediction -//var ATNSimulator = require('./ATNSimulator').ATNSimulator -//var PredictionMode = require('./PredictionMode').PredictionMode -//var RuleContext = require('./../RuleContext').RuleContext -//var ParserRuleContext = require('./../ParserRuleContext').ParserRuleContext -//var SemanticContext = require('./SemanticContext').SemanticContext -//var StarLoopEntryState = require('./ATNState').StarLoopEntryState -//var RuleStopState = require('./ATNState').RuleStopState -//var PredictionContext = require('./../PredictionContext').PredictionContext -//var Interval = require('./../IntervalSet').Interval -//var Transitions = require('./Transition') -var Transition = Transitions.Transition -var SetTransition = Transitions.SetTransition -var NotSetTransition = Transitions.NotSetTransition -var RuleTransition = Transitions.RuleTransition -var ActionTransition = Transitions.ActionTransition -//var NoViableAltException = require('./../error/Errors').NoViableAltException +type ParserATNSimulator struct { + parser *Parser + predictionMode int + _input *TokenStream + _startIndex int + _dfa *DFA + decisionToDFA []*DFA + mergeCache DoubleDict + _outerContext *ParserRuleContext +} -//var SingletonPredictionContext = require('./../PredictionContext').SingletonPredictionContext -//var predictionContextFromRuleContext = require('./../PredictionContext').predictionContextFromRuleContext +func NewParserATNSimulator(parser *Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *ParserATNSimulator { + + this := new(ParserATNSimulator) + + this.InitParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) + + return this +} + +func (this *ParserATNSimulator) InitParserATNSimulator(parser *Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) { + + this.InitATNSimulator(atn, sharedContextCache) -func ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) { - ATNSimulator.call(this, atn, sharedContextCache) this.parser = parser this.decisionToDFA = decisionToDFA // SLL, LL, or LL + exact ambig detection?// @@ -282,22 +274,19 @@ func ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) { // also be examined during cache lookup. // this.mergeCache = nil - return this + } -//ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype) -//ParserATNSimulator.prototype.constructor = ParserATNSimulator - -ParserATNSimulator.prototype.debug = false -ParserATNSimulator.prototype.debug_list_atn_decisions = false -ParserATNSimulator.prototype.dfa_debug = false -ParserATNSimulator.prototype.retry_debug = false +var ParserATNSimulatorprototypedebug = false +var ParserATNSimulatorprototypedebug_list_atn_decisions = false +var ParserATNSimulatorprototypedfa_debug = false +var ParserATNSimulatorprototyperetry_debug = false func (this *ParserATNSimulator) reset() { } -func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) { - if (this.debug || this.debug_list_atn_decisions) { +func (this *ParserATNSimulator) adaptivePredict(input *TokenStream, decision int, outerContext *ParserRuleContext) int { + if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) { fmt.Println("adaptivePredict decision " + decision + " exec LA(1)==" + this.getLookaheadName(input) + " line " + input.LT(1).line + ":" + @@ -328,7 +317,7 @@ func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) { if (outerContext==nil) { outerContext = RuleContext.EMPTY } - if (this.debug || this.debug_list_atn_decisions) { + if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) { fmt.Println("predictATN decision " + dfa.decision + " exec LA(1)==" + this.getLookaheadName(input) + ", outerContext=" + outerContext.toString(this.parser.ruleNames)) @@ -362,7 +351,7 @@ func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) { } } var alt = this.execATN(dfa, s0, input, index, outerContext) - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("DFA after predictATN: " + dfa.toString(this.parser.literalNames)) } return alt @@ -403,8 +392,8 @@ func (this *ParserATNSimulator) adaptivePredict(input, decision, outerContext) { // conflict // conflict + preds // -ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, outerContext ) { - if (this.debug || this.debug_list_atn_decisions) { +func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input *TokenStream, startIndex int, outerContext *ParserRuleContext ) int { + if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) { fmt.Println("execATN decision " + dfa.decision + " exec LA(1)==" + this.getLookaheadName(input) + " line " + input.LT(1).line + ":" + input.LT(1).column) @@ -412,16 +401,16 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute var alt var previousD = s0 - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("s0 = " + s0) } var t = input.LA(1) - while(true) { // while more work + for(true) { // for more work var D = this.getExistingTargetState(previousD, t) if(D==nil) { D = this.computeTargetState(dfa, previousD, t) } - if(D==ATNSimulator.ERROR) { + if(D==ATNSimulatorERROR) { // if any configs in previous dipped into outer context, that // means that input up to t actually finished entry rule // at least for SLL decision. Full LL doesn't dip into outer @@ -434,7 +423,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute var e = this.noViableAlt(input, outerContext, previousD.configs, startIndex) input.seek(startIndex) alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD.configs, outerContext) - if(alt!=ATN.INVALID_ALT_NUMBER) { + if(alt!=ATNINVALID_ALT_NUMBER) { return alt } else { panic e @@ -444,7 +433,7 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute // IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error) var conflictingAlts = nil if (D.predicates!=nil) { - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("DFA state has preds in DFA sim LL failover") } var conflictIndex = input.index @@ -452,8 +441,8 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute input.seek(startIndex) } conflictingAlts = this.evalSemanticContext(D.predicates, outerContext, true) - if (conflictingAlts.length==1) { - if(this.debug) { + if (len(conflictingAlts)==1) { + if(ParserATNSimulatorprototypedebug) { fmt.Println("Full LL avoided") } return conflictingAlts.minValue() @@ -480,9 +469,9 @@ ParserATNSimulator.prototype.execATN = function(dfa, s0, input, startIndex, oute var stopIndex = input.index input.seek(startIndex) var alts = this.evalSemanticContext(D.predicates, outerContext, true) - if (alts.length==0) { + if (len(alts)==0) { panic this.noViableAlt(input, outerContext, D.configs, startIndex) - } else if (alts.length==1) { + } else if (len(alts)==1) { return alts.minValue() } else { // report ambiguity after predicate evaluation to make sure the correct set of ambig alts is reported. @@ -532,15 +521,15 @@ func (this *ParserATNSimulator) getExistingTargetState(previousD, t) { func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) { var reach = this.computeReachSet(previousD.configs, t, false) if(reach==nil) { - this.addDFAEdge(dfa, previousD, t, ATNSimulator.ERROR) - return ATNSimulator.ERROR + this.addDFAEdge(dfa, previousD, t, ATNSimulatorERROR) + return ATNSimulatorERROR } // create Newtarget state we'll add to DFA after it's complete var D = NewDFAState(nil, reach) var predictedAlt = this.getUniqueAlt(reach) - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { var altSubSets = PredictionModegetConflictingAltSubsets(reach) fmt.Println("SLL altSubSets=" + Utils.arrayToString(altSubSets) + ", previous=" + previousD.configs + @@ -550,7 +539,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) { PredictionModeallSubsetsConflict(altSubSets) + ", conflictingAlts=" + this.getConflictingAlts(reach)) } - if (predictedAlt!=ATN.INVALID_ALT_NUMBER) { + if (predictedAlt!=ATNINVALID_ALT_NUMBER) { // NO CONFLICT, UNIQUELY PREDICTED ALT D.isAcceptState = true D.configs.uniqueAlt = predictedAlt @@ -566,7 +555,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) { if (D.isAcceptState && D.configs.hasSemanticContext) { this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision)) if( D.predicates!=nil) { - D.prediction = ATN.INVALID_ALT_NUMBER + D.prediction = ATNINVALID_ALT_NUMBER } } // all adds to dfa are done after we've created full D state @@ -577,14 +566,14 @@ func (this *ParserATNSimulator) computeTargetState(dfa, previousD, t) { func (this *ParserATNSimulator) predicateDFAState(dfaState, decisionState) { // We need to test all predicates, even in DFA states that // uniquely predict alternative. - var nalts = decisionState.transitions.length + var nalts = len(decisionState.transitions) // Update DFA so reach becomes accept state with (predicate,alt) // pairs if preds found for conflicting alts var altsToCollectPredsFrom = this.getConflictingAltsOrUniqueAlt(dfaState.configs) var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts) if (altToPred!=nil) { dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred) - dfaState.prediction = ATN.INVALID_ALT_NUMBER // make sure we use preds + dfaState.prediction = ATNINVALID_ALT_NUMBER // make sure we use preds } else { // There are preds in configs but they might go away // when OR'd together like {p}? || NONE == NONE. If neither @@ -594,12 +583,12 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState, decisionState) { } // comes back with reach.uniqueAlt set to a valid alt -ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how far we got before failing over +func execATNWithFullContext(dfa, D, // how far we got before failing over s0, input, startIndex, outerContext) { - if (this.debug || this.debug_list_atn_decisions) { + if (ParserATNSimulatorprototypedebug || ParserATNSimulatorprototypedebug_list_atn_decisions) { fmt.Println("execATNWithFullContext "+s0) } var fullCtx = true @@ -609,7 +598,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa input.seek(startIndex) var t = input.LA(1) var predictedAlt = -1 - for (true) { // while more work + for (true) { // for more work reach = this.computeReachSet(previous, t, fullCtx) if (reach==nil) { // if any configs in previous dipped into outer context, that @@ -624,26 +613,26 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa var e = this.noViableAlt(input, outerContext, previous, startIndex) input.seek(startIndex) var alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext) - if(alt!=ATN.INVALID_ALT_NUMBER) { + if(alt!=ATNINVALID_ALT_NUMBER) { return alt } else { panic e } } var altSubSets = PredictionModegetConflictingAltSubsets(reach) - if(this.debug) { + if(ParserATNSimulatorprototypedebug) { fmt.Println("LL altSubSets=" + altSubSets + ", predict=" + PredictionModegetUniqueAlt(altSubSets) + ", resolvesToJustOneViableAlt=" + PredictionModeresolvesToJustOneViableAlt(altSubSets)) } reach.uniqueAlt = this.getUniqueAlt(reach) // unique prediction? - if(reach.uniqueAlt!=ATN.INVALID_ALT_NUMBER) { + if(reach.uniqueAlt!=ATNINVALID_ALT_NUMBER) { predictedAlt = reach.uniqueAlt break } else if (this.predictionMode != PredictionModeLL_EXACT_AMBIG_DETECTION) { predictedAlt = PredictionModeresolvesToJustOneViableAlt(altSubSets) - if(predictedAlt != ATN.INVALID_ALT_NUMBER) { + if(predictedAlt != ATNINVALID_ALT_NUMBER) { break } } else { @@ -667,7 +656,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa // If the configuration set uniquely predicts an alternative, // without conflict, then we know that it's a full LL decision // not SLL. - if (reach.uniqueAlt != ATN.INVALID_ALT_NUMBER ) { + if (reach.uniqueAlt != ATNINVALID_ALT_NUMBER ) { this.reportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.index) return predictedAlt } @@ -704,7 +693,7 @@ ParserATNSimulator.prototype.execATNWithFullContext = function(dfa, D, // how fa } func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) { - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("in computeReachSet, starting closure: " + closure) } if( this.mergeCache==nil) { @@ -727,7 +716,7 @@ func (this *ParserATNSimulator) computeReachSet(closure, t, fullCtx) { // First figure out where we can reach on input t for i:=0; i0) { + if (len(semInvalidConfigs.items)>0) { alt = this.getAltThatFinishedDecisionEntryRule(semInvalidConfigs) - if (alt!=ATN.INVALID_ALT_NUMBER) { // syntactically viable path exists + if (alt!=ATNINVALID_ALT_NUMBER) { // syntactically viable path exists return alt } } - return ATN.INVALID_ALT_NUMBER + return ATNINVALID_ALT_NUMBER } func (this *ParserATNSimulator) getAltThatFinishedDecisionEntryRule(configs) { var alts = [] - for(var i=0i0 || ((c.state instanceof RuleStopState) && c.context.hasEmptyPath())) { if(alts.indexOf(c.alt)<0) { @@ -1123,8 +1112,8 @@ func (this *ParserATNSimulator) getAltThatFinishedDecisionEntryRule(configs) { } } } - if (alts.length==0) { - return ATN.INVALID_ALT_NUMBER + if (len(alts)==0) { + return ATNINVALID_ALT_NUMBER } else { return Math.min.apply(nil, alts) } @@ -1141,7 +1130,7 @@ func (this *ParserATNSimulator) getAltThatFinishedDecisionEntryRule(configs) { func (this *ParserATNSimulator) splitAccordingToSemanticValidity( configs, outerContext) { var succeeded = NewATNConfigSet(configs.fullCtx) var failed = NewATNConfigSet(configs.fullCtx) - for(var i=0i50) { - panic "problem" + panic("problem") } } if (config.state instanceof RuleStopState) { // We hit rule end. If we have context info, use it // run thru all possible stack tops in ctx if (! config.context.isEmpty()) { - for ( var i =0 i=_p, ctx dependent=true") if (this.parser!=nil) { @@ -1383,14 +1372,14 @@ func (this *ParserATNSimulator) precedenceTransition(config, pt, collectPredica } else { c = NewATNConfig({state:pt.target}, config) } - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("config from pred transition=" + c) } return c } func (this *ParserATNSimulator) predTransition(config, pt, collectPredicates, inContext, fullCtx) { - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("PRED (collectPredicates=" + collectPredicates + ") " + pt.ruleIndex + ":" + pt.predIndex + ", ctx dependent=" + pt.isCtxDependent) if (this.parser!=nil) { @@ -1418,14 +1407,14 @@ func (this *ParserATNSimulator) predTransition(config, pt, collectPredicates, in } else { c = NewATNConfig({state:pt.target}, config) } - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("config from pred transition=" + c) } return c } func (this *ParserATNSimulator) ruleTransition(config, t) { - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("CALL rule " + this.getRuleName(t.target.ruleIndex) + ", ctx=" + config.context) } var returnState = t.followState @@ -1476,7 +1465,7 @@ func (this *ParserATNSimulator) getConflictingAlts(configs) { func (this *ParserATNSimulator) getConflictingAltsOrUniqueAlt(configs) { var conflictingAlts = nil - if (configs.uniqueAlt!= ATN.INVALID_ALT_NUMBER) { + if (configs.uniqueAlt!= ATNINVALID_ALT_NUMBER) { conflictingAlts = NewBitSet() conflictingAlts.add(configs.uniqueAlt) } else { @@ -1490,7 +1479,7 @@ func (this *ParserATNSimulator) getTokenName( t) { return "EOF" } if( this.parser!=nil && this.parser.literalNames!=nil) { - if (t >= this.parser.literalNames.length) { + if (t >= len(this.parser.literalNames)) { fmt.Println("" + t + " ttype out of range: " + this.parser.literalNames) fmt.Println("" + this.parser.getInputStream().getTokens()) } else { @@ -1511,10 +1500,10 @@ func (this *ParserATNSimulator) getLookaheadName(input) { func (this *ParserATNSimulator) dumpDeadEndConfigs(nvae) { fmt.Println("dead end configs: ") var decs = nvae.getDeadEndConfigs() - for(var i=0 i0) { + if (len(c.state.transitions)>0) { var t = c.state.transitions[0] if _, ok := t.(AtomTransition); ok { trans = "Atom "+ this.getTokenName(t.label) @@ -1532,13 +1521,13 @@ func (this *ParserATNSimulator) noViableAlt(input, outerContext, configs, startI } func (this *ParserATNSimulator) getUniqueAlt(configs) { - var alt = ATN.INVALID_ALT_NUMBER - for(var i=0i " + to + " upon " + this.getTokenName(t)) } if (to==nil) { @@ -1580,7 +1569,7 @@ func (this *ParserATNSimulator) addDFAEdge(dfa, from_, t, to) { } from_.edges[t+1] = to // connect - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { var names = this.parser==nil ? nil : this.parser.literalNames fmt.Println("DFA=\n" + dfa.toString(names)) } @@ -1602,7 +1591,7 @@ func (this *ParserATNSimulator) addDFAEdge(dfa, from_, t, to) { // state was not already present. // func (this *ParserATNSimulator) addDFAState(dfa, D) { - if (D == ATNSimulator.ERROR) { + if (D == ATNSimulatorERROR) { return D } var hash = D.hashString() @@ -1610,20 +1599,20 @@ func (this *ParserATNSimulator) addDFAState(dfa, D) { if(existing!=nil) { return existing } - D.stateNumber = dfa.states.length + D.stateNumber = len(dfa.states) if (! D.configs.readOnly) { D.configs.optimizeConfigs(this) D.configs.setReadonly(true) } dfa.states[hash] = D - if (this.debug) { + if (ParserATNSimulatorprototypedebug) { fmt.Println("adding NewDFA state: " + D) } return D } func (this *ParserATNSimulator) reportAttemptingFullContext(dfa, conflictingAlts, configs, startIndex, stopIndex) { - if (this.debug || this.retry_debug) { + if (ParserATNSimulatorprototypedebug || this.retry_debug) { var interval = NewInterval(startIndex, stopIndex + 1) fmt.Println("reportAttemptingFullContext decision=" + dfa.decision + ":" + configs + ", input=" + this.parser.getTokenStream().getText(interval)) @@ -1634,7 +1623,7 @@ func (this *ParserATNSimulator) reportAttemptingFullContext(dfa, conflictingAlts } func (this *ParserATNSimulator) reportContextSensitivity(dfa, prediction, configs, startIndex, stopIndex) { - if (this.debug || this.retry_debug) { + if (ParserATNSimulatorprototypedebug || this.retry_debug) { var interval = NewInterval(startIndex, stopIndex + 1) fmt.Println("reportContextSensitivity decision=" + dfa.decision + ":" + configs + ", input=" + this.parser.getTokenStream().getText(interval)) @@ -1647,7 +1636,7 @@ func (this *ParserATNSimulator) reportContextSensitivity(dfa, prediction, config // If context sensitive parsing, we know it's ambiguity not conflict// func (this *ParserATNSimulator) reportAmbiguity(dfa, D, startIndex, stopIndex, exact, ambigAlts, configs ) { - if (this.debug || this.retry_debug) { + if (ParserATNSimulatorprototypedebug || this.retry_debug) { var interval = NewInterval(startIndex, stopIndex + 1) fmt.Println("reportAmbiguity " + ambigAlts + ":" + configs + ", input=" + this.parser.getTokenStream().getText(interval)) diff --git a/runtime/Go/src/antlr4/ParserRuleContext.go b/runtime/Go/src/antlr4/ParserRuleContext.go index bac827066..c0972fd19 100644 --- a/runtime/Go/src/antlr4/ParserRuleContext.go +++ b/runtime/Go/src/antlr4/ParserRuleContext.go @@ -41,16 +41,16 @@ func NewParserRuleContext(parent *ParserRuleContext, invokingStateNumber int) *P prc := new(ParserRuleContext) - prc.initRuleContext(parent, invokingStateNumber) - prc.initParserRuleContext(parent, invokingStateNumber) + prc.InitRuleContext(parent, invokingStateNumber) + prc.InitParserRuleContext(parent, invokingStateNumber) return prc } -func (prc *ParserRuleContext) initParserRuleContext(parent *ParserRuleContext, invokingStateNumber int){ +func (prc *ParserRuleContext) InitParserRuleContext(parent *ParserRuleContext, invokingStateNumber int){ - prc.initRuleContext(parent, invokingStateNumber) + prc.InitRuleContext(parent, invokingStateNumber) prc.ruleIndex = -1 // * If we are debugging or building a parse tree for a visitor, @@ -224,7 +224,7 @@ type InterpreterRuleContext struct { func NewInterpreterRuleContext(parent *InterpreterRuleContext, invokingStateNumber, ruleIndex int) { prc := new(InterpreterRuleContext) - prc.initParserRuleContext( parent, invokingStateNumber ) + prc.InitParserRuleContext( parent, invokingStateNumber ) prc.ruleIndex = ruleIndex diff --git a/runtime/Go/src/antlr4/PredictionContext.go b/runtime/Go/src/antlr4/PredictionContext.go index 7936f3228..43ce459cf 100644 --- a/runtime/Go/src/antlr4/PredictionContext.go +++ b/runtime/Go/src/antlr4/PredictionContext.go @@ -712,8 +712,12 @@ func combineCommonParents(parents []*PredictionContext) { } } -//func getCachedPredictionContext(context *PredictionContext, contextCache *PredictionContextCache, visited) *PredictionContext { -// if (context.isEmpty()) { +func getCachedPredictionContext(context *PredictionContext, contextCache *PredictionContextCache, visited map[*PredictionContext]*PredictionContext) *PredictionContext { + + panic("getCachedPredictionContext not implemented") + + return nil + // if (context.isEmpty()) { // return context // } // var existing = visited[context] || nil @@ -758,7 +762,7 @@ func combineCommonParents(parents []*PredictionContext) { // visited[context] = updated // // return updated -//} +} // ter's recursive version of Sam's getAllNodes() //func getAllContextNodes(context, nodes, visited) { diff --git a/runtime/Go/src/antlr4/Recognizer.go b/runtime/Go/src/antlr4/Recognizer.go index 11a382835..7ff6966a0 100644 --- a/runtime/Go/src/antlr4/Recognizer.go +++ b/runtime/Go/src/antlr4/Recognizer.go @@ -13,11 +13,11 @@ type Recognizer struct { func NewRecognizer() *Recognizer { rec := new(Recognizer) - rec.initRecognizer() + rec.InitRecognizer() return rec } -func (rec *Recognizer) initRecognizer() { +func (rec *Recognizer) InitRecognizer() { rec._listeners = []ParseTreeListener{ ConsoleErrorListenerINSTANCE } rec._interp = nil rec.state = -1 diff --git a/runtime/Go/src/antlr4/RuleContext.go b/runtime/Go/src/antlr4/RuleContext.go index ceec6cb62..efbb1926f 100644 --- a/runtime/Go/src/antlr4/RuleContext.go +++ b/runtime/Go/src/antlr4/RuleContext.go @@ -35,12 +35,12 @@ type RuleContext struct { func NewRuleContext(parent *RuleContext, invokingState int) *RuleContext { rn := &RuleContext{RuleNode{}} - rn.initRuleContext(parent, invokingState) + rn.InitRuleContext(parent, invokingState) return rn } -func (rn *RuleContext) initRuleContext(parent *RuleContext, invokingState int) { +func (rn *RuleContext) InitRuleContext(parent *RuleContext, invokingState int) { // What context invoked this rule? rn.parentCtx = parent diff --git a/runtime/Go/src/antlr4/Transition.go b/runtime/Go/src/antlr4/Transition.go index 283de3f00..962ca86e1 100644 --- a/runtime/Go/src/antlr4/Transition.go +++ b/runtime/Go/src/antlr4/Transition.go @@ -27,12 +27,12 @@ func Transition (target *ATNState) *Transition { } t := new(Transition) - t.initTransition(target) + t.InitTransition(target) return t } -func (t *Transition) initTransition(target *ATNState) { +func (t *Transition) InitTransition(target *ATNState) { t.target = target // Are we epsilon, action, sempred? t.isEpsilon = false @@ -103,7 +103,7 @@ type AtomTransition struct { func NewAtomTransition ( target *ATNState, label int ) *AtomTransition { t := new(AtomTransition) - t.initTransition( target ) + t.InitTransition( target ) t.label_ = label // The token type or character value or, signifies special label. t.label = t.makeLabel() @@ -134,7 +134,7 @@ type RuleTransition struct { func NewRuleTransition ( ruleStart *ATNState, ruleIndex, precedence, followState int ) *RuleTransition { t := new(RuleTransition) - t.initTransition( ruleStart ) + t.InitTransition( ruleStart ) t.ruleIndex = ruleIndex t.precedence = precedence @@ -161,7 +161,7 @@ type EpsilonTransition struct { func NewEpsilonTransition ( target *ATNState, outermostPrecedenceReturn int ) *EpsilonTransition { t := new(EpsilonTransition) - t.initTransition( target ) + t.InitTransition( target ) t.serializationType = TransitionEPSILON t.isEpsilon = true @@ -187,7 +187,7 @@ type RangeTransition struct { func NewRangeTransition ( target *ATNState, start, stop int ) *RangeTransition { t := new(RangeTransition) - t.initTransition( target ) + t.InitTransition( target ) t.serializationType = TransitionRANGE t.start = start @@ -218,7 +218,7 @@ func (t *RangeTransition) toString() string { //func NewAbstractPredicateTransition ( target *ATNState ) *AbstractPredicateTransition { // // t := new(AbstractPredicateTransition) -// t.initTransition( target ) +// t.InitTransition( target ) // // return t //} @@ -234,7 +234,7 @@ type PredicateTransition struct { func PredicateTransition ( target *ATNState, ruleIndex, predIndex int, isCtxDependent bool ) *PredicateTransition { t := new(PredicateTransition) - t.initTransition(target) + t.InitTransition(target) t.serializationType = TransitionPREDICATE t.ruleIndex = ruleIndex @@ -267,7 +267,7 @@ type ActionTransition struct { func NewActionTransition ( target *ATNState, ruleIndex, actionIndex int, isCtxDependent bool ) *ActionTransition { t := new(ActionTransition) - t.initTransition( target ) + t.InitTransition( target ) t.serializationType = TransitionACTION t.ruleIndex = ruleIndex @@ -297,13 +297,13 @@ type SetTransition struct { func NewSetTransition ( target *ATNState, set *IntervalSet ) *SetTransition { t := new(SetTransition) - t.initTransition( target ) - t.initSetTransition( set ) + t.InitTransition( target ) + t.InitSetTransition( set ) return t } -func (t *SetTransition) initSetTransition( set *IntervalSet ) { +func (t *SetTransition) InitSetTransition( set *IntervalSet ) { t.serializationType = TransitionSET if (set !=nil && set !=nil) { @@ -333,8 +333,8 @@ type NotSetTransition struct { func NotSetTransition ( target *ATNState, set *IntervalSet) *NotSetTransition { t := new(NotSetTransition) - t.initTransition( target ) - t.initSetTransition( target ) + t.InitTransition( target ) + t.InitSetTransition( target ) t.serializationType = TransitionNOT_SET @@ -359,7 +359,7 @@ type WildcardTransition struct { func NewWildcardTransition ( target *ATNState ) *WildcardTransition { t := new(WildcardTransition) - t.initTransition( target ) + t.InitTransition( target ) t.serializationType = TransitionWILDCARD return t @@ -383,7 +383,7 @@ type PrecedencePredicateTransition struct { func PrecedencePredicateTransition ( target *ATNState, precedence int ) *PrecedencePredicateTransition { t := new(PrecedencePredicateTransition) - t.initTransition( target ) + t.InitTransition( target ) t.serializationType = TransitionPRECEDENCE t.precedence = precedence diff --git a/runtime/Go/src/antlr4/Tree.go b/runtime/Go/src/antlr4/Tree.go index 3c5de4892..33a83f032 100644 --- a/runtime/Go/src/antlr4/Tree.go +++ b/runtime/Go/src/antlr4/Tree.go @@ -85,12 +85,12 @@ type TerminalNodeImpl struct { func NewTerminalNodeImpl(symbol *Token) *TerminalNodeImpl { tn := &TerminalNodeImpl{TerminalNode{}} - tn.initTerminalNodeImpl(symbol) + tn.InitTerminalNodeImpl(symbol) return tn } -func (this *TerminalNodeImpl) initTerminalNodeImpl(symbol *Token) { +func (this *TerminalNodeImpl) InitTerminalNodeImpl(symbol *Token) { this.parentCtx = nil this.symbol = symbol } @@ -154,7 +154,7 @@ type ErrorNodeImpl struct { func NewErrorNodeImpl(token *Token) *ErrorNodeImpl { en := new(ErrorNodeImpl) - en.initTerminalNodeImpl(token) + en.InitTerminalNodeImpl(token) return en } diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java index d83c449a0..805a5ec45 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNDeserializer.java @@ -368,7 +368,7 @@ public class ATNDeserializer { int ndecisions = toInt(data[p++]); for (int i=1; i<=ndecisions; i++) { int s = toInt(data[p++]); - DecisionState decState = (DecisionState)atn.states.get(s); + DecisionState decState = atn.states.get(s); atn.decisionToState.add(decState); decState.decision = i-1; } diff --git a/runtime/JavaScript/src/antlr4/IntervalSet.js b/runtime/JavaScript/src/antlr4/IntervalSet.js index 9e58f2f06..9bbce5bbe 100644 --- a/runtime/JavaScript/src/antlr4/IntervalSet.js +++ b/runtime/JavaScript/src/antlr4/IntervalSet.js @@ -33,7 +33,7 @@ function IntervalSet() { this.readOnly = false; } -IntervalSet.prototype.first = function(v) { +IntervalSet.prototype.first = function() { if (this.intervals === null || this.intervals.length===0) { return Token.INVALID_TYPE; } else { diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index 22a660a1c..0190dee81 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -106,10 +106,10 @@ func New(input) { var deserializer = NewATNDeserializer() var deserializedAtn = deserializer.deserialize(serializedATN) - var decisionToDFA = make([]dfa.DFA,len(deserializedAtn.decisionToState)) + var decisionToDFA = make([]DFA,len(deserializedAtn.decisionToState)) for index, ds := range deserializedAtn.decisionToState { - decisionToDFA[index] = dfa.NewDFA(ds, index) + decisionToDFA[index] = NewDFA(ds, index) } var sharedContextCache = NewPredictionContextCache() @@ -661,7 +661,7 @@ type struct { func New(parser *Parser, parent *ParserRuleContext, invokingState int}>) { var p = new() - p.initParserRuleContext( parent, invokingState ) + p.InitParserRuleContext( parent, invokingState ) p.parser = parser p.ruleIndex = RULE_ @@ -738,7 +738,7 @@ func (s *) accept(visitor *ParseTreeVisitor) { -AttributeDecl(d) ::= "p. = null" +AttributeDecl(d) ::= "p. = null" /** If we don't know location of label def x, use this template */ labelref(x) ::= "localctx." @@ -820,15 +820,15 @@ func New(input *TokenStream) * { var deserializer = NewATNDeserializer() var deserializedAtn = deserializer.deserialize(serializedATN) - var decisionToDFA = make([]dfa.DFA,len(deserializedAtn.decisionToState)) + var decisionToDFA = make([]DFA,len(deserializedAtn.decisionToState)) for index, ds := range deserializedAtn.decisionToState { - decisionToDFA[index] = dfa.NewDFA(ds, index) + decisionToDFA[index] = NewDFA(ds, index) } lex := new() - initLexer(lex, input); + this.InitLexer(lex, input); lex._interp = NewLexerATNSimulator(lex, atn, decisionToDFA, NewPredictionContextCache()) lex.modeNames = [...]string{ "}; separator=", ", wrap, anchor> } @@ -865,7 +865,7 @@ var serializedATN = strings.Join( [...]string{" /** Using a type to init value map, try to init a type; if not in table * must be an object, default value is "nil". */ -initValue(typeName) ::= << +InitValue(typeName) ::= << >>