From 68c10e3715c1a02985b6698cf5442215d4689979 Mon Sep 17 00:00:00 2001 From: Robert Lowry Date: Wed, 20 Nov 2024 22:06:36 -0600 Subject: [PATCH] lex: remove leading 0's to not parse integers in octal --- lex.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lex.go b/lex.go index 760f297..964151c 100644 --- a/lex.go +++ b/lex.go @@ -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) @@ -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)} }