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. --- spec/spec.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/spec.go (limited to 'spec/spec.go') diff --git a/spec/spec.go b/spec/spec.go new file mode 100644 index 0000000..d827b68 --- /dev/null +++ b/spec/spec.go @@ -0,0 +1,28 @@ +package spec + +type LexEntry struct { + Kind string `json:"kind"` + Pattern string `json:"pattern"` +} + +func NewLexEntry(kind string, pattern string) *LexEntry { + return &LexEntry{ + Kind: kind, + Pattern: pattern, + } +} + +type LexSpec struct { + Entries []*LexEntry `json:"entries"` +} + +type TransitionTable struct { + InitialState int `json:"initial_state"` + AcceptingStates map[int]int `json:"accepting_states"` + Transition [][]int `json:"transition"` +} + +type CompiledLexSpec struct { + Kinds []string `json:"kinds"` + DFA *TransitionTable `json:"dfa"` +} -- cgit v1.2.3