diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-14 20:19:22 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-14 20:19:22 +0900 |
commit | 467f223668d13ffa42679e6c928d82d5d402d87d (patch) | |
tree | b518082b8af4d79b19b41e8beacc085d6f0cf84f /compiler/lexer_test.go | |
parent | Add dot symbol matching any single character (diff) | |
download | tre-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.go | 32 |
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), }, }, |