diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-01 17:17:53 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-08-01 21:18:34 +0900 |
commit | 2433c27f26bc1be2d9b33f6550482abc48fa31ef (patch) | |
tree | c7cbc22929045e2d5dccdc37cc978138b59c1bdb /compiler/parser.go | |
parent | Add unique kind IDs to tokens (diff) | |
download | tre-2433c27f26bc1be2d9b33f6550482abc48fa31ef.tar.gz tre-2433c27f26bc1be2d9b33f6550482abc48fa31ef.tar.xz |
Change APIs
Change fields of tokens, results of lexical analysis, as follows:
- Rename: mode -> mode_id
- Rename: kind_id -> mode_kind_id
- Add: kind_id
The kind ID is unique across all modes, but the mode kind ID is unique only within a mode.
Change fields of a transition table as follows:
- Rename: initial_mode -> initial_mode_id
- Rename: modes -> mode_names
- Rename: kinds -> kind_names
- Rename: specs[].kinds -> specs[].kind_names
- Rename: specs[].dfa.initial_state -> specs[].dfa.initial_state_id
Change public types defined in the spec package as follows:
- Rename: LexModeNum -> LexModeID
- Rename: LexKind -> LexKindName
- Add: LexKindID
- Add: StateID
Diffstat (limited to 'compiler/parser.go')
-rw-r--r-- | compiler/parser.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/compiler/parser.go b/compiler/parser.go index 06a762d..1c9126a 100644 --- a/compiler/parser.go +++ b/compiler/parser.go @@ -7,6 +7,8 @@ import ( "fmt" "io" "strings" + + "github.com/nihei9/maleeni/spec" ) type ParseErrors struct { @@ -23,7 +25,7 @@ func (e *ParseErrors) Error() string { } type ParseError struct { - ID int + ID spec.LexModeKindID Pattern []byte Cause error Details string @@ -44,13 +46,13 @@ func raiseSyntaxError(synErr *SyntaxError) { type symbolTable struct { symPos2Byte map[symbolPosition]byteRange - endPos2ID map[symbolPosition]int + endPos2ID map[symbolPosition]spec.LexModeKindID } func genSymbolTable(root astNode) *symbolTable { symTab := &symbolTable{ symPos2Byte: map[symbolPosition]byteRange{}, - endPos2ID: map[symbolPosition]int{}, + endPos2ID: map[symbolPosition]spec.LexModeKindID{}, } return genSymTab(symTab, root) } @@ -76,7 +78,7 @@ func genSymTab(symTab *symbolTable, node astNode) *symbolTable { return symTab } -func parse(regexps map[int][]byte, fragments map[string][]byte) (astNode, *symbolTable, error) { +func parse(regexps map[spec.LexModeKindID][]byte, fragments map[string][]byte) (astNode, *symbolTable, error) { if len(regexps) == 0 { return nil, nil, fmt.Errorf("parse() needs at least one token entry") } @@ -159,7 +161,7 @@ func parseFragments(fragments map[string][]byte) (map[string]astNode, error) { return fragmentASTs, nil } -func parseRegexp(regexps map[int][]byte, fragmentASTs map[string]astNode) (astNode, error) { +func parseRegexp(regexps map[spec.LexModeKindID][]byte, fragmentASTs map[string]astNode) (astNode, error) { symPos := symbolPositionMin var root astNode var perrs []*ParseError |