forked from jasder/antlr
More cleanup to ensure embedded fields are initialized
This commit is contained in:
parent
8cba3ecc3a
commit
ce20f3ff31
|
@ -189,7 +189,7 @@ func (this *ATNConfig) toString() string {
|
|||
}
|
||||
|
||||
type LexerATNConfig struct {
|
||||
ATNConfig
|
||||
*ATNConfig
|
||||
|
||||
lexerActionExecutor *LexerActionExecutor
|
||||
passedThroughNonGreedyDecision bool
|
||||
|
@ -199,7 +199,7 @@ func NewLexerATNConfig6(state IATNState, alt int, context IPredictionContext) *L
|
|||
|
||||
this := new(LexerATNConfig)
|
||||
|
||||
this.ATNConfig = NewATNConfig(state, alt, context, SemanticContextNONE)
|
||||
this.ATNConfig = NewATNConfig5(state, alt, context, SemanticContextNONE)
|
||||
|
||||
this.passedThroughNonGreedyDecision = false
|
||||
this.lexerActionExecutor = nil
|
||||
|
@ -210,7 +210,7 @@ func NewLexerATNConfig5(state IATNState, alt int, context IPredictionContext, le
|
|||
|
||||
this := new(LexerATNConfig)
|
||||
|
||||
this.ATNConfig = NewATNConfig(state, alt, context, SemanticContextNONE)
|
||||
this.ATNConfig = NewATNConfig5(state, alt, context, SemanticContextNONE)
|
||||
this.lexerActionExecutor = lexerActionExecutor
|
||||
this.passedThroughNonGreedyDecision = false
|
||||
return this
|
||||
|
@ -250,8 +250,7 @@ func NewLexerATNConfig1(state IATNState, alt int, context IPredictionContext) *L
|
|||
|
||||
this := new(LexerATNConfig)
|
||||
|
||||
// c IATNConfig , state IATNState, context IPredictionContext, semanticContext SemanticContext
|
||||
this.ATNConfig = NewATNConfig(state, alt, context, SemanticContextNONE)
|
||||
this.ATNConfig = NewATNConfig5(state, alt, context, SemanticContextNONE)
|
||||
|
||||
this.lexerActionExecutor = nil
|
||||
this.passedThroughNonGreedyDecision = false
|
||||
|
|
|
@ -40,14 +40,7 @@ type ATNConfigSet struct {
|
|||
|
||||
func NewATNConfigSet(fullCtx bool) *ATNConfigSet {
|
||||
|
||||
this := new(ATNConfigSet)
|
||||
|
||||
this.ATNConfigSet = NewATNConfigSet(fullCtx)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (a *ATNConfigSet) InitATNConfigSet(fullCtx bool) {
|
||||
a := new(ATNConfigSet)
|
||||
|
||||
// The reason that we need a.is because we don't want the hash map to use
|
||||
// the standard hash code and equals. We need all configurations with the
|
||||
|
@ -86,6 +79,8 @@ func (a *ATNConfigSet) InitATNConfigSet(fullCtx bool) {
|
|||
a.dipsIntoOuterContext = false
|
||||
|
||||
a.cachedHashString = "-1"
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// Adding a Newconfig means merging contexts with existing configs for
|
||||
|
|
|
@ -112,7 +112,7 @@ func (this *ATNDeserializer) reset(data []uint16) {
|
|||
// don't adjust the first value since that's the version number
|
||||
if i == 0 {
|
||||
temp[i] = c
|
||||
} else{
|
||||
} else {
|
||||
temp[i] = c - 2
|
||||
}
|
||||
}
|
||||
|
@ -284,14 +284,14 @@ func (this *ATNDeserializer) readEdges(atn *ATN, sets []*IntervalSet) {
|
|||
continue
|
||||
}
|
||||
var outermostPrecedenceReturn = -1
|
||||
if atn.ruleToStartState[t.getTarGet().GetRuleIndex()].isPrecedenceRule {
|
||||
if atn.ruleToStartState[t.getTarget().GetRuleIndex()].isPrecedenceRule {
|
||||
if t.precedence == 0 {
|
||||
outermostPrecedenceReturn = t.getTarGet().GetRuleIndex()
|
||||
outermostPrecedenceReturn = t.getTarget().GetRuleIndex()
|
||||
}
|
||||
}
|
||||
|
||||
trans := NewEpsilonTransition(t.followState, outermostPrecedenceReturn)
|
||||
atn.ruleToStopState[t.getTarGet().GetRuleIndex()].AddTransition(trans, -1)
|
||||
atn.ruleToStopState[t.getTarget().GetRuleIndex()].AddTransition(trans, -1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,14 +311,14 @@ func (this *ATNDeserializer) readEdges(atn *ATN, sets []*IntervalSet) {
|
|||
}
|
||||
if s2, ok := state.(*PlusLoopbackState); ok {
|
||||
for j := 0; j < len(s2.GetTransitions()); j++ {
|
||||
target := s2.GetTransitions()[j].getTarGet()
|
||||
target := s2.GetTransitions()[j].getTarget()
|
||||
if t2, ok := target.(*PlusBlockStartState); ok {
|
||||
t2.loopBackState = state
|
||||
}
|
||||
}
|
||||
} else if s2, ok := state.(*StarLoopbackState); ok {
|
||||
for j := 0; j < len(s2.GetTransitions()); j++ {
|
||||
target := s2.GetTransitions()[j].getTarGet()
|
||||
target := s2.GetTransitions()[j].getTarget()
|
||||
if t2, ok := target.(*StarLoopEntryState); ok {
|
||||
t2.loopBackState = state
|
||||
}
|
||||
|
@ -413,8 +413,8 @@ func (this *ATNDeserializer) generateRuleBypassTransition(atn *ATN, idx int) {
|
|||
if transition == excludeTransition {
|
||||
continue
|
||||
}
|
||||
if transition.getTarGet() == endState {
|
||||
transition.setTarGet(bypassStop)
|
||||
if transition.getTarget() == endState {
|
||||
transition.setTarget(bypassStop)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -444,12 +444,12 @@ func (this *ATNDeserializer) stateIsEndStateFor(state IATNState, idx int) IATNSt
|
|||
if _, ok := state.(*StarLoopEntryState); !ok {
|
||||
return nil
|
||||
}
|
||||
var maybeLoopEndState = state.GetTransitions()[len(state.GetTransitions())-1].getTarGet()
|
||||
var maybeLoopEndState = state.GetTransitions()[len(state.GetTransitions())-1].getTarget()
|
||||
if _, ok := maybeLoopEndState.(*LoopEndState); !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, ok := maybeLoopEndState.GetTransitions()[0].getTarGet().(*RuleStopState)
|
||||
_, ok := maybeLoopEndState.GetTransitions()[0].getTarget().(*RuleStopState)
|
||||
|
||||
if maybeLoopEndState.(*LoopEndState).epsilonOnlyTransitions && ok {
|
||||
return state
|
||||
|
@ -476,9 +476,9 @@ func (this *ATNDeserializer) markPrecedenceDecisions(atn *ATN) {
|
|||
// precedence rule should continue or complete.
|
||||
//
|
||||
if atn.ruleToStartState[state.GetRuleIndex()].isPrecedenceRule {
|
||||
var maybeLoopEndState = state.GetTransitions()[len(state.GetTransitions())-1].getTarGet()
|
||||
var maybeLoopEndState = state.GetTransitions()[len(state.GetTransitions())-1].getTarget()
|
||||
if s3, ok := maybeLoopEndState.(*LoopEndState); ok {
|
||||
s := maybeLoopEndState.GetTransitions()[0].getTarGet()
|
||||
s := maybeLoopEndState.GetTransitions()[0].getTarget()
|
||||
_, ok2 := s.(*RuleStopState)
|
||||
if s3.epsilonOnlyTransitions && ok2 {
|
||||
s.(*StarLoopEntryState).precedenceRuleDecision = true
|
||||
|
@ -512,11 +512,11 @@ func (this *ATNDeserializer) verifyATN(atn *ATN) {
|
|||
|
||||
switch s2 := state.(type) {
|
||||
case *StarBlockStartState:
|
||||
_, ok2 := s2.GetTransitions()[1].getTarGet().(*LoopEndState)
|
||||
_, ok2 := s2.GetTransitions()[1].getTarget().(*LoopEndState)
|
||||
this.checkCondition(ok2, "")
|
||||
this.checkCondition(!s2.nonGreedy, "")
|
||||
case *LoopEndState:
|
||||
s3, ok2 := s2.GetTransitions()[1].getTarGet().(*StarBlockStartState)
|
||||
s3, ok2 := s2.GetTransitions()[1].getTarget().(*StarBlockStartState)
|
||||
this.checkCondition(ok2, "")
|
||||
this.checkCondition(s3.nonGreedy, "")
|
||||
default:
|
||||
|
@ -525,7 +525,7 @@ func (this *ATNDeserializer) verifyATN(atn *ATN) {
|
|||
|
||||
case *StarLoopbackState:
|
||||
this.checkCondition(len(state.GetTransitions()) == 1, "")
|
||||
_, ok2 := state.GetTransitions()[0].getTarGet().(*StarLoopEntryState)
|
||||
_, ok2 := state.GetTransitions()[0].getTarget().(*StarLoopEntryState)
|
||||
this.checkCondition(ok2, "")
|
||||
case *LoopEndState:
|
||||
this.checkCondition(s2.loopBackState != nil, "")
|
||||
|
@ -638,6 +638,7 @@ func (this *ATNDeserializer) edgeFactory(atn *ATN, typeIndex, src, trg, arg1, ar
|
|||
}
|
||||
|
||||
func (this *ATNDeserializer) stateFactory(typeIndex, ruleIndex int) IATNState {
|
||||
|
||||
var s IATNState
|
||||
switch typeIndex {
|
||||
case ATNStateInvalidType:
|
||||
|
|
|
@ -9,14 +9,10 @@ func NewATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) *ATNS
|
|||
|
||||
this := new(ATNSimulator)
|
||||
|
||||
this.ATNSimulator = NewATNSimulator(atn, sharedContextCache)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ATNSimulator) InitATNSimulator(atn *ATN, sharedContextCache *PredictionContextCache) {
|
||||
this.atn = atn
|
||||
this.sharedContextCache = sharedContextCache
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
var ATNSimulatorERROR = NewDFAState(0x7FFFFFFF, NewATNConfigSet(false))
|
||||
|
|
|
@ -78,12 +78,6 @@ type ATNState struct {
|
|||
func NewATNState() *ATNState {
|
||||
|
||||
as := new(ATNState)
|
||||
as.ATNState = NewATNState()
|
||||
|
||||
return as
|
||||
}
|
||||
|
||||
func (as *ATNState) InitATNState() {
|
||||
|
||||
// Which ATN are we in?
|
||||
as.atn = nil
|
||||
|
@ -96,6 +90,7 @@ func (as *ATNState) InitATNState() {
|
|||
// Used to cache lookahead during parsing, not used during construction
|
||||
as.nextTokenWithinRule = nil
|
||||
|
||||
return as
|
||||
}
|
||||
|
||||
func (as *ATNState) GetRuleIndex() int {
|
||||
|
@ -199,16 +194,11 @@ func NewDecisionState() *DecisionState {
|
|||
this := new(DecisionState)
|
||||
|
||||
this.ATNState = NewATNState()
|
||||
this.DecisionState = NewDecisionState()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *DecisionState) InitDecisionState() {
|
||||
|
||||
this.decision = -1
|
||||
this.nonGreedy = false
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
// The start of a regular {@code (...)} block.
|
||||
|
@ -223,14 +213,9 @@ func NewBlockStartState() *BlockStartState {
|
|||
this := new(BlockStartState)
|
||||
|
||||
this.DecisionState = NewDecisionState()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *BlockStartState) InitBlockStartState() {
|
||||
|
||||
this.endState = nil
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
type BasicBlockStartState struct {
|
||||
|
@ -249,7 +234,7 @@ func NewBasicBlockStartState() *BasicBlockStartState {
|
|||
|
||||
// Terminal node of a simple {@code (a|b|c)} block.
|
||||
type BlockEndState struct {
|
||||
ATNState
|
||||
*ATNState
|
||||
|
||||
startState IATNState
|
||||
}
|
||||
|
@ -271,7 +256,7 @@ func NewBlockEndState() *BlockEndState {
|
|||
// error handling.
|
||||
//
|
||||
type RuleStopState struct {
|
||||
ATNState
|
||||
*ATNState
|
||||
}
|
||||
|
||||
func NewRuleStopState() *RuleStopState {
|
||||
|
@ -283,7 +268,7 @@ func NewRuleStopState() *RuleStopState {
|
|||
}
|
||||
|
||||
type RuleStartState struct {
|
||||
ATNState
|
||||
*ATNState
|
||||
|
||||
stopState IATNState
|
||||
isPrecedenceRule bool
|
||||
|
@ -396,6 +381,7 @@ func NewStarLoopEntryState() *StarLoopEntryState {
|
|||
// Mark the end of a * or + loop.
|
||||
type LoopEndState struct {
|
||||
*ATNState
|
||||
|
||||
loopBackState IATNState
|
||||
}
|
||||
|
||||
|
|
|
@ -26,11 +26,6 @@ type BufferedTokenStream struct {
|
|||
func NewBufferedTokenStream(tokenSource TokenSource) *BufferedTokenStream {
|
||||
|
||||
ts := new(BufferedTokenStream)
|
||||
ts.BufferedTokenStream = NewBufferedTokenStream(tokenSource)
|
||||
return ts
|
||||
}
|
||||
|
||||
func (ts *BufferedTokenStream) InitBufferedTokenStream(tokenSource TokenSource) {
|
||||
|
||||
// The {@link TokenSource} from which tokens for bt stream are fetched.
|
||||
ts.tokenSource = tokenSource
|
||||
|
@ -68,6 +63,7 @@ func (ts *BufferedTokenStream) InitBufferedTokenStream(tokenSource TokenSource)
|
|||
// <ul>
|
||||
ts.fetchedEOF = false
|
||||
|
||||
return ts
|
||||
}
|
||||
|
||||
func (bt *BufferedTokenStream) Mark() int {
|
||||
|
|
|
@ -24,15 +24,11 @@ func NewDFASerializer(dfa *DFA, literalNames, symbolicNames []string) *DFASerial
|
|||
|
||||
this := new(DFASerializer)
|
||||
|
||||
this.DFASerializer = NewDFASerializer(dfa, literalNames, symbolicNames)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *DFASerializer) InitDFASerializer(dfa *DFA, literalNames, symbolicNames []string) {
|
||||
this.dfa = dfa
|
||||
this.literalNames = literalNames
|
||||
this.symbolicNames = symbolicNames
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *DFASerializer) toString() string {
|
||||
|
@ -106,7 +102,7 @@ func (this *DFASerializer) GetStateString(s *DFAState) string {
|
|||
}
|
||||
|
||||
type LexerDFASerializer struct {
|
||||
DFASerializer
|
||||
*DFASerializer
|
||||
}
|
||||
|
||||
func NewLexerDFASerializer(dfa *DFA) *LexerDFASerializer {
|
||||
|
|
|
@ -33,16 +33,16 @@ func NewDiagnosticErrorListener(exactOnly bool) *DiagnosticErrorListener {
|
|||
|
||||
n := new(DiagnosticErrorListener)
|
||||
|
||||
// whether all ambiguities or only exact ambiguities are reported.
|
||||
// whether all ambiguities or only exact ambiguities are Reported.
|
||||
n.exactOnly = exactOnly
|
||||
return n
|
||||
}
|
||||
|
||||
func (this *DiagnosticErrorListener) reportAmbiguity(recognizer *Parser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
func (this *DiagnosticErrorListener) ReportAmbiguity(recognizer *Parser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
if this.exactOnly && !exact {
|
||||
return
|
||||
}
|
||||
var msg = "reportAmbiguity d=" +
|
||||
var msg = "ReportAmbiguity d=" +
|
||||
this.getDecisionDescription(recognizer, dfa) +
|
||||
": ambigAlts=" +
|
||||
this.getConflictingAlts(ambigAlts, configs).toString() +
|
||||
|
@ -51,17 +51,17 @@ func (this *DiagnosticErrorListener) reportAmbiguity(recognizer *Parser, dfa *DF
|
|||
recognizer.notifyErrorListeners(msg, nil, nil)
|
||||
}
|
||||
|
||||
func (this *DiagnosticErrorListener) reportAttemptingFullContext(recognizer *Parser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||
func (this *DiagnosticErrorListener) ReportAttemptingFullContext(recognizer *Parser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||
|
||||
var msg = "reportAttemptingFullContext d=" +
|
||||
var msg = "ReportAttemptingFullContext d=" +
|
||||
this.getDecisionDescription(recognizer, dfa) +
|
||||
", input='" +
|
||||
recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'"
|
||||
recognizer.notifyErrorListeners(msg, nil, nil)
|
||||
}
|
||||
|
||||
func (this *DiagnosticErrorListener) reportContextSensitivity(recognizer *Parser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||
var msg = "reportContextSensitivity d=" +
|
||||
func (this *DiagnosticErrorListener) ReportContextSensitivity(recognizer *Parser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||
var msg = "ReportContextSensitivity d=" +
|
||||
this.getDecisionDescription(recognizer, dfa) +
|
||||
", input='" +
|
||||
recognizer.GetTokenStream().GetTextFromInterval(NewInterval(startIndex, stopIndex)) + "'"
|
||||
|
@ -88,15 +88,15 @@ func (this *DiagnosticErrorListener) getDecisionDescription(recognizer *Parser,
|
|||
// configuration set, if that information was not already provided by the
|
||||
// parser.
|
||||
//
|
||||
// @param reportedAlts The set of conflicting or ambiguous alternatives, as
|
||||
// reported by the parser.
|
||||
// @param ReportedAlts The set of conflicting or ambiguous alternatives, as
|
||||
// Reported by the parser.
|
||||
// @param configs The conflicting or ambiguous configuration set.
|
||||
// @return Returns {@code reportedAlts} if it is not {@code nil}, otherwise
|
||||
// @return Returns {@code ReportedAlts} if it is not {@code nil}, otherwise
|
||||
// returns the set of alternatives represented in {@code configs}.
|
||||
//
|
||||
func (this *DiagnosticErrorListener) getConflictingAlts(reportedAlts *BitSet, set *ATNConfigSet) *BitSet {
|
||||
if reportedAlts != nil {
|
||||
return reportedAlts
|
||||
func (this *DiagnosticErrorListener) getConflictingAlts(ReportedAlts *BitSet, set *ATNConfigSet) *BitSet {
|
||||
if ReportedAlts != nil {
|
||||
return ReportedAlts
|
||||
}
|
||||
var result = NewBitSet()
|
||||
for i := 0; i < len(set.configs); i++ {
|
||||
|
|
|
@ -10,10 +10,10 @@ import (
|
|||
// necessary.
|
||||
|
||||
type IErrorListener interface {
|
||||
syntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException)
|
||||
reportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet)
|
||||
reportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet)
|
||||
reportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet)
|
||||
SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException)
|
||||
ReportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet)
|
||||
ReportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet)
|
||||
ReportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet)
|
||||
}
|
||||
|
||||
type DefaultErrorListener struct {
|
||||
|
@ -23,16 +23,16 @@ func NewErrorListener() *DefaultErrorListener {
|
|||
return new(DefaultErrorListener)
|
||||
}
|
||||
|
||||
func (this *DefaultErrorListener) syntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||
func (this *DefaultErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||
}
|
||||
|
||||
func (this *DefaultErrorListener) reportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
func (this *DefaultErrorListener) ReportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
}
|
||||
|
||||
func (this *DefaultErrorListener) reportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||
func (this *DefaultErrorListener) ReportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||
}
|
||||
|
||||
func (this *DefaultErrorListener) reportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||
func (this *DefaultErrorListener) ReportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||
}
|
||||
|
||||
type ConsoleErrorListener struct {
|
||||
|
@ -60,7 +60,7 @@ var ConsoleErrorListenerINSTANCE = NewConsoleErrorListener()
|
|||
// line <em>line</em>:<em>charPositionInLine</em> <em>msg</em>
|
||||
// </pre>
|
||||
//
|
||||
func (this *ConsoleErrorListener) syntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||
func (this *ConsoleErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||
fmt.Errorf("line " + strconv.Itoa(line) + ":" + strconv.Itoa(column) + " " + msg)
|
||||
}
|
||||
|
||||
|
@ -78,26 +78,26 @@ func NewProxyErrorListener(delegates []IErrorListener) *ProxyErrorListener {
|
|||
return l
|
||||
}
|
||||
|
||||
func (this *ProxyErrorListener) syntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||
func (this *ProxyErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||
for _, d := range this.delegates {
|
||||
d.syntaxError(recognizer, offendingSymbol, line, column, msg, e)
|
||||
d.SyntaxError(recognizer, offendingSymbol, line, column, msg, e)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ProxyErrorListener) reportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
func (this *ProxyErrorListener) ReportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
for _, d := range this.delegates {
|
||||
d.reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
|
||||
d.ReportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ProxyErrorListener) reportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||
func (this *ProxyErrorListener) ReportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||
for _, d := range this.delegates {
|
||||
d.reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs)
|
||||
d.ReportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ProxyErrorListener) reportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||
func (this *ProxyErrorListener) ReportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||
for _, d := range this.delegates {
|
||||
d.reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs)
|
||||
d.ReportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,39 +14,13 @@ type IErrorStrategy interface {
|
|||
Sync(IParser)
|
||||
inErrorRecoveryMode(IParser) bool
|
||||
ReportError(IParser, IRecognitionException)
|
||||
reportMatch(IParser)
|
||||
}
|
||||
|
||||
type ErrorStrategy struct {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) reset(recognizer IParser) {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) RecoverInline(recognizer IParser) {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) Recover(recognizer IParser, e IRecognitionException) {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) Sync(recognizer IParser) {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) inErrorRecoveryMode(recognizer IParser) {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) ReportError(recognizer IParser, e IRecognitionException) {
|
||||
}
|
||||
|
||||
func (this *ErrorStrategy) reportMatch(recognizer IParser) {
|
||||
|
||||
ReportMatch(IParser)
|
||||
}
|
||||
|
||||
// This is the default implementation of {@link ANTLRErrorStrategy} used for
|
||||
// error reporting and recovery in ANTLR parsers.
|
||||
// error Reporting and recovery in ANTLR parsers.
|
||||
//
|
||||
type DefaultErrorStrategy struct {
|
||||
*ErrorStrategy
|
||||
|
||||
errorRecoveryMode bool
|
||||
lastErrorIndex int
|
||||
|
@ -56,14 +30,9 @@ type DefaultErrorStrategy struct {
|
|||
func NewDefaultErrorStrategy() *DefaultErrorStrategy {
|
||||
|
||||
d := new(DefaultErrorStrategy)
|
||||
d.DefaultErrorStrategy = NewDefaultErrorStrategy()
|
||||
return d
|
||||
}
|
||||
|
||||
func (d *DefaultErrorStrategy) InitDefaultErrorStrategy() {
|
||||
|
||||
// Indicates whether the error strategy is currently "recovering from an
|
||||
// error". This is used to suppress reporting multiple error messages while
|
||||
// error". This is used to suppress Reporting multiple error messages while
|
||||
// attempting to recover from a detected syntax error.
|
||||
//
|
||||
// @see //inErrorRecoveryMode
|
||||
|
@ -78,7 +47,7 @@ func (d *DefaultErrorStrategy) InitDefaultErrorStrategy() {
|
|||
//
|
||||
d.lastErrorIndex = -1
|
||||
d.lastErrorStates = nil
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
// <p>The default implementation simply calls {@link //endErrorCondition} to
|
||||
|
@ -89,7 +58,7 @@ func (this *DefaultErrorStrategy) reset(recognizer IParser) {
|
|||
|
||||
//
|
||||
// This method is called to enter error recovery mode when a recognition
|
||||
// exception is reported.
|
||||
// exception is Reported.
|
||||
//
|
||||
// @param recognizer the parser instance
|
||||
//
|
||||
|
@ -118,7 +87,7 @@ func (this *DefaultErrorStrategy) endErrorCondition(recognizer IParser) {
|
|||
//
|
||||
// <p>The default implementation simply calls {@link //endErrorCondition}.</p>
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportMatch(recognizer IParser) {
|
||||
func (this *DefaultErrorStrategy) ReportMatch(recognizer IParser) {
|
||||
this.endErrorCondition(recognizer)
|
||||
}
|
||||
|
||||
|
@ -127,25 +96,25 @@ func (this *DefaultErrorStrategy) reportMatch(recognizer IParser) {
|
|||
//
|
||||
// <p>The default implementation returns immediately if the handler is already
|
||||
// in error recovery mode. Otherwise, it calls {@link //beginErrorCondition}
|
||||
// and dispatches the reporting task based on the runtime type of {@code e}
|
||||
// and dispatches the Reporting task based on the runtime type of {@code e}
|
||||
// according to the following table.</p>
|
||||
//
|
||||
// <ul>
|
||||
// <li>{@link NoViableAltException}: Dispatches the call to
|
||||
// {@link //reportNoViableAlternative}</li>
|
||||
// {@link //ReportNoViableAlternative}</li>
|
||||
// <li>{@link InputMisMatchException}: Dispatches the call to
|
||||
// {@link //reportInputMisMatch}</li>
|
||||
// {@link //ReportInputMisMatch}</li>
|
||||
// <li>{@link FailedPredicateException}: Dispatches the call to
|
||||
// {@link //reportFailedPredicate}</li>
|
||||
// <li>All other types: calls {@link Parser//notifyErrorListeners} to report
|
||||
// {@link //ReportFailedPredicate}</li>
|
||||
// <li>All other types: calls {@link Parser//notifyErrorListeners} to Report
|
||||
// the exception</li>
|
||||
// </ul>
|
||||
//
|
||||
func (this *DefaultErrorStrategy) ReportError(recognizer IParser, e IRecognitionException) {
|
||||
// if we've already reported an error and have not Matched a token
|
||||
// yet successfully, don't report any errors.
|
||||
// if we've already Reported an error and have not Matched a token
|
||||
// yet successfully, don't Report any errors.
|
||||
if this.inErrorRecoveryMode(recognizer) {
|
||||
return // don't report spurious errors
|
||||
return // don't Report spurious errors
|
||||
}
|
||||
this.beginErrorCondition(recognizer)
|
||||
|
||||
|
@ -155,11 +124,11 @@ func (this *DefaultErrorStrategy) ReportError(recognizer IParser, e IRecognition
|
|||
// fmt.Println(e.stack)
|
||||
recognizer.notifyErrorListeners(e.GetMessage(), e.GetOffendingToken(), e)
|
||||
case *NoViableAltException:
|
||||
this.reportNoViableAlternative(recognizer, t)
|
||||
this.ReportNoViableAlternative(recognizer, t)
|
||||
case *InputMisMatchException:
|
||||
this.reportInputMisMatch(recognizer, t)
|
||||
this.ReportInputMisMatch(recognizer, t)
|
||||
case *FailedPredicateException:
|
||||
this.reportFailedPredicate(recognizer, t)
|
||||
this.ReportFailedPredicate(recognizer, t)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +223,7 @@ func (this *DefaultErrorStrategy) Sync(recognizer IParser) {
|
|||
case ATNStateSTAR_BLOCK_START:
|
||||
case ATNStatePLUS_BLOCK_START:
|
||||
case ATNStateSTAR_LOOP_ENTRY:
|
||||
// report error and recover if possible
|
||||
// Report error and recover if possible
|
||||
if this.singleTokenDeletion(recognizer) != nil {
|
||||
return
|
||||
} else {
|
||||
|
@ -263,7 +232,7 @@ func (this *DefaultErrorStrategy) Sync(recognizer IParser) {
|
|||
break
|
||||
case ATNStatePLUS_LOOP_BACK:
|
||||
case ATNStateSTAR_LOOP_BACK:
|
||||
this.reportUnwantedToken(recognizer)
|
||||
this.ReportUnwantedToken(recognizer)
|
||||
var expecting = NewIntervalSet()
|
||||
expecting.addSet(recognizer.getExpectedTokens())
|
||||
var whatFollowsLoopIterationOrRule = expecting.addSet(this.getErrorRecoverySet(recognizer))
|
||||
|
@ -282,7 +251,7 @@ func (this *DefaultErrorStrategy) Sync(recognizer IParser) {
|
|||
// @param recognizer the parser instance
|
||||
// @param e the recognition exception
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer IParser, e *NoViableAltException) {
|
||||
func (this *DefaultErrorStrategy) ReportNoViableAlternative(recognizer IParser, e *NoViableAltException) {
|
||||
var tokens = recognizer.GetTokenStream()
|
||||
var input string
|
||||
if tokens != nil {
|
||||
|
@ -307,7 +276,7 @@ func (this *DefaultErrorStrategy) reportNoViableAlternative(recognizer IParser,
|
|||
// @param recognizer the parser instance
|
||||
// @param e the recognition exception
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportInputMisMatch(recognizer IParser, e *InputMisMatchException) {
|
||||
func (this *DefaultErrorStrategy) ReportInputMisMatch(recognizer IParser, e *InputMisMatchException) {
|
||||
var msg = "misMatched input " + this.GetTokenErrorDisplay(e.offendingToken) +
|
||||
" expecting " + e.getExpectedTokens().toStringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false)
|
||||
recognizer.notifyErrorListeners(msg, e.offendingToken, e)
|
||||
|
@ -322,13 +291,13 @@ func (this *DefaultErrorStrategy) reportInputMisMatch(recognizer IParser, e *Inp
|
|||
// @param recognizer the parser instance
|
||||
// @param e the recognition exception
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportFailedPredicate(recognizer IParser, e *FailedPredicateException) {
|
||||
func (this *DefaultErrorStrategy) ReportFailedPredicate(recognizer IParser, e *FailedPredicateException) {
|
||||
var ruleName = recognizer.GetRuleNames()[recognizer.GetParserRuleContext().GetRuleIndex()]
|
||||
var msg = "rule " + ruleName + " " + e.message
|
||||
recognizer.notifyErrorListeners(msg, e.offendingToken, e)
|
||||
}
|
||||
|
||||
// This method is called to report a syntax error which requires the removal
|
||||
// This method is called to Report a syntax error which requires the removal
|
||||
// of a token from the input stream. At the time this method is called, the
|
||||
// erroneous symbol is current {@code LT(1)} symbol and has not yet been
|
||||
// removed from the input stream. When this method returns,
|
||||
|
@ -345,7 +314,7 @@ func (this *DefaultErrorStrategy) reportFailedPredicate(recognizer IParser, e *F
|
|||
//
|
||||
// @param recognizer the parser instance
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportUnwantedToken(recognizer IParser) {
|
||||
func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer IParser) {
|
||||
if this.inErrorRecoveryMode(recognizer) {
|
||||
return
|
||||
}
|
||||
|
@ -358,7 +327,7 @@ func (this *DefaultErrorStrategy) reportUnwantedToken(recognizer IParser) {
|
|||
recognizer.notifyErrorListeners(msg, t, nil)
|
||||
}
|
||||
|
||||
// This method is called to report a syntax error which requires the
|
||||
// This method is called to Report a syntax error which requires the
|
||||
// insertion of a missing token into the input stream. At the time this
|
||||
// method is called, the missing token has not yet been inserted. When this
|
||||
// method returns, {@code recognizer} is in error recovery mode.
|
||||
|
@ -374,7 +343,7 @@ func (this *DefaultErrorStrategy) reportUnwantedToken(recognizer IParser) {
|
|||
//
|
||||
// @param recognizer the parser instance
|
||||
//
|
||||
func (this *DefaultErrorStrategy) reportMissingToken(recognizer IParser) {
|
||||
func (this *DefaultErrorStrategy) ReportMissingToken(recognizer IParser) {
|
||||
if this.inErrorRecoveryMode(recognizer) {
|
||||
return
|
||||
}
|
||||
|
@ -476,10 +445,10 @@ func (this *DefaultErrorStrategy) singleTokenInsertion(recognizer IParser) bool
|
|||
// is free to conjure up and insert the missing token
|
||||
var atn = recognizer.GetInterpreter().atn
|
||||
var currentState = atn.states[recognizer.GetState()]
|
||||
var next = currentState.GetTransitions()[0].getTarGet()
|
||||
var next = currentState.GetTransitions()[0].getTarget()
|
||||
var expectingAtLL2 = atn.nextTokens(next, recognizer.GetParserRuleContext())
|
||||
if expectingAtLL2.contains(currentSymbolType) {
|
||||
this.reportMissingToken(recognizer)
|
||||
this.ReportMissingToken(recognizer)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
|
@ -494,9 +463,9 @@ func (this *DefaultErrorStrategy) singleTokenInsertion(recognizer IParser) bool
|
|||
// returned token was a successful Match.
|
||||
//
|
||||
// <p>If the single-token deletion is successful, this method calls
|
||||
// {@link //reportUnwantedToken} to report the error, followed by
|
||||
// {@link //ReportUnwantedToken} to Report the error, followed by
|
||||
// {@link Parser//consume} to actually "delete" the extraneous token. Then,
|
||||
// before returning {@link //reportMatch} is called to signal a successful
|
||||
// before returning {@link //ReportMatch} is called to signal a successful
|
||||
// Match.</p>
|
||||
//
|
||||
// @param recognizer the parser instance
|
||||
|
@ -508,7 +477,7 @@ func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer IParser) *Token
|
|||
var nextTokenType = recognizer.GetTokenStream().LA(2)
|
||||
var expecting = this.getExpectedTokens(recognizer)
|
||||
if expecting.contains(nextTokenType) {
|
||||
this.reportUnwantedToken(recognizer)
|
||||
this.ReportUnwantedToken(recognizer)
|
||||
// print("recoverFromMisMatchedToken deleting " \
|
||||
// + str(recognizer.GetTokenStream().LT(1)) \
|
||||
// + " since " + str(recognizer.GetTokenStream().LT(2)) \
|
||||
|
@ -516,7 +485,7 @@ func (this *DefaultErrorStrategy) singleTokenDeletion(recognizer IParser) *Token
|
|||
recognizer.Consume() // simply delete extra token
|
||||
// we want to return the token we're actually Matching
|
||||
var MatchedSymbol = recognizer.getCurrentToken()
|
||||
this.reportMatch(recognizer) // we know current token is correct
|
||||
this.ReportMatch(recognizer) // we know current token is correct
|
||||
return MatchedSymbol
|
||||
} else {
|
||||
return nil
|
||||
|
@ -731,7 +700,7 @@ func (this *DefaultErrorStrategy) consumeUntil(recognizer IParser, set *Interval
|
|||
// implementation of {@link BailErrorStrategy//Sync} improves the performance of
|
||||
// the first stage.</li>
|
||||
// <li><strong>Silent validation:</strong> When syntax errors are not being
|
||||
// reported or logged, and the parse result is simply ignored if errors occur,
|
||||
// Reported or logged, and the parse result is simply ignored if errors occur,
|
||||
// the {@link BailErrorStrategy} avoids wasting work on recovering from errors
|
||||
// when the result will be ignored either way.</li>
|
||||
// </ul>
|
||||
|
@ -742,12 +711,13 @@ func (this *DefaultErrorStrategy) consumeUntil(recognizer IParser, set *Interval
|
|||
// @see Parser//setErrorHandler(ANTLRErrorStrategy)
|
||||
|
||||
type BailErrorStrategy struct {
|
||||
DefaultErrorStrategy
|
||||
*DefaultErrorStrategy
|
||||
}
|
||||
|
||||
func NewBailErrorStrategy() *BailErrorStrategy {
|
||||
|
||||
this := new(BailErrorStrategy)
|
||||
|
||||
this.DefaultErrorStrategy = NewDefaultErrorStrategy()
|
||||
|
||||
return this
|
||||
|
|
|
@ -36,12 +36,6 @@ func NewRecognitionException(message string, recognizer IRecognizer, input IntSt
|
|||
// TODO may be able to use - "runtime" func Stack(buf []byte, all bool) int
|
||||
|
||||
t := new(RecognitionException)
|
||||
t.RecognitionException = NewRecognitionException(message, recognizer, input, ctx)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *RecognitionException) InitRecognitionException(message string, recognizer IRecognizer, input IntStream, ctx IRuleContext) {
|
||||
|
||||
t.message = message
|
||||
t.recognizer = recognizer
|
||||
|
@ -60,6 +54,8 @@ func (t *RecognitionException) InitRecognitionException(message string, recogniz
|
|||
if t.recognizer != nil {
|
||||
t.offendingState = t.recognizer.GetState()
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (this *RecognitionException) GetMessage() string {
|
||||
|
@ -137,7 +133,7 @@ type NoViableAltException struct {
|
|||
// Indicates that the parser could not decide which of two or more paths
|
||||
// to take based upon the remaining input. It tracks the starting token
|
||||
// of the offending input and also knows where the parser was
|
||||
// in the various paths when the error. Reported by reportNoViableAlternative()
|
||||
// in the various paths when the error. Reported by ReportNoViableAlternative()
|
||||
//
|
||||
func NewNoViableAltException(recognizer IParser, input TokenStream, startToken *Token, offendingToken *Token, deadEndConfigs *ATNConfigSet, ctx IParserRuleContext) *NoViableAltException {
|
||||
|
||||
|
|
|
@ -11,18 +11,12 @@ func NewInputStream(data string) *InputStream {
|
|||
|
||||
is := new(InputStream)
|
||||
|
||||
is.InputStream = NewInputStream(data)
|
||||
|
||||
return is
|
||||
}
|
||||
|
||||
func (is *InputStream) InitInputStream(data string) {
|
||||
|
||||
is.name = "<empty>"
|
||||
is.index = 0
|
||||
is.data = []rune(data)
|
||||
is.size = len(is.data) // number of runes
|
||||
|
||||
return is
|
||||
}
|
||||
|
||||
func (is *InputStream) reset() {
|
||||
|
|
|
@ -38,7 +38,7 @@ func (la *LL1Analyzer) getDecisionLookahead(s IATNState) []*IntervalSet {
|
|||
look[alt] = NewIntervalSet()
|
||||
var lookBusy = NewSet(nil, nil)
|
||||
var seeThruPreds = false // fail to get lookahead upon pred
|
||||
la._LOOK(s.GetTransitions()[alt].getTarGet(), nil, PredictionContextEMPTY, look[alt], lookBusy, NewBitSet(), seeThruPreds, false)
|
||||
la._LOOK(s.GetTransitions()[alt].getTarget(), nil, PredictionContextEMPTY, look[alt], lookBusy, NewBitSet(), seeThruPreds, false)
|
||||
// Wipe out lookahead for la alternative if we found nothing
|
||||
// or we had a predicate when we !seeThruPreds
|
||||
if look[alt].length() == 0 || look[alt].contains(LL1AnalyzerHIT_PRED) {
|
||||
|
@ -168,26 +168,26 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
|
|||
|
||||
if t1, ok := t.(*RuleTransition); ok {
|
||||
|
||||
if calledRuleStack.contains(t1.getTarGet().GetRuleIndex()) {
|
||||
if calledRuleStack.contains(t1.getTarget().GetRuleIndex()) {
|
||||
continue
|
||||
}
|
||||
|
||||
newContext := SingletonPredictionContextCreate(ctx, t1.followState.GetStateNumber())
|
||||
|
||||
defer func() {
|
||||
calledRuleStack.remove(t1.getTarGet().GetRuleIndex())
|
||||
calledRuleStack.remove(t1.getTarget().GetRuleIndex())
|
||||
}()
|
||||
|
||||
calledRuleStack.add(t1.getTarGet().GetRuleIndex())
|
||||
la._LOOK(t.getTarGet(), stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||
calledRuleStack.add(t1.getTarget().GetRuleIndex())
|
||||
la._LOOK(t.getTarget(), stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||
} else if t2, ok := t.(*AbstractPredicateTransition); ok {
|
||||
if seeThruPreds {
|
||||
la._LOOK(t2.getTarGet(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||
la._LOOK(t2.getTarget(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||
} else {
|
||||
look.addOne(LL1AnalyzerHIT_PRED)
|
||||
}
|
||||
} else if t.getIsEpsilon() {
|
||||
la._LOOK(t.getTarGet(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||
la._LOOK(t.getTarget(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||
} else if _, ok := t.(*WildcardTransition); ok {
|
||||
look.addRange(TokenMinUserTokenType, la.atn.maxTokenType)
|
||||
} else {
|
||||
|
|
|
@ -48,18 +48,12 @@ func NewLexer(input CharStream) *Lexer {
|
|||
lexer := new(Lexer)
|
||||
|
||||
lexer.Recognizer = NewRecognizer()
|
||||
lexer.Lexer = NewLexer(input)
|
||||
|
||||
return lexer
|
||||
}
|
||||
lexer._input = input
|
||||
lexer._factory = CommonTokenFactoryDEFAULT
|
||||
lexer._tokenFactorySourcePair = &TokenSourceCharStreamPair{lexer, input}
|
||||
|
||||
func (l *Lexer) InitLexer(input CharStream) {
|
||||
|
||||
l._input = input
|
||||
l._factory = CommonTokenFactoryDEFAULT
|
||||
l._tokenFactorySourcePair = &TokenSourceCharStreamPair{l, input}
|
||||
|
||||
l.Interpreter = nil // child classes must populate it
|
||||
lexer.Interpreter = nil // child classes must populate it
|
||||
|
||||
// The goal of all lexer rules/methods is to create a token object.
|
||||
// l is an instance variable as multiple rules may collaborate to
|
||||
|
@ -68,37 +62,38 @@ func (l *Lexer) InitLexer(input CharStream) {
|
|||
// emissions, then set l to the last token to be Matched or
|
||||
// something nonnil so that the auto token emit mechanism will not
|
||||
// emit another token.
|
||||
l._token = nil
|
||||
lexer._token = nil
|
||||
|
||||
// What character index in the stream did the current token start at?
|
||||
// Needed, for example, to get the text for current token. Set at
|
||||
// the start of nextToken.
|
||||
l._tokenStartCharIndex = -1
|
||||
lexer._tokenStartCharIndex = -1
|
||||
|
||||
// The line on which the first character of the token resides///
|
||||
l._tokenStartLine = -1
|
||||
lexer._tokenStartLine = -1
|
||||
|
||||
// The character position of first character within the line///
|
||||
l._tokenStartColumn = -1
|
||||
lexer._tokenStartColumn = -1
|
||||
|
||||
// Once we see EOF on char stream, next token will be EOF.
|
||||
// If you have DONE : EOF then you see DONE EOF.
|
||||
l._hitEOF = false
|
||||
lexer._hitEOF = false
|
||||
|
||||
// The channel number for the current token///
|
||||
l._channel = TokenDefaultChannel
|
||||
lexer._channel = TokenDefaultChannel
|
||||
|
||||
// The token type for the current token///
|
||||
l._type = TokenInvalidType
|
||||
lexer._type = TokenInvalidType
|
||||
|
||||
l._modeStack = make([]int, 0)
|
||||
l._mode = LexerDefaultMode
|
||||
lexer._modeStack = make([]int, 0)
|
||||
lexer._mode = LexerDefaultMode
|
||||
|
||||
// You can set the text for the current token to override what is in
|
||||
// the input char buffer. Use setText() or can set l instance var.
|
||||
// /
|
||||
l._text = nil
|
||||
lexer._text = nil
|
||||
|
||||
return lexer
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -160,7 +155,7 @@ func (l *Lexer) safeMatch() (ret int) {
|
|||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
if re, ok := e.(IRecognitionException); ok {
|
||||
l.notifyListeners(re) // report error
|
||||
l.notifyListeners(re) // Report error
|
||||
l.Recover(re)
|
||||
ret = LexerSkip // default
|
||||
}
|
||||
|
@ -367,7 +362,7 @@ func (l *Lexer) notifyListeners(e IRecognitionException) {
|
|||
var text = l._input.GetTextFromInterval(NewInterval(start, stop))
|
||||
var msg = "token recognition error at: '" + text + "'"
|
||||
var listener = l.getErrorListenerDispatch()
|
||||
listener.syntaxError(l, nil, l._tokenStartLine, l._tokenStartColumn, msg, e)
|
||||
listener.SyntaxError(l, nil, l._tokenStartLine, l._tokenStartColumn, msg, e)
|
||||
}
|
||||
|
||||
func (l *Lexer) getErrorDisplayForChar(c rune) string {
|
||||
|
|
|
@ -48,7 +48,7 @@ func (this *SimState) reset() {
|
|||
}
|
||||
|
||||
type LexerATNSimulator struct {
|
||||
ATNSimulator
|
||||
*ATNSimulator
|
||||
|
||||
recog ILexer
|
||||
predictionMode int
|
||||
|
@ -190,10 +190,10 @@ func (this *LexerATNSimulator) execATN(input CharStream, ds0 *DFAState) int {
|
|||
// A character will take us back to an existing DFA state
|
||||
// that already has lots of edges out of it. e.g., .* in comments.
|
||||
// print("Target for:" + str(s) + " and:" + str(t))
|
||||
var target = this.getExistingTarGetState(s, t)
|
||||
var target = this.getExistingTargetState(s, t)
|
||||
// print("Existing:" + str(target))
|
||||
if target == nil {
|
||||
target = this.computeTarGetState(input, s, t)
|
||||
target = this.computeTargetState(input, s, t)
|
||||
// print("Computed:" + str(target))
|
||||
}
|
||||
if target == ATNSimulatorERROR {
|
||||
|
@ -227,7 +227,7 @@ func (this *LexerATNSimulator) execATN(input CharStream, ds0 *DFAState) int {
|
|||
// @return The existing target DFA state for the given input symbol
|
||||
// {@code t}, or {@code nil} if the target state for this edge is not
|
||||
// already cached
|
||||
func (this *LexerATNSimulator) getExistingTarGetState(s *DFAState, t int) *DFAState {
|
||||
func (this *LexerATNSimulator) getExistingTargetState(s *DFAState, t int) *DFAState {
|
||||
if s.edges == nil || t < LexerATNSimulatorMIN_DFA_EDGE || t > LexerATNSimulatorMAX_DFA_EDGE {
|
||||
return nil
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ func (this *LexerATNSimulator) getExistingTarGetState(s *DFAState, t int) *DFASt
|
|||
// @return The computed target DFA state for the given input symbol
|
||||
// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
||||
// returns {@link //ERROR}.
|
||||
func (this *LexerATNSimulator) computeTarGetState(input CharStream, s *DFAState, t int) *DFAState {
|
||||
func (this *LexerATNSimulator) computeTargetState(input CharStream, s *DFAState, t int) *DFAState {
|
||||
var reach = NewOrderedATNConfigSet()
|
||||
// if we don't find an existing DFA state
|
||||
// Fill reach starting from closure, following t transitions
|
||||
|
@ -304,7 +304,7 @@ func (this *LexerATNSimulator) getReachableConfigSet(input CharStream, closure *
|
|||
}
|
||||
for j := 0; j < len(cfg.GetState().GetTransitions()); j++ {
|
||||
var trans = cfg.GetState().GetTransitions()[j] // for each transition
|
||||
var target = this.getReachableTarGet(trans, t)
|
||||
var target = this.getReachableTarget(trans, t)
|
||||
if target != nil {
|
||||
var lexerActionExecutor = cfg.(*LexerATNConfig).lexerActionExecutor
|
||||
if lexerActionExecutor != nil {
|
||||
|
@ -336,9 +336,9 @@ func (this *LexerATNSimulator) accept(input CharStream, lexerActionExecutor *Lex
|
|||
}
|
||||
}
|
||||
|
||||
func (this *LexerATNSimulator) getReachableTarGet(trans ITransition, t int) IATNState {
|
||||
func (this *LexerATNSimulator) getReachableTarget(trans ITransition, t int) IATNState {
|
||||
if trans.Matches(t, 0, 0xFFFE) {
|
||||
return trans.getTarGet()
|
||||
return trans.getTarget()
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
@ -348,7 +348,7 @@ func (this *LexerATNSimulator) computeStartState(input CharStream, p IATNState)
|
|||
|
||||
var configs = NewOrderedATNConfigSet()
|
||||
for i := 0; i < len(p.GetTransitions()); i++ {
|
||||
var target = p.GetTransitions()[i].getTarGet()
|
||||
var target = p.GetTransitions()[i].getTarget()
|
||||
var cfg = NewLexerATNConfig6(target, i+1, PredictionContextEMPTY)
|
||||
this.closure(input, cfg, configs.ATNConfigSet, false, false, false)
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ func (this *LexerATNSimulator) closure(input CharStream, config *LexerATNConfig,
|
|||
}
|
||||
for j := 0; j < len(config.state.GetTransitions()); j++ {
|
||||
var trans = config.state.GetTransitions()[j]
|
||||
cfg := this.getEpsilonTarGet(input, config, trans, configs, speculative, treatEofAsEpsilon)
|
||||
cfg := this.getEpsilonTarget(input, config, trans, configs, speculative, treatEofAsEpsilon)
|
||||
if cfg != nil {
|
||||
currentAltReachedAcceptState = this.closure(input, cfg, configs,
|
||||
currentAltReachedAcceptState, speculative, treatEofAsEpsilon)
|
||||
|
@ -418,7 +418,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 ITransition,
|
||||
configs *ATNConfigSet, speculative, treatEofAsEpsilon bool) *LexerATNConfig {
|
||||
|
||||
var cfg *LexerATNConfig
|
||||
|
@ -427,7 +427,7 @@ func (this *LexerATNSimulator) getEpsilonTarGet(input CharStream, config *LexerA
|
|||
|
||||
rt := trans.(*RuleTransition)
|
||||
var newContext = SingletonPredictionContextCreate(config.context, rt.followState.GetStateNumber())
|
||||
cfg = NewLexerATNConfig2(config, trans.getTarGet(), newContext)
|
||||
cfg = NewLexerATNConfig2(config, trans.getTarget(), newContext)
|
||||
|
||||
} else if trans.getSerializationType() == TransitionPRECEDENCE {
|
||||
panic("Precedence predicates are not supported in lexers.")
|
||||
|
@ -457,7 +457,7 @@ func (this *LexerATNSimulator) getEpsilonTarGet(input CharStream, config *LexerA
|
|||
}
|
||||
configs.hasSemanticContext = true
|
||||
if this.evaluatePredicate(input, pt.ruleIndex, pt.predIndex, speculative) {
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarGet())
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarget())
|
||||
}
|
||||
} else if trans.getSerializationType() == TransitionACTION {
|
||||
if config.context == nil || config.context.hasEmptyPath() {
|
||||
|
@ -474,19 +474,19 @@ func (this *LexerATNSimulator) getEpsilonTarGet(input CharStream, config *LexerA
|
|||
// additional modifications are needed before we can support
|
||||
// the split operation.
|
||||
var lexerActionExecutor = LexerActionExecutorappend(config.lexerActionExecutor, this.atn.lexerActions[trans.(*ActionTransition).actionIndex])
|
||||
cfg = NewLexerATNConfig3(config, trans.getTarGet(), lexerActionExecutor)
|
||||
cfg = NewLexerATNConfig3(config, trans.getTarget(), lexerActionExecutor)
|
||||
} else {
|
||||
// ignore actions in referenced rules
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarGet())
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarget())
|
||||
}
|
||||
} else if trans.getSerializationType() == TransitionEPSILON {
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarGet())
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarget())
|
||||
} else if trans.getSerializationType() == TransitionATOM ||
|
||||
trans.getSerializationType() == TransitionRANGE ||
|
||||
trans.getSerializationType() == TransitionSET {
|
||||
if treatEofAsEpsilon {
|
||||
if trans.Matches(TokenEOF, 0, 0xFFFF) {
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarGet())
|
||||
cfg = NewLexerATNConfig4(config, trans.getTarget())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,13 @@ type LexerAction struct {
|
|||
|
||||
func NewLexerAction(action int) *LexerAction {
|
||||
la := new(LexerAction)
|
||||
la.LexerAction = NewLexerAction(action)
|
||||
|
||||
la.actionType = action
|
||||
la.isPositionDependent = false
|
||||
|
||||
return la
|
||||
}
|
||||
|
||||
func (la *LexerAction) InitLexerAction(action int) {
|
||||
la.actionType = action
|
||||
la.isPositionDependent = false
|
||||
}
|
||||
|
||||
func (this *LexerAction) execute(lexer ILexer) {
|
||||
panic("Not implemented")
|
||||
|
|
|
@ -32,7 +32,7 @@ type Parser struct {
|
|||
buildParseTrees bool
|
||||
_tracer *TraceListener
|
||||
_parseListeners []ParseTreeListener
|
||||
_syntaxErrors int
|
||||
_SyntaxErrors int
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,6 @@ func NewParser(input TokenStream) *Parser {
|
|||
|
||||
p := new(Parser)
|
||||
|
||||
p.Parser = NewParser(input)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Parser) InitParser(input TokenStream) {
|
||||
|
||||
p.Recognizer = NewRecognizer()
|
||||
|
||||
|
@ -73,10 +67,12 @@ func (p *Parser) InitParser(input TokenStream) {
|
|||
// The list of {@link ParseTreeListener} listeners registered to receive
|
||||
// events during the parse.
|
||||
p._parseListeners = nil
|
||||
// The number of syntax errors reported during parsing. p.value is
|
||||
// The number of syntax errors Reported during parsing. p.value is
|
||||
// incremented each time {@link //notifyErrorListeners} is called.
|
||||
p._syntaxErrors = 0
|
||||
p._SyntaxErrors = 0
|
||||
p.setInputStream(input)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// p.field maps from the serialized ATN string to the deserialized {@link
|
||||
|
@ -94,7 +90,7 @@ func (p *Parser) reset() {
|
|||
}
|
||||
p._errHandler.reset(p)
|
||||
p._ctx = nil
|
||||
p._syntaxErrors = 0
|
||||
p._SyntaxErrors = 0
|
||||
p.setTrace(nil)
|
||||
p._precedenceStack = make([]int, 0)
|
||||
p._precedenceStack.Push(0)
|
||||
|
@ -112,7 +108,7 @@ func (p *Parser) GetParseListeners() []ParseTreeListener {
|
|||
}
|
||||
|
||||
// Match current input symbol against {@code ttype}. If the symbol type
|
||||
// Matches, {@link ANTLRErrorStrategy//reportMatch} and {@link //consume} are
|
||||
// Matches, {@link ANTLRErrorStrategy//ReportMatch} and {@link //consume} are
|
||||
// called to complete the Match process.
|
||||
//
|
||||
// <p>If the symbol type does not Match,
|
||||
|
@ -131,7 +127,7 @@ func (p *Parser) GetParseListeners() []ParseTreeListener {
|
|||
func (p *Parser) Match(ttype int) *Token {
|
||||
var t = p.getCurrentToken()
|
||||
if t.tokenType == ttype {
|
||||
p._errHandler.reportMatch(p)
|
||||
p._errHandler.ReportMatch(p)
|
||||
p.Consume()
|
||||
} else {
|
||||
t = p._errHandler.RecoverInline(p)
|
||||
|
@ -146,7 +142,7 @@ func (p *Parser) Match(ttype int) *Token {
|
|||
}
|
||||
|
||||
// Match current input symbol as a wildcard. If the symbol type Matches
|
||||
// (i.e. has a value greater than 0), {@link ANTLRErrorStrategy//reportMatch}
|
||||
// (i.e. has a value greater than 0), {@link ANTLRErrorStrategy//ReportMatch}
|
||||
// and {@link //consume} are called to complete the Match process.
|
||||
//
|
||||
// <p>If the symbol type does not Match,
|
||||
|
@ -164,7 +160,7 @@ func (p *Parser) Match(ttype int) *Token {
|
|||
func (p *Parser) MatchWildcard() *Token {
|
||||
var t = p.getCurrentToken()
|
||||
if t.tokenType > 0 {
|
||||
p._errHandler.reportMatch(p)
|
||||
p._errHandler.ReportMatch(p)
|
||||
p.Consume()
|
||||
} else {
|
||||
t = p._errHandler.RecoverInline(p)
|
||||
|
@ -385,11 +381,11 @@ func (p *Parser) notifyErrorListeners(msg string, offendingToken *Token, err IRe
|
|||
if offendingToken == nil {
|
||||
offendingToken = p.getCurrentToken()
|
||||
}
|
||||
p._syntaxErrors += 1
|
||||
p._SyntaxErrors += 1
|
||||
var line = offendingToken.line
|
||||
var column = offendingToken.column
|
||||
listener := p.getErrorListenerDispatch()
|
||||
listener.syntaxError(p, offendingToken, line, column, msg, err)
|
||||
listener.SyntaxError(p, offendingToken, line, column, msg, err)
|
||||
}
|
||||
|
||||
func (p *Parser) Consume() *Token {
|
||||
|
|
|
@ -23,13 +23,6 @@ func NewParserATNSimulator(parser IParser, atn *ATN, decisionToDFA []*DFA, share
|
|||
|
||||
this := new(ParserATNSimulator)
|
||||
|
||||
this.ParserATNSimulator = NewParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) InitParserATNSimulator(parser IParser, atn *ATN, decisionToDFA []*DFA, sharedContextCache *PredictionContextCache) {
|
||||
|
||||
this.ATNSimulator = NewATNSimulator(atn, sharedContextCache)
|
||||
|
||||
this.parser = parser
|
||||
|
@ -51,6 +44,7 @@ func (this *ParserATNSimulator) InitParserATNSimulator(parser IParser, atn *ATN,
|
|||
//
|
||||
this.mergeCache = nil
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
var ParserATNSimulatorprototypedebug = false
|
||||
|
@ -163,10 +157,10 @@ func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int,
|
|||
// collecting predicates and adding semantic context to DFA accept states
|
||||
// adding rule context to context-sensitive DFA accept states
|
||||
// consuming an input symbol
|
||||
// reporting a conflict
|
||||
// reporting an ambiguity
|
||||
// reporting a context sensitivity
|
||||
// reporting insufficient predicates
|
||||
// Reporting a conflict
|
||||
// Reporting an ambiguity
|
||||
// Reporting a context sensitivity
|
||||
// Reporting insufficient predicates
|
||||
|
||||
// cover these cases:
|
||||
// dead end
|
||||
|
@ -190,9 +184,9 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
|
|||
}
|
||||
var t = input.LA(1)
|
||||
for true { // for more work
|
||||
var D = this.getExistingTarGetState(previousD, t)
|
||||
var D = this.getExistingTargetState(previousD, t)
|
||||
if D == nil {
|
||||
D = this.computeTarGetState(dfa, previousD, t)
|
||||
D = this.computeTargetState(dfa, previousD, t)
|
||||
}
|
||||
if D == ATNSimulatorERROR {
|
||||
// if any configs in previous dipped into outer context, that
|
||||
|
@ -232,7 +226,7 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
|
|||
return conflictingAlts.minValue()
|
||||
}
|
||||
if conflictIndex != startIndex {
|
||||
// restore the index so reporting the fallback to full
|
||||
// restore the index so Reporting the fallback to full
|
||||
// context occurs with the index at the correct spot
|
||||
input.Seek(conflictIndex)
|
||||
}
|
||||
|
@ -242,7 +236,7 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
|
|||
}
|
||||
var fullCtx = true
|
||||
var s0_closure = this.computeStartState(dfa.atnStartState, outerContext, fullCtx)
|
||||
this.reportAttemptingFullContext(dfa, conflictingAlts, D.configs, startIndex, input.Index())
|
||||
this.ReportAttemptingFullContext(dfa, conflictingAlts, D.configs, startIndex, input.Index())
|
||||
alt := this.execATNWithFullContext(dfa, D, s0_closure, input, startIndex, outerContext)
|
||||
return alt
|
||||
}
|
||||
|
@ -258,8 +252,8 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
|
|||
} else if alts.length() == 1 {
|
||||
return alts.minValue()
|
||||
} else {
|
||||
// report ambiguity after predicate evaluation to make sure the correct set of ambig alts is reported.
|
||||
this.reportAmbiguity(dfa, D, startIndex, stopIndex, false, alts, D.configs)
|
||||
// Report ambiguity after predicate evaluation to make sure the correct set of ambig alts is Reported.
|
||||
this.ReportAmbiguity(dfa, D, startIndex, stopIndex, false, alts, D.configs)
|
||||
return alts.minValue()
|
||||
}
|
||||
}
|
||||
|
@ -284,7 +278,7 @@ func (this *ParserATNSimulator) execATN(dfa *DFA, s0 *DFAState, input TokenStrea
|
|||
// {@code t}, or {@code nil} if the target state for this edge is not
|
||||
// already cached
|
||||
|
||||
func (this *ParserATNSimulator) getExistingTarGetState(previousD *DFAState, t int) *DFAState {
|
||||
func (this *ParserATNSimulator) getExistingTargetState(previousD *DFAState, t int) *DFAState {
|
||||
var edges = previousD.edges
|
||||
if edges == nil {
|
||||
return nil
|
||||
|
@ -304,7 +298,7 @@ func (this *ParserATNSimulator) getExistingTarGetState(previousD *DFAState, t in
|
|||
// {@code t}. If {@code t} does not lead to a valid DFA state, this method
|
||||
// returns {@link //ERROR}.
|
||||
|
||||
func (this *ParserATNSimulator) computeTarGetState(dfa *DFA, previousD *DFAState, t int) *DFAState {
|
||||
func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState, t int) *DFAState {
|
||||
var reach = this.computeReachSet(previousD.configs, t, false)
|
||||
|
||||
if reach == nil {
|
||||
|
@ -443,7 +437,7 @@ func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0
|
|||
// without conflict, then we know that it's a full LL decision
|
||||
// not SLL.
|
||||
if reach.uniqueAlt != ATNINVALID_ALT_NUMBER {
|
||||
this.reportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.Index())
|
||||
this.ReportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.Index())
|
||||
return predictedAlt
|
||||
}
|
||||
// We do not check predicates here because we have checked them
|
||||
|
@ -473,7 +467,7 @@ func (this *ParserATNSimulator) execATNWithFullContext(dfa *DFA, D *DFAState, s0
|
|||
// the fact that we should predict alternative 1. We just can't say for
|
||||
// sure that there is an ambiguity without looking further.
|
||||
|
||||
this.reportAmbiguity(dfa, D, startIndex, input.Index(), foundExactAmbig, nil, reach)
|
||||
this.ReportAmbiguity(dfa, D, startIndex, input.Index(), foundExactAmbig, nil, reach)
|
||||
|
||||
return predictedAlt
|
||||
}
|
||||
|
@ -524,7 +518,7 @@ func (this *ParserATNSimulator) computeReachSet(closure *ATNConfigSet, t int, fu
|
|||
|
||||
for j := 0; j < len(c.GetState().GetTransitions()); j++ {
|
||||
var trans = c.GetState().GetTransitions()[j]
|
||||
var target = this.getReachableTarGet(trans, t)
|
||||
var target = this.getReachableTarget(trans, t)
|
||||
if target != nil {
|
||||
var cfg = NewATNConfig4(c, target)
|
||||
intermediate.add(cfg, this.mergeCache)
|
||||
|
@ -660,7 +654,7 @@ func (this *ParserATNSimulator) computeStartState(p IATNState, ctx IRuleContext,
|
|||
var initialContext = predictionContextFromRuleContext(this.atn, ctx)
|
||||
var configs = NewATNConfigSet(fullCtx)
|
||||
for i := 0; i < len(p.GetTransitions()); i++ {
|
||||
var target = p.GetTransitions()[i].getTarGet()
|
||||
var target = p.GetTransitions()[i].getTarget()
|
||||
var c = NewATNConfig5(target, i+1, initialContext, nil)
|
||||
var closureBusy = NewSet(nil, nil)
|
||||
this.closure(c, configs, closureBusy, true, fullCtx, false)
|
||||
|
@ -768,9 +762,9 @@ func (this *ParserATNSimulator) applyPrecedenceFilter(configs *ATNConfigSet) *AT
|
|||
return configSet
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) getReachableTarGet(trans ITransition, ttype int) IATNState {
|
||||
func (this *ParserATNSimulator) getReachableTarget(trans ITransition, ttype int) IATNState {
|
||||
if trans.Matches(ttype, 0, this.atn.maxTokenType) {
|
||||
return trans.getTarGet()
|
||||
return trans.getTarget()
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
@ -834,7 +828,7 @@ func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts *BitSet, altTo
|
|||
// algorithm to identify an ATN configuration which successfully parsed the
|
||||
// decision entry rule. Choosing such an alternative ensures that the
|
||||
// {@link ParserRuleContext} returned by the calling rule will be complete
|
||||
// and valid, and the syntax error will be reported later at a more
|
||||
// and valid, and the syntax error will be Reported later at a more
|
||||
// localized location.</p>
|
||||
//
|
||||
// <ul>
|
||||
|
@ -867,7 +861,7 @@ func (this *ParserATNSimulator) getPredicatePredictions(ambigAlts *BitSet, altTo
|
|||
//
|
||||
// @return The value to return from {@link //AdaptivePredict}, or
|
||||
// {@link ATN//INVALID_ALT_NUMBER} if a suitable alternative was not
|
||||
// identified and {@link //AdaptivePredict} should report an error instead.
|
||||
// identified and {@link //AdaptivePredict} should Report an error instead.
|
||||
//
|
||||
func (this *ParserATNSimulator) getSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(configs *ATNConfigSet, outerContext IParserRuleContext) int {
|
||||
var cfgs = this.splitAccordingToSemanticValidity(configs, outerContext)
|
||||
|
@ -1052,7 +1046,7 @@ func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSe
|
|||
var t = p.GetTransitions()[i]
|
||||
_, ok := t.(*ActionTransition)
|
||||
var continueCollecting = collectPredicates && !ok
|
||||
var c = this.getEpsilonTarGet(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon)
|
||||
var c = this.getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon)
|
||||
if c != nil {
|
||||
if !t.getIsEpsilon() && closureBusy.add(c) != c {
|
||||
// avoid infinite recursion for EOF* and EOF+
|
||||
|
@ -1103,7 +1097,7 @@ func (this *ParserATNSimulator) getRuleName(index int) string {
|
|||
}
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) getEpsilonTarGet(config IATNConfig, t ITransition, collectPredicates, inContext, fullCtx, treatEofAsEpsilon bool) *ATNConfig {
|
||||
func (this *ParserATNSimulator) getEpsilonTarget(config IATNConfig, t ITransition, collectPredicates, inContext, fullCtx, treatEofAsEpsilon bool) *ATNConfig {
|
||||
|
||||
switch t.getSerializationType() {
|
||||
case TransitionRULE:
|
||||
|
@ -1115,13 +1109,13 @@ func (this *ParserATNSimulator) getEpsilonTarGet(config IATNConfig, t ITransitio
|
|||
case TransitionACTION:
|
||||
return this.actionTransition(config, t.(*ActionTransition))
|
||||
case TransitionEPSILON:
|
||||
return NewATNConfig4(config, t.getTarGet())
|
||||
return NewATNConfig4(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 NewATNConfig4(config, t.getTarget())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -1130,7 +1124,7 @@ func (this *ParserATNSimulator) getEpsilonTarGet(config IATNConfig, t ITransitio
|
|||
// transition is traversed
|
||||
if treatEofAsEpsilon {
|
||||
if t.Matches(TokenEOF, 0, 1) {
|
||||
return NewATNConfig4(config, t.getTarGet())
|
||||
return NewATNConfig4(config, t.getTarget())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -1139,7 +1133,7 @@ func (this *ParserATNSimulator) getEpsilonTarGet(config IATNConfig, t ITransitio
|
|||
// transition is traversed
|
||||
if treatEofAsEpsilon {
|
||||
if t.Matches(TokenEOF, 0, 1) {
|
||||
return NewATNConfig4(config, t.getTarGet())
|
||||
return NewATNConfig4(config, t.getTarget())
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -1152,7 +1146,7 @@ func (this *ParserATNSimulator) actionTransition(config IATNConfig, t *ActionTra
|
|||
if ParserATNSimulatorprototypedebug {
|
||||
fmt.Println("ACTION edge " + strconv.Itoa(t.ruleIndex) + ":" + strconv.Itoa(t.actionIndex))
|
||||
}
|
||||
return NewATNConfig4(config, t.getTarGet())
|
||||
return NewATNConfig4(config, t.getTarget())
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) precedenceTransition(config IATNConfig,
|
||||
|
@ -1177,14 +1171,14 @@ func (this *ParserATNSimulator) precedenceTransition(config IATNConfig,
|
|||
var predSucceeds = pt.getPredicate().evaluate(this.parser, this._outerContext)
|
||||
this._input.Seek(currentPosition)
|
||||
if predSucceeds {
|
||||
c = NewATNConfig4(config, pt.getTarGet()) // no pred context
|
||||
c = NewATNConfig4(config, pt.getTarget()) // no pred context
|
||||
}
|
||||
} else {
|
||||
newSemCtx := SemanticContextandContext(config.GetSemanticContext(), pt.getPredicate())
|
||||
c = NewATNConfig3(config, pt.getTarGet(), newSemCtx)
|
||||
c = NewATNConfig3(config, pt.getTarget(), newSemCtx)
|
||||
}
|
||||
} else {
|
||||
c = NewATNConfig4(config, pt.getTarGet())
|
||||
c = NewATNConfig4(config, pt.getTarget())
|
||||
}
|
||||
if ParserATNSimulatorprototypedebug {
|
||||
fmt.Println("config from pred transition=" + c.toString())
|
||||
|
@ -1213,14 +1207,14 @@ func (this *ParserATNSimulator) predTransition(config IATNConfig, pt *PredicateT
|
|||
var predSucceeds = pt.getPredicate().evaluate(this.parser, this._outerContext)
|
||||
this._input.Seek(currentPosition)
|
||||
if predSucceeds {
|
||||
c = NewATNConfig4(config, pt.getTarGet()) // no pred context
|
||||
c = NewATNConfig4(config, pt.getTarget()) // no pred context
|
||||
}
|
||||
} else {
|
||||
var newSemCtx = SemanticContextandContext(config.GetSemanticContext(), pt.getPredicate())
|
||||
c = NewATNConfig3(config, pt.getTarGet(), newSemCtx)
|
||||
c = NewATNConfig3(config, pt.getTarget(), newSemCtx)
|
||||
}
|
||||
} else {
|
||||
c = NewATNConfig4(config, pt.getTarGet())
|
||||
c = NewATNConfig4(config, pt.getTarget())
|
||||
}
|
||||
if ParserATNSimulatorprototypedebug {
|
||||
fmt.Println("config from pred transition=" + c.toString())
|
||||
|
@ -1230,11 +1224,11 @@ func (this *ParserATNSimulator) predTransition(config IATNConfig, pt *PredicateT
|
|||
|
||||
func (this *ParserATNSimulator) ruleTransition(config IATNConfig, t *RuleTransition) *ATNConfig {
|
||||
if ParserATNSimulatorprototypedebug {
|
||||
fmt.Println("CALL rule " + this.getRuleName(t.getTarGet().GetRuleIndex()) + ", ctx=" + config.GetContext().toString())
|
||||
fmt.Println("CALL rule " + this.getRuleName(t.getTarget().GetRuleIndex()) + ", ctx=" + config.GetContext().toString())
|
||||
}
|
||||
var returnState = t.followState
|
||||
var newContext = SingletonPredictionContextCreate(config.GetContext(), returnState.GetStateNumber())
|
||||
return NewATNConfig1(config, t.getTarGet(), newContext)
|
||||
return NewATNConfig1(config, t.getTarget(), newContext)
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) getConflictingAlts(configs *ATNConfigSet) *BitSet {
|
||||
|
@ -1442,37 +1436,37 @@ func (this *ParserATNSimulator) addDFAState(dfa *DFA, D *DFAState) *DFAState {
|
|||
return D
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) reportAttemptingFullContext(dfa *DFA, conflictingAlts *BitSet, configs *ATNConfigSet, startIndex, stopIndex int) {
|
||||
func (this *ParserATNSimulator) ReportAttemptingFullContext(dfa *DFA, conflictingAlts *BitSet, configs *ATNConfigSet, startIndex, stopIndex int) {
|
||||
if ParserATNSimulatorprototypedebug || ParserATNSimulatorprototyperetry_debug {
|
||||
var interval = NewInterval(startIndex, stopIndex+1)
|
||||
fmt.Println("reportAttemptingFullContext decision=" + strconv.Itoa(dfa.decision) + ":" + configs.toString() +
|
||||
fmt.Println("ReportAttemptingFullContext decision=" + strconv.Itoa(dfa.decision) + ":" + configs.toString() +
|
||||
", input=" + this.parser.GetTokenStream().GetTextFromInterval(interval))
|
||||
}
|
||||
if this.parser != nil {
|
||||
this.parser.getErrorListenerDispatch().reportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs)
|
||||
this.parser.getErrorListenerDispatch().ReportAttemptingFullContext(this.parser, dfa, startIndex, stopIndex, conflictingAlts, configs)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ParserATNSimulator) reportContextSensitivity(dfa *DFA, prediction int, configs *ATNConfigSet, startIndex, stopIndex int) {
|
||||
func (this *ParserATNSimulator) ReportContextSensitivity(dfa *DFA, prediction int, configs *ATNConfigSet, startIndex, stopIndex int) {
|
||||
if ParserATNSimulatorprototypedebug || ParserATNSimulatorprototyperetry_debug {
|
||||
var interval = NewInterval(startIndex, stopIndex+1)
|
||||
fmt.Println("reportContextSensitivity decision=" + strconv.Itoa(dfa.decision) + ":" + configs.toString() +
|
||||
fmt.Println("ReportContextSensitivity decision=" + strconv.Itoa(dfa.decision) + ":" + configs.toString() +
|
||||
", input=" + this.parser.GetTokenStream().GetTextFromInterval(interval))
|
||||
}
|
||||
if this.parser != nil {
|
||||
this.parser.getErrorListenerDispatch().reportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs)
|
||||
this.parser.getErrorListenerDispatch().ReportContextSensitivity(this.parser, dfa, startIndex, stopIndex, prediction, configs)
|
||||
}
|
||||
}
|
||||
|
||||
// If context sensitive parsing, we know it's ambiguity not conflict//
|
||||
func (this *ParserATNSimulator) reportAmbiguity(dfa *DFA, D *DFAState, startIndex, stopIndex int,
|
||||
func (this *ParserATNSimulator) ReportAmbiguity(dfa *DFA, D *DFAState, startIndex, stopIndex int,
|
||||
exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||
if ParserATNSimulatorprototypedebug || ParserATNSimulatorprototyperetry_debug {
|
||||
var interval = NewInterval(startIndex, stopIndex+1)
|
||||
fmt.Println("reportAmbiguity " + ambigAlts.toString() + ":" + configs.toString() +
|
||||
fmt.Println("ReportAmbiguity " + ambigAlts.toString() + ":" + configs.toString() +
|
||||
", input=" + this.parser.GetTokenStream().GetTextFromInterval(interval))
|
||||
}
|
||||
if this.parser != nil {
|
||||
this.parser.getErrorListenerDispatch().reportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
|
||||
this.parser.getErrorListenerDispatch().ReportAmbiguity(this.parser, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,14 +35,6 @@ func NewParserRuleContext(parent IParserRuleContext, invokingStateNumber int) *P
|
|||
|
||||
prc := new(ParserRuleContext)
|
||||
|
||||
prc.ParserRuleContext = NewParserRuleContext(parent, invokingStateNumber)
|
||||
|
||||
return prc
|
||||
|
||||
}
|
||||
|
||||
func (prc *ParserRuleContext) InitParserRuleContext(parent IParserRuleContext, invokingStateNumber int) {
|
||||
|
||||
prc.RuleContext = NewRuleContext(parent, invokingStateNumber)
|
||||
|
||||
prc.RuleIndex = -1
|
||||
|
@ -59,6 +51,8 @@ func (prc *ParserRuleContext) InitParserRuleContext(parent IParserRuleContext, i
|
|||
// completed, prc is {@code nil}.
|
||||
prc.exception = nil
|
||||
|
||||
return prc
|
||||
|
||||
}
|
||||
|
||||
func (prc *ParserRuleContext) SetException(e IRecognitionException) {
|
||||
|
|
|
@ -154,12 +154,9 @@ type SingletonPredictionContext struct {
|
|||
}
|
||||
|
||||
func NewSingletonPredictionContext(parent IPredictionContext, returnState int) *SingletonPredictionContext {
|
||||
s := new(SingletonPredictionContext)
|
||||
s.SingletonPredictionContext = NewSingletonPredictionContext(parent, returnState)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SingletonPredictionContext) InitSingletonPredictionContext(parent IPredictionContext, returnState int) {
|
||||
s := new(SingletonPredictionContext)
|
||||
s.PredictionContext = NewPredictionContext("")
|
||||
|
||||
if parent != nil {
|
||||
s.cachedHashString = calculateHashString(parent, returnState)
|
||||
|
@ -170,6 +167,7 @@ func (s *SingletonPredictionContext) InitSingletonPredictionContext(parent IPred
|
|||
s.parentCtx = parent
|
||||
s.returnState = returnState
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func SingletonPredictionContextCreate(parent IPredictionContext, returnState int) IPredictionContext {
|
||||
|
@ -287,8 +285,7 @@ func NewArrayPredictionContext(parents []IPredictionContext, returnStates []int)
|
|||
// returnState == {@link //EMPTY_RETURN_STATE}.
|
||||
|
||||
c := new(ArrayPredictionContext)
|
||||
|
||||
c.cachedHashString = ""
|
||||
c.PredictionContext = NewPredictionContext("")
|
||||
|
||||
for i := range parents {
|
||||
c.cachedHashString += calculateHashString(parents[i], returnStates[i])
|
||||
|
|
|
@ -22,7 +22,7 @@ const (
|
|||
// <p>
|
||||
// When using this prediction mode, the parser will either return a correct
|
||||
// parse tree (i.e. the same parse tree that would be returned with the
|
||||
// {@link //LL} prediction mode), or it will report a syntax error. If a
|
||||
// {@link //LL} prediction mode), or it will Report a syntax error. If a
|
||||
// syntax error is encountered when using the {@link //SLL} prediction mode,
|
||||
// it may be due to either an actual syntax error in the input or indicate
|
||||
// that the particular combination of grammar and input requires the more
|
||||
|
@ -44,7 +44,7 @@ const (
|
|||
// When using this prediction mode, the parser will make correct decisions
|
||||
// for all syntactically-correct grammar and input combinations. However, in
|
||||
// cases where the grammar is truly ambiguous this prediction mode might not
|
||||
// report a precise answer for <em>exactly which</em> alternatives are
|
||||
// Report a precise answer for <em>exactly which</em> alternatives are
|
||||
// ambiguous.</p>
|
||||
//
|
||||
// <p>
|
||||
|
@ -361,7 +361,7 @@ func PredictionModeallConfigsInRuleStopStates(configs *ATNConfigSet) bool {
|
|||
//
|
||||
// <p><strong>EXACT AMBIGUITY DETECTION</strong></p>
|
||||
//
|
||||
// <p>If all states report the same conflicting set of alternatives, then we
|
||||
// <p>If all states Report the same conflicting set of alternatives, then we
|
||||
// know we have the exact ambiguity set.</p>
|
||||
//
|
||||
// <p><code>|A_<em>i</em>|>1</code> and
|
||||
|
|
|
@ -35,13 +35,9 @@ type Recognizer struct {
|
|||
|
||||
func NewRecognizer() *Recognizer {
|
||||
rec := new(Recognizer)
|
||||
rec.Recognizer = NewRecognizer()
|
||||
return rec
|
||||
}
|
||||
|
||||
func (rec *Recognizer) InitRecognizer() {
|
||||
rec._listeners = []IErrorListener{ConsoleErrorListenerINSTANCE}
|
||||
rec.state = -1
|
||||
return rec
|
||||
}
|
||||
|
||||
var tokenTypeMapCache = make(map[string]int)
|
||||
|
|
|
@ -49,13 +49,6 @@ func NewRuleContext(parent IRuleContext, invokingState int) *RuleContext {
|
|||
|
||||
rn := new(RuleContext)
|
||||
|
||||
rn.RuleContext = NewRuleContext(parent, invokingState)
|
||||
|
||||
return rn
|
||||
}
|
||||
|
||||
func (rn *RuleContext) InitRuleContext(parent IRuleContext, invokingState int) {
|
||||
|
||||
// What context invoked this rule?
|
||||
rn.parentCtx = parent
|
||||
|
||||
|
@ -67,6 +60,8 @@ func (rn *RuleContext) InitRuleContext(parent IRuleContext, invokingState int) {
|
|||
} else {
|
||||
rn.invokingState = invokingState
|
||||
}
|
||||
|
||||
return rn
|
||||
}
|
||||
|
||||
func (this *RuleContext) setChildren(elems []Tree) {
|
||||
|
|
|
@ -15,8 +15,8 @@ import (
|
|||
// ATN transitions.</p>
|
||||
|
||||
type ITransition interface {
|
||||
getTarGet() IATNState
|
||||
setTarGet(IATNState)
|
||||
getTarget() IATNState
|
||||
setTarget(IATNState)
|
||||
getIsEpsilon() bool
|
||||
getLabel() *IntervalSet
|
||||
getSerializationType() int
|
||||
|
@ -37,23 +37,20 @@ func NewTransition(target IATNState) *Transition {
|
|||
}
|
||||
|
||||
t := new(Transition)
|
||||
t.Transition = NewTransition(target)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *Transition) InitTransition(target IATNState) {
|
||||
t.target = target
|
||||
// Are we epsilon, action, sempred?
|
||||
t.isEpsilon = false
|
||||
t.label = nil
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *Transition) getTarGet() IATNState {
|
||||
func (t *Transition) getTarget() IATNState {
|
||||
return t.target
|
||||
}
|
||||
|
||||
func (t *Transition) setTarGet(s IATNState) {
|
||||
func (t *Transition) setTarget(s IATNState) {
|
||||
t.target = s
|
||||
}
|
||||
|
||||
|
@ -320,12 +317,6 @@ func NewSetTransition(target IATNState, set *IntervalSet) *SetTransition {
|
|||
|
||||
t := new(SetTransition)
|
||||
t.Transition = NewTransition(target)
|
||||
t.SetTransition = NewSetTransition(set)
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *SetTransition) InitSetTransition(set *IntervalSet) {
|
||||
|
||||
t.serializationType = TransitionSET
|
||||
if set != nil && set != nil {
|
||||
|
@ -335,6 +326,7 @@ func (t *SetTransition) InitSetTransition(set *IntervalSet) {
|
|||
t.label.addOne(TokenInvalidType)
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *SetTransition) Matches(symbol, minVocabSymbol, maxVocabSymbol int) bool {
|
||||
|
@ -346,14 +338,14 @@ func (t *SetTransition) toString() string {
|
|||
}
|
||||
|
||||
type NotSetTransition struct {
|
||||
SetTransition
|
||||
*SetTransition
|
||||
}
|
||||
|
||||
func NewNotSetTransition(target IATNState, set *IntervalSet) *NotSetTransition {
|
||||
|
||||
t := new(NotSetTransition)
|
||||
t.Transition = NewTransition(target)
|
||||
t.SetTransition = NewSetTransition(set)
|
||||
|
||||
t.SetTransition = NewSetTransition(target, set)
|
||||
|
||||
t.serializationType = TransitionNOT_SET
|
||||
|
||||
|
|
|
@ -93,15 +93,12 @@ type TerminalNodeImpl struct {
|
|||
func NewTerminalNodeImpl(symbol *Token) *TerminalNodeImpl {
|
||||
tn := new(TerminalNodeImpl)
|
||||
|
||||
tn.TerminalNodeImpl = NewTerminalNodeImpl(symbol)
|
||||
tn.parentCtx = nil
|
||||
tn.symbol = symbol
|
||||
|
||||
return tn
|
||||
}
|
||||
|
||||
func (this *TerminalNodeImpl) InitTerminalNodeImpl(symbol *Token) {
|
||||
this.parentCtx = nil
|
||||
this.symbol = symbol
|
||||
}
|
||||
|
||||
func (this *TerminalNodeImpl) getChild(i int) Tree {
|
||||
return nil
|
||||
|
|
|
@ -122,7 +122,7 @@ func New<parser.name>(input antlr4.TokenStream) *<parser.name> {
|
|||
|
||||
parser := new(<parser.name>)
|
||||
|
||||
parser.Parser = NewParser(input)
|
||||
parser.Parser = antlr4.NewParser(input)
|
||||
|
||||
parser.Interpreter = antlr4.NewParserATNSimulator(parser, deserializedATN, decisionToDFA, sharedContextCache)
|
||||
parser.RuleNames = ruleNames
|
||||
|
@ -663,7 +663,7 @@ func New<struct.name>(parser antlr4.IParser, parent antlr4.IParserRuleContext, i
|
|||
|
||||
var p = new(<struct.name>)
|
||||
|
||||
p.ParserRuleContext = NewParserRuleContext( parent, invokingState )
|
||||
p.ParserRuleContext = antlr4.NewParserRuleContext( parent, invokingState )
|
||||
|
||||
p.parser = parser
|
||||
p.RuleIndex = <parser.name>RULE_<struct.derivedFromName>
|
||||
|
@ -823,7 +823,7 @@ func New<lexer.name>(input antlr4.CharStream) *<lexer.name> {
|
|||
|
||||
lex := new(<lexer.name>)
|
||||
|
||||
lex.Lexer = NewLexer(input)
|
||||
lex.Lexer = antlr4.NewLexer(input)
|
||||
|
||||
lex.Interpreter = antlr4.NewLexerATNSimulator(lex, lexerAtn, lexerDecisionToDFA, antlr4.NewPredictionContextCache())
|
||||
|
||||
|
|
Loading…
Reference in New Issue