use ascii space/digits in scanner

cc #572
This commit is contained in:
Gokcehan 2021-01-30 18:29:32 +03:00
parent 2aa50aecaf
commit 9d451ffd19

15
scan.go
View File

@ -5,7 +5,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"strconv" "strconv"
"unicode"
) )
type tokenType byte type tokenType byte
@ -82,15 +81,23 @@ func (s *scanner) peek() byte {
} }
func isSpace(b byte) bool { 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 { func isDigit(b byte) bool {
return unicode.IsDigit(rune(b)) return '0' <= b && b <= '9'
} }
func isPrefix(b byte) bool { func isPrefix(b byte) bool {
return b == '$' || b == '%' || b == '!' || b == '&' switch b {
case '$', '%', '!', '&':
return true
}
return false
} }
func (s *scanner) scan() bool { func (s *scanner) scan() bool {