From 9d451ffd19f975314a6a2c8989100d762e2f5319 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sat, 30 Jan 2021 18:29:32 +0300 Subject: [PATCH] use ascii space/digits in scanner cc #572 --- scan.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scan.go b/scan.go index 85fd39c..3ac93af 100644 --- a/scan.go +++ b/scan.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "log" "strconv" - "unicode" ) type tokenType byte @@ -82,15 +81,23 @@ func (s *scanner) peek() byte { } func isSpace(b byte) bool { - return unicode.IsSpace(rune(b)) + switch b { + case '\t', '\n', '\v', '\f', '\r', ' ': + return true + } + return false } func isDigit(b byte) bool { - return unicode.IsDigit(rune(b)) + return '0' <= b && b <= '9' } func isPrefix(b byte) bool { - return b == '$' || b == '%' || b == '!' || b == '&' + switch b { + case '$', '%', '!', '&': + return true + } + return false } func (s *scanner) scan() bool {