aboutsummaryrefslogtreecommitdiff
path: root/driver/lexer_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-08-01 17:17:53 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-08-01 21:18:34 +0900
commit2433c27f26bc1be2d9b33f6550482abc48fa31ef (patch)
treec7cbc22929045e2d5dccdc37cc978138b59c1bdb /driver/lexer_test.go
parentAdd unique kind IDs to tokens (diff)
downloadtre-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 'driver/lexer_test.go')
-rw-r--r--driver/lexer_test.go18
1 files changed, 9 insertions, 9 deletions
diff --git a/driver/lexer_test.go b/driver/lexer_test.go
index 79ee12e..5abe83c 100644
--- a/driver/lexer_test.go
+++ b/driver/lexer_test.go
@@ -16,7 +16,7 @@ func newLexEntry(modes []string, kind string, pattern string, push string, pop b
ms = append(ms, spec.LexModeName(m))
}
return &spec.LexEntry{
- Kind: spec.LexKind(kind),
+ Kind: spec.LexKindName(kind),
Pattern: spec.LexPattern(pattern),
Modes: ms,
Push: spec.LexModeName(push),
@@ -26,7 +26,7 @@ func newLexEntry(modes []string, kind string, pattern string, push string, pop b
func newLexEntryDefaultNOP(kind string, pattern string) *spec.LexEntry {
return &spec.LexEntry{
- Kind: spec.LexKind(kind),
+ Kind: spec.LexKindName(kind),
Pattern: spec.LexPattern(pattern),
Modes: []spec.LexModeName{
spec.LexModeNameDefault,
@@ -36,18 +36,18 @@ func newLexEntryDefaultNOP(kind string, pattern string) *spec.LexEntry {
func newLexEntryFragment(kind string, pattern string) *spec.LexEntry {
return &spec.LexEntry{
- Kind: spec.LexKind(kind),
+ Kind: spec.LexKindName(kind),
Pattern: spec.LexPattern(pattern),
Fragment: true,
}
}
func newTokenDefault(kindID int, modeKindID int, kindName string, match byteSequence) *Token {
- return newToken(spec.LexModeNumDefault, spec.LexModeNameDefault, kindID, modeKindID, kindName, match)
+ return newToken(spec.LexModeIDDefault, spec.LexModeNameDefault, spec.LexKindID(kindID), spec.LexModeKindID(modeKindID), spec.LexKindName(kindName), match)
}
func newEOFTokenDefault() *Token {
- return newEOFToken(spec.LexModeNumDefault, spec.LexModeNameDefault)
+ return newEOFToken(spec.LexModeIDDefault, spec.LexModeNameDefault)
}
func TestLexer_Next(t *testing.T) {
@@ -604,7 +604,7 @@ func TestLexer_Next(t *testing.T) {
},
passiveModeTran: true,
tran: func(l *Lexer, tok *Token) error {
- switch l.clspec.Modes[l.Mode().Int()] {
+ switch l.clspec.ModeNames[l.Mode()] {
case "default":
switch tok.KindName {
case "push_1":
@@ -653,7 +653,7 @@ func TestLexer_Next(t *testing.T) {
// Active mode transition and an external transition function can be used together.
passiveModeTran: false,
tran: func(l *Lexer, tok *Token) error {
- switch l.clspec.Modes[l.Mode().Int()] {
+ switch l.clspec.ModeNames[l.Mode()] {
case "mode_1":
switch tok.KindName {
case "push_2":
@@ -736,10 +736,10 @@ func TestLexer_Next(t *testing.T) {
func testToken(t *testing.T, expected, actual *Token) {
t.Helper()
- if actual.Mode != expected.Mode ||
+ if actual.ModeID != expected.ModeID ||
actual.ModeName != expected.ModeName ||
actual.KindID != expected.KindID ||
- actual.Kind != expected.Kind ||
+ actual.ModeKindID != expected.ModeKindID ||
actual.KindName != expected.KindName ||
!bytes.Equal(actual.Match(), expected.Match()) ||
actual.EOF != expected.EOF ||