mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Support quoted map keys too
This commit is contained in:
17
conf/lex.go
17
conf/lex.go
@@ -434,13 +434,28 @@ func lexMapKeyStart(lx *lexer) stateFn {
|
||||
return lexCommentStart
|
||||
}
|
||||
lx.backup()
|
||||
case r == sqStringStart || r == dqStringStart:
|
||||
lx.next()
|
||||
return lexSkip(lx, lexMapQuotedKey)
|
||||
}
|
||||
lx.ignore()
|
||||
lx.next()
|
||||
return lexMapKey
|
||||
}
|
||||
|
||||
// lexKey consumes the text of a key. Assumes that the first character (which
|
||||
// lexMapQuotedKey consumes the text of a key between quotes.
|
||||
func lexMapQuotedKey(lx *lexer) stateFn {
|
||||
r := lx.peek()
|
||||
if r == sqStringEnd || r == dqStringEnd {
|
||||
lx.emit(itemKey)
|
||||
lx.next()
|
||||
return lexSkip(lx, lexMapKeyEnd)
|
||||
}
|
||||
lx.next()
|
||||
return lexMapQuotedKey
|
||||
}
|
||||
|
||||
// lexMapKey consumes the text of a key. Assumes that the first character (which
|
||||
// is not whitespace) has already been consumed.
|
||||
func lexMapKey(lx *lexer) stateFn {
|
||||
r := lx.peek()
|
||||
|
||||
@@ -424,3 +424,18 @@ func TestNonQuotedStrings(t *testing.T) {
|
||||
lx := lex(noquotes)
|
||||
expect(t, lx, expectedItems)
|
||||
}
|
||||
|
||||
func TestMapQuotedKeys(t *testing.T) {
|
||||
expectedItems := []item{
|
||||
{itemKey, "foo", 1},
|
||||
{itemMapStart, "", 1},
|
||||
{itemKey, "bar", 1},
|
||||
{itemInteger, "4242", 1},
|
||||
{itemMapEnd, "", 1},
|
||||
{itemEOF, "", 1},
|
||||
}
|
||||
lx := lex("foo = {'bar' = 4242}")
|
||||
expect(t, lx, expectedItems)
|
||||
lx = lex("foo = {\"bar\" = 4242}")
|
||||
expect(t, lx, expectedItems)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user