From ce8ff5d640246603bb12a277609999c664325315 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Sun, 21 Apr 2013 23:43:43 -0400 Subject: [PATCH] Allow whitespace to term non-quoted string --- conf/lex.go | 5 +++-- conf/lex_test.go | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/conf/lex.go b/conf/lex.go index 4de198d0..294d4895 100644 --- a/conf/lex.go +++ b/conf/lex.go @@ -508,7 +508,7 @@ func lexMapEnd(lx *lexer) stateFn { // Checks if the unquoted string was actually a boolean func (lx *lexer) isBool() bool { str := lx.input[lx.start:lx.pos] - return str == "true" || str == "false" || str == "TRUE" || str == "FALSE" + return str == "true" || str == "false" || str == "TRUE" || str == "FALSE" } // lexString consumes the inner contents of a string. It assumes that the @@ -518,7 +518,8 @@ func lexString(lx *lexer) stateFn { switch { case r == '\\': return lexStringEscape - case isNL(r) || r == eof || r == optValTerm: + // Termination of non-quoted strings + case isNL(r) || r == eof || r == optValTerm || isWhitespace(r): lx.backup() if lx.isBool() { lx.emit(itemBool) diff --git a/conf/lex_test.go b/conf/lex_test.go index 3e384976..e5f39022 100644 --- a/conf/lex_test.go +++ b/conf/lex_test.go @@ -361,7 +361,7 @@ t true f false tstr "true" tkey = two -fkey = five +fkey = five # This should be a string ` func TestNonQuotedStrings(t *testing.T) { @@ -389,6 +389,9 @@ func TestNonQuotedStrings(t *testing.T) { {itemString, "two", 12}, {itemKey, "fkey", 13}, {itemString, "five", 13}, + {itemCommentStart, "", 13}, + {itemText, " This should be a string", 13}, + {itemEOF, "", 14}, } lx := lex(noquotes)