Add optional OnAnchor method to EventHandler (#530)

ref #110
This commit is contained in:
caryoscelus
2019-03-12 22:24:32 +00:00
committed by Jesse Beder
parent a2a113c6ff
commit eca9cfd648
7 changed files with 729 additions and 516 deletions

View File

@@ -71,8 +71,12 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) {
}
std::string tag;
std::string anchor_name;
anchor_t anchor;
ParseProperties(tag, anchor);
ParseProperties(tag, anchor, anchor_name);
if (!anchor_name.empty())
eventHandler.OnAnchor(mark, anchor_name);
const Token& token = m_scanner.peek();
@@ -356,8 +360,10 @@ void SingleDocParser::HandleCompactMapWithNoKey(EventHandler& eventHandler) {
// ParseProperties
// . Grabs any tag or anchor tokens and deals with them.
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor) {
void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor,
std::string& anchor_name) {
tag.clear();
anchor_name.clear();
anchor = NullAnchor;
while (1) {
@@ -369,7 +375,7 @@ void SingleDocParser::ParseProperties(std::string& tag, anchor_t& anchor) {
ParseTag(tag);
break;
case Token::ANCHOR:
ParseAnchor(anchor);
ParseAnchor(anchor, anchor_name);
break;
default:
return;
@@ -387,11 +393,12 @@ void SingleDocParser::ParseTag(std::string& tag) {
m_scanner.pop();
}
void SingleDocParser::ParseAnchor(anchor_t& anchor) {
void SingleDocParser::ParseAnchor(anchor_t& anchor, std::string& anchor_name) {
Token& token = m_scanner.peek();
if (anchor)
throw ParserException(token.mark, ErrorMsg::MULTIPLE_ANCHORS);
anchor_name = token.value;
anchor = RegisterAnchor(token.value);
m_scanner.pop();
}
@@ -411,4 +418,4 @@ anchor_t SingleDocParser::LookupAnchor(const Mark& mark,
return it->second;
}
}
} // namespace YAML

View File

@@ -43,9 +43,10 @@ class SingleDocParser : private noncopyable {
void HandleCompactMap(EventHandler& eventHandler);
void HandleCompactMapWithNoKey(EventHandler& eventHandler);
void ParseProperties(std::string& tag, anchor_t& anchor);
void ParseProperties(std::string& tag, anchor_t& anchor,
std::string& anchor_name);
void ParseTag(std::string& tag);
void ParseAnchor(anchor_t& anchor);
void ParseAnchor(anchor_t& anchor, std::string& anchor_name);
anchor_t RegisterAnchor(const std::string& name);
anchor_t LookupAnchor(const Mark& mark, const std::string& name) const;
@@ -60,6 +61,6 @@ class SingleDocParser : private noncopyable {
anchor_t m_curAnchor;
};
}
} // namespace YAML
#endif // SINGLEDOCPARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66