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.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'spec/lexer.go') diff --git a/spec/lexer.go b/spec/lexer.go index 1f8805a..1f50a27 100644 --- a/spec/lexer.go +++ b/spec/lexer.go @@ -210,9 +210,25 @@ func (l *lexer) lexAndSkipWSs() (*token, error) { Row: l.row, } case "terminal_close": - return newTerminalPatternToken(b.String(), newPosition(l.row)), nil + pat := b.String() + if pat == "" { + return nil, &verr.SpecError{ + Cause: synErrEmptyPattern, + Row: l.row, + } + } + return newTerminalPatternToken(pat, newPosition(l.row)), nil + } + } + case "literal_pattern": + pat := strings.Trim(tok.Text(), "'") + if pat == "" { + return nil, &verr.SpecError{ + Cause: synErrEmptyPattern, + Row: l.row, } } + return newTerminalPatternToken(mlspec.EscapePattern(pat), newPosition(l.row)), nil case "colon": return newSymbolToken(tokenKindColon, newPosition(l.row)), nil case "or": -- cgit v1.2.3