From dbbe5921d7fc1094e6a1380d1f031756c57e369d Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Fri, 2 Oct 2015 11:16:26 -0400 Subject: [PATCH] Allow empty string values --- forge_test.go | 2 ++ scanner.go | 4 ++++ test.cfg | 1 + 3 files changed, 7 insertions(+) diff --git a/forge_test.go b/forge_test.go index a7ad3e8..1d8a3a7 100644 --- a/forge_test.go +++ b/forge_test.go @@ -16,6 +16,7 @@ primary { string = "primary string value"; string_with_quote = "some \"quoted\" str\\ing"; single = 'hello world'; + empty = ''; single_with_quote = '\'hello\' "world"'; # Semicolons are optional @@ -70,6 +71,7 @@ func assertDirectives(values map[string]interface{}, t *testing.T) { assertEqual(primary["string"], "primary string value", t) assertEqual(primary["string_with_quote"], "some \"quoted\" str\\ing", t) assertEqual(primary["single"], "hello world", t) + assertEqual(primary["empty"], "", t) assertEqual(primary["single_with_quote"], "'hello' \"world\"", t) assertEqual(primary["integer500"], int64(500), t) assertEqual(primary["float"], float64(80.80), t) diff --git a/scanner.go b/scanner.go index 865c1ab..670b431 100644 --- a/scanner.go +++ b/scanner.go @@ -123,6 +123,10 @@ func (scanner *Scanner) parseNumber(negative bool) { func (scanner *Scanner) parseString(delimiter rune) { scanner.curTok.ID = token.STRING scanner.curTok.Literal = "" + if scanner.curCh == delimiter { + scanner.readRune() + return + } // Whether or not we are trying to escape a character escape := false diff --git a/test.cfg b/test.cfg index d9b6f78..1c6b94e 100644 --- a/test.cfg +++ b/test.cfg @@ -5,6 +5,7 @@ primary { string = "primary string value"; string_with_quote = "some \"quoted\" str\\ing"; single = 'hello world'; + empty = ''; single_with_quote = '\'hello\' "world"'; # Semicolons are optional