Skip to content

Commit 5047694

Browse files
fix: Improve number parsing in lexer
Co-Authored-By: [email protected] <[email protected]>
1 parent 9bc63b2 commit 5047694

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

jparse/lexer.go

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -495,24 +495,14 @@ func (l *lexer) scanNumber() token {
495495
return token{Type: typeNumber, Value: l.input[pos:l.current], Position: pos}
496496
}
497497

498-
// Handle decimal point at start
499-
if l.peek() == '.' {
500-
l.nextRune()
501-
if !l.acceptAll(isDigit) {
502-
l.backup()
503-
return token{Type: typeDot, Value: ".", Position: pos}
504-
}
505-
return token{Type: typeNumber, Value: l.input[pos:l.current], Position: pos}
506-
}
507-
508-
// Handle decimal numbers
498+
// Handle regular decimal numbers
509499
hasDigits := l.acceptAll(isDigit)
510500

511-
// Handle decimal point after digits
501+
// Handle decimal point
512502
if l.acceptRune('.') {
513-
if !l.acceptAll(isDigit) {
503+
if !l.acceptAll(isDigit) && !hasDigits {
514504
l.backup()
515-
return token{Type: typeNumber, Value: l.input[pos : l.current-1], Position: pos}
505+
return token{Type: typeDot, Value: ".", Position: pos}
516506
}
517507
}
518508

@@ -524,7 +514,7 @@ func (l *lexer) scanNumber() token {
524514
}
525515
}
526516

527-
if !hasDigits && l.input[pos] != '.' {
517+
if !hasDigits && !l.acceptAll(isDigit) {
528518
return token{Type: typeError, Value: "invalid number literal", Position: pos}
529519
}
530520

0 commit comments

Comments
 (0)