Fixed lexer changes made in #3434

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2022-09-03 20:02:25 -06:00
parent 1a9b3c49c0
commit 6ebbb4a41a
2 changed files with 12 additions and 7 deletions

View File

@@ -1009,17 +1009,12 @@ func lexConvenientNumber(lx *lexer) stateFn {
case r == 'b' || r == 'B' || r == 'i' || r == 'I': case r == 'b' || r == 'B' || r == 'i' || r == 'I':
return lexConvenientNumber return lexConvenientNumber
} }
if isNL(r) || r == eof || r == mapEnd || r == optValTerm || r == mapValTerm || isWhitespace(r) || unicode.IsDigit(r) {
lx.backup() lx.backup()
if isNL(r) || r == eof || r == mapEnd || r == optValTerm || r == mapValTerm || isWhitespace(r) || unicode.IsDigit(r) {
lx.emit(itemInteger) lx.emit(itemInteger)
return lx.pop() return lx.pop()
} }
// This is not a number, so we have to backup to the start and consider // This is not a number, so treat it as a string.
// this to be a string
pos, start := lx.pos, lx.start
for i := pos; i > start; i-- {
lx.backup()
}
lx.stringStateFn = lexString lx.stringStateFn = lexString
return lexString return lexString
} }

View File

@@ -330,6 +330,16 @@ func TestConvenientIntegerValues(t *testing.T) {
} }
lx = lex("foo = 3Mbs,") lx = lex("foo = 3Mbs,")
expect(t, lx, expectedItems) 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) { func TestSimpleKeyFloatValues(t *testing.T) {