More refactoring and cleanup

This commit is contained in:
Peter Boyer 2015-12-31 15:36:56 -05:00
parent 0726f4c2bb
commit ddb296cf01
30 changed files with 540 additions and 536 deletions

View File

@ -1,23 +1,26 @@
package antlr4
import "fmt"
// Temporary - for debugging purposes of the Go port
const (
PortDebug = false
)
var ATNINVALID_ALT_NUMBER = 0
var ATNInvalidAltNumber = 0
type ATN struct {
DecisionToState []IDecisionState
DecisionToState []DecisionState
grammarType int
maxTokenType int
states []IATNState
states []ATNState
ruleToStartState []*RuleStartState
ruleToStopState []*RuleStopState
modeNameToStartState map[string]*TokensStartState
modeToStartState []*TokensStartState
ruleToTokenType []int
lexerActions []ILexerAction
lexerActions []LexerAction
}
func NewATN(grammarType int, maxTokenType int) *ATN {
@ -29,11 +32,11 @@ func NewATN(grammarType int, maxTokenType int) *ATN {
atn.grammarType = grammarType
// The maximum value for any symbol recognized by a transition in the ATN.
atn.maxTokenType = maxTokenType
atn.states = make([]IATNState, 0)
atn.states = make([]ATNState, 0)
// Each subrule/rule is a decision point and we must track them so we
// can go back later and build DFA predictors for them. This includes
// all the rules, subrules, optional blocks, ()+, ()* etc...
atn.DecisionToState = make([]IDecisionState, 0)
atn.DecisionToState = make([]DecisionState, 0)
// Maps from rule index to starting state number.
atn.ruleToStartState = make([]*RuleStartState, 0)
// Maps from rule index to stop state number.
@ -58,7 +61,7 @@ func NewATN(grammarType int, maxTokenType int) *ATN {
// If {@code ctx} is nil, the set of tokens will not include what can follow
// the rule surrounding {@code s}. In other words, the set will be
// restricted to tokens reachable staying within {@code s}'s rule.
func (this *ATN) nextTokensInContext(s IATNState, ctx IRuleContext) *IntervalSet {
func (this *ATN) nextTokensInContext(s ATNState, ctx RuleContext) *IntervalSet {
var anal = NewLL1Analyzer(this)
var res = anal.LOOK(s, nil, ctx)
return res
@ -67,7 +70,7 @@ func (this *ATN) nextTokensInContext(s IATNState, ctx IRuleContext) *IntervalSet
// Compute the set of valid tokens that can occur starting in {@code s} and
// staying in same rule. {@link Token//EPSILON} is in set if we reach end of
// rule.
func (this *ATN) nextTokensNoContext(s IATNState) *IntervalSet {
func (this *ATN) nextTokensNoContext(s ATNState) *IntervalSet {
if s.GetNextTokenWithinRule() != nil {
if PortDebug {
fmt.Println("DEBUG 1")
@ -83,7 +86,7 @@ func (this *ATN) nextTokensNoContext(s IATNState) *IntervalSet {
return s.GetNextTokenWithinRule()
}
func (this *ATN) nextTokens(s IATNState, ctx IRuleContext) *IntervalSet {
func (this *ATN) nextTokens(s ATNState, ctx RuleContext) *IntervalSet {
if ctx == nil {
return this.nextTokensNoContext(s)
} else {
@ -91,7 +94,7 @@ func (this *ATN) nextTokens(s IATNState, ctx IRuleContext) *IntervalSet {
}
}
func (this *ATN) addState(state IATNState) {
func (this *ATN) addState(state ATNState) {
if state != nil {
state.SetATN(this)
state.SetStateNumber(len(this.states))
@ -99,17 +102,17 @@ func (this *ATN) addState(state IATNState) {
this.states = append(this.states, state)
}
func (this *ATN) removeState(state IATNState) {
func (this *ATN) removeState(state ATNState) {
this.states[state.GetStateNumber()] = nil // just free mem, don't shift states in list
}
func (this *ATN) defineDecisionState(s IDecisionState) int {
func (this *ATN) defineDecisionState(s DecisionState) int {
this.DecisionToState = append(this.DecisionToState, s)
s.setDecision( len(this.DecisionToState) - 1 )
return s.getDecision()
}
func (this *ATN) getDecisionState(decision int) IDecisionState {
func (this *ATN) getDecisionState(decision int) DecisionState {
if len(this.DecisionToState) == 0 {
return nil
} else {
@ -135,7 +138,7 @@ func (this *ATN) getDecisionState(decision int) IDecisionState {
// @panics IllegalArgumentException if the ATN does not contain a state with
// number {@code stateNumber}
func (this *ATN) getExpectedTokens(stateNumber int, ctx IRuleContext) *IntervalSet {
func (this *ATN) getExpectedTokens(stateNumber int, ctx RuleContext) *IntervalSet {
if stateNumber < 0 || stateNumber >= len(this.states) {
panic("Invalid state number.")
}
@ -153,7 +156,7 @@ func (this *ATN) getExpectedTokens(stateNumber int, ctx IRuleContext) *IntervalS
following = this.nextTokens(rt.(*RuleTransition).followState, nil)
expected.addSet(following)
expected.removeOne(TokenEpsilon)
ctx = ctx.GetParent().(IRuleContext)
ctx = ctx.GetParent().(RuleContext)
}
if following.contains(TokenEpsilon) {
expected.addOne(TokenEOF)

View File

@ -20,7 +20,7 @@ type ATNConfig interface {
getPrecedenceFilterSuppressed() bool
setPrecedenceFilterSuppressed(bool)
GetState() IATNState
GetState() ATNState
GetAlt() int
GetSemanticContext() SemanticContext
@ -37,14 +37,14 @@ type ATNConfig interface {
type BaseATNConfig struct {
precedenceFilterSuppressed bool
state IATNState
state ATNState
alt int
context IPredictionContext
semanticContext SemanticContext
reachesIntoOuterContext int
}
func NewATNConfig7(old *BaseATNConfig) *BaseATNConfig { // dup
func NewBaseATNConfig7(old *BaseATNConfig) *BaseATNConfig { // dup
a := new(BaseATNConfig)
a.state = old.state
a.alt = old.alt
@ -54,11 +54,11 @@ func NewATNConfig7(old *BaseATNConfig) *BaseATNConfig { // dup
return a
}
func NewATNConfig6(state IATNState, alt int, context IPredictionContext) *BaseATNConfig {
return NewATNConfig5(state, alt, context, SemanticContextNONE)
func NewBaseATNConfig6(state ATNState, alt int, context IPredictionContext) *BaseATNConfig {
return NewBaseATNConfig5(state, alt, context, SemanticContextNONE)
}
func NewATNConfig5(state IATNState, alt int, context IPredictionContext, semanticContext SemanticContext) *BaseATNConfig {
func NewBaseATNConfig5(state ATNState, alt int, context IPredictionContext, semanticContext SemanticContext) *BaseATNConfig {
a := new(BaseATNConfig)
if (semanticContext == nil){
@ -73,23 +73,23 @@ func NewATNConfig5(state IATNState, alt int, context IPredictionContext, semanti
return a
}
func NewATNConfig4(c ATNConfig, state IATNState) *BaseATNConfig {
return NewATNConfig(c, state, c.GetContext(), c.GetSemanticContext())
func NewBaseATNConfig4(c ATNConfig, state ATNState) *BaseATNConfig {
return NewBaseATNConfig(c, state, c.GetContext(), c.GetSemanticContext())
}
func NewATNConfig3(c ATNConfig, state IATNState, semanticContext SemanticContext) *BaseATNConfig {
return NewATNConfig(c, state, c.GetContext(), semanticContext)
func NewBaseATNConfig3(c ATNConfig, state ATNState, semanticContext SemanticContext) *BaseATNConfig {
return NewBaseATNConfig(c, state, c.GetContext(), semanticContext)
}
func NewATNConfig2(c ATNConfig, semanticContext SemanticContext) *BaseATNConfig {
return NewATNConfig(c, c.GetState(), c.GetContext(), semanticContext)
func NewBaseATNConfig2(c ATNConfig, semanticContext SemanticContext) *BaseATNConfig {
return NewBaseATNConfig(c, c.GetState(), c.GetContext(), semanticContext)
}
func NewATNConfig1(c ATNConfig, state IATNState, context IPredictionContext) *BaseATNConfig {
return NewATNConfig(c, state, context, c.GetSemanticContext())
func NewBaseATNConfig1(c ATNConfig, state ATNState, context IPredictionContext) *BaseATNConfig {
return NewBaseATNConfig(c, state, context, c.GetSemanticContext())
}
func NewATNConfig(c ATNConfig, state IATNState, context IPredictionContext, semanticContext SemanticContext) *BaseATNConfig {
func NewBaseATNConfig(c ATNConfig, state ATNState, context IPredictionContext, semanticContext SemanticContext) *BaseATNConfig {
a := new(BaseATNConfig)
if (semanticContext == nil){
@ -113,7 +113,7 @@ func (this *BaseATNConfig) setPrecedenceFilterSuppressed(v bool) {
this.precedenceFilterSuppressed = v
}
func (this *BaseATNConfig) GetState() IATNState {
func (this *BaseATNConfig) GetState() ATNState {
return this.state
}
@ -201,62 +201,62 @@ type LexerATNConfig struct {
passedThroughNonGreedyDecision bool
}
func NewLexerATNConfig6(state IATNState, alt int, context IPredictionContext) *LexerATNConfig {
func NewLexerATNConfig6(state ATNState, alt int, context IPredictionContext) *LexerATNConfig {
this := new(LexerATNConfig)
this.BaseATNConfig = NewATNConfig5(state, alt, context, SemanticContextNONE)
this.BaseATNConfig = NewBaseATNConfig5(state, alt, context, SemanticContextNONE)
this.passedThroughNonGreedyDecision = false
this.lexerActionExecutor = nil
return this
}
func NewLexerATNConfig5(state IATNState, alt int, context IPredictionContext, lexerActionExecutor *LexerActionExecutor) *LexerATNConfig {
func NewLexerATNConfig5(state ATNState, alt int, context IPredictionContext, lexerActionExecutor *LexerActionExecutor) *LexerATNConfig {
this := new(LexerATNConfig)
this.BaseATNConfig = NewATNConfig5(state, alt, context, SemanticContextNONE)
this.BaseATNConfig = NewBaseATNConfig5(state, alt, context, SemanticContextNONE)
this.lexerActionExecutor = lexerActionExecutor
this.passedThroughNonGreedyDecision = false
return this
}
func NewLexerATNConfig4(c *LexerATNConfig, state IATNState) *LexerATNConfig {
func NewLexerATNConfig4(c *LexerATNConfig, state ATNState) *LexerATNConfig {
this := new(LexerATNConfig)
this.BaseATNConfig = NewATNConfig(c, state, c.GetContext(), c.GetSemanticContext())
this.BaseATNConfig = NewBaseATNConfig(c, state, c.GetContext(), c.GetSemanticContext())
this.lexerActionExecutor = c.lexerActionExecutor
this.passedThroughNonGreedyDecision = checkNonGreedyDecision(c, state)
return this
}
func NewLexerATNConfig3(c *LexerATNConfig, state IATNState, lexerActionExecutor *LexerActionExecutor) *LexerATNConfig {
func NewLexerATNConfig3(c *LexerATNConfig, state ATNState, lexerActionExecutor *LexerActionExecutor) *LexerATNConfig {
this := new(LexerATNConfig)
this.BaseATNConfig = NewATNConfig(c, state, c.GetContext(), c.GetSemanticContext())
this.BaseATNConfig = NewBaseATNConfig(c, state, c.GetContext(), c.GetSemanticContext())
this.lexerActionExecutor = lexerActionExecutor
this.passedThroughNonGreedyDecision = checkNonGreedyDecision(c, state)
return this
}
func NewLexerATNConfig2(c *LexerATNConfig, state IATNState, context IPredictionContext) *LexerATNConfig {
func NewLexerATNConfig2(c *LexerATNConfig, state ATNState, context IPredictionContext) *LexerATNConfig {
this := new(LexerATNConfig)
this.BaseATNConfig = NewATNConfig(c, state, context, c.GetSemanticContext())
this.BaseATNConfig = NewBaseATNConfig(c, state, context, c.GetSemanticContext())
this.lexerActionExecutor = c.lexerActionExecutor
this.passedThroughNonGreedyDecision = checkNonGreedyDecision(c, state)
return this
}
func NewLexerATNConfig1(state IATNState, alt int, context IPredictionContext) *LexerATNConfig {
func NewLexerATNConfig1(state ATNState, alt int, context IPredictionContext) *LexerATNConfig {
this := new(LexerATNConfig)
this.BaseATNConfig = NewATNConfig5(state, alt, context, SemanticContextNONE)
this.BaseATNConfig = NewBaseATNConfig5(state, alt, context, SemanticContextNONE)
this.lexerActionExecutor = nil
this.passedThroughNonGreedyDecision = false
@ -304,7 +304,7 @@ func (this *LexerATNConfig) equals(other interface{}) bool {
}
}
func checkNonGreedyDecision(source *LexerATNConfig, target IATNState) bool {
ds, ok := target.(IDecisionState)
func checkNonGreedyDecision(source *LexerATNConfig, target ATNState) bool {
ds, ok := target.(DecisionState)
return source.passedThroughNonGreedyDecision || (ok && ds.getNonGreedy())
}

View File

@ -7,21 +7,21 @@ import (
type ATNConfigSet interface {
Hasher
Add(config ATNConfig, mergeCache *DoubleDict) bool
AddAll(coll []ATNConfig) bool
Add(ATNConfig, *DoubleDict) bool
AddAll([]ATNConfig) bool
GetStates() *Set
GetPredicates() []SemanticContext
GetItems() []ATNConfig
OptimizeConfigs(interpreter *ATNSimulator)
OptimizeConfigs(interpreter *BaseATNSimulator)
Equals(other interface{}) bool
Length() int
IsEmpty() bool
Contains(item *BaseATNConfig) bool
ContainsFast(item *BaseATNConfig) bool
Contains(ATNConfig) bool
ContainsFast(ATNConfig) bool
Clear()
String() string
@ -177,7 +177,7 @@ func (this *BaseATNConfigSet) GetItems() []ATNConfig {
return this.configs
}
func (this *BaseATNConfigSet) OptimizeConfigs(interpreter *ATNSimulator) {
func (this *BaseATNConfigSet) OptimizeConfigs(interpreter *BaseATNSimulator) {
if this.readOnly {
panic("This set is readonly")
}
@ -242,14 +242,14 @@ func (this *BaseATNConfigSet) IsEmpty() bool {
return len(this.configs) == 0
}
func (this *BaseATNConfigSet) Contains(item *BaseATNConfig) bool {
func (this *BaseATNConfigSet) Contains(item ATNConfig) bool {
if this.configLookup == nil {
panic("This method is not implemented for readonly sets.")
}
return this.configLookup.contains(item)
}
func (this *BaseATNConfigSet) ContainsFast(item *BaseATNConfig) bool {
func (this *BaseATNConfigSet) ContainsFast(item ATNConfig) bool {
if this.configLookup == nil {
panic("This method is not implemented for readonly sets.")
}
@ -320,7 +320,7 @@ func (this *BaseATNConfigSet) String() string {
s += ",hasSemanticContext=" + fmt.Sprint(this.hasSemanticContext)
}
if (this.uniqueAlt != ATNINVALID_ALT_NUMBER ){
if (this.uniqueAlt != ATNInvalidAltNumber ){
s += ",uniqueAlt=" + fmt.Sprint(this.uniqueAlt)
}

View File

@ -187,7 +187,7 @@ func (this *ATNDeserializer) readStates(atn *ATN) {
var numNonGreedyStates = this.readInt()
for j := 0; j < numNonGreedyStates; j++ {
stateNumber := this.readInt()
atn.states[stateNumber].(IDecisionState).setNonGreedy( true )
atn.states[stateNumber].(DecisionState).setNonGreedy( true )
}
var numPrecedenceStates = this.readInt()
@ -324,7 +324,7 @@ func (this *ATNDeserializer) readDecisions(atn *ATN) {
var ndecisions = this.readInt()
for i := 0; i < ndecisions; i++ {
var s = this.readInt()
var decState = atn.states[s].(IDecisionState)
var decState = atn.states[s].(DecisionState)
atn.DecisionToState = append(atn.DecisionToState, decState)
decState.setDecision( i )
}
@ -333,7 +333,7 @@ func (this *ATNDeserializer) readDecisions(atn *ATN) {
func (this *ATNDeserializer) readLexerActions(atn *ATN) {
if atn.grammarType == ATNTypeLexer {
var count = this.readInt()
atn.lexerActions = make([]ILexerAction, count) // initIntArray(count, nil)
atn.lexerActions = make([]LexerAction, count) // initIntArray(count, nil)
for i := 0; i < count; i++ {
var actionType = this.readInt()
var data1 = this.readInt()
@ -372,12 +372,12 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn *ATN, idx int) {
bypassStart.endState = bypassStop
atn.defineDecisionState(bypassStart.DecisionState)
atn.defineDecisionState(bypassStart.BaseDecisionState)
bypassStop.startState = bypassStart
var excludeTransition ITransition = nil
var endState IATNState = nil
var excludeTransition Transition = nil
var endState ATNState = nil
if atn.ruleToStartState[idx].isPrecedenceRule {
// wrap from the beginning of the rule to the StarLoopEntryState
@ -418,7 +418,7 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn *ATN, idx int) {
var count = len(ruleToStartState.GetTransitions())
for count > 0 {
bypassStart.AddTransition(ruleToStartState.GetTransitions()[count-1], -1)
ruleToStartState.SetTransitions([]ITransition{ruleToStartState.GetTransitions()[len(ruleToStartState.GetTransitions())-1]})
ruleToStartState.SetTransitions([]Transition{ruleToStartState.GetTransitions()[len(ruleToStartState.GetTransitions())-1]})
}
// link the new states
atn.ruleToStartState[idx].AddTransition(NewEpsilonTransition(bypassStart, -1), -1)
@ -430,7 +430,7 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn *ATN, idx int) {
bypassStart.AddTransition(NewEpsilonTransition(MatchState, -1), -1)
}
func (this *ATNDeserializer) stateIsEndStateFor(state IATNState, idx int) IATNState {
func (this *ATNDeserializer) stateIsEndStateFor(state ATNState, idx int) ATNState {
if state.GetRuleIndex() != idx {
return nil
}
@ -528,7 +528,7 @@ func (this *ATNDeserializer) verifyATN(atn *ATN) {
this.checkCondition(s2.endState != nil, "")
case *BlockEndState:
this.checkCondition(s2.startState != nil, "")
case IDecisionState:
case DecisionState:
this.checkCondition(len(s2.GetTransitions()) <= 1 || s2.getDecision() >= 0, "")
default:
_, ok := s2.(*RuleStopState)
@ -586,7 +586,7 @@ func (this *ATNDeserializer) readUUID() string {
byteToHex[bb[14]] + byteToHex[bb[15]]
}
func (this *ATNDeserializer) edgeFactory(atn *ATN, typeIndex, src, trg, arg1, arg2, arg3 int, sets []*IntervalSet) ITransition {
func (this *ATNDeserializer) edgeFactory(atn *ATN, typeIndex, src, trg, arg1, arg2, arg3 int, sets []*IntervalSet) Transition {
var target = atn.states[trg]
@ -624,9 +624,9 @@ func (this *ATNDeserializer) edgeFactory(atn *ATN, typeIndex, src, trg, arg1, ar
panic("The specified transition type is not valid.")
}
func (this *ATNDeserializer) stateFactory(typeIndex, ruleIndex int) IATNState {
func (this *ATNDeserializer) stateFactory(typeIndex, ruleIndex int) ATNState {
var s IATNState
var s ATNState
switch typeIndex {
case ATNStateInvalidType:
return nil
@ -663,7 +663,7 @@ func (this *ATNDeserializer) stateFactory(typeIndex, ruleIndex int) IATNState {
return s
}
func (this *ATNDeserializer) lexerActionFactory(typeIndex, data1, data2 int) ILexerAction {
func (this *ATNDeserializer) lexerActionFactory(typeIndex, data1, data2 int) LexerAction {
switch typeIndex {
case LexerActionTypeCHANNEL:
return NewLexerChannelAction(data1)

View File

@ -1,13 +1,13 @@
package antlr4
type ATNSimulator struct {
type BaseATNSimulator struct {
atn *ATN
sharedContextCache *PredictionContextCache
}
func NewATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNSimulator {
func NewBaseATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *BaseATNSimulator {
this := new(ATNSimulator)
this := new(BaseATNSimulator)
this.atn = atn
this.sharedContextCache = sharedContextCache
@ -15,9 +15,9 @@ func NewATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNS
return this
}
var ATNSimulatorERROR = NewDFAState(0x7FFFFFFF, NewBaseATNConfigSet(false))
var ATNSimulatorError = NewDFAState(0x7FFFFFFF, NewBaseATNConfigSet(false))
func (this *ATNSimulator) getCachedContext(context IPredictionContext) IPredictionContext {
func (this *BaseATNSimulator) getCachedContext(context IPredictionContext) IPredictionContext {
if this.sharedContextCache == nil {
return context
}

View File

@ -38,7 +38,7 @@ const (
var INITIAL_NUM_TRANSITIONS = 4
type IATNState interface {
type ATNState interface {
GetEpsilonOnlyTransitions() bool
GetRuleIndex() int
@ -55,14 +55,14 @@ type IATNState interface {
GetStateNumber() int
SetStateNumber(int)
GetTransitions() []ITransition
SetTransitions([]ITransition)
AddTransition(ITransition, int)
GetTransitions() []Transition
SetTransitions([]Transition)
AddTransition(Transition, int)
String() string
}
type ATNState struct {
type BaseATNState struct {
// Which ATN are we in?
atn *ATN
stateNumber int
@ -70,14 +70,14 @@ type ATNState struct {
ruleIndex int
epsilonOnlyTransitions bool
// Track the transitions emanating from this ATN state.
transitions []ITransition
transitions []Transition
// Used to cache lookahead during parsing, not used during construction
nextTokenWithinRule *IntervalSet
}
func NewATNState() *ATNState {
func NewBaseATNState() *BaseATNState {
as := new(ATNState)
as := new(BaseATNState)
// Which ATN are we in?
as.atn = nil
@ -86,77 +86,77 @@ func NewATNState() *ATNState {
as.ruleIndex = 0 // at runtime, we don't have Rule objects
as.epsilonOnlyTransitions = false
// Track the transitions emanating from this ATN state.
as.transitions = make([]ITransition, 0)
as.transitions = make([]Transition, 0)
// Used to cache lookahead during parsing, not used during construction
as.nextTokenWithinRule = nil
return as
}
func (as *ATNState) GetRuleIndex() int {
func (as *BaseATNState) GetRuleIndex() int {
return as.ruleIndex
}
func (as *ATNState) SetRuleIndex(v int) {
func (as *BaseATNState) SetRuleIndex(v int) {
as.ruleIndex = v
}
func (as *ATNState) GetEpsilonOnlyTransitions() bool {
func (as *BaseATNState) GetEpsilonOnlyTransitions() bool {
return as.epsilonOnlyTransitions
}
func (as *ATNState) GetATN() *ATN {
func (as *BaseATNState) GetATN() *ATN {
return as.atn
}
func (as *ATNState) SetATN(atn *ATN) {
func (as *BaseATNState) SetATN(atn *ATN) {
as.atn = atn
}
func (as *ATNState) GetTransitions() []ITransition {
func (as *BaseATNState) GetTransitions() []Transition {
return as.transitions
}
func (as *ATNState) SetTransitions(t []ITransition) {
func (as *BaseATNState) SetTransitions(t []Transition) {
as.transitions = t
}
func (as *ATNState) GetStateType() int {
func (as *BaseATNState) GetStateType() int {
return as.stateType
}
func (as *ATNState) GetStateNumber() int {
func (as *BaseATNState) GetStateNumber() int {
return as.stateNumber
}
func (as *ATNState) SetStateNumber(stateNumber int) {
func (as *BaseATNState) SetStateNumber(stateNumber int) {
as.stateNumber = stateNumber
}
func (as *ATNState) GetNextTokenWithinRule() *IntervalSet {
func (as *BaseATNState) GetNextTokenWithinRule() *IntervalSet {
return as.nextTokenWithinRule
}
func (as *ATNState) SetNextTokenWithinRule(v *IntervalSet) {
func (as *BaseATNState) SetNextTokenWithinRule(v *IntervalSet) {
as.nextTokenWithinRule = v
}
func (this *ATNState) String() string {
func (this *BaseATNState) String() string {
return strconv.Itoa(this.stateNumber)
}
func (this *ATNState) equals(other interface{}) bool {
if ot, ok := other.(IATNState); ok {
func (this *BaseATNState) equals(other interface{}) bool {
if ot, ok := other.(ATNState); ok {
return this.stateNumber == ot.GetStateNumber()
} else {
return false
}
}
func (this *ATNState) isNonGreedyExitState() bool {
func (this *BaseATNState) isNonGreedyExitState() bool {
return false
}
func (this *ATNState) AddTransition(trans ITransition, index int) {
func (this *BaseATNState) AddTransition(trans Transition, index int) {
if len(this.transitions) == 0 {
this.epsilonOnlyTransitions = trans.getIsEpsilon()
} else if this.epsilonOnlyTransitions != trans.getIsEpsilon() {
@ -165,26 +165,26 @@ func (this *ATNState) AddTransition(trans ITransition, index int) {
if index == -1 {
this.transitions = append(this.transitions, trans)
} else {
this.transitions = append(this.transitions[:index], append([]ITransition{trans}, this.transitions[index:]...)...)
this.transitions = append(this.transitions[:index], append([]Transition{trans}, this.transitions[index:]...)...)
// this.transitions.splice(index, 1, trans)
}
}
type BasicState struct {
*ATNState
*BaseATNState
}
func NewBasicState() *BasicState {
this := new(BasicState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.stateType = ATNStateBASIC
return this
}
type IDecisionState interface {
type DecisionState interface {
IATNState
ATNState
getDecision() int
setDecision(int)
@ -194,18 +194,18 @@ type IDecisionState interface {
}
type DecisionState struct {
*ATNState
type BaseDecisionState struct {
*BaseATNState
decision int
nonGreedy bool
}
func NewDecisionState() *DecisionState {
func NewBaseDecisionState() *BaseDecisionState {
this := new(DecisionState)
this := new(BaseDecisionState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.decision = -1
this.nonGreedy = false
@ -213,25 +213,25 @@ func NewDecisionState() *DecisionState {
return this
}
func (s *DecisionState) getDecision() int {
func (s *BaseDecisionState) getDecision() int {
return s.decision
}
func (s *DecisionState) setDecision(b int) {
func (s *BaseDecisionState) setDecision(b int) {
s.decision = b
}
func (s *DecisionState) getNonGreedy() bool {
func (s *BaseDecisionState) getNonGreedy() bool {
return s.nonGreedy
}
func (s *DecisionState) setNonGreedy(b bool) {
func (s *BaseDecisionState) setNonGreedy(b bool) {
s.nonGreedy = b
}
type IBlockStartState interface {
IDecisionState
DecisionState
getEndState() *BlockEndState
setEndState(*BlockEndState)
@ -240,7 +240,7 @@ type IBlockStartState interface {
// The start of a regular {@code (...)} block.
type BlockStartState struct {
*DecisionState
*BaseDecisionState
endState *BlockEndState
}
@ -249,7 +249,7 @@ func NewBlockStartState() *BlockStartState {
this := new(BlockStartState)
this.DecisionState = NewDecisionState()
this.BaseDecisionState = NewBaseDecisionState()
this.endState = nil
return this
@ -280,16 +280,16 @@ func NewBasicBlockStartState() *BasicBlockStartState {
// Terminal node of a simple {@code (a|b|c)} block.
type BlockEndState struct {
*ATNState
*BaseATNState
startState IATNState
startState ATNState
}
func NewBlockEndState() *BlockEndState {
this := new(BlockEndState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.stateType = ATNStateBLOCK_END
this.startState = nil
@ -302,21 +302,21 @@ func NewBlockEndState() *BlockEndState {
// error handling.
//
type RuleStopState struct {
*ATNState
*BaseATNState
}
func NewRuleStopState() *RuleStopState {
this := new(RuleStopState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.stateType = ATNStateRULE_STOP
return this
}
type RuleStartState struct {
*ATNState
*BaseATNState
stopState IATNState
stopState ATNState
isPrecedenceRule bool
}
@ -324,7 +324,7 @@ func NewRuleStartState() *RuleStartState {
this := new(RuleStartState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.stateType = ATNStateRULE_START
this.stopState = nil
this.isPrecedenceRule = false
@ -336,14 +336,14 @@ func NewRuleStartState() *RuleStartState {
// one to the loop back to start of the block and one to exit.
//
type PlusLoopbackState struct {
*DecisionState
*BaseDecisionState
}
func NewPlusLoopbackState() *PlusLoopbackState {
this := new(PlusLoopbackState)
this.DecisionState = NewDecisionState()
this.BaseDecisionState = NewBaseDecisionState()
this.stateType = ATNStatePLUS_LOOP_BACK
return this
@ -357,7 +357,7 @@ func NewPlusLoopbackState() *PlusLoopbackState {
type PlusBlockStartState struct {
*BlockStartState
loopBackState IATNState
loopBackState ATNState
}
func NewPlusBlockStartState() *PlusBlockStartState {
@ -389,23 +389,23 @@ func NewStarBlockStartState() *StarBlockStartState {
}
type StarLoopbackState struct {
*ATNState
*BaseATNState
}
func NewStarLoopbackState() *StarLoopbackState {
this := new(StarLoopbackState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.stateType = ATNStateSTAR_LOOP_BACK
return this
}
type StarLoopEntryState struct {
*DecisionState
*BaseDecisionState
loopBackState IATNState
loopBackState ATNState
precedenceRuleDecision bool
}
@ -413,7 +413,7 @@ func NewStarLoopEntryState() *StarLoopEntryState {
this := new(StarLoopEntryState)
this.DecisionState = NewDecisionState()
this.BaseDecisionState = NewBaseDecisionState()
this.stateType = ATNStateSTAR_LOOP_ENTRY
this.loopBackState = nil
@ -426,16 +426,16 @@ func NewStarLoopEntryState() *StarLoopEntryState {
// Mark the end of a * or + loop.
type LoopEndState struct {
*ATNState
*BaseATNState
loopBackState IATNState
loopBackState ATNState
}
func NewLoopEndState() *LoopEndState {
this := new(LoopEndState)
this.ATNState = NewATNState()
this.BaseATNState = NewBaseATNState()
this.stateType = ATNStateLOOP_END
this.loopBackState = nil
@ -445,14 +445,14 @@ func NewLoopEndState() *LoopEndState {
// The Tokens rule start state linking to each lexer rule start state */
type TokensStartState struct {
*DecisionState
*BaseDecisionState
}
func NewTokensStartState() *TokensStartState {
this := new(TokensStartState)
this.DecisionState = NewDecisionState()
this.BaseDecisionState = NewBaseDecisionState()
this.stateType = ATNStateTOKEN_START
return this

View File

@ -271,7 +271,7 @@ func (bt *CommonTokenStream) GetTextFromTokens(start, end IToken) string {
return bt.GetTextFromInterval(NewInterval(start.GetTokenIndex(), end.GetTokenIndex()))
}
func (bt *CommonTokenStream) GetTextFromRuleContext(interval IRuleContext) string {
func (bt *CommonTokenStream) GetTextFromRuleContext(interval RuleContext) string {
return bt.GetTextFromInterval(interval.GetSourceInterval())
}
@ -323,7 +323,7 @@ type CommonTokenStream struct {
channel int
}
func NewCommonTokenStream(lexer ILexer, channel int) *CommonTokenStream {
func NewCommonTokenStream(lexer Lexer, channel int) *CommonTokenStream {
ts := new(CommonTokenStream)

View File

@ -2,14 +2,14 @@ package antlr4
import "sort"
type DFA struct {
atnStartState IDecisionState
atnStartState DecisionState
decision int
_states map[string]*DFAState
s0 *DFAState
precedenceDfa bool
}
func NewDFA(atnStartState IDecisionState, decision int) *DFA {
func NewDFA(atnStartState DecisionState, decision int) *DFA {
this := new(DFA)

View File

@ -10,7 +10,7 @@ import (
// necessary.
type IErrorListener interface {
SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException)
SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e RecognitionException)
ReportAmbiguity(recognizer Parser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs ATNConfigSet)
ReportAttemptingFullContext(recognizer Parser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs ATNConfigSet)
ReportContextSensitivity(recognizer Parser, dfa *DFA, startIndex, stopIndex, prediction int, configs ATNConfigSet)
@ -23,7 +23,7 @@ func NewDefaultErrorListener() *DefaultErrorListener {
return new(DefaultErrorListener)
}
func (this *DefaultErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
func (this *DefaultErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e RecognitionException) {
if PortDebug {
fmt.Println("SyntaxError!")
}
@ -72,7 +72,7 @@ var ConsoleErrorListenerINSTANCE = NewConsoleErrorListener()
// line <em>line</em>:<em>charPositionInLine</em> <em>msg</em>
// </pre>
//
func (this *ConsoleErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
func (this *ConsoleErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e RecognitionException) {
fmt.Println("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg)
}
@ -90,7 +90,7 @@ func NewProxyErrorListener(delegates []IErrorListener) *ProxyErrorListener {
return l
}
func (this *ProxyErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
func (this *ProxyErrorListener) SyntaxError(recognizer Recognizer, offendingSymbol interface{}, line, column int, msg string, e RecognitionException) {
for _, d := range this.delegates {
d.SyntaxError(recognizer, offendingSymbol, line, column, msg, e)
}

View File

@ -10,10 +10,10 @@ import (
type IErrorStrategy interface {
reset(Parser)
RecoverInline(Parser) IToken
Recover(Parser, IRecognitionException)
Recover(Parser, RecognitionException)
Sync(Parser)
inErrorRecoveryMode(Parser) bool
ReportError(Parser, IRecognitionException)
ReportError(Parser, RecognitionException)
ReportMatch(Parser)
}
@ -110,7 +110,7 @@ func (this *DefaultErrorStrategy) ReportMatch(recognizer Parser) {
// the exception</li>
// </ul>
//
func (this *DefaultErrorStrategy) ReportError(recognizer Parser, e IRecognitionException) {
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) {
@ -139,7 +139,7 @@ func (this *DefaultErrorStrategy) ReportError(recognizer Parser, e IRecognitionE
// until we find one in the reSynchronization set--loosely the set of tokens
// that can follow the current rule.</p>
//
func (this *DefaultErrorStrategy) Recover(recognizer Parser, e IRecognitionException) {
func (this *DefaultErrorStrategy) Recover(recognizer Parser, e RecognitionException) {
if this.lastErrorIndex == recognizer.GetInputStream().Index() &&
this.lastErrorStates != nil && this.lastErrorStates.contains(recognizer.GetState()) {
@ -697,7 +697,7 @@ func (this *DefaultErrorStrategy) getErrorRecoverySet(recognizer Parser) *Interv
var rt = invokingState.GetTransitions()[0]
var follow = atn.nextTokens(rt.(*RuleTransition).followState, nil)
recoverSet.addSet(follow)
ctx = ctx.GetParent().(IParserRuleContext)
ctx = ctx.GetParent().(ParserRuleContext)
}
recoverSet.removeOne(TokenEpsilon)
return recoverSet
@ -758,11 +758,11 @@ func NewBailErrorStrategy() *BailErrorStrategy {
// rule func catches. Use {@link Exception//getCause()} to get the
// original {@link RecognitionException}.
//
func (this *BailErrorStrategy) Recover(recognizer Parser, e IRecognitionException) {
func (this *BailErrorStrategy) Recover(recognizer Parser, e RecognitionException) {
var context = recognizer.GetParserRuleContext()
for context != nil {
context.SetException(e)
context = context.GetParent().(IParserRuleContext)
context = context.GetParent().(ParserRuleContext)
}
panic(NewParseCancellationException()) // TODO we don't emit e properly
}

View File

@ -8,22 +8,22 @@ import ()
// in the input, where it is in the ATN, the rule invocation stack,
// and what kind of problem occurred.
type IRecognitionException interface {
type RecognitionException interface {
GetOffendingToken() IToken
GetMessage() string
GetInputStream() IntStream
}
type RecognitionException struct {
type BaseRecognitionException struct {
message string
recognizer Recognizer
offendingToken IToken
offendingState int
ctx IRuleContext
ctx RuleContext
input IntStream
}
func NewRecognitionException(message string, recognizer Recognizer, input IntStream, ctx IRuleContext) *RecognitionException {
func NewBaseRecognitionException(message string, recognizer Recognizer, input IntStream, ctx RuleContext) *BaseRecognitionException {
// todo
// Error.call(this)
@ -35,7 +35,7 @@ func NewRecognitionException(message string, recognizer Recognizer, input IntStr
// }
// TODO may be able to use - "runtime" func Stack(buf []byte, all bool) int
t := new(RecognitionException)
t := new(BaseRecognitionException)
t.message = message
t.recognizer = recognizer
@ -58,15 +58,15 @@ func NewRecognitionException(message string, recognizer Recognizer, input IntStr
return t
}
func (this *RecognitionException) GetMessage() string {
func (this *BaseRecognitionException) GetMessage() string {
return this.message
}
func (this *RecognitionException) GetOffendingToken() IToken {
func (this *BaseRecognitionException) GetOffendingToken() IToken {
return this.offendingToken
}
func (this *RecognitionException) GetInputStream() IntStream {
func (this *BaseRecognitionException) GetInputStream() IntStream {
return this.input
}
@ -82,7 +82,7 @@ func (this *RecognitionException) GetInputStream() IntStream {
// @return The set of token types that could potentially follow the current
// state in the ATN, or {@code nil} if the information is not available.
// /
func (this *RecognitionException) getExpectedTokens() *IntervalSet {
func (this *BaseRecognitionException) getExpectedTokens() *IntervalSet {
if this.recognizer != nil {
return this.recognizer.GetATN().getExpectedTokens(this.offendingState, this.ctx)
} else {
@ -90,22 +90,22 @@ func (this *RecognitionException) getExpectedTokens() *IntervalSet {
}
}
func (this *RecognitionException) String() string {
func (this *BaseRecognitionException) String() string {
return this.message
}
type LexerNoViableAltException struct {
*RecognitionException
*BaseRecognitionException
startIndex int
deadEndConfigs ATNConfigSet
}
func NewLexerNoViableAltException(lexer ILexer, input CharStream, startIndex int, deadEndConfigs ATNConfigSet) *LexerNoViableAltException {
func NewLexerNoViableAltException(lexer Lexer, input CharStream, startIndex int, deadEndConfigs ATNConfigSet) *LexerNoViableAltException {
this := new(LexerNoViableAltException)
this.RecognitionException = NewRecognitionException("", lexer, input, nil)
this.BaseRecognitionException = NewBaseRecognitionException("", lexer, input, nil)
this.startIndex = startIndex
this.deadEndConfigs = deadEndConfigs
@ -122,11 +122,11 @@ func (this *LexerNoViableAltException) String() string {
}
type NoViableAltException struct {
*RecognitionException
*BaseRecognitionException
startToken IToken
offendingToken IToken
ctx IParserRuleContext
ctx ParserRuleContext
deadEndConfigs ATNConfigSet
}
@ -135,7 +135,7 @@ type NoViableAltException struct {
// of the offending input and also knows where the parser was
// in the various paths when the error. Reported by ReportNoViableAlternative()
//
func NewNoViableAltException(recognizer Parser, input TokenStream, startToken IToken, offendingToken IToken, deadEndConfigs ATNConfigSet, ctx IParserRuleContext) *NoViableAltException {
func NewNoViableAltException(recognizer Parser, input TokenStream, startToken IToken, offendingToken IToken, deadEndConfigs ATNConfigSet, ctx ParserRuleContext) *NoViableAltException {
if ctx == nil {
ctx = recognizer.GetParserRuleContext()
@ -154,7 +154,7 @@ func NewNoViableAltException(recognizer Parser, input TokenStream, startToken IT
}
this := new(NoViableAltException)
this.RecognitionException = NewRecognitionException("", recognizer, input, ctx)
this.BaseRecognitionException = NewBaseRecognitionException("", recognizer, input, ctx)
// Which configurations did we try at input.Index() that couldn't Match
// input.LT(1)?//
@ -170,7 +170,7 @@ func NewNoViableAltException(recognizer Parser, input TokenStream, startToken IT
}
type InputMisMatchException struct {
*RecognitionException
*BaseRecognitionException
}
// This signifies any kind of misMatched input exceptions such as
@ -179,7 +179,7 @@ type InputMisMatchException struct {
func NewInputMisMatchException(recognizer Parser) *InputMisMatchException {
this := new(InputMisMatchException)
this.RecognitionException = NewRecognitionException("", recognizer, recognizer.GetInputStream(), recognizer.GetParserRuleContext())
this.BaseRecognitionException = NewBaseRecognitionException("", recognizer, recognizer.GetInputStream(), recognizer.GetParserRuleContext())
this.offendingToken = recognizer.getCurrentToken()
@ -193,7 +193,7 @@ func NewInputMisMatchException(recognizer Parser) *InputMisMatchException {
// prediction.
type FailedPredicateException struct {
*RecognitionException
*BaseRecognitionException
ruleIndex int
predicateIndex int
@ -204,7 +204,7 @@ func NewFailedPredicateException(recognizer *BaseParser, predicate string, messa
this := new(FailedPredicateException)
this.RecognitionException = NewRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.GetInputStream(), recognizer._ctx)
this.BaseRecognitionException = NewBaseRecognitionException(this.formatMessage(predicate, message), recognizer, recognizer.GetInputStream(), recognizer._ctx)
var s = recognizer.Interpreter.atn.states[recognizer.state]
var trans = s.GetTransitions()[0]

View File

@ -30,7 +30,7 @@ const (
//
// @param s the ATN state
// @return the expected symbols for each outgoing transition of {@code s}.
func (la *LL1Analyzer) getDecisionLookahead(s IATNState) []*IntervalSet {
func (la *LL1Analyzer) getDecisionLookahead(s ATNState) []*IntervalSet {
if s == nil {
return nil
}
@ -68,7 +68,7 @@ func (la *LL1Analyzer) getDecisionLookahead(s IATNState) []*IntervalSet {
// @return The set of tokens that can follow {@code s} in the ATN in the
// specified {@code ctx}.
///
func (la *LL1Analyzer) LOOK(s, stopState IATNState, ctx IRuleContext) *IntervalSet {
func (la *LL1Analyzer) LOOK(s, stopState ATNState, ctx RuleContext) *IntervalSet {
var r = NewIntervalSet()
var seeThruPreds = true // ignore preds get all lookahead
var lookContext IPredictionContext
@ -123,7 +123,7 @@ func (la *LL1Analyzer) LOOK(s, stopState IATNState, ctx IRuleContext) *IntervalS
// is {@code nil}.
func (la *LL1Analyzer) __LOOK(s, stopState IATNState, ctx IPredictionContext, look *IntervalSet, lookBusy *Set, calledRuleStack *BitSet, seeThruPreds, addEOF bool, i int){
func (la *LL1Analyzer) __LOOK(s, stopState ATNState, ctx IPredictionContext, look *IntervalSet, lookBusy *Set, calledRuleStack *BitSet, seeThruPreds, addEOF bool, i int){
returnState := la.atn.states[ctx.getReturnState(i)]
@ -140,9 +140,9 @@ func (la *LL1Analyzer) __LOOK(s, stopState IATNState, ctx IPredictionContext, lo
}
func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, look *IntervalSet, lookBusy *Set, calledRuleStack *BitSet, seeThruPreds, addEOF bool) {
func (la *LL1Analyzer) _LOOK(s, stopState ATNState, ctx IPredictionContext, look *IntervalSet, lookBusy *Set, calledRuleStack *BitSet, seeThruPreds, addEOF bool) {
c := NewATNConfig6(s, 0, ctx)
c := NewBaseATNConfig6(s, 0, ctx)
if lookBusy.contains(c) {
return
@ -212,7 +212,7 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
fmt.Println(look)
}
} else if t2, ok := t.(IAbstractPredicateTransition); ok {
} else if t2, ok := t.(AbstractPredicateTransition); ok {
if PortDebug {
fmt.Println("DEBUG 9")
}
@ -249,7 +249,7 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
}
}
func (la *LL1Analyzer) ___LOOK(stopState IATNState, ctx IPredictionContext, look *IntervalSet, lookBusy *Set, calledRuleStack *BitSet, seeThruPreds, addEOF bool, t1 *RuleTransition) {
func (la *LL1Analyzer) ___LOOK(stopState ATNState, ctx IPredictionContext, look *IntervalSet, lookBusy *Set, calledRuleStack *BitSet, seeThruPreds, addEOF bool, t1 *RuleTransition) {
newContext := SingletonPredictionContextCreate(ctx, t1.followState.GetStateNumber())

View File

@ -11,7 +11,8 @@ import (
// of speed.
///
type ILexer interface {
type Lexer interface {
TokenSource
Recognizer
@ -22,7 +23,7 @@ type ILexer interface {
mode(int)
}
type Lexer struct {
type BaseLexer struct {
*BaseRecognizer
Interpreter *LexerATNSimulator
@ -43,9 +44,9 @@ type Lexer struct {
actionType int
}
func NewLexer(input CharStream) *Lexer {
func NewBaseLexer(input CharStream) *BaseLexer {
lexer := new(Lexer)
lexer := new(BaseLexer)
lexer.BaseRecognizer = NewBaseRecognizer()
@ -109,7 +110,7 @@ const (
LexerMaxCharValue = '\uFFFE'
)
func (l *Lexer) reset() {
func (l *BaseLexer) reset() {
// wack Lexer state variables
if l._input != nil {
l._input.Seek(0) // rewind the input
@ -129,32 +130,32 @@ func (l *Lexer) reset() {
l.Interpreter.reset()
}
func (l *Lexer) GetInputStream() CharStream {
func (l *BaseLexer) GetInputStream() CharStream {
return l._input
}
func (l *Lexer) GetSourceName() string {
func (l *BaseLexer) GetSourceName() string {
return l.GrammarFileName
}
func (l *Lexer) setChannel(v int) {
func (l *BaseLexer) setChannel(v int) {
l._channel = v
}
func (l *Lexer) GetTokenFactory() TokenFactory {
func (l *BaseLexer) GetTokenFactory() TokenFactory {
return l._factory
}
func (l *Lexer) setTokenFactory(f TokenFactory) {
func (l *BaseLexer) setTokenFactory(f TokenFactory) {
l._factory = f
}
func (l *Lexer) safeMatch() (ret int) {
func (l *BaseLexer) safeMatch() (ret int) {
// previously in catch block
defer func() {
if e := recover(); e != nil {
if re, ok := e.(IRecognitionException); ok {
if re, ok := e.(RecognitionException); ok {
l.notifyListeners(re) // Report error
l.Recover(re)
ret = LexerSkip // default
@ -166,7 +167,7 @@ func (l *Lexer) safeMatch() (ret int) {
}
// Return a token from l source i.e., Match a token on the char stream.
func (l *Lexer) nextToken() IToken {
func (l *BaseLexer) nextToken() IToken {
if l._input == nil {
panic("nextToken requires a non-nil input stream.")
}
@ -237,19 +238,19 @@ func (l *Lexer) nextToken() IToken {
// if token==nil at end of any token rule, it creates one for you
// and emits it.
// /
func (l *Lexer) skip() {
func (l *BaseLexer) skip() {
l._type = LexerSkip
}
func (l *Lexer) more() {
func (l *BaseLexer) more() {
l._type = LexerMore
}
func (l *Lexer) mode(m int) {
func (l *BaseLexer) mode(m int) {
l._mode = m
}
func (l *Lexer) pushMode(m int) {
func (l *BaseLexer) pushMode(m int) {
if LexerATNSimulatorDebug {
fmt.Println("pushMode " + strconv.Itoa(m))
}
@ -257,7 +258,7 @@ func (l *Lexer) pushMode(m int) {
l.mode(m)
}
func (l *Lexer) popMode() int {
func (l *BaseLexer) popMode() int {
if len(l._modeStack) == 0 {
panic("Empty Stack")
}
@ -269,11 +270,11 @@ func (l *Lexer) popMode() int {
return l._mode
}
func (l *Lexer) inputStream() CharStream {
func (l *BaseLexer) inputStream() CharStream {
return l._input
}
func (l *Lexer) setInputStream(input CharStream) {
func (l *BaseLexer) setInputStream(input CharStream) {
l._input = nil
l._tokenFactorySourcePair = &TokenSourceCharStreamPair{l, l._input}
l.reset()
@ -286,7 +287,7 @@ func (l *Lexer) setInputStream(input CharStream) {
// and GetToken (to push tokens into a list and pull from that list
// rather than a single variable as l implementation does).
// /
func (l *Lexer) emitToken(token IToken) {
func (l *BaseLexer) emitToken(token IToken) {
l._token = token
}
@ -296,7 +297,7 @@ func (l *Lexer) emitToken(token IToken) {
// use that to set the token's text. Override l method to emit
// custom Token objects or provide a Newfactory.
// /
func (l *Lexer) emit() IToken {
func (l *BaseLexer) emit() IToken {
if PortDebug {
fmt.Println("emit")
}
@ -305,7 +306,7 @@ func (l *Lexer) emit() IToken {
return t
}
func (l *Lexer) emitEOF() IToken {
func (l *BaseLexer) emitEOF() IToken {
cpos := l.getCharPositionInLine()
lpos := l.getLine()
if PortDebug {
@ -316,30 +317,30 @@ func (l *Lexer) emitEOF() IToken {
return eof
}
func (l *Lexer) getCharPositionInLine() int {
func (l *BaseLexer) getCharPositionInLine() int {
return l.Interpreter.column
}
func (l *Lexer) getLine() int {
func (l *BaseLexer) getLine() int {
return l.Interpreter.line
}
func (l *Lexer) getType() int {
func (l *BaseLexer) getType() int {
return l._type
}
func (l *Lexer) setType(t int) {
func (l *BaseLexer) setType(t int) {
l._type = t
}
// What is the index of the current character of lookahead?///
func (l *Lexer) getCharIndex() int {
func (l *BaseLexer) getCharIndex() int {
return l._input.Index()
}
// Return the text Matched so far for the current token or any text override.
//Set the complete text of l token it wipes any previous changes to the text.
func (l *Lexer) text() string {
func (l *BaseLexer) text() string {
if l._text != "" {
return l._text
} else {
@ -347,18 +348,18 @@ func (l *Lexer) text() string {
}
}
func (l *Lexer) setText(text string) {
func (l *BaseLexer) setText(text string) {
l._text = text
}
func (this *Lexer) GetATN() *ATN {
func (this *BaseLexer) GetATN() *ATN {
return this.Interpreter.atn
}
// Return a list of all Token objects in input char stream.
// Forces load of all tokens. Does not include EOF token.
// /
func (l *Lexer) getAllTokens() []IToken {
func (l *BaseLexer) getAllTokens() []IToken {
if PortDebug {
fmt.Println("getAllTokens")
}
@ -374,7 +375,7 @@ func (l *Lexer) getAllTokens() []IToken {
return tokens
}
func (l *Lexer) notifyListeners(e IRecognitionException) {
func (l *BaseLexer) notifyListeners(e RecognitionException) {
var start = l._tokenStartCharIndex
var stop = l._input.Index()
var text = l._input.GetTextFromInterval(NewInterval(start, stop))
@ -383,7 +384,7 @@ func (l *Lexer) notifyListeners(e IRecognitionException) {
listener.SyntaxError(l, nil, l._tokenStartLine, l._tokenStartColumn, msg, e)
}
func (l *Lexer) getErrorDisplayForChar(c rune) string {
func (l *BaseLexer) getErrorDisplayForChar(c rune) string {
if c == TokenEOF {
return "<EOF>"
} else if c == '\n' {
@ -397,7 +398,7 @@ func (l *Lexer) getErrorDisplayForChar(c rune) string {
}
}
func (l *Lexer) getCharErrorDisplay(c rune) string {
func (l *BaseLexer) getCharErrorDisplay(c rune) string {
return "'" + l.getErrorDisplayForChar(c) + "'"
}
@ -406,7 +407,7 @@ func (l *Lexer) getCharErrorDisplay(c rune) string {
// it all works out. You can instead use the rule invocation stack
// to do sophisticated error recovery if you are in a fragment rule.
// /
func (l *Lexer) Recover(re IRecognitionException) {
func (l *BaseLexer) Recover(re RecognitionException) {
if l._input.LA(1) != TokenEOF {
if _, ok := re.(*LexerNoViableAltException); ok {
// skip a char and try again

View File

@ -48,9 +48,9 @@ func (this *SimState) reset() {
}
type LexerATNSimulator struct {
*ATNSimulator
*BaseATNSimulator
recog ILexer
recog Lexer
predictionMode int
decisionToDFA []*DFA
mergeCache DoubleDict
@ -62,11 +62,11 @@ type LexerATNSimulator struct {
Match_calls int
}
func NewLexerATNSimulator(recog ILexer, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *LexerATNSimulator {
func NewLexerATNSimulator(recog Lexer, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *LexerATNSimulator {
this := new(LexerATNSimulator)
this.ATNSimulator = NewATNSimulator(atn, sharedContextCache)
this.BaseATNSimulator = NewBaseATNSimulator(atn, sharedContextCache)
this.decisionToDFA = decisionToDFA
this.recog = recog
@ -212,7 +212,7 @@ func (this *LexerATNSimulator) execATN(input CharStream, ds0 *DFAState) int {
target = this.computeTargetState(input, s, t)
// print("Computed:" + str(target))
}
if target == ATNSimulatorERROR {
if target == ATNSimulatorError {
break
}
// If this is a consumable input element, make sure to consume before
@ -282,10 +282,10 @@ func (this *LexerATNSimulator) computeTargetState(input CharStream, s *DFAState,
if !reach.hasSemanticContext {
// we got nowhere on t, don't panic out this knowledge it'd
// cause a failover from DFA later.
this.addDFAEdge(s, t, ATNSimulatorERROR, nil)
this.addDFAEdge(s, t, ATNSimulatorError, nil)
}
// stop when we can't Match any more char
return ATNSimulatorERROR
return ATNSimulatorError
}
// Add an edge from s to target DFA found/created for reach
return this.addDFAEdge(s, t, nil, reach.BaseATNConfigSet)
@ -315,7 +315,7 @@ func (this *LexerATNSimulator) failOrAccept(prevAccept *SimState, input CharStre
func (this *LexerATNSimulator) getReachableConfigSet(input CharStream, closure ATNConfigSet, reach ATNConfigSet, t int) {
// 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
var skipAlt = ATNINVALID_ALT_NUMBER
var skipAlt = ATNInvalidAltNumber
for _, cfg := range closure.GetItems() {
var currentAltReachedAcceptState = (cfg.GetAlt() == skipAlt)
if currentAltReachedAcceptState && cfg.(*LexerATNConfig).passedThroughNonGreedyDecision {
@ -357,7 +357,7 @@ func (this *LexerATNSimulator) accept(input CharStream, lexerActionExecutor *Lex
}
}
func (this *LexerATNSimulator) getReachableTarget(trans ITransition, t int) IATNState {
func (this *LexerATNSimulator) getReachableTarget(trans Transition, t int) ATNState {
if trans.Matches(t, 0, 0xFFFE) {
return trans.getTarget()
} else {
@ -365,7 +365,7 @@ func (this *LexerATNSimulator) getReachableTarget(trans ITransition, t int) IATN
}
}
func (this *LexerATNSimulator) computeStartState(input CharStream, p IATNState) *OrderedATNConfigSet {
func (this *LexerATNSimulator) computeStartState(input CharStream, p ATNState) *OrderedATNConfigSet {
if PortDebug {
fmt.Println("DEBUG" + strconv.Itoa(len(p.GetTransitions())))
@ -450,7 +450,7 @@ func (this *LexerATNSimulator) closure(input CharStream, config *LexerATNConfig,
}
// side-effect: can alter configs.hasSemanticContext
func (this *LexerATNSimulator) getEpsilonTarget(input CharStream, config *LexerATNConfig, trans ITransition,
func (this *LexerATNSimulator) getEpsilonTarget(input CharStream, config *LexerATNConfig, trans Transition,
configs ATNConfigSet, speculative, treatEofAsEpsilon bool) *LexerATNConfig {
var cfg *LexerATNConfig

View File

@ -13,21 +13,21 @@ const (
LexerActionTypeTYPE = 7 //The type of a {@link LexerTypeAction} action.
)
type ILexerAction interface {
type LexerAction interface {
getActionType() int
getIsPositionDependent() bool
execute(lexer ILexer)
execute(lexer Lexer)
Hash() string
equals(other ILexerAction) bool
equals(other LexerAction) bool
}
type LexerAction struct {
type BaseLexerAction struct {
actionType int
isPositionDependent bool
}
func NewLexerAction(action int) *LexerAction {
la := new(LexerAction)
func NewBaseLexerAction(action int) *BaseLexerAction {
la := new(BaseLexerAction)
la.actionType = action
la.isPositionDependent = false
@ -36,23 +36,23 @@ func NewLexerAction(action int) *LexerAction {
}
func (this *LexerAction) execute(lexer ILexer) {
func (this *BaseLexerAction) execute(lexer Lexer) {
panic("Not implemented")
}
func (this *LexerAction) getActionType() int {
func (this *BaseLexerAction) getActionType() int {
return this.actionType
}
func (this *LexerAction) getIsPositionDependent() bool {
func (this *BaseLexerAction) getIsPositionDependent() bool {
return this.isPositionDependent
}
func (this *LexerAction) Hash() string {
func (this *BaseLexerAction) Hash() string {
return strconv.Itoa(this.actionType)
}
func (this *LexerAction) equals(other ILexerAction) bool {
func (this *BaseLexerAction) equals(other LexerAction) bool {
return this == other
}
@ -62,19 +62,19 @@ func (this *LexerAction) equals(other ILexerAction) bool {
// <p>The {@code skip} command does not have any parameters, so this action is
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerSkipAction struct {
*LexerAction
*BaseLexerAction
}
func NewLexerSkipAction() *LexerSkipAction {
la := new(LexerSkipAction)
la.LexerAction = NewLexerAction(LexerActionTypeSKIP)
la.BaseLexerAction = NewBaseLexerAction(LexerActionTypeSKIP)
return la
}
// Provides a singleton instance of this parameterless lexer action.
var LexerSkipActionINSTANCE = NewLexerSkipAction()
func (this *LexerSkipAction) execute(lexer ILexer) {
func (this *LexerSkipAction) execute(lexer Lexer) {
lexer.skip()
}
@ -85,19 +85,19 @@ func (this *LexerSkipAction) String() string {
// Implements the {@code type} lexer action by calling {@link Lexer//setType}
// with the assigned type.
type LexerTypeAction struct {
*LexerAction
*BaseLexerAction
_type int
}
func NewLexerTypeAction(_type int) *LexerTypeAction {
this := new(LexerTypeAction)
this.LexerAction = NewLexerAction(LexerActionTypeTYPE)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypeTYPE)
this._type = _type
return this
}
func (this *LexerTypeAction) execute(lexer ILexer) {
func (this *LexerTypeAction) execute(lexer Lexer) {
lexer.setType(this._type)
}
@ -105,7 +105,7 @@ func (this *LexerTypeAction) Hash() string {
return strconv.Itoa(this.actionType) + strconv.Itoa(this._type)
}
func (this *LexerTypeAction) equals(other ILexerAction) bool {
func (this *LexerTypeAction) equals(other LexerAction) bool {
if this == other {
return true
} else if _, ok := other.(*LexerTypeAction); !ok {
@ -122,7 +122,7 @@ func (this *LexerTypeAction) String() string {
// Implements the {@code pushMode} lexer action by calling
// {@link Lexer//pushMode} with the assigned mode.
type LexerPushModeAction struct {
*LexerAction
*BaseLexerAction
mode int
}
@ -130,7 +130,7 @@ type LexerPushModeAction struct {
func NewLexerPushModeAction(mode int) *LexerPushModeAction {
this := new(LexerPushModeAction)
this.LexerAction = NewLexerAction(LexerActionTypePUSH_MODE)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypePUSH_MODE)
this.mode = mode
return this
@ -138,7 +138,7 @@ func NewLexerPushModeAction(mode int) *LexerPushModeAction {
// <p>This action is implemented by calling {@link Lexer//pushMode} with the
// value provided by {@link //getMode}.</p>
func (this *LexerPushModeAction) execute(lexer ILexer) {
func (this *LexerPushModeAction) execute(lexer Lexer) {
lexer.pushMode(this.mode)
}
@ -146,7 +146,7 @@ func (this *LexerPushModeAction) Hash() string {
return strconv.Itoa(this.actionType) + strconv.Itoa(this.mode)
}
func (this *LexerPushModeAction) equals(other ILexerAction) bool {
func (this *LexerPushModeAction) equals(other LexerAction) bool {
if this == other {
return true
} else if _, ok := other.(*LexerPushModeAction); !ok {
@ -165,14 +165,14 @@ func (this *LexerPushModeAction) String() string {
// <p>The {@code popMode} command does not have any parameters, so this action is
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerPopModeAction struct {
*LexerAction
*BaseLexerAction
}
func NewLexerPopModeAction() *LexerPopModeAction {
this := new(LexerPopModeAction)
this.LexerAction = NewLexerAction(LexerActionTypePOP_MODE)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypePOP_MODE)
return this
}
@ -180,7 +180,7 @@ func NewLexerPopModeAction() *LexerPopModeAction {
var LexerPopModeActionINSTANCE = NewLexerPopModeAction()
// <p>This action is implemented by calling {@link Lexer//popMode}.</p>
func (this *LexerPopModeAction) execute(lexer ILexer) {
func (this *LexerPopModeAction) execute(lexer Lexer) {
lexer.popMode()
}
@ -194,12 +194,12 @@ func (this *LexerPopModeAction) String() string {
// implemented as a singleton instance exposed by {@link //INSTANCE}.</p>
type LexerMoreAction struct {
*LexerAction
*BaseLexerAction
}
func NewLexerMoreAction() *LexerModeAction {
this := new(LexerModeAction)
this.LexerAction = NewLexerAction(LexerActionTypeMORE)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypeMORE)
return this
}
@ -207,7 +207,7 @@ func NewLexerMoreAction() *LexerModeAction {
var LexerMoreActionINSTANCE = NewLexerMoreAction()
// <p>This action is implemented by calling {@link Lexer//popMode}.</p>
func (this *LexerMoreAction) execute(lexer ILexer) {
func (this *LexerMoreAction) execute(lexer Lexer) {
lexer.more()
}
@ -218,21 +218,21 @@ func (this *LexerMoreAction) String() string {
// Implements the {@code mode} lexer action by calling {@link Lexer//mode} with
// the assigned mode.
type LexerModeAction struct {
*LexerAction
*BaseLexerAction
mode int
}
func NewLexerModeAction(mode int) *LexerModeAction {
this := new(LexerModeAction)
this.LexerAction = NewLexerAction(LexerActionTypeMODE)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypeMODE)
this.mode = mode
return this
}
// <p>This action is implemented by calling {@link Lexer//mode} with the
// value provided by {@link //getMode}.</p>
func (this *LexerModeAction) execute(lexer ILexer) {
func (this *LexerModeAction) execute(lexer Lexer) {
lexer.mode(this.mode)
}
@ -240,7 +240,7 @@ func (this *LexerModeAction) Hash() string {
return strconv.Itoa(this.actionType) + strconv.Itoa(this.mode)
}
func (this *LexerModeAction) equals(other ILexerAction) bool {
func (this *LexerModeAction) equals(other LexerAction) bool {
if this == other {
return true
} else if _, ok := other.(*LexerModeAction); !ok {
@ -272,13 +272,13 @@ func (this *LexerModeAction) String() string {
// {@link Recognizer//action}.
type LexerCustomAction struct {
*LexerAction
*BaseLexerAction
ruleIndex, actionIndex int
}
func NewLexerCustomAction(ruleIndex, actionIndex int) *LexerCustomAction {
this := new(LexerCustomAction)
this.LexerAction = NewLexerAction(LexerActionTypeCUSTOM)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypeCUSTOM)
this.ruleIndex = ruleIndex
this.actionIndex = actionIndex
this.isPositionDependent = true
@ -287,7 +287,7 @@ func NewLexerCustomAction(ruleIndex, actionIndex int) *LexerCustomAction {
// <p>Custom actions are implemented by calling {@link Lexer//action} with the
// appropriate rule and action indexes.</p>
func (this *LexerCustomAction) execute(lexer ILexer) {
func (this *LexerCustomAction) execute(lexer Lexer) {
lexer.Action(nil, this.ruleIndex, this.actionIndex)
}
@ -295,7 +295,7 @@ func (this *LexerCustomAction) Hash() string {
return strconv.Itoa(this.actionType) + strconv.Itoa(this.ruleIndex) + strconv.Itoa(this.actionIndex)
}
func (this *LexerCustomAction) equals(other ILexerAction) bool {
func (this *LexerCustomAction) equals(other LexerAction) bool {
if this == other {
return true
} else if _, ok := other.(*LexerCustomAction); !ok {
@ -310,21 +310,21 @@ func (this *LexerCustomAction) equals(other ILexerAction) bool {
// Constructs a New{@code channel} action with the specified channel value.
// @param channel The channel value to pass to {@link Lexer//setChannel}.
type LexerChannelAction struct {
*LexerAction
*BaseLexerAction
channel int
}
func NewLexerChannelAction(channel int) *LexerChannelAction {
this := new(LexerChannelAction)
this.LexerAction = NewLexerAction(LexerActionTypeCHANNEL)
this.BaseLexerAction = NewBaseLexerAction(LexerActionTypeCHANNEL)
this.channel = channel
return this
}
// <p>This action is implemented by calling {@link Lexer//setChannel} with the
// value provided by {@link //getChannel}.</p>
func (this *LexerChannelAction) execute(lexer ILexer) {
func (this *LexerChannelAction) execute(lexer Lexer) {
lexer.setChannel(this.channel)
}
@ -332,7 +332,7 @@ func (this *LexerChannelAction) Hash() string {
return strconv.Itoa(this.actionType) + strconv.Itoa(this.channel)
}
func (this *LexerChannelAction) equals(other ILexerAction) bool {
func (this *LexerChannelAction) equals(other LexerAction) bool {
if this == other {
return true
} else if _, ok := other.(*LexerChannelAction); !ok {
@ -367,17 +367,17 @@ func (this *LexerChannelAction) String() string {
// @param action The lexer action to execute at a particular offset in the
// input {@link CharStream}.
type LexerIndexedCustomAction struct {
*LexerAction
*BaseLexerAction
offset int
lexerAction ILexerAction
lexerAction LexerAction
isPositionDependent bool
}
func NewLexerIndexedCustomAction(offset int, lexerAction ILexerAction) *LexerIndexedCustomAction {
func NewLexerIndexedCustomAction(offset int, lexerAction LexerAction) *LexerIndexedCustomAction {
this := new(LexerIndexedCustomAction)
this.LexerAction = NewLexerAction(lexerAction.getActionType())
this.BaseLexerAction = NewBaseLexerAction(lexerAction.getActionType())
this.offset = offset
this.lexerAction = lexerAction
@ -388,7 +388,7 @@ func NewLexerIndexedCustomAction(offset int, lexerAction ILexerAction) *LexerInd
// <p>This method calls {@link //execute} on the result of {@link //getAction}
// using the provided {@code lexer}.</p>
func (this *LexerIndexedCustomAction) execute(lexer ILexer) {
func (this *LexerIndexedCustomAction) execute(lexer Lexer) {
// assume the input stream position was properly set by the calling code
this.lexerAction.execute(lexer)
}
@ -397,7 +397,7 @@ func (this *LexerIndexedCustomAction) Hash() string {
return strconv.Itoa(this.actionType) + strconv.Itoa(this.offset) + this.lexerAction.Hash()
}
func (this *LexerIndexedCustomAction) equals(other ILexerAction) bool {
func (this *LexerIndexedCustomAction) equals(other LexerAction) bool {
if this == other {
return true
} else if _, ok := other.(*LexerIndexedCustomAction); !ok {

View File

@ -8,14 +8,14 @@ package antlr4
// not cause bloating of the {@link DFA} created for the lexer.</p>
type LexerActionExecutor struct {
lexerActions []ILexerAction
lexerActions []LexerAction
cachedHashString string
}
func NewLexerActionExecutor(lexerActions []ILexerAction) *LexerActionExecutor {
func NewLexerActionExecutor(lexerActions []LexerAction) *LexerActionExecutor {
if lexerActions == nil {
lexerActions = make([]ILexerAction, 0)
lexerActions = make([]LexerAction, 0)
}
this := new(LexerActionExecutor)
@ -48,9 +48,9 @@ func NewLexerActionExecutor(lexerActions []ILexerAction) *LexerActionExecutor {
//
// @return A {@link LexerActionExecutor} for executing the combine actions
// of {@code lexerActionExecutor} and {@code lexerAction}.
func LexerActionExecutorappend(lexerActionExecutor *LexerActionExecutor, lexerAction ILexerAction) *LexerActionExecutor {
func LexerActionExecutorappend(lexerActionExecutor *LexerActionExecutor, lexerAction LexerAction) *LexerActionExecutor {
if lexerActionExecutor == nil {
return NewLexerActionExecutor([]ILexerAction{lexerAction})
return NewLexerActionExecutor([]LexerAction{lexerAction})
}
var lexerActions = append(lexerActionExecutor.lexerActions, lexerAction)
@ -88,12 +88,12 @@ func LexerActionExecutorappend(lexerActionExecutor *LexerActionExecutor, lexerAc
// for all position-dependent lexer actions.
// /
func (this *LexerActionExecutor) fixOffsetBeforeMatch(offset int) *LexerActionExecutor {
var updatedLexerActions []ILexerAction = nil
var updatedLexerActions []LexerAction = nil
for i := 0; i < len(this.lexerActions); i++ {
_, ok := this.lexerActions[i].(*LexerIndexedCustomAction)
if this.lexerActions[i].getIsPositionDependent() && !ok {
if updatedLexerActions == nil {
updatedLexerActions = make([]ILexerAction, 0)
updatedLexerActions = make([]LexerAction, 0)
for _, a := range this.lexerActions {
updatedLexerActions = append(updatedLexerActions, a)
@ -128,7 +128,7 @@ func (this *LexerActionExecutor) fixOffsetBeforeMatch(offset int) *LexerActionEx
// {@link IntStream//seek} to set the {@code input} position to the beginning
// of the token.
// /
func (this *LexerActionExecutor) execute(lexer ILexer, input CharStream, startIndex int) {
func (this *LexerActionExecutor) execute(lexer Lexer, input CharStream, startIndex int) {
var requiresSeek = false
var stopIndex = input.Index()
@ -139,7 +139,7 @@ func (this *LexerActionExecutor) execute(lexer ILexer, input CharStream, startIn
}()
for i := 0; i < len(this.lexerActions); i++ {
var lexerAction ILexerAction = this.lexerActions[i]
var lexerAction LexerAction = this.lexerActions[i]
if la, ok := lexerAction.(*LexerIndexedCustomAction); ok {
var offset = la.offset
input.Seek(startIndex + offset)

View File

@ -8,17 +8,17 @@ type Parser interface {
GetErrorHandler() IErrorStrategy
GetTokenStream() TokenStream
GetTokenFactory() TokenFactory
GetParserRuleContext() IParserRuleContext
GetParserRuleContext() ParserRuleContext
Consume() IToken
GetParseListeners() []ParseTreeListener
GetInputStream() IntStream
getCurrentToken() IToken
getExpectedTokens() *IntervalSet
NotifyErrorListeners(msg string, offendingToken IToken, err IRecognitionException)
NotifyErrorListeners(msg string, offendingToken IToken, err RecognitionException)
isExpectedToken(symbol int) bool
getPrecedence() int
getRuleInvocationStack(IParserRuleContext) []string
getRuleInvocationStack(ParserRuleContext) []string
}
type BaseParser struct {
@ -30,7 +30,7 @@ type BaseParser struct {
_input TokenStream
_errHandler IErrorStrategy
_precedenceStack IntStack
_ctx IParserRuleContext
_ctx ParserRuleContext
_tracer *TraceListener
_parseListeners []ParseTreeListener
@ -188,7 +188,7 @@ func (p *BaseParser) MatchWildcard() IToken {
return t
}
func (p *BaseParser) GetParserRuleContext() IParserRuleContext {
func (p *BaseParser) GetParserRuleContext() ParserRuleContext {
return p._ctx
}
@ -357,7 +357,7 @@ func (p *BaseParser) GetATNWithBypassAlts() {
// String id = m.Get("ID")
// </pre>
func (p *BaseParser) compileParseTreePattern(pattern, patternRuleIndex, lexer ILexer) {
func (p *BaseParser) compileParseTreePattern(pattern, patternRuleIndex, lexer Lexer) {
panic("NewParseTreePatternMatcher not implemented!")
//
@ -403,7 +403,7 @@ func (p *BaseParser) getCurrentToken() IToken {
return p._input.LT(1)
}
func (p *BaseParser) NotifyErrorListeners(msg string, offendingToken IToken, err IRecognitionException) {
func (p *BaseParser) NotifyErrorListeners(msg string, offendingToken IToken, err RecognitionException) {
if offendingToken == nil {
offendingToken = p.getCurrentToken()
}
@ -456,7 +456,7 @@ func (p *BaseParser) addContextToParseTree() {
}
}
func (p *BaseParser) EnterRule(localctx IParserRuleContext, state, ruleIndex int) {
func (p *BaseParser) EnterRule(localctx ParserRuleContext, state, ruleIndex int) {
p.SetState(state)
p._ctx = localctx
p._ctx.setStart(p._input.LT(1))
@ -476,19 +476,19 @@ func (p *BaseParser) ExitRule() {
}
p.SetState(p._ctx.getInvokingState())
if p._ctx.GetParent() != nil {
p._ctx = p._ctx.GetParent().(IParserRuleContext)
p._ctx = p._ctx.GetParent().(ParserRuleContext)
} else {
p._ctx = nil
}
}
func (p *BaseParser) EnterOuterAlt(localctx IParserRuleContext, altNum int) {
func (p *BaseParser) EnterOuterAlt(localctx ParserRuleContext, altNum int) {
// if we have Newlocalctx, make sure we replace existing ctx
// that is previous child of parse tree
if p.BuildParseTrees && p._ctx != localctx {
if p._ctx.GetParent() != nil {
p._ctx.GetParent().(IParserRuleContext).removeLastChild()
p._ctx.GetParent().(IParserRuleContext).addChild(localctx)
p._ctx.GetParent().(ParserRuleContext).removeLastChild()
p._ctx.GetParent().(ParserRuleContext).addChild(localctx)
}
}
p._ctx = localctx
@ -507,7 +507,7 @@ func (p *BaseParser) getPrecedence() int {
}
}
func (p *BaseParser) EnterRecursionRule(localctx IParserRuleContext, state, ruleIndex, precedence int) {
func (p *BaseParser) EnterRecursionRule(localctx ParserRuleContext, state, ruleIndex, precedence int) {
p.SetState(state)
p._precedenceStack.Push(precedence)
p._ctx = localctx
@ -521,7 +521,7 @@ func (p *BaseParser) EnterRecursionRule(localctx IParserRuleContext, state, rule
//
// Like {@link //EnterRule} but for recursive rules.
func (p *BaseParser) PushNewRecursionContext(localctx IParserRuleContext, state, ruleIndex int) {
func (p *BaseParser) PushNewRecursionContext(localctx ParserRuleContext, state, ruleIndex int) {
var previous = p._ctx
previous.setParent(localctx)
previous.setInvokingState(state)
@ -538,7 +538,7 @@ func (p *BaseParser) PushNewRecursionContext(localctx IParserRuleContext, state,
}
}
func (p *BaseParser) UnrollRecursionContexts(parentCtx IParserRuleContext) {
func (p *BaseParser) UnrollRecursionContexts(parentCtx ParserRuleContext) {
p._precedenceStack.Pop()
p._ctx.setStop(p._input.LT(-1))
var retCtx = p._ctx // save current ctx (return value)
@ -546,7 +546,7 @@ func (p *BaseParser) UnrollRecursionContexts(parentCtx IParserRuleContext) {
if p._parseListeners != nil {
for p._ctx != parentCtx {
p.TriggerExitRuleEvent()
p._ctx = p._ctx.GetParent().(IParserRuleContext)
p._ctx = p._ctx.GetParent().(ParserRuleContext)
}
} else {
p._ctx = parentCtx
@ -559,22 +559,22 @@ func (p *BaseParser) UnrollRecursionContexts(parentCtx IParserRuleContext) {
}
}
func (p *BaseParser) getInvokingContext(ruleIndex int) IParserRuleContext {
func (p *BaseParser) getInvokingContext(ruleIndex int) ParserRuleContext {
var ctx = p._ctx
for ctx != nil {
if ctx.GetRuleIndex() == ruleIndex {
return ctx
}
ctx = ctx.GetParent().(IParserRuleContext)
ctx = ctx.GetParent().(ParserRuleContext)
}
return nil
}
func (p *BaseParser) Precpred(localctx IRuleContext, precedence int) bool {
func (p *BaseParser) Precpred(localctx RuleContext, precedence int) bool {
return precedence >= p._precedenceStack[len(p._precedenceStack)-1]
}
func (p *BaseParser) inContext(context IParserRuleContext) bool {
func (p *BaseParser) inContext(context ParserRuleContext) bool {
// TODO: useful in parser?
return false
}
@ -611,7 +611,7 @@ func (p *BaseParser) isExpectedToken(symbol int) bool {
if following.contains(symbol) {
return true
}
ctx = ctx.GetParent().(IParserRuleContext)
ctx = ctx.GetParent().(ParserRuleContext)
}
if following.contains(TokenEpsilon) && symbol == TokenEOF {
return true
@ -653,7 +653,7 @@ func (p *BaseParser) GetRuleIndex(ruleName string) int {
//
// this very useful for error messages.
func (this *BaseParser) getRuleInvocationStack(p IParserRuleContext) []string {
func (this *BaseParser) getRuleInvocationStack(p ParserRuleContext) []string {
if p == nil {
p = this._ctx
}
@ -666,7 +666,7 @@ func (this *BaseParser) getRuleInvocationStack(p IParserRuleContext) []string {
} else {
stack = append(stack, this.GetRuleNames()[ruleIndex])
}
p = p.GetParent().(IParserRuleContext)
p = p.GetParent().(ParserRuleContext)
}
return stack
}

View File

@ -7,7 +7,7 @@ import (
)
type ParserATNSimulator struct {
*ATNSimulator
*BaseATNSimulator
parser Parser
predictionMode int
@ -16,14 +16,14 @@ type ParserATNSimulator struct {
_dfa *DFA
decisionToDFA []*DFA
mergeCache *DoubleDict
_outerContext IParserRuleContext
_outerContext ParserRuleContext
}
func NewParserATNSimulator(parser Parser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) *ParserATNSimulator {
this := new(ParserATNSimulator)
this.ATNSimulator = NewATNSimulator(atn, sharedContextCache)
this.BaseATNSimulator = NewBaseATNSimulator(atn, sharedContextCache)
this.parser = parser
this.decisionToDFA = decisionToDFA
@ -55,7 +55,7 @@ var ParserATNSimulatorRetryDebug = false
func (this *ParserATNSimulator) reset() {
}
func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int, outerContext IParserRuleContext) int {
func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int, outerContext ParserRuleContext) int {
if PortDebug {
fmt.Println("Adaptive predict")
@ -111,7 +111,7 @@ func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int,
// closure block that determines whether a precedence rule
// should continue or complete.
var t2 IATNState = dfa.atnStartState
var t2 ATNState = dfa.atnStartState
t, ok := t2.(*StarLoopEntryState)
if !dfa.precedenceDfa && ok {
if t.precedenceRuleDecision {
@ -174,7 +174,7 @@ func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int,
// conflict
// conflict + preds
//
func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStream, startIndex int, outerContext IParserRuleContext) int {
func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStream, startIndex int, outerContext ParserRuleContext) int {
if ParserATNSimulatorDebug || ParserATNSimulatorListATNDecisions {
fmt.Println("execATN decision " + strconv.Itoa(dfa.decision) +
@ -193,7 +193,7 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
if D == nil {
D = this.computeTargetState(dfa, previousD, t)
}
if D == ATNSimulatorERROR {
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
@ -206,7 +206,7 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
e := this.noViableAlt(input, outerContext, previousD.configs, startIndex)
input.Seek(startIndex)
alt := this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD.configs, outerContext)
if alt != ATNINVALID_ALT_NUMBER {
if alt != ATNInvalidAltNumber {
return alt
} else {
panic(e)
@ -307,8 +307,8 @@ func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState
var reach = this.computeReachSet(previousD.configs, t, false)
if reach == nil {
this.addDFAEdge(dfa, previousD, t, ATNSimulatorERROR)
return ATNSimulatorERROR
this.addDFAEdge(dfa, previousD, t, ATNSimulatorError)
return ATNSimulatorError
}
// create Newtarget state we'll add to DFA after it's complete
var D = NewDFAState(-1, reach)
@ -325,7 +325,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState
fmt.Sprint(PredictionModeallSubsetsConflict(altSubSets)) +
", conflictingAlts=" + this.getConflictingAlts(reach).String())
}
if predictedAlt != ATNINVALID_ALT_NUMBER {
if predictedAlt != ATNInvalidAltNumber {
// NO CONFLICT, UNIQUELY PREDICTED ALT
D.isAcceptState = true
D.configs.SetUniqueAlt( predictedAlt )
@ -341,7 +341,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState
if D.isAcceptState && D.configs.HasSemanticContext() {
this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision))
if D.predicates != nil {
D.setPrediction( ATNINVALID_ALT_NUMBER )
D.setPrediction(ATNInvalidAltNumber)
}
}
// all adds to dfa are done after we've created full D state
@ -349,7 +349,7 @@ func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState
return D
}
func (this *ParserATNSimulator) predicateDFAState(dfaState *DFAState, decisionState IDecisionState) {
func (this *ParserATNSimulator) predicateDFAState(dfaState *DFAState, decisionState DecisionState) {
// We need to test all predicates, even in DFA states that
// uniquely predict alternative.
var nalts = len(decisionState.GetTransitions())
@ -359,7 +359,7 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState *DFAState, decisionSt
var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts)
if altToPred != nil {
dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred)
dfaState.setPrediction( ATNINVALID_ALT_NUMBER ) // make sure we use preds
dfaState.setPrediction(ATNInvalidAltNumber) // 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
@ -369,7 +369,7 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState *DFAState, decisionSt
}
// comes back with reach.uniqueAlt set to a valid alt
func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0 ATNConfigSet, input TokenStream, startIndex int, outerContext IParserRuleContext) int {
func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0 ATNConfigSet, input TokenStream, startIndex int, outerContext ParserRuleContext) int {
if ParserATNSimulatorDebug || ParserATNSimulatorListATNDecisions {
fmt.Println("execATNWithFullContext " + s0.String())
@ -398,7 +398,7 @@ func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0
var e = this.noViableAlt(input, outerContext, previous, startIndex)
input.Seek(startIndex)
var alt = this.getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext)
if alt != ATNINVALID_ALT_NUMBER {
if alt != ATNInvalidAltNumber {
return alt
} else {
panic(e)
@ -412,12 +412,12 @@ func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0
}
reach.SetUniqueAlt( this.getUniqueAlt(reach) )
// unique prediction?
if reach.GetUniqueAlt() != ATNINVALID_ALT_NUMBER {
if reach.GetUniqueAlt() != ATNInvalidAltNumber {
predictedAlt = reach.GetUniqueAlt()
break
} else if this.predictionMode != PredictionModeLL_EXACT_AMBIG_DETECTION {
predictedAlt = PredictionModeresolvesToJustOneViableAlt(altSubSets)
if predictedAlt != ATNINVALID_ALT_NUMBER {
if predictedAlt != ATNInvalidAltNumber {
break
}
} else {
@ -441,7 +441,7 @@ func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0
// If the configuration set uniquely predicts an alternative,
// without conflict, then we know that it's a full LL decision
// not SLL.
if reach.GetUniqueAlt() != ATNINVALID_ALT_NUMBER {
if reach.GetUniqueAlt() != ATNInvalidAltNumber {
this.ReportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.Index())
return predictedAlt
}
@ -523,7 +523,7 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
var trans = c.GetState().GetTransitions()[j]
var target = this.getReachableTarget(trans, t)
if target != nil {
var cfg = NewATNConfig4(c, target)
var cfg = NewBaseATNConfig4(c, target)
intermediate.Add(cfg, this.mergeCache)
if ParserATNSimulatorDebug {
fmt.Println("added " + cfg.String() + " to intermediate")
@ -550,7 +550,7 @@ func (this *ParserATNSimulator) computeReachSet(closure ATNConfigSet, t int, ful
// Also don't pursue the closure if there is unique alternative
// among the configurations.
reach = intermediate
} else if this.getUniqueAlt(intermediate) != ATNINVALID_ALT_NUMBER {
} else if this.getUniqueAlt(intermediate) != ATNInvalidAltNumber {
// Also don't pursue the closure if there is unique alternative
// among the configurations.
reach = intermediate
@ -644,20 +644,20 @@ func (this *ParserATNSimulator) removeAllConfigsNotInRuleStopState(configs ATNCo
var nextTokens = this.atn.nextTokens(config.GetState(), nil)
if nextTokens.contains(TokenEpsilon) {
var endOfRuleState = this.atn.ruleToStopState[config.GetState().GetRuleIndex()]
result.Add(NewATNConfig4(config, endOfRuleState), this.mergeCache)
result.Add(NewBaseATNConfig4(config, endOfRuleState), this.mergeCache)
}
}
}
return result
}
func (this *ParserATNSimulator) computeStartState(p IATNState, ctx IRuleContext, fullCtx bool) ATNConfigSet {
func (this *ParserATNSimulator) computeStartState(p ATNState, ctx RuleContext, fullCtx bool) ATNConfigSet {
// always at least the implicit call to start rule
var initialContext = predictionContextFromRuleContext(this.atn, ctx)
var configs = NewBaseATNConfigSet(fullCtx)
for i := 0; i < len(p.GetTransitions()); i++ {
var target = p.GetTransitions()[i].getTarget()
var c = NewATNConfig6(target, i+1, initialContext)
var c = NewBaseATNConfig6(target, i+1, initialContext)
var closureBusy = NewSet(nil, nil)
this.closure(c, configs, closureBusy, true, fullCtx, false)
}
@ -737,7 +737,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs ATNConfigSet) ATNC
}
statesFromAlt1[config.GetState().GetStateNumber()] = config.GetContext()
if updatedContext != config.GetSemanticContext() {
configSet.Add(NewATNConfig2(config, updatedContext), this.mergeCache)
configSet.Add(NewBaseATNConfig2(config, updatedContext), this.mergeCache)
} else {
configSet.Add(config, this.mergeCache)
}
@ -762,7 +762,7 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs ATNConfigSet) ATNC
return configSet
}
func (this *ParserATNSimulator) getReachableTarget(trans ITransition, ttype int) IATNState {
func (this *ParserATNSimulator) getReachableTarget(trans Transition, ttype int) ATNState {
if trans.Matches(ttype, 0, this.atn.maxTokenType) {
return trans.getTarget()
} else {
@ -862,22 +862,22 @@ func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts *BitSet, altTo
// {@link ATN//INVALID_ALT_NUMBER} if a suitable alternative was not
// identified and {@link //AdaptivePredict} should Report an error instead.
//
func (this *ParserATNSimulator) getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(configs ATNConfigSet, outerContext IParserRuleContext) int {
func (this *ParserATNSimulator) getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(configs ATNConfigSet, outerContext ParserRuleContext) int {
var cfgs = this.splitAccordingToSemanticValidity(configs, outerContext)
var semValidConfigs = cfgs[0]
var semInvalidConfigs = cfgs[1]
var alt = this.GetAltThatFinishedDecisionEntryRule(semValidConfigs)
if alt != ATNINVALID_ALT_NUMBER { // semantically/syntactically viable path exists
if alt != ATNInvalidAltNumber { // semantically/syntactically viable path exists
return alt
}
// Is there a syntactically valid path with a failed pred?
if len(semInvalidConfigs.GetItems()) > 0 {
alt = this.GetAltThatFinishedDecisionEntryRule(semInvalidConfigs)
if alt != ATNINVALID_ALT_NUMBER { // syntactically viable path exists
if alt != ATNInvalidAltNumber { // syntactically viable path exists
return alt
}
}
return ATNINVALID_ALT_NUMBER
return ATNInvalidAltNumber
}
func (this *ParserATNSimulator) GetAltThatFinishedDecisionEntryRule(configs ATNConfigSet) int {
@ -891,7 +891,7 @@ func (this *ParserATNSimulator) GetAltThatFinishedDecisionEntryRule(configs ATNC
}
}
if alts.length() == 0 {
return ATNINVALID_ALT_NUMBER
return ATNInvalidAltNumber
} else {
return alts.first()
}
@ -910,7 +910,7 @@ type ATNConfigSetPair struct {
item0, item1 ATNConfigSet
}
func (this *ParserATNSimulator) splitAccordingToSemanticValidity(configs ATNConfigSet, outerContext IParserRuleContext) []ATNConfigSet {
func (this *ParserATNSimulator) splitAccordingToSemanticValidity(configs ATNConfigSet, outerContext ParserRuleContext) []ATNConfigSet {
var succeeded = NewBaseATNConfigSet(configs.FullContext())
var failed = NewBaseATNConfigSet(configs.FullContext())
@ -935,7 +935,7 @@ func (this *ParserATNSimulator) splitAccordingToSemanticValidity(configs ATNConf
// then we stop at the first predicate that evaluates to true. This
// includes pairs with nil predicates.
//
func (this *ParserATNSimulator) evalSemanticContext(predPredictions []*PredPrediction, outerContext IParserRuleContext, complete bool) *BitSet {
func (this *ParserATNSimulator) evalSemanticContext(predPredictions []*PredPrediction, outerContext ParserRuleContext, complete bool) *BitSet {
var predictions = NewBitSet()
for i := 0; i < len(predPredictions); i++ {
var pair = predPredictions[i]
@ -987,7 +987,7 @@ func (this *ParserATNSimulator) closureCheckingStopState(config ATNConfig, confi
for i := 0; i < config.GetContext().length(); i++ {
if config.GetContext().getReturnState(i) == PredictionContextEMPTY_RETURN_STATE {
if fullCtx {
configs.Add(NewATNConfig1(config, config.GetState(), PredictionContextEMPTY), this.mergeCache)
configs.Add(NewBaseATNConfig1(config, config.GetState(), PredictionContextEMPTY), this.mergeCache)
continue
} else {
// we have no context info, just chase follow links (if greedy)
@ -1004,7 +1004,7 @@ func (this *ParserATNSimulator) closureCheckingStopState(config ATNConfig, confi
returnState := this.atn.states[config.GetContext().getReturnState(i)]
newContext := config.GetContext().GetParent(i) // "pop" return state
c := NewATNConfig5(returnState, config.GetAlt(), newContext, config.GetSemanticContext())
c := NewBaseATNConfig5(returnState, config.GetAlt(), newContext, config.GetSemanticContext())
// While we have context to pop back from, we may have
// gotten that context AFTER having falling off a rule.
// Make sure we track that we are now out of context.
@ -1114,7 +1114,7 @@ func (this *ParserATNSimulator) getRuleName(index int) string {
}
}
func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t ITransition, collectPredicates, inContext, fullCtx, treatEofAsEpsilon bool) *BaseATNConfig {
func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t Transition, collectPredicates, inContext, fullCtx, treatEofAsEpsilon bool) *BaseATNConfig {
switch t.getSerializationType() {
case TransitionRULE:
@ -1126,13 +1126,13 @@ func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t ITransition
case TransitionACTION:
return this.actionTransition(config, t.(*ActionTransition))
case TransitionEPSILON:
return NewATNConfig4(config, t.getTarget())
return NewBaseATNConfig4(config, t.getTarget())
case TransitionATOM:
// EOF transitions act like epsilon transitions after the first EOF
// transition is traversed
if treatEofAsEpsilon {
if t.Matches(TokenEOF, 0, 1) {
return NewATNConfig4(config, t.getTarget())
return NewBaseATNConfig4(config, t.getTarget())
}
}
return nil
@ -1141,7 +1141,7 @@ func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t ITransition
// transition is traversed
if treatEofAsEpsilon {
if t.Matches(TokenEOF, 0, 1) {
return NewATNConfig4(config, t.getTarget())
return NewBaseATNConfig4(config, t.getTarget())
}
}
return nil
@ -1150,7 +1150,7 @@ func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t ITransition
// transition is traversed
if treatEofAsEpsilon {
if t.Matches(TokenEOF, 0, 1) {
return NewATNConfig4(config, t.getTarget())
return NewBaseATNConfig4(config, t.getTarget())
}
}
return nil
@ -1163,7 +1163,7 @@ func (this *ParserATNSimulator) actionTransition(config ATNConfig, t *ActionTran
if ParserATNSimulatorDebug {
fmt.Println("ACTION edge " + strconv.Itoa(t.ruleIndex) + ":" + strconv.Itoa(t.actionIndex))
}
return NewATNConfig4(config, t.getTarget())
return NewBaseATNConfig4(config, t.getTarget())
}
func (this *ParserATNSimulator) precedenceTransition(config ATNConfig,
@ -1188,14 +1188,14 @@ func (this *ParserATNSimulator) precedenceTransition(config ATNConfig,
var predSucceeds = pt.getPredicate().evaluate(this.parser, this._outerContext)
this._input.Seek(currentPosition)
if predSucceeds {
c = NewATNConfig4(config, pt.getTarget()) // no pred context
c = NewBaseATNConfig4(config, pt.getTarget()) // no pred context
}
} else {
newSemCtx := SemanticContextandContext(config.GetSemanticContext(), pt.getPredicate())
c = NewATNConfig3(config, pt.getTarget(), newSemCtx)
c = NewBaseATNConfig3(config, pt.getTarget(), newSemCtx)
}
} else {
c = NewATNConfig4(config, pt.getTarget())
c = NewBaseATNConfig4(config, pt.getTarget())
}
if ParserATNSimulatorDebug {
fmt.Println("config from pred transition=" + c.String())
@ -1224,14 +1224,14 @@ func (this *ParserATNSimulator) predTransition(config ATNConfig, pt *PredicateTr
var predSucceeds = pt.getPredicate().evaluate(this.parser, this._outerContext)
this._input.Seek(currentPosition)
if predSucceeds {
c = NewATNConfig4(config, pt.getTarget()) // no pred context
c = NewBaseATNConfig4(config, pt.getTarget()) // no pred context
}
} else {
var newSemCtx = SemanticContextandContext(config.GetSemanticContext(), pt.getPredicate())
c = NewATNConfig3(config, pt.getTarget(), newSemCtx)
c = NewBaseATNConfig3(config, pt.getTarget(), newSemCtx)
}
} else {
c = NewATNConfig4(config, pt.getTarget())
c = NewBaseATNConfig4(config, pt.getTarget())
}
if ParserATNSimulatorDebug {
fmt.Println("config from pred transition=" + c.String())
@ -1245,7 +1245,7 @@ func (this *ParserATNSimulator) ruleTransition(config ATNConfig, t *RuleTransiti
}
var returnState = t.followState
var newContext = SingletonPredictionContextCreate(config.GetContext(), returnState.GetStateNumber())
return NewATNConfig1(config, t.getTarget(), newContext)
return NewBaseATNConfig1(config, t.getTarget(), newContext)
}
func (this *ParserATNSimulator) getConflictingAlts(configs ATNConfigSet) *BitSet {
@ -1291,7 +1291,7 @@ func (this *ParserATNSimulator) getConflictingAlts(configs ATNConfigSet) *BitSet
func (this *ParserATNSimulator) getConflictingAltsOrUniqueAlt(configs ATNConfigSet) *BitSet {
var conflictingAlts *BitSet = nil
if configs.GetUniqueAlt() != ATNINVALID_ALT_NUMBER {
if configs.GetUniqueAlt() != ATNInvalidAltNumber {
conflictingAlts = NewBitSet()
conflictingAlts.add(configs.GetUniqueAlt())
} else {
@ -1360,17 +1360,17 @@ func (this *ParserATNSimulator) dumpDeadEndConfigs(nvae *NoViableAltException) {
// }
}
func (this *ParserATNSimulator) noViableAlt(input TokenStream, outerContext IParserRuleContext, configs ATNConfigSet, startIndex int) *NoViableAltException {
func (this *ParserATNSimulator) noViableAlt(input TokenStream, outerContext ParserRuleContext, configs ATNConfigSet, startIndex int) *NoViableAltException {
return NewNoViableAltException(this.parser, input, input.Get(startIndex), input.LT(1), configs, outerContext)
}
func (this *ParserATNSimulator) getUniqueAlt(configs ATNConfigSet) int {
var alt = ATNINVALID_ALT_NUMBER
var alt = ATNInvalidAltNumber
for _,c := range configs.GetItems() {
if alt == ATNINVALID_ALT_NUMBER {
if alt == ATNInvalidAltNumber {
alt = c.GetAlt() // found first alt
} else if c.GetAlt() != alt {
return ATNINVALID_ALT_NUMBER
return ATNInvalidAltNumber
}
}
return alt
@ -1439,7 +1439,7 @@ func (this *ParserATNSimulator) addDFAEdge(dfa *DFA, from_ *DFAState, t int, to
// state was not already present.
//
func (this *ParserATNSimulator) addDFAState(dfa *DFA, D *DFAState) *DFAState {
if D == ATNSimulatorERROR {
if D == ATNSimulatorError {
return D
}
var hash = D.Hash()
@ -1449,7 +1449,7 @@ func (this *ParserATNSimulator) addDFAState(dfa *DFA, D *DFAState) *DFAState {
}
D.stateNumber = len(dfa.GetStates())
if !D.configs.ReadOnly() {
D.configs.OptimizeConfigs(this.ATNSimulator)
D.configs.OptimizeConfigs(this.BaseATNSimulator)
D.configs.SetReadOnly(true)
}
dfa.GetStates()[hash] = D

View File

@ -4,10 +4,10 @@ import (
"reflect"
)
type IParserRuleContext interface {
IRuleContext
type ParserRuleContext interface {
RuleContext
SetException(IRecognitionException)
SetException(RecognitionException)
addTokenNode(token IToken) *TerminalNodeImpl
addErrorNode(badToken IToken) *ErrorNodeImpl
EnterRule(listener ParseTreeListener)
@ -19,23 +19,23 @@ type IParserRuleContext interface {
setStop(IToken)
getStop() IToken
addChild(child IRuleContext) IRuleContext
addChild(child RuleContext) RuleContext
removeLastChild()
}
type ParserRuleContext struct {
*RuleContext
type BaseParserRuleContext struct {
*BaseRuleContext
children []ParseTree
start, stop IToken
exception IRecognitionException
exception RecognitionException
}
func NewParserRuleContext(parent IParserRuleContext, invokingStateNumber int) *ParserRuleContext {
func NewBaseParserRuleContext(parent ParserRuleContext, invokingStateNumber int) *BaseParserRuleContext {
prc := new(ParserRuleContext)
prc := new(BaseParserRuleContext)
prc.RuleContext = NewRuleContext(parent, invokingStateNumber)
prc.BaseRuleContext = NewBaseRuleContext(parent, invokingStateNumber)
prc.RuleIndex = -1
// * If we are debugging or building a parse tree for a Visitor,
@ -55,26 +55,26 @@ func NewParserRuleContext(parent IParserRuleContext, invokingStateNumber int) *P
}
func (prc *ParserRuleContext) SetException(e IRecognitionException) {
func (prc *BaseParserRuleContext) SetException(e RecognitionException) {
prc.exception = e
}
func (prc *ParserRuleContext) GetParent() Tree {
func (prc *BaseParserRuleContext) GetParent() Tree {
return prc.parentCtx
}
func (prc *ParserRuleContext) setParent(ctx Tree) {
prc.parentCtx = ctx.(IParserRuleContext)
func (prc *BaseParserRuleContext) setParent(ctx Tree) {
prc.parentCtx = ctx.(ParserRuleContext)
}
func (prc *ParserRuleContext) setChildren(cs []Tree) {
func (prc *BaseParserRuleContext) setChildren(cs []Tree) {
prc.children = make([]ParseTree, len(cs))
for _, c := range cs {
prc.addChild(c.(IRuleContext))
prc.addChild(c.(RuleContext))
}
}
func (prc *ParserRuleContext) CopyFrom(ctx *ParserRuleContext) {
func (prc *BaseParserRuleContext) CopyFrom(ctx *BaseParserRuleContext) {
// from RuleContext
prc.parentCtx = ctx.parentCtx
prc.invokingState = ctx.invokingState
@ -84,14 +84,14 @@ func (prc *ParserRuleContext) CopyFrom(ctx *ParserRuleContext) {
}
// Double dispatch methods for listeners
func (prc *ParserRuleContext) EnterRule(listener ParseTreeListener) {
func (prc *BaseParserRuleContext) EnterRule(listener ParseTreeListener) {
}
func (prc *ParserRuleContext) ExitRule(listener ParseTreeListener) {
func (prc *BaseParserRuleContext) ExitRule(listener ParseTreeListener) {
}
// * Does not set parent link other add methods do that///
func (prc *ParserRuleContext) addTerminalNodeChild(child TerminalNode) TerminalNode {
func (prc *BaseParserRuleContext) addTerminalNodeChild(child TerminalNode) TerminalNode {
if prc.children == nil {
prc.children = make([]ParseTree, 0)
}
@ -99,7 +99,7 @@ func (prc *ParserRuleContext) addTerminalNodeChild(child TerminalNode) TerminalN
return child
}
func (prc *ParserRuleContext) addChild(child IRuleContext) IRuleContext {
func (prc *BaseParserRuleContext) addChild(child RuleContext) RuleContext {
if prc.children == nil {
prc.children = make([]ParseTree, 0)
}
@ -111,13 +111,13 @@ func (prc *ParserRuleContext) addChild(child IRuleContext) IRuleContext {
// we entered a rule. If we have // label, we will need to remove
// generic ruleContext object.
// /
func (prc *ParserRuleContext) removeLastChild() {
func (prc *BaseParserRuleContext) removeLastChild() {
if prc.children != nil && len(prc.children) > 0 {
prc.children = prc.children[0 : len(prc.children)-1]
}
}
func (prc *ParserRuleContext) addTokenNode(token IToken) *TerminalNodeImpl {
func (prc *BaseParserRuleContext) addTokenNode(token IToken) *TerminalNodeImpl {
var node = NewTerminalNodeImpl(token)
prc.addTerminalNodeChild(node)
@ -126,14 +126,14 @@ func (prc *ParserRuleContext) addTokenNode(token IToken) *TerminalNodeImpl {
}
func (prc *ParserRuleContext) addErrorNode(badToken IToken) *ErrorNodeImpl {
func (prc *BaseParserRuleContext) addErrorNode(badToken IToken) *ErrorNodeImpl {
var node = NewErrorNodeImpl(badToken)
prc.addTerminalNodeChild(node)
node.parentCtx = prc
return node
}
func (prc *ParserRuleContext) getChild(i int) Tree {
func (prc *BaseParserRuleContext) getChild(i int) Tree {
if prc.children != nil && len(prc.children) >= i {
return prc.children[i]
} else {
@ -141,15 +141,15 @@ func (prc *ParserRuleContext) getChild(i int) Tree {
}
}
func (prc *ParserRuleContext) getChildOfType(i int, childType reflect.Type) IRuleContext {
func (prc *BaseParserRuleContext) getChildOfType(i int, childType reflect.Type) RuleContext {
if childType == nil {
return prc.getChild(i).(IRuleContext)
return prc.getChild(i).(RuleContext)
} else {
for j := 0; j < len(prc.children); j++ {
var child = prc.children[j]
if reflect.TypeOf(child) == childType {
if i == 0 {
return child.(IRuleContext)
return child.(RuleContext)
} else {
i -= 1
}
@ -159,23 +159,23 @@ func (prc *ParserRuleContext) getChildOfType(i int, childType reflect.Type) IRul
}
}
func (prc *ParserRuleContext) setStart(t IToken) {
func (prc *BaseParserRuleContext) setStart(t IToken) {
prc.start = t
}
func (prc *ParserRuleContext) getStart() IToken {
func (prc *BaseParserRuleContext) getStart() IToken {
return prc.start
}
func (prc *ParserRuleContext) setStop(t IToken) {
func (prc *BaseParserRuleContext) setStop(t IToken) {
prc.stop = t
}
func (prc *ParserRuleContext) getStop() IToken {
func (prc *BaseParserRuleContext) getStop() IToken {
return prc.stop
}
func (prc *ParserRuleContext) GetToken(ttype int, i int) TerminalNode {
func (prc *BaseParserRuleContext) GetToken(ttype int, i int) TerminalNode {
for j := 0; j < len(prc.children); j++ {
var child = prc.children[j]
@ -192,7 +192,7 @@ func (prc *ParserRuleContext) GetToken(ttype int, i int) TerminalNode {
return nil
}
func (prc *ParserRuleContext) GetTokens(ttype int) []TerminalNode {
func (prc *BaseParserRuleContext) GetTokens(ttype int) []TerminalNode {
if prc.children == nil {
return make([]TerminalNode, 0)
} else {
@ -209,12 +209,12 @@ func (prc *ParserRuleContext) GetTokens(ttype int) []TerminalNode {
}
}
func (prc *ParserRuleContext) GetTypedRuleContext(ctxType reflect.Type, i int) interface{} {
func (prc *BaseParserRuleContext) GetTypedRuleContext(ctxType reflect.Type, i int) interface{} {
panic("GetTypedRuleContexts not implemented")
// return prc.getChild(i, ctxType)
}
func (prc *ParserRuleContext) GetTypedRuleContexts(ctxType reflect.Type) []interface{} {
func (prc *BaseParserRuleContext) GetTypedRuleContexts(ctxType reflect.Type) []interface{} {
panic("GetTypedRuleContexts not implemented")
// if (prc.children== nil) {
// return []
@ -230,7 +230,7 @@ func (prc *ParserRuleContext) GetTypedRuleContexts(ctxType reflect.Type) []inter
// }
}
func (prc *ParserRuleContext) getChildCount() int {
func (prc *BaseParserRuleContext) getChildCount() int {
if prc.children == nil {
return 0
} else {
@ -238,7 +238,7 @@ func (prc *ParserRuleContext) getChildCount() int {
}
}
func (prc *ParserRuleContext) GetSourceInterval() *Interval {
func (prc *BaseParserRuleContext) GetSourceInterval() *Interval {
if prc.start == nil || prc.stop == nil {
return TreeINVALID_INTERVAL
} else {
@ -246,21 +246,21 @@ func (prc *ParserRuleContext) GetSourceInterval() *Interval {
}
}
var RuleContextEMPTY = NewParserRuleContext(nil, -1)
var RuleContextEMPTY = NewBaseParserRuleContext(nil, -1)
type IInterpreterRuleContext interface {
IParserRuleContext
ParserRuleContext
}
type InterpreterRuleContext struct {
*ParserRuleContext
*BaseParserRuleContext
}
func NewInterpreterRuleContext(parent InterpreterRuleContext, invokingStateNumber, ruleIndex int) *InterpreterRuleContext {
prc := new(InterpreterRuleContext)
prc.ParserRuleContext = NewParserRuleContext(parent, invokingStateNumber)
prc.BaseParserRuleContext = NewBaseParserRuleContext(parent, invokingStateNumber)
prc.RuleIndex = ruleIndex

View File

@ -345,7 +345,7 @@ func (this *ArrayPredictionContext) String() string {
// Convert a {@link RuleContext} tree to a {@link PredictionContext} graph.
// Return {@link //EMPTY} if {@code outerContext} is empty or nil.
// /
func predictionContextFromRuleContext(a *ATN, outerContext IRuleContext) IPredictionContext {
func predictionContextFromRuleContext(a *ATN, outerContext RuleContext) IPredictionContext {
if outerContext == nil {
outerContext = RuleContextEMPTY
}
@ -355,7 +355,7 @@ func predictionContextFromRuleContext(a *ATN, outerContext IRuleContext) IPredic
return PredictionContextEMPTY
}
// If we have a parent, convert it to a PredictionContext graph
var parent = predictionContextFromRuleContext(a, outerContext.GetParent().(IRuleContext))
var parent = predictionContextFromRuleContext(a, outerContext.GetParent().(RuleContext))
var state = a.states[outerContext.getInvokingState()]
var transition = state.GetTransitions()[0]

View File

@ -183,8 +183,8 @@ func PredictionModehasSLLConflictTerminatingPrediction(mode int, configs ATNConf
var dup = NewBaseATNConfigSet(false)
for _, c := range configs.GetItems() {
// NewATNConfig({semanticContext:}, c)
c = NewATNConfig2(c, SemanticContextNONE)
// NewBaseATNConfig({semanticContext:}, c)
c = NewBaseATNConfig2(c, SemanticContextNONE)
dup.Add(c, nil)
}
configs = dup
@ -458,7 +458,7 @@ func PredictionModegetUniqueAlt(altsets []*BitSet) int {
if all.length() == 1 {
return all.minValue()
} else {
return ATNINVALID_ALT_NUMBER
return ATNInvalidAltNumber
}
}
@ -543,15 +543,15 @@ func PredictionModehasStateAssociatedWithOneAlt(configs ATNConfigSet) bool {
}
func PredictionModegetSingleViableAlt(altsets []*BitSet) int {
var result = ATNINVALID_ALT_NUMBER
var result = ATNInvalidAltNumber
for i := 0; i < len(altsets); i++ {
var alts = altsets[i]
var minAlt = alts.minValue()
if result == ATNINVALID_ALT_NUMBER {
if result == ATNInvalidAltNumber {
result = minAlt
} else if result != minAlt { // more than 1 viable alt
return ATNINVALID_ALT_NUMBER
return ATNInvalidAltNumber
}
}
return result

View File

@ -12,12 +12,12 @@ type Recognizer interface {
GetLiteralNames() []string
GetSymbolicNames() []string
GetRuleNames() []string
Sempred(localctx IRuleContext, ruleIndex int, actionIndex int) bool
Precpred(localctx IRuleContext, precedence int) bool
Sempred(localctx RuleContext, ruleIndex int, actionIndex int) bool
Precpred(localctx RuleContext, precedence int) bool
GetState() int
SetState(int)
Action(_localctx IRuleContext, ruleIndex, actionIndex int)
Action(_localctx RuleContext, ruleIndex, actionIndex int)
GetATN() *ATN
getErrorListenerDispatch() IErrorListener
@ -50,7 +50,7 @@ func (this *BaseRecognizer) checkVersion(toolVersion string) {
}
}
func (this *BaseRecognizer) Action(context IRuleContext, ruleIndex, actionIndex int) {
func (this *BaseRecognizer) Action(context RuleContext, ruleIndex, actionIndex int) {
panic("action not implemented on Recognizer!")
}
@ -162,7 +162,7 @@ func (this *BaseRecognizer) GetTokenType(tokenName string) int {
//}
// What is the error header, normally line/character position information?//
func (this *BaseRecognizer) getErrorHeader(e IRecognitionException) string {
func (this *BaseRecognizer) getErrorHeader(e RecognitionException) string {
var line = e.GetOffendingToken().GetLine()
var column = e.GetOffendingToken().GetColumn()
return "line " + strconv.Itoa(line) + ":" + strconv.Itoa(column)
@ -206,10 +206,10 @@ func (this *BaseRecognizer) getErrorListenerDispatch() IErrorListener {
// subclass needs to override these if there are sempreds or actions
// that the ATN interp needs to execute
func (this *BaseRecognizer) Sempred(localctx IRuleContext, ruleIndex int, actionIndex int) bool {
func (this *BaseRecognizer) Sempred(localctx RuleContext, ruleIndex int, actionIndex int) bool {
return true
}
func (this *BaseRecognizer) Precpred(localctx IRuleContext, precedence int) bool {
func (this *BaseRecognizer) Precpred(localctx RuleContext, precedence int) bool {
return true
}

View File

@ -25,7 +25,7 @@ import (
// @see ParserRuleContext
//
type IRuleContext interface {
type RuleContext interface {
RuleNode
getInvokingState() int
@ -35,19 +35,19 @@ type IRuleContext interface {
isEmpty() bool
String([]string, IRuleContext) string
String([]string, RuleContext) string
}
type RuleContext struct {
parentCtx IRuleContext
type BaseRuleContext struct {
parentCtx RuleContext
invokingState int
RuleIndex int
children []Tree
}
func NewRuleContext(parent IRuleContext, invokingState int) *RuleContext {
func NewBaseRuleContext(parent RuleContext, invokingState int) *BaseRuleContext {
rn := new(RuleContext)
rn := new(BaseRuleContext)
// What context invoked this rule?
rn.parentCtx = parent
@ -64,31 +64,31 @@ func NewRuleContext(parent IRuleContext, invokingState int) *RuleContext {
return rn
}
func (this *RuleContext) setChildren(elems []Tree) {
func (this *BaseRuleContext) setChildren(elems []Tree) {
this.children = elems
}
func (this *RuleContext) setParent(v Tree) {
this.parentCtx = v.(IRuleContext)
func (this *BaseRuleContext) setParent(v Tree) {
this.parentCtx = v.(RuleContext)
}
func (this *RuleContext) getInvokingState() int {
func (this *BaseRuleContext) getInvokingState() int {
return this.invokingState
}
func (this *RuleContext) setInvokingState(t int) {
func (this *BaseRuleContext) setInvokingState(t int) {
this.invokingState = t
}
func (this *RuleContext) GetRuleIndex() int {
func (this *BaseRuleContext) GetRuleIndex() int {
return this.RuleIndex
}
func (this *RuleContext) getChildren() []Tree {
func (this *BaseRuleContext) getChildren() []Tree {
return this.children
}
func (this *RuleContext) depth() int {
func (this *BaseRuleContext) depth() int {
var n = 0
var p Tree = this
for p != nil {
@ -100,21 +100,21 @@ func (this *RuleContext) depth() int {
// A context is empty if there is no invoking state meaning nobody call
// current context.
func (this *RuleContext) isEmpty() bool {
func (this *BaseRuleContext) isEmpty() bool {
return this.invokingState == -1
}
// satisfy the ParseTree / SyntaxTree interface
func (this *RuleContext) GetSourceInterval() *Interval {
func (this *BaseRuleContext) GetSourceInterval() *Interval {
return TreeINVALID_INTERVAL
}
func (this *RuleContext) getRuleContext() IRuleContext {
func (this *BaseRuleContext) getRuleContext() RuleContext {
return this
}
func (this *RuleContext) getPayload() interface{} {
func (this *BaseRuleContext) getPayload() interface{} {
return this
}
@ -125,32 +125,32 @@ func (this *RuleContext) getPayload() interface{} {
// added to the parse trees, they will not appear in the output of this
// method.
//
func (this *RuleContext) GetText() string {
func (this *BaseRuleContext) GetText() string {
if this.getChildCount() == 0 {
return ""
} else {
var s string
for _, child := range this.children {
s += child.(IRuleContext).GetText()
s += child.(RuleContext).GetText()
}
return s
}
}
func (this *RuleContext) getChild(i int) Tree {
func (this *BaseRuleContext) getChild(i int) Tree {
return nil
}
func (this *RuleContext) GetParent() Tree {
func (this *BaseRuleContext) GetParent() Tree {
return this.parentCtx
}
func (this *RuleContext) getChildCount() int {
func (this *BaseRuleContext) getChildCount() int {
return 0
}
func (this *RuleContext) accept(Visitor ParseTreeVisitor) interface{} {
func (this *BaseRuleContext) accept(Visitor ParseTreeVisitor) interface{} {
return Visitor.VisitChildren(this)
}
@ -160,13 +160,13 @@ func (this *RuleContext) accept(Visitor ParseTreeVisitor) interface{} {
// (root child1 .. childN). Print just a node if this is a leaf.
//
func (this *RuleContext) StringTree(ruleNames []string, recog Recognizer) string {
func (this *BaseRuleContext) StringTree(ruleNames []string, recog Recognizer) string {
return TreesStringTree(this, ruleNames, recog)
}
func (this *RuleContext) String(ruleNames []string, stop IRuleContext) string {
func (this *BaseRuleContext) String(ruleNames []string, stop RuleContext) string {
var p IRuleContext = this
var p RuleContext = this
var s = "["
for p != nil && p != stop {
if ruleNames == nil {
@ -183,12 +183,12 @@ func (this *RuleContext) String(ruleNames []string, stop IRuleContext) string {
}
s += ruleName
}
if p.GetParent() != nil && (ruleNames != nil || !p.GetParent().(IRuleContext).isEmpty()) {
if p.GetParent() != nil && (ruleNames != nil || !p.GetParent().(RuleContext).isEmpty()) {
s += " "
}
pi := p.GetParent()
if (pi != nil){
p = pi.(IRuleContext)
p = pi.(RuleContext)
} else {
p = nil
}

View File

@ -14,8 +14,8 @@ import (
//
type SemanticContext interface {
evaluate(parser Recognizer, outerContext IRuleContext) bool
evalPrecedence(parser Recognizer, outerContext IRuleContext) SemanticContext
evaluate(parser Recognizer, outerContext RuleContext) bool
evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext
equals(interface{}) bool
String() string
}
@ -73,13 +73,13 @@ func NewPredicate(ruleIndex, predIndex int, isCtxDependent bool) *Predicate {
var SemanticContextNONE SemanticContext = NewPredicate(-1, -1, false)
func (this *Predicate) evalPrecedence(parser Recognizer, outerContext IRuleContext) SemanticContext {
func (this *Predicate) evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext {
return this
}
func (this *Predicate) evaluate(parser Recognizer, outerContext IRuleContext) bool {
func (this *Predicate) evaluate(parser Recognizer, outerContext RuleContext) bool {
var localctx IRuleContext = nil
var localctx RuleContext = nil
if this.isCtxDependent {
localctx = outerContext
@ -120,11 +120,11 @@ func NewPrecedencePredicate(precedence int) *PrecedencePredicate {
return this
}
func (this *PrecedencePredicate) evaluate(parser Recognizer, outerContext IRuleContext) bool {
func (this *PrecedencePredicate) evaluate(parser Recognizer, outerContext RuleContext) bool {
return parser.Precpred(outerContext, this.precedence)
}
func (this *PrecedencePredicate) evalPrecedence(parser Recognizer, outerContext IRuleContext) SemanticContext {
func (this *PrecedencePredicate) evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext {
if parser.Precpred(outerContext, this.precedence) {
return SemanticContextNONE
} else {
@ -243,7 +243,7 @@ func (this *AND) Hash() string {
// The evaluation of predicates by this context is short-circuiting, but
// unordered.</p>
//
func (this *AND) evaluate(parser Recognizer, outerContext IRuleContext) bool {
func (this *AND) evaluate(parser Recognizer, outerContext RuleContext) bool {
for i := 0; i < len(this.opnds); i++ {
if !this.opnds[i].evaluate(parser, outerContext) {
return false
@ -252,7 +252,7 @@ func (this *AND) evaluate(parser Recognizer, outerContext IRuleContext) bool {
return true
}
func (this *AND) evalPrecedence(parser Recognizer, outerContext IRuleContext) SemanticContext {
func (this *AND) evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext {
var differs = false
var operands = make([]SemanticContext, 0)
@ -379,7 +379,7 @@ func (this *OR) Hash() string {
// The evaluation of predicates by this context is short-circuiting, but
// unordered.</p>
//
func (this *OR) evaluate(parser Recognizer, outerContext IRuleContext) bool {
func (this *OR) evaluate(parser Recognizer, outerContext RuleContext) bool {
for i := 0; i < len(this.opnds); i++ {
if this.opnds[i].evaluate(parser, outerContext) {
return true
@ -388,7 +388,7 @@ func (this *OR) evaluate(parser Recognizer, outerContext IRuleContext) bool {
return false
}
func (this *OR) evalPrecedence(parser Recognizer, outerContext IRuleContext) SemanticContext {
func (this *OR) evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext {
var differs = false
var operands = make([]SemanticContext, 0)
for i := 0; i < len(this.opnds); i++ {

View File

@ -11,6 +11,6 @@ type TokenStream interface {
GetAllText() string
GetTextFromInterval(*Interval) string
GetTextFromRuleContext(IRuleContext) string
GetTextFromRuleContext(RuleContext) string
GetTextFromTokens(IToken, IToken) string
}

View File

@ -15,7 +15,7 @@ func NewTraceListener(parser *BaseParser) *TraceListener {
func (this *TraceListener) VisitErrorNode(_ ErrorNode) {
}
func (this *TraceListener) EnterEveryRule(ctx IParserRuleContext) {
func (this *TraceListener) EnterEveryRule(ctx ParserRuleContext) {
fmt.Println("enter " + this.parser.GetRuleNames()[ctx.GetRuleIndex()] + ", LT(1)=" + this.parser._input.LT(1).GetText())
}
@ -23,6 +23,6 @@ func (this *TraceListener) VisitTerminal(node TerminalNode) {
fmt.Println("consume " + fmt.Sprint(node.getSymbol()) + " rule " + this.parser.GetRuleNames()[this.parser._ctx.GetRuleIndex()])
}
func (this *TraceListener) ExitEveryRule(ctx IParserRuleContext) {
func (this *TraceListener) ExitEveryRule(ctx ParserRuleContext) {
fmt.Println("exit " + this.parser.GetRuleNames()[ctx.GetRuleIndex()] + ", LT(1)=" + this.parser._input.LT(1).GetText())
}

View File

@ -14,30 +14,30 @@ import (
// the states. We'll use the term Edge for the DFA to distinguish them from
// ATN transitions.</p>
type ITransition interface {
getTarget() IATNState
setTarget(IATNState)
type Transition interface {
getTarget() ATNState
setTarget(ATNState)
getIsEpsilon() bool
getLabel() *IntervalSet
getSerializationType() int
Matches(int, int, int) bool
}
type Transition struct {
target IATNState
type BaseTransition struct {
target ATNState
isEpsilon bool
label_ int
label *IntervalSet
serializationType int
}
func NewTransition(target IATNState) *Transition {
func NewBaseTransition(target ATNState) *BaseTransition {
if target == nil || target == nil {
panic("target cannot be nil.")
}
t := new(Transition)
t := new(BaseTransition)
t.target = target
// Are we epsilon, action, sempred?
@ -47,27 +47,27 @@ func NewTransition(target IATNState) *Transition {
return t
}
func (t *Transition) getTarget() IATNState {
func (t *BaseTransition) getTarget() ATNState {
return t.target
}
func (t *Transition) setTarget(s IATNState) {
func (t *BaseTransition) setTarget(s ATNState) {
t.target = s
}
func (t *Transition) getIsEpsilon() bool {
func (t *BaseTransition) getIsEpsilon() bool {
return t.isEpsilon
}
func (t *Transition) getLabel() *IntervalSet {
func (t *BaseTransition) getLabel() *IntervalSet {
return t.label
}
func (t *Transition) getSerializationType() int {
func (t *BaseTransition) getSerializationType() int {
return t.serializationType
}
func (t *Transition) Matches(symbol, minVocabSymbol, maxVocabSymbol int) bool {
func (t *BaseTransition) Matches(symbol, minVocabSymbol, maxVocabSymbol int) bool {
panic("Not implemented")
}
@ -124,13 +124,13 @@ var TransitionserializationNames = []string{
// TODO: make all transitions sets? no, should remove set edges
type AtomTransition struct {
*Transition
*BaseTransition
}
func NewAtomTransition(target IATNState, label int) *AtomTransition {
func NewAtomTransition(target ATNState, label int) *AtomTransition {
t := new(AtomTransition)
t.Transition = NewTransition(target)
t.BaseTransition = NewBaseTransition(target)
t.label_ = label // The token type or character value or, signifies special label.
t.label = t.makeLabel()
@ -154,16 +154,16 @@ func (t *AtomTransition) String() string {
}
type RuleTransition struct {
*Transition
*BaseTransition
followState IATNState
followState ATNState
ruleIndex, precedence int
}
func NewRuleTransition(ruleStart IATNState, ruleIndex, precedence int, followState IATNState) *RuleTransition {
func NewRuleTransition(ruleStart ATNState, ruleIndex, precedence int, followState ATNState) *RuleTransition {
t := new(RuleTransition)
t.Transition = NewTransition(ruleStart)
t.BaseTransition = NewBaseTransition(ruleStart)
t.ruleIndex = ruleIndex
t.precedence = precedence
@ -179,15 +179,15 @@ func (t *RuleTransition) Matches(symbol, minVocabSymbol, maxVocabSymbol int) boo
}
type EpsilonTransition struct {
*Transition
*BaseTransition
outermostPrecedenceReturn int
}
func NewEpsilonTransition(target IATNState, outermostPrecedenceReturn int) *EpsilonTransition {
func NewEpsilonTransition(target ATNState, outermostPrecedenceReturn int) *EpsilonTransition {
t := new(EpsilonTransition)
t.Transition = NewTransition(target)
t.BaseTransition = NewBaseTransition(target)
t.serializationType = TransitionEPSILON
t.isEpsilon = true
@ -204,15 +204,15 @@ func (t *EpsilonTransition) String() string {
}
type RangeTransition struct {
*Transition
*BaseTransition
start, stop int
}
func NewRangeTransition(target IATNState, start, stop int) *RangeTransition {
func NewRangeTransition(target ATNState, start, stop int) *RangeTransition {
t := new(RangeTransition)
t.Transition = NewTransition(target)
t.BaseTransition = NewBaseTransition(target)
t.serializationType = TransitionRANGE
t.start = start
@ -235,36 +235,36 @@ func (t *RangeTransition) String() string {
return "'" + string(t.start) + "'..'" + string(t.stop) + "'"
}
type IAbstractPredicateTransition interface {
ITransition
type AbstractPredicateTransition interface {
Transition
IAbstractPredicateTransitionFoo()
}
type AbstractPredicateTransition struct {
*Transition
type BaseAbstractPredicateTransition struct {
*BaseTransition
}
func NewAbstractPredicateTransition(target IATNState) *AbstractPredicateTransition {
func NewBasePredicateTransition(target ATNState) *BaseAbstractPredicateTransition {
t := new(AbstractPredicateTransition)
t.Transition = NewTransition(target)
t := new(BaseAbstractPredicateTransition)
t.BaseTransition = NewBaseTransition(target)
return t
}
func (a *AbstractPredicateTransition) IAbstractPredicateTransitionFoo(){}
func (a *BaseAbstractPredicateTransition) IAbstractPredicateTransitionFoo(){}
type PredicateTransition struct {
*AbstractPredicateTransition
*BaseAbstractPredicateTransition
isCtxDependent bool
ruleIndex, predIndex int
}
func NewPredicateTransition(target IATNState, ruleIndex, predIndex int, isCtxDependent bool) *PredicateTransition {
func NewPredicateTransition(target ATNState, ruleIndex, predIndex int, isCtxDependent bool) *PredicateTransition {
t := new(PredicateTransition)
t.AbstractPredicateTransition = NewAbstractPredicateTransition(target)
t.BaseAbstractPredicateTransition = NewBasePredicateTransition(target)
t.serializationType = TransitionPREDICATE
t.ruleIndex = ruleIndex
@ -287,16 +287,16 @@ func (t *PredicateTransition) String() string {
}
type ActionTransition struct {
*Transition
*BaseTransition
isCtxDependent bool
ruleIndex, actionIndex, predIndex int
}
func NewActionTransition(target IATNState, ruleIndex, actionIndex int, isCtxDependent bool) *ActionTransition {
func NewActionTransition(target ATNState, ruleIndex, actionIndex int, isCtxDependent bool) *ActionTransition {
t := new(ActionTransition)
t.Transition = NewTransition(target)
t.BaseTransition = NewBaseTransition(target)
t.serializationType = TransitionACTION
t.ruleIndex = ruleIndex
@ -315,13 +315,13 @@ func (t *ActionTransition) String() string {
}
type SetTransition struct {
*Transition
*BaseTransition
}
func NewSetTransition(target IATNState, set *IntervalSet) *SetTransition {
func NewSetTransition(target ATNState, set *IntervalSet) *SetTransition {
t := new(SetTransition)
t.Transition = NewTransition(target)
t.BaseTransition = NewBaseTransition(target)
t.serializationType = TransitionSET
if set != nil && set != nil {
@ -346,7 +346,7 @@ type NotSetTransition struct {
*SetTransition
}
func NewNotSetTransition(target IATNState, set *IntervalSet) *NotSetTransition {
func NewNotSetTransition(target ATNState, set *IntervalSet) *NotSetTransition {
t := new(NotSetTransition)
@ -366,13 +366,13 @@ func (t *NotSetTransition) String() string {
}
type WildcardTransition struct {
*Transition
*BaseTransition
}
func NewWildcardTransition(target IATNState) *WildcardTransition {
func NewWildcardTransition(target ATNState) *WildcardTransition {
t := new(WildcardTransition)
t.Transition = NewTransition(target)
t.BaseTransition = NewBaseTransition(target)
t.serializationType = TransitionWILDCARD
return t
@ -387,15 +387,15 @@ func (t *WildcardTransition) String() string {
}
type PrecedencePredicateTransition struct {
*AbstractPredicateTransition
*BaseAbstractPredicateTransition
precedence int
}
func NewPrecedencePredicateTransition(target IATNState, precedence int) *PrecedencePredicateTransition {
func NewPrecedencePredicateTransition(target ATNState, precedence int) *PrecedencePredicateTransition {
t := new(PrecedencePredicateTransition)
t.AbstractPredicateTransition = NewAbstractPredicateTransition(target)
t.BaseAbstractPredicateTransition = NewBasePredicateTransition(target)
t.serializationType = TransitionPRECEDENCE
t.precedence = precedence

View File

@ -35,7 +35,7 @@ type ParseTree interface {
type RuleNode interface {
ParseTree
getRuleContext() IRuleContext
getRuleContext() RuleContext
}
type TerminalNode interface {
@ -80,12 +80,12 @@ type ParseTreeVisitor interface {
type ParseTreeListener interface {
VisitTerminal(node TerminalNode)
VisitErrorNode(node ErrorNode)
EnterEveryRule(ctx IParserRuleContext)
ExitEveryRule(ctx IParserRuleContext)
EnterEveryRule(ctx ParserRuleContext)
ExitEveryRule(ctx ParserRuleContext)
}
type TerminalNodeImpl struct {
parentCtx IRuleContext
parentCtx RuleContext
symbol IToken
}
@ -121,7 +121,7 @@ func (this *TerminalNodeImpl) GetParent() Tree {
}
func (this *TerminalNodeImpl) setParent(t Tree) {
this.parentCtx = t.(IRuleContext)
this.parentCtx = t.(RuleContext)
}
func (this *TerminalNodeImpl) getPayload() interface{} {
@ -210,13 +210,13 @@ func (this *ParseTreeWalker) walk(listener ParseTreeListener, t Tree) {
// the rule specific. We to them in reverse order upon finishing the node.
//
func (this *ParseTreeWalker) EnterRule(listener ParseTreeListener, r RuleNode) {
var ctx = r.getRuleContext().(IParserRuleContext)
var ctx = r.getRuleContext().(ParserRuleContext)
listener.EnterEveryRule(ctx)
ctx.EnterRule(listener)
}
func (this *ParseTreeWalker) ExitRule(listener ParseTreeListener, r RuleNode) {
var ctx = r.getRuleContext().(IParserRuleContext)
var ctx = r.getRuleContext().(ParserRuleContext)
ctx.ExitRule(listener)
listener.ExitEveryRule(ctx)
}

View File

@ -101,7 +101,7 @@ func Trees_findAllNodes(t ParseTree, index int, findTokens bool, nodes []ParseTr
// check this node (the root) first
t2, ok := t.(TerminalNode)
t3, ok2 := t.(IParserRuleContext)
t3, ok2 := t.(ParserRuleContext)
if findTokens && ok {
if t2.getSymbol().GetTokenType() == index {

View File

@ -40,10 +40,10 @@ type <file.grammarName>Listener struct {
}
func (l *<file.grammarName>Listener) EnterEveryRule(node antlr4.IParserRuleContext) {
func (l *<file.grammarName>Listener) EnterEveryRule(node antlr4.ParserRuleContext) {
\}
func (l *<file.grammarName>Listener) ExitEveryRule(node antlr4.IParserRuleContext) {
func (l *<file.grammarName>Listener) ExitEveryRule(node antlr4.ParserRuleContext) {
\}
func (l *<file.grammarName>Listener) VisitTerminal(ctx antlr4.TerminalNode) {
@ -54,11 +54,11 @@ func (l *<file.grammarName>Listener) VisitErrorNode(ctx antlr4.ErrorNode) {
<file.listenerNames:{lname |
// Enter a parse tree produced by <file.parserName>#<lname>.
func (l *<file.grammarName>Listener) Enter<lname; format="cap">(ctx antlr4.IParserRuleContext) {
func (l *<file.grammarName>Listener) Enter<lname; format="cap">(ctx antlr4.ParserRuleContext) {
\}
// Exit a parse tree produced by <file.parserName>#<lname>.
func (l *<file.grammarName>Listener) Exit<lname; format="cap">(ctx antlr4.IParserRuleContext) {
func (l *<file.grammarName>Listener) Exit<lname; format="cap">(ctx antlr4.ParserRuleContext) {
\}
}; separator="\n">
@ -86,7 +86,7 @@ type <file.grammarName>Visitor struct {
<file.VisitorNames:{lname |
// Visit a parse tree produced by <file.parserName>#<lname>.
func (l <file.grammarName>Visitor) Visit<lname; format="cap">(ctx IParserRuleContext) {
func (l <file.grammarName>Visitor) Visit<lname; format="cap">(ctx antlr4.ParserRuleContext) {
\}
}; separator="\n">
@ -108,7 +108,7 @@ var symbolicNames = []string{ <parser.symbolicNames:{t | <t>}; null="\"\"", sepa
var ruleNames = []string{ <parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor> }
type <parser.name> struct {
<superClass; null="*antlr4.Parser">
<superClass; null="*antlr4.BaseParser">
}
func New<parser.name>(input antlr4.TokenStream) *<parser.name> {
@ -122,7 +122,7 @@ func New<parser.name>(input antlr4.TokenStream) *<parser.name> {
parser := new(<parser.name>)
parser.Parser = antlr4.NewParser(input)
parser.BaseParser = antlr4.NewBaseParser(input)
parser.Interpreter = antlr4.NewParserATNSimulator(parser, deserializedATN, decisionToDFA, sharedContextCache)
parser.RuleNames = ruleNames
@ -249,7 +249,7 @@ func (p *<parser.name>) <currentRule.name; format="cap">(<currentRule.args:{a |
<if(exceptions)>
<exceptions; separator="\n">
<else>
if v, ok := err.(antlr4.IRecognitionException); ok {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException( v )
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
@ -278,7 +278,7 @@ LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,
func (p *<parser.name>) <currentRule.name; format="cap">(_p<if(currentRule.args)>, <args:{a | , <a>}><endif>) *<currentRule.ctxType> {
_parentctx := p.GetParent().(IParserRuleContext)
_parentctx := p.GetParent().(ParserRuleContext)
_parentState := p.GetState()
localctx := New<currentRule.ctxType>(p, p.GetParserRuleContext(), _parentState<args:{a | , <a.name>}>)
_prevctx := localctx
@ -294,7 +294,7 @@ func (p *<parser.name>) <currentRule.name; format="cap">(_p<if(currentRule.args)
defer func(){
if err := recover(); err != nil {
if v, ok := err.(antlr4.IRecognitionException); ok {
if v, ok := err.(antlr4.RecognitionException); ok {
localctx.SetException(v)
p.GetErrorHandler().ReportError(p, v)
p.GetErrorHandler().Recover(p, v)
@ -654,16 +654,16 @@ StructDecl(struct,ctorAttrs,attrs,getters,dispatchMethods,interfaces,extensionMe
superClass={ParserRuleContext}) ::= <<
type <struct.name> struct {
*antlr4.ParserRuleContext
*antlr4.BaseParserRuleContext
parser antlr4.IParser
parser antlr4.Parser
}
func New<struct.name>(parser antlr4.IParser, parent antlr4.IParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name>}>) *<struct.name> {
func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name>}>) *<struct.name> {
var p = new(<struct.name>)
p.ParserRuleContext = antlr4.NewParserRuleContext( parent, invokingState )
p.BaseParserRuleContext = antlr4.NewBaseParserRuleContext( parent, invokingState )
p.parser = parser
p.RuleIndex = <parser.name>RULE_<struct.derivedFromName>
@ -688,11 +688,11 @@ func (s *<struct.name>) CopyFrom(ctx <struct.name>) {
AltLabelStructDecl(struct,attrs,getters,dispatchMethods) ::= <<
type <struct.name> struct {
parent antlr4.IParserRuleContext
parser antlr4.IParser
parent antlr4.ParserRuleContext
parser antlr4.Parser
}
func New<struct.name>(parser antlr4.IParser, ctx antlr4.IParserRuleContext) *<struct.name> {
func New<struct.name>(parser antlr4.Parser, ctx antlr4.ParserRuleContext) *<struct.name> {
var p = new(<struct.name>)
@ -807,7 +807,7 @@ var lexerSymbolicNames = []string{ <lexer.symbolicNames:{t | <t>}; null="\"\"",
var lexerRuleNames = []string{ <lexer.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor> }
type <lexer.name> struct {
*<if(superClass)><superClass><else>antlr4.Lexer<endif>
*<if(superClass)><superClass><else>antlr4.BaseLexer<endif>
modeNames []string
// EOF string
@ -823,7 +823,7 @@ func New<lexer.name>(input antlr4.CharStream) *<lexer.name> {
lex := new(<lexer.name>)
lex.Lexer = antlr4.NewLexer(input)
lex.BaseLexer = antlr4.NewBaseLexer(input)
lex.Interpreter = antlr4.NewLexerATNSimulator(lex, lexerAtn, lexerDecisionToDFA, antlr4.NewPredictionContextCache())