aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/dfa.go8
-rw-r--r--driver/lexer.go4
-rw-r--r--spec/spec.go2
3 files changed, 9 insertions, 5 deletions
diff --git a/compiler/dfa.go b/compiler/dfa.go
index de2c451..ad42322 100644
--- a/compiler/dfa.go
+++ b/compiler/dfa.go
@@ -107,8 +107,12 @@ func genTransitionTable(dfa *DFA) (*spec.TransitionTable, error) {
state2Num[s] = i + 1
}
- acc := map[int]int{}
- for s, id := range dfa.AcceptingStatesTable {
+ acc := make([]int, len(dfa.States)+1)
+ for _, s := range dfa.States {
+ id, ok := dfa.AcceptingStatesTable[s]
+ if !ok {
+ continue
+ }
acc[state2Num[s]] = id
}
diff --git a/driver/lexer.go b/driver/lexer.go
index 485bfd9..7886720 100644
--- a/driver/lexer.go
+++ b/driver/lexer.go
@@ -264,8 +264,8 @@ func (l *lexer) next() (*Token, error) {
return newInvalidToken(mode, modeName, newByteSequence(buf)), nil
}
state = nextState
- id, ok := spec.DFA.AcceptingStates[state]
- if ok {
+ id := spec.DFA.AcceptingStates[state]
+ if id != 0 {
tok = newToken(mode, modeName, id, spec.Kinds[id].String(), newByteSequence(buf))
unfixedBufLen = 0
}
diff --git a/spec/spec.go b/spec/spec.go
index 1dba132..7398ea3 100644
--- a/spec/spec.go
+++ b/spec/spec.go
@@ -171,7 +171,7 @@ type UniqueEntriesTable struct {
type TransitionTable struct {
InitialState int `json:"initial_state"`
- AcceptingStates map[int]int `json:"accepting_states"`
+ AcceptingStates []int `json:"accepting_states"`
RowCount int `json:"row_count"`
ColCount int `json:"col_count"`
Transition *UniqueEntriesTable `json:"transition,omitempty"`