Skip to content

Commit df6a01d

Browse files
fix: Handle leading zeros and decimal numbers correctly in lexer
Co-Authored-By: [email protected] <[email protected]>
1 parent 7903b90 commit df6a01d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jparse/lexer.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,20 @@ func (l *lexer) scanNumber() token {
455455
}
456456
// Handle leading zeros
457457
if isDigit(next) {
458-
return token{Type: typeNumber, Value: "0", Position: pos}
458+
l.acceptAll(isDigit)
459+
if l.acceptRune('.') {
460+
if !l.acceptAll(isDigit) {
461+
l.backup()
462+
return token{Type: typeNumber, Value: l.input[pos:l.current-1], Position: pos}
463+
}
464+
}
465+
if l.acceptRunes2('e', 'E') {
466+
l.acceptRunes2('+', '-')
467+
if !l.acceptAll(isDigit) {
468+
return token{Type: typeError, Value: "invalid number literal", Position: pos}
469+
}
470+
}
471+
return token{Type: typeNumber, Value: l.input[pos:l.current], Position: pos}
459472
}
460473
}
461474

0 commit comments

Comments
 (0)