Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lex: remove leading 0's to not parse integers in octal #85

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ func lexText(l *lexer) lexStateFn {

func lexNumber(l *lexer) lexStateFn {
numberBuf := make([]rune, 0, 10)

// // remove leading zeros
for l.nextRune == '0' {
_, eof := l.next()
if eof {
l.tokens <- token{tokNumber, "0"}
l.tokens <- token{typ: tokEOF}
return nil
}
}

for unicode.IsDigit(l.nextRune) {
r, eof := l.next()
numberBuf = append(numberBuf, r)
Expand All @@ -237,6 +248,11 @@ func lexNumber(l *lexer) lexStateFn {
}
}

if len(numberBuf) == 0 {
l.tokens <- token{tokNumber, "0"}
return lexInput
}

if len(numberBuf) > 0 {
l.tokens <- token{tokNumber, string(numberBuf)}
}
Expand Down
Loading