Optimize numbers
This commit is contained in:
parent
0d2df2c6e5
commit
bfdb311495
|
@ -218,20 +218,15 @@ func lexBool(l *Lexer) stateFn {
|
||||||
}
|
}
|
||||||
|
|
||||||
func lexNumber(l *Lexer) stateFn {
|
func lexNumber(l *Lexer) stateFn {
|
||||||
var (
|
numDots := 0
|
||||||
last rune
|
|
||||||
numDots = 0
|
|
||||||
)
|
|
||||||
for {
|
for {
|
||||||
switch r := l.next(); r {
|
switch r := l.next(); r {
|
||||||
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
|
case '1', '2', '3', '4', '5', '6', '7', '8', '9', '0':
|
||||||
last = r
|
|
||||||
case '.':
|
case '.':
|
||||||
numDots++
|
numDots++
|
||||||
last = r
|
|
||||||
default:
|
default:
|
||||||
l.backup()
|
l.backup()
|
||||||
if numDots > 1 || last == '.' {
|
if numDots > 1 || r == '.' {
|
||||||
return l.errorf("Invalid number: %q", l.val())
|
return l.errorf("Invalid number: %q", l.val())
|
||||||
}
|
}
|
||||||
l.emit(Number)
|
l.emit(Number)
|
||||||
|
|
Loading…
Reference in New Issue