Added case for parsing a compact key: value pair in a flow sequence with a null key

This commit is contained in:
Jesse Beder
2009-10-29 22:01:01 +00:00
parent fadc2ad39f
commit d372729b92
3 changed files with 23 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ namespace YAML
case Token::BLOCK_MAP_START: ParseBlock(pScanner, state); break;
case Token::FLOW_MAP_START: ParseFlow(pScanner, state); break;
case Token::FLOW_MAP_COMPACT: ParseCompact(pScanner, state); break;
case Token::VALUE: ParseCompactWithNoKey(pScanner, state); break;
default: break;
}
}
@@ -178,6 +179,20 @@ namespace YAML
m_data[pKey.release()] = pValue.release();
}
// ParseCompactWithNoKey
// . Single key: value pair in a flow sequence
void Map::ParseCompactWithNoKey(Scanner *pScanner, const ParserState& state)
{
std::auto_ptr <Node> pKey(new Node), pValue(new Node);
// grab value
pScanner->pop();
pValue->Parse(pScanner, state);
// assign the map with the actual pointers
m_data[pKey.release()] = pValue.release();
}
void Map::Write(Emitter& out) const
{
out << BeginMap;

View File

@@ -42,6 +42,7 @@ namespace YAML
void ParseBlock(Scanner *pScanner, const ParserState& state);
void ParseFlow(Scanner *pScanner, const ParserState& state);
void ParseCompact(Scanner *pScanner, const ParserState& state);
void ParseCompactWithNoKey(Scanner *pScanner, const ParserState& state);
private:
node_map m_data;

View File

@@ -64,6 +64,13 @@ namespace YAML
// save location
m_mark = pScanner->peek().mark;
// special case: a value node by itself must be a map, with no header
if(pScanner->peek().type == Token::VALUE) {
m_pContent = new Map;
m_pContent->Parse(pScanner, state);
return;
}
ParseHeader(pScanner, state);