From 0baa69676ca83dbb4fe7241478a6ecf6c85418a9 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Thu, 22 Jul 2021 20:30:23 +0900 Subject: 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 #(...). --- spec/lexer_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'spec/lexer_test.go') 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(), }, }, @@ -63,6 +64,16 @@ func TestLexer_Run(t *testing.T) { newEOFToken(), }, }, + { + 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", -- cgit v1.2.3