aboutsummaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-04-01 21:03:40 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-04-01 21:03:40 +0900
commit69643f8e38ee74406365704f73be4d5f865af8da (patch)
treefca8d8371527a59f09778fa124d4b90addca6c88 /driver
parentPass values in error type to panic() (diff)
downloadtre-69643f8e38ee74406365704f73be4d5f865af8da.tar.gz
tre-69643f8e38ee74406365704f73be4d5f865af8da.tar.xz
Add logical inverse expression
[^a-z] matches any character that is not in the range a-z.
Diffstat (limited to 'driver')
-rw-r--r--driver/lexer_test.go23
1 files changed, 20 insertions, 3 deletions
diff --git a/driver/lexer_test.go b/driver/lexer_test.go
index bdf5f03..0c9f720 100644
--- a/driver/lexer_test.go
+++ b/driver/lexer_test.go
@@ -136,18 +136,23 @@ func TestLexer_Next(t *testing.T) {
lspec: &spec.LexSpec{
Entries: []*spec.LexEntry{
// all 1 byte characters
- spec.NewLexEntry("1ByteChar", "[\x00-\x7f]"),
+ //
+ // NOTE:
+ // maleeni cannot handle the null character in patterns because compiler.lexer,
+ // specifically read() and restore(), recognizes the null characters as that a symbol doesn't exist.
+ // There is room for improvement in this behavior of the lexer.
+ spec.NewLexEntry("1ByteChar", "[\x01-\x7f]"),
},
},
src: string([]byte{
- 0x00,
0x01,
+ 0x02,
0x7e,
0x7f,
}),
tokens: []*Token{
- newToken(1, "1ByteChar", []byte{0x00}),
newToken(1, "1ByteChar", []byte{0x01}),
+ newToken(1, "1ByteChar", []byte{0x02}),
newToken(1, "1ByteChar", []byte{0x7e}),
newToken(1, "1ByteChar", []byte{0x7f}),
newEOFToken(),
@@ -391,6 +396,18 @@ func TestLexer_Next(t *testing.T) {
newEOFToken(),
},
},
+ {
+ lspec: &spec.LexSpec{
+ Entries: []*spec.LexEntry{
+ spec.NewLexEntry("NonNumber", "[^0-9]+[0-9]"),
+ },
+ },
+ src: "foo9",
+ tokens: []*Token{
+ newToken(1, "NonNumber", []byte("foo9")),
+ newEOFToken(),
+ },
+ },
}
for _, tt := range test {
clspec, err := compiler.Compile(tt.lspec)