From 60c411638fa97ef597332ef9c59da5a2072a0338 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Wed, 7 Aug 2013 12:32:08 -0700 Subject: [PATCH] quoted strings should allow internal spaces --- conf/lex.go | 18 +++++++++++++++++- conf/lex_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/conf/lex.go b/conf/lex.go index 85eae215..87fe466b 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -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 { diff --git a/conf/lex_test.go b/conf/lex_test.go index f146d424..a2848337 100644 --- a/conf/lex_test.go +++ b/conf/lex_test.go @@ -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) +} + +