From 6ebbb4a41a950d3e04e964d6bbdd757bdc035bdf Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Sat, 3 Sep 2022 20:02:25 -0600 Subject: [PATCH] Fixed lexer changes made in #3434 Signed-off-by: Ivan Kozlovic --- conf/lex.go | 9 ++------- conf/lex_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/conf/lex.go b/conf/lex.go index c102c2ff..c85a61ff 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -1009,17 +1009,12 @@ func lexConvenientNumber(lx *lexer) stateFn { case r == 'b' || r == 'B' || r == 'i' || r == 'I': return lexConvenientNumber } + lx.backup() if isNL(r) || r == eof || r == mapEnd || r == optValTerm || r == mapValTerm || isWhitespace(r) || unicode.IsDigit(r) { - lx.backup() lx.emit(itemInteger) return lx.pop() } - // This is not a number, so we have to backup to the start and consider - // this to be a string - pos, start := lx.pos, lx.start - for i := pos; i > start; i-- { - lx.backup() - } + // This is not a number, so treat it as a string. lx.stringStateFn = lexString return lexString } diff --git a/conf/lex_test.go b/conf/lex_test.go index 8623bd70..7fc4df43 100644 --- a/conf/lex_test.go +++ b/conf/lex_test.go @@ -330,6 +330,16 @@ func TestConvenientIntegerValues(t *testing.T) { } lx = lex("foo = 3Mbs,") expect(t, lx, expectedItems) + + expectedItems = []item{ + {itemKey, "foo", 1, 0}, + {itemInteger, "4Gb", 1, 6}, + {itemKey, "bar", 1, 11}, + {itemString, "5Gø", 1, 17}, + {itemEOF, "", 1, 0}, + } + lx = lex("foo = 4Gb, bar = 5Gø") + expect(t, lx, expectedItems) } func TestSimpleKeyFloatValues(t *testing.T) {