From c313f7870bd547534c7c7bb0ad01003ab9983b34 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Tue, 16 Feb 2021 00:07:40 +0900 Subject: 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. --- compiler/dfa.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'compiler/dfa.go') 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, -- cgit v1.2.3