aboutsummaryrefslogtreecommitdiff
path: root/spec/lexer_test.go
diff options
context:
space:
mode:
authorRyo Nihei <nihei.dev@gmail.com>2021-07-22 20:30:23 +0900
committerRyo Nihei <nihei.dev@gmail.com>2021-07-22 20:30:23 +0900
commit0baa69676ca83dbb4fe7241478a6ecf6c85418a9 (patch)
treef337b96c1d2c4742647b9e4570d34788014333d3 /spec/lexer_test.go
parentWrite a description file (diff)
downloadcotia-0baa69676ca83dbb4fe7241478a6ecf6c85418a9.tar.gz
cotia-0baa69676ca83dbb4fe7241478a6ecf6c85418a9.tar.xz
Add literal pattern syntax and change tree structure syntax
- Literal patterns don't interpret the special characters of regular expressions. In other words, 'abc|def' matches only `abc|def`, not `abc` or `def`. - Change tree structure syntax from '(...) to #(...).
Diffstat (limited to 'spec/lexer_test.go')
-rw-r--r--spec/lexer_test.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/spec/lexer_test.go b/spec/lexer_test.go
index 89553d0..569f278 100644
--- a/spec/lexer_test.go
+++ b/spec/lexer_test.go
@@ -32,18 +32,19 @@ func TestLexer_Run(t *testing.T) {
}{
{
caption: "the lexer can recognize all kinds of tokens",
- src: `id"terminal":|;#'()$1...`,
+ src: `id"terminal"'.*+?|()[\':|;#()$1...#`,
tokens: []*token{
idTok("id"),
termPatTok("terminal"),
+ termPatTok(`\.\*\+\?\|\(\)\[\\`),
symTok(tokenKindColon),
symTok(tokenKindOr),
symTok(tokenKindSemicolon),
- symTok(tokenKindDirectiveMarker),
symTok(tokenKindTreeNodeOpen),
symTok(tokenKindTreeNodeClose),
posTok(1),
symTok(tokenKindExpantion),
+ symTok(tokenKindDirectiveMarker),
newEOFToken(),
},
},
@@ -64,6 +65,16 @@ func TestLexer_Run(t *testing.T) {
},
},
{
+ caption: "a pattern must include at least one character",
+ src: `""`,
+ err: synErrEmptyPattern,
+ },
+ {
+ caption: "a literal pattern must include at least one character",
+ src: `''`,
+ err: synErrEmptyPattern,
+ },
+ {
caption: "the lexer can recognize newlines and combine consecutive newlines into one",
src: "\u000A | \u000D | \u000D\u000A | \u000A\u000A \u000D\u000D \u000D\u000A\u000D\u000A",
tokens: []*token{