From e5fb2fe4f4dfc7dff550b934933b88e9392a6e11 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Wed, 24 Feb 2021 01:30:08 +0900 Subject: Add range expression [a-z] matches any one character from a to z. The order of the characters depends on Unicode code points. --- compiler/lexer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'compiler/lexer.go') diff --git a/compiler/lexer.go b/compiler/lexer.go index 91cd209..acc9658 100644 --- a/compiler/lexer.go +++ b/compiler/lexer.go @@ -19,6 +19,7 @@ const ( tokenKindGroupClose = tokenKind(")") tokenKindBExpOpen = tokenKind("[") tokenKindBExpClose = tokenKind("]") + tokenKindCharRange = tokenKind("-") tokenKindEOF = tokenKind("eof") ) @@ -124,6 +125,8 @@ func (l *lexer) nextInDefault(c rune) (*token, error) { func (l *lexer) nextInBExp(c rune) (*token, error) { switch c { + case '-': + return newToken(tokenKindCharRange, nullChar), nil case ']': l.mode = lexerModeDefault return newToken(tokenKindBExpClose, nullChar), nil @@ -138,7 +141,7 @@ func (l *lexer) nextInBExp(c rune) (*token, error) { } } switch { - case c == '\\' || c == ']': + case c == '\\' || c == '-' || c == ']': return newToken(tokenKindChar, c), nil default: return nil, &SyntaxError{ -- cgit v1.2.3