diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-16 00:07:40 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-16 00:07:40 +0900 |
commit | c313f7870bd547534c7c7bb0ad01003ab9983b34 (patch) | |
tree | f1b6a443c4372f9eb69f314009d721703e208a0b /spec/spec.go | |
parent | Add bracket expression matching specified character (diff) | |
download | tre-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 'spec/spec.go')
-rw-r--r-- | spec/spec.go | 28 |
1 files changed, 28 insertions, 0 deletions
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"` +} |