From 5217149ed44cf826329108be336d084b52d6265d Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Sun, 6 Sep 2009 21:52:56 +0000 Subject: [PATCH] Fixed bug with complex keys (and simplified the parsing for flow maps) --- src/map.cpp | 19 ++++++++----------- src/scantoken.cpp | 3 --- yaml-reader/spectests.cpp | 4 ++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 6a57009..6d8873e 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -122,24 +122,21 @@ namespace YAML pScanner->pop(); break; } - - // now it better be a key - if(token.type != Token::KEY) - throw ParserException(token.mark, ErrorMsg::END_OF_MAP_FLOW); - - pScanner->pop(); - + std::auto_ptr pKey(new Node), pValue(new Node); - // grab key - pKey->Parse(pScanner, state); - + // grab key (if non-null) + if(token.type == Token::KEY) { + pScanner->pop(); + pKey->Parse(pScanner, state); + } + // now grab value (optional) if(!pScanner->empty() && pScanner->peek().type == Token::VALUE) { pScanner->pop(); pValue->Parse(pScanner, state); } - + // now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node) Token& nextToken = pScanner->peek(); if(nextToken.type == Token::FLOW_ENTRY) diff --git a/src/scantoken.cpp b/src/scantoken.cpp index e92fd6d..0692fd5 100644 --- a/src/scantoken.cpp +++ b/src/scantoken.cpp @@ -182,9 +182,6 @@ namespace YAML // Value void Scanner::ScanValue() { - // just in case we have an empty key - InsertPotentialSimpleKey(); - // and check that simple key bool isSimpleKey = VerifySimpleKey(); diff --git a/yaml-reader/spectests.cpp b/yaml-reader/spectests.cpp index 2e0b3fd..60ee539 100644 --- a/yaml-reader/spectests.cpp +++ b/yaml-reader/spectests.cpp @@ -325,8 +325,8 @@ namespace Test { parser.GetNextDocument(doc); YAML_ASSERT(doc.size() == 2); - YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago Cubs")].size() == 1); - YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago Cubs")][0] == "2001-07-23"); + YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")].size() == 1); + YAML_ASSERT(doc[Pair("Detroit Tigers", "Chicago cubs")][0] == "2001-07-23"); YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")].size() == 3); YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][0] == "2001-07-02"); YAML_ASSERT(doc[Pair("New York Yankees", "Atlanta Braves")][1] == "2001-08-12");