aboutsummaryrefslogtreecommitdiff
path: root/compiler/dfa.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-02-16 00:07:40 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-02-16 00:07:40 +0900
commitc313f7870bd547534c7c7bb0ad01003ab9983b34 (patch)
treef1b6a443c4372f9eb69f314009d721703e208a0b /compiler/dfa.go
parentAdd bracket expression matching specified character (diff)
downloadtre-c313f7870bd547534c7c7bb0ad01003ab9983b34.tar.gz
tre-c313f7870bd547534c7c7bb0ad01003ab9983b34.tar.xz
Add types of lexical specifications
APIs of compiler and driver packages use these types. Because CompiledLexSpec struct a lexer takes has kind names of lexical specification entries, the lexer sets them to tokens.
Diffstat (limited to 'compiler/dfa.go')
-rw-r--r--compiler/dfa.go12
1 files changed, 4 insertions, 8 deletions
diff --git a/compiler/dfa.go b/compiler/dfa.go
index fec93ce..b07954f 100644
--- a/compiler/dfa.go
+++ b/compiler/dfa.go
@@ -2,6 +2,8 @@ package compiler
import (
"sort"
+
+ "github.com/nihei9/maleeni/spec"
)
type DFA struct {
@@ -99,13 +101,7 @@ func genDFA(root astNode, symTab *symbolTable) *DFA {
}
}
-type TransitionTable struct {
- InitialState int `json:"initial_state"`
- AcceptingStates map[int]int `json:"accepting_states"`
- Transition [][]int `json:"transition"`
-}
-
-func GenTransitionTable(dfa *DFA) (*TransitionTable, error) {
+func genTransitionTable(dfa *DFA) (*spec.TransitionTable, error) {
state2Num := map[string]int{}
for i, s := range dfa.States {
state2Num[s] = i + 1
@@ -125,7 +121,7 @@ func GenTransitionTable(dfa *DFA) (*TransitionTable, error) {
tran[state2Num[s]] = entry
}
- return &TransitionTable{
+ return &spec.TransitionTable{
InitialState: state2Num[dfa.InitialState],
AcceptingStates: acc,
Transition: tran,