mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fixed null key/value bug, added tests
This commit is contained in:
@@ -33,10 +33,10 @@ namespace YAML
|
||||
const RegEx DocStart = RegEx("---") + (BlankOrBreak || RegEx());
|
||||
const RegEx DocEnd = RegEx("...") + (BlankOrBreak || RegEx());
|
||||
const RegEx DocIndicator = DocStart || DocEnd;
|
||||
const RegEx BlockEntry = RegEx('-') + BlankOrBreak;
|
||||
const RegEx BlockEntry = RegEx('-') + (BlankOrBreak || RegEx());
|
||||
const RegEx Key = RegEx('?'),
|
||||
KeyInFlow = RegEx('?') + BlankOrBreak;
|
||||
const RegEx Value = RegEx(':') + BlankOrBreak,
|
||||
const RegEx Value = RegEx(':') + (BlankOrBreak || RegEx()),
|
||||
ValueInFlow = RegEx(':') + BlankOrBreak;
|
||||
const RegEx Comment = RegEx('#');
|
||||
const RegEx AnchorEnd = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak;
|
||||
@@ -48,7 +48,7 @@ namespace YAML
|
||||
// . In the flow context ? is illegal and : and - must not be followed with a space.
|
||||
const RegEx PlainScalar = !(BlankOrBreak || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + Blank)),
|
||||
PlainScalarInFlow = !(BlankOrBreak || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank));
|
||||
const RegEx EndScalar = RegEx(':') + BlankOrBreak,
|
||||
const RegEx EndScalar = RegEx(':') + (BlankOrBreak || RegEx()),
|
||||
EndScalarInFlow = (RegEx(':') + BlankOrBreak) || RegEx(",?[]{}", REGEX_OR);
|
||||
|
||||
const RegEx EscSingleQuote = RegEx("\'\'");
|
||||
|
16
src/map.cpp
16
src/map.cpp
@@ -61,17 +61,21 @@ namespace YAML
|
||||
throw ParserException(Mark::null(), ErrorMsg::END_OF_MAP);
|
||||
|
||||
Token token = pScanner->peek();
|
||||
if(token.type != TT_KEY && token.type != TT_BLOCK_END)
|
||||
if(token.type != TT_KEY && token.type != TT_VALUE && token.type != TT_BLOCK_END)
|
||||
throw ParserException(token.mark, ErrorMsg::END_OF_MAP);
|
||||
|
||||
pScanner->pop();
|
||||
if(token.type == TT_BLOCK_END)
|
||||
if(token.type == TT_BLOCK_END) {
|
||||
pScanner->pop();
|
||||
break;
|
||||
}
|
||||
|
||||
std::auto_ptr <Node> pKey(new Node), pValue(new Node);
|
||||
|
||||
// grab key
|
||||
pKey->Parse(pScanner, state);
|
||||
|
||||
// grab key (if non-null)
|
||||
if(token.type == TT_KEY) {
|
||||
pScanner->pop();
|
||||
pKey->Parse(pScanner, state);
|
||||
}
|
||||
|
||||
// now grab value (optional)
|
||||
if(!pScanner->empty() && pScanner->peek().type == TT_VALUE) {
|
||||
|
@@ -243,8 +243,11 @@ namespace YAML
|
||||
|
||||
bool Node::GetScalar(std::string& s) const
|
||||
{
|
||||
if(!m_pContent)
|
||||
return false;
|
||||
if(!m_pContent) {
|
||||
s = "~";
|
||||
return true;
|
||||
}
|
||||
|
||||
return m_pContent->GetScalar(s);
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,7 @@ namespace YAML
|
||||
TT_ANCHOR,
|
||||
TT_ALIAS,
|
||||
TT_TAG,
|
||||
TT_SCALAR,
|
||||
TT_NULL
|
||||
TT_SCALAR
|
||||
};
|
||||
|
||||
const std::string TokenNames[] = {
|
||||
@@ -52,8 +51,7 @@ namespace YAML
|
||||
"ANCHOR",
|
||||
"ALIAS",
|
||||
"TAG",
|
||||
"SCALAR",
|
||||
"NULL"
|
||||
"SCALAR"
|
||||
};
|
||||
|
||||
struct Token {
|
||||
|
Reference in New Issue
Block a user