diff options
author | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-24 01:30:08 +0900 |
---|---|---|
committer | Ryo Nihei <nihei.dev@gmail.com> | 2021-02-24 01:30:08 +0900 |
commit | e5fb2fe4f4dfc7dff550b934933b88e9392a6e11 (patch) | |
tree | 7ffa58f2106d8b3bbbe931b84f73a9fb5c2b51a1 /compiler/lexer.go | |
parent | Add + and ? operators (diff) | |
download | tre-e5fb2fe4f4dfc7dff550b934933b88e9392a6e11.tar.gz tre-e5fb2fe4f4dfc7dff550b934933b88e9392a6e11.tar.xz |
Add range expression
[a-z] matches any one character from a to z. The order of the characters depends on Unicode code points.
Diffstat (limited to 'compiler/lexer.go')
-rw-r--r-- | compiler/lexer.go | 5 |
1 files changed, 4 insertions, 1 deletions
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{ |