quoted strings should allow internal spaces

This commit is contained in:
Derek Collison
2013-08-07 12:32:08 -07:00
parent 2833a1f05a
commit 60c411638f
2 changed files with 43 additions and 1 deletions

View File

@@ -328,7 +328,7 @@ func lexValue(lx *lexer) stateFn {
return lexMapKeyStart
case r == dqStringStart || r == sqStringStart:
lx.ignore() // ignore the " or '
return lexString
return lexQuotedString
case r == '-':
return lexNumberStart
case isDigit(r):
@@ -553,6 +553,22 @@ func (lx *lexer) isBool() bool {
return str == "true" || str == "false" || str == "TRUE" || str == "FALSE"
}
// lexQuotedString consumes the inner contents of a string. It assumes that the
// beginning '"' has already been consumed and ignored. It will not interpret any
// internal contents.
func lexQuotedString(lx *lexer) stateFn {
r := lx.next()
switch {
case r == dqStringEnd || r == sqStringEnd:
lx.backup()
lx.emit(itemString)
lx.next()
lx.ignore()
return lx.pop()
}
return lexQuotedString
}
// lexString consumes the inner contents of a string. It assumes that the
// beginning '"' has already been consumed and ignored.
func lexString(lx *lexer) stateFn {

View File

@@ -457,3 +457,29 @@ func TestSpecialCharsMapQuotedKeys(t *testing.T) {
lx = lex("foo = {\"bar-1.2.3\" = { port:4242 }}")
expect(t, lx, expectedItems)
}
var mlnestedmap = `
systems {
allinone {
description: "This is a description."
}
}
`
func TestDoubleNestedMapsNewLines(t *testing.T) {
expectedItems := []item{
{itemKey, "systems", 2},
{itemMapStart, "", 2},
{itemKey, "allinone", 3},
{itemMapStart, "", 3},
{itemKey, "description", 4},
{itemString, "This is a description.", 4},
{itemMapEnd, "", 5},
{itemMapEnd, "", 6},
{itemEOF, "", 7},
}
lx := lex(mlnestedmap)
expect(t, lx, expectedItems)
}