From e6a0cce6db6273c8e753dd448601cdd70de4ae3d Mon Sep 17 00:00:00 2001 From: Peter Boyer Date: Fri, 25 Dec 2015 16:46:09 -0600 Subject: [PATCH] Time to find more bugs --- runtime/Go/src/antlr4/ATNConfigSet.go | 5 ++++- runtime/Go/src/antlr4/DFA.go | 27 +++++++++++++++---------- runtime/Go/src/antlr4/PredictionMode.go | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/runtime/Go/src/antlr4/ATNConfigSet.go b/runtime/Go/src/antlr4/ATNConfigSet.go index 98433b1cf..48f482a32 100644 --- a/runtime/Go/src/antlr4/ATNConfigSet.go +++ b/runtime/Go/src/antlr4/ATNConfigSet.go @@ -253,8 +253,11 @@ func (this *ATNConfigSet) setReadonly(readOnly bool) { func (this *ATNConfigSet) toString() string { s := "" - for _,c := range this.configs { + for i,c := range this.configs { s += c.toString() + if (i != len(this.configs)-1){ + s += "," + } } if (this.hasSemanticContext){ diff --git a/runtime/Go/src/antlr4/DFA.go b/runtime/Go/src/antlr4/DFA.go index 74feeadf0..ede0e56b0 100644 --- a/runtime/Go/src/antlr4/DFA.go +++ b/runtime/Go/src/antlr4/DFA.go @@ -1,4 +1,5 @@ package antlr4 +import "sort" type DFA struct { atnStartState IDecisionState @@ -107,21 +108,25 @@ func (this *DFA) GetStates() map[string]*DFAState { return this._states } +type DFAStateList []*DFAState + +func (a DFAStateList) Len() int { return len(a) } +func (a DFAStateList) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a DFAStateList) Less(i, j int) bool { return a[i].stateNumber < a[j].stateNumber } + // Return a list of all states in this DFA, ordered by state number. func (this *DFA) sortedStates() []*DFAState { - panic("Not implemented") + // extract the values + vs := make([]*DFAState, len(this._states)) + i := 0 + for _,v := range this._states { + vs[i] = v + i++ + } - return nil - // states_ is a map of state/state, where key=value - // var keys = Object.keys(this._states) - // var list = [] - // for i:=0; i