aboutsummaryrefslogtreecommitdiff
path: root/compiler/lexer_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-02-14 20:19:22 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-02-14 20:19:22 +0900
commit467f223668d13ffa42679e6c928d82d5d402d87d (patch)
treeb518082b8af4d79b19b41e8beacc085d6f0cf84f /compiler/lexer_test.go
parentAdd dot symbol matching any single character (diff)
downloadtre-467f223668d13ffa42679e6c928d82d5d402d87d.tar.gz
tre-467f223668d13ffa42679e6c928d82d5d402d87d.tar.xz
Add bracket expression matching specified character
The bracket expression matches any single character specified in it. In the bracket expression, the special characters like ., *, and so on are also handled as normal characters.
Diffstat (limited to 'compiler/lexer_test.go')
-rw-r--r--compiler/lexer_test.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/compiler/lexer_test.go b/compiler/lexer_test.go
index 75770b0..11cf043 100644
--- a/compiler/lexer_test.go
+++ b/compiler/lexer_test.go
@@ -31,19 +31,21 @@ func TestLexer(t *testing.T) {
},
{
caption: "lexer can recognize the special characters",
- src: ".*|()",
+ src: ".*|()[]",
tokens: []*token{
newToken(tokenKindAnyChar, nullChar),
newToken(tokenKindRepeat, nullChar),
newToken(tokenKindAlt, nullChar),
newToken(tokenKindGroupOpen, nullChar),
newToken(tokenKindGroupClose, nullChar),
+ newToken(tokenKindBExpOpen, nullChar),
+ newToken(tokenKindBExpClose, nullChar),
newToken(tokenKindEOF, nullChar),
},
},
{
caption: "lexer can recognize the escape sequences",
- src: "\\\\\\.\\*\\|\\(\\)",
+ src: "\\\\\\.\\*\\|\\(\\)\\[\\]",
tokens: []*token{
newToken(tokenKindChar, '\\'),
newToken(tokenKindChar, '.'),
@@ -51,6 +53,32 @@ func TestLexer(t *testing.T) {
newToken(tokenKindChar, '|'),
newToken(tokenKindChar, '('),
newToken(tokenKindChar, ')'),
+ newToken(tokenKindChar, '['),
+ newToken(tokenKindChar, ']'),
+ newToken(tokenKindEOF, nullChar),
+ },
+ },
+ {
+ caption: "in a bracket expression, the special characters are also handled as normal characters",
+ src: "[\\\\.*|()[\\]].*|()][",
+ tokens: []*token{
+ newToken(tokenKindBExpOpen, nullChar),
+ newToken(tokenKindChar, '\\'),
+ newToken(tokenKindChar, '.'),
+ newToken(tokenKindChar, '*'),
+ newToken(tokenKindChar, '|'),
+ newToken(tokenKindChar, '('),
+ newToken(tokenKindChar, ')'),
+ newToken(tokenKindChar, '['),
+ newToken(tokenKindChar, ']'),
+ newToken(tokenKindBExpClose, nullChar),
+ newToken(tokenKindAnyChar, nullChar),
+ newToken(tokenKindRepeat, nullChar),
+ newToken(tokenKindAlt, nullChar),
+ newToken(tokenKindGroupOpen, nullChar),
+ newToken(tokenKindGroupClose, nullChar),
+ newToken(tokenKindBExpClose, nullChar),
+ newToken(tokenKindBExpOpen, nullChar),
newToken(tokenKindEOF, nullChar),
},
},