diff options
author | bnagaev <bnagaev@yandex-team.ru> | 2022-02-10 16:47:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:04 +0300 |
commit | c74559fb88da8adac0d9186cfa55a6b13c47695f (patch) | |
tree | b83306b6e37edeea782e9eed673d89286c4fef35 /contrib/libs/yaml-cpp/src/parser.cpp | |
parent | d6449ba66291ff0c0d352c82e6eb3efb4c8a7e8d (diff) | |
download | ydb-c74559fb88da8adac0d9186cfa55a6b13c47695f.tar.gz |
Restoring authorship annotation for <bnagaev@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/libs/yaml-cpp/src/parser.cpp')
-rw-r--r-- | contrib/libs/yaml-cpp/src/parser.cpp | 208 |
1 files changed, 104 insertions, 104 deletions
diff --git a/contrib/libs/yaml-cpp/src/parser.cpp b/contrib/libs/yaml-cpp/src/parser.cpp index 1c5ff53c89..cd69f39fce 100644 --- a/contrib/libs/yaml-cpp/src/parser.cpp +++ b/contrib/libs/yaml-cpp/src/parser.cpp @@ -1,129 +1,129 @@ -#include <cstdio> -#include <sstream> - -#include "directives.h" // IWYU pragma: keep -#include "scanner.h" // IWYU pragma: keep -#include "singledocparser.h" -#include "token.h" -#include "yaml-cpp/exceptions.h" // IWYU pragma: keep -#include "yaml-cpp/parser.h" - -namespace YAML { -class EventHandler; - -Parser::Parser() {} - -Parser::Parser(std::istream& in) { Load(in); } - -Parser::~Parser() {} - -Parser::operator bool() const { - return m_pScanner.get() && !m_pScanner->empty(); -} - -void Parser::Load(std::istream& in) { - m_pScanner.reset(new Scanner(in)); - m_pDirectives.reset(new Directives); -} - -bool Parser::HandleNextDocument(EventHandler& eventHandler) { - if (!m_pScanner.get()) - return false; - - ParseDirectives(); +#include <cstdio> +#include <sstream> + +#include "directives.h" // IWYU pragma: keep +#include "scanner.h" // IWYU pragma: keep +#include "singledocparser.h" +#include "token.h" +#include "yaml-cpp/exceptions.h" // IWYU pragma: keep +#include "yaml-cpp/parser.h" + +namespace YAML { +class EventHandler; + +Parser::Parser() {} + +Parser::Parser(std::istream& in) { Load(in); } + +Parser::~Parser() {} + +Parser::operator bool() const { + return m_pScanner.get() && !m_pScanner->empty(); +} + +void Parser::Load(std::istream& in) { + m_pScanner.reset(new Scanner(in)); + m_pDirectives.reset(new Directives); +} + +bool Parser::HandleNextDocument(EventHandler& eventHandler) { + if (!m_pScanner.get()) + return false; + + ParseDirectives(); if (m_pScanner->empty()) { - return false; + return false; } - - SingleDocParser sdp(*m_pScanner, *m_pDirectives); - sdp.HandleDocument(eventHandler); - return true; -} - -void Parser::ParseDirectives() { - bool readDirective = false; - - while (1) { + + SingleDocParser sdp(*m_pScanner, *m_pDirectives); + sdp.HandleDocument(eventHandler); + return true; +} + +void Parser::ParseDirectives() { + bool readDirective = false; + + while (1) { if (m_pScanner->empty()) { - break; + break; } - - Token& token = m_pScanner->peek(); + + Token& token = m_pScanner->peek(); if (token.type != Token::DIRECTIVE) { - break; + break; } - - // we keep the directives from the last document if none are specified; - // but if any directives are specific, then we reset them + + // we keep the directives from the last document if none are specified; + // but if any directives are specific, then we reset them if (!readDirective) { - m_pDirectives.reset(new Directives); + m_pDirectives.reset(new Directives); } - - readDirective = true; - HandleDirective(token); - m_pScanner->pop(); - } -} - -void Parser::HandleDirective(const Token& token) { + + readDirective = true; + HandleDirective(token); + m_pScanner->pop(); + } +} + +void Parser::HandleDirective(const Token& token) { if (token.value == "YAML") { - HandleYamlDirective(token); + HandleYamlDirective(token); } else if (token.value == "TAG") { - HandleTagDirective(token); + HandleTagDirective(token); } -} - -void Parser::HandleYamlDirective(const Token& token) { +} + +void Parser::HandleYamlDirective(const Token& token) { if (token.params.size() != 1) { - throw ParserException(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS); + throw ParserException(token.mark, ErrorMsg::YAML_DIRECTIVE_ARGS); } - + if (!m_pDirectives->version.isDefault) { - throw ParserException(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE); + throw ParserException(token.mark, ErrorMsg::REPEATED_YAML_DIRECTIVE); } - - std::stringstream str(token.params[0]); - str >> m_pDirectives->version.major; - str.get(); - str >> m_pDirectives->version.minor; + + std::stringstream str(token.params[0]); + str >> m_pDirectives->version.major; + str.get(); + str >> m_pDirectives->version.minor; if (!str || str.peek() != EOF) { - throw ParserException( - token.mark, std::string(ErrorMsg::YAML_VERSION) + token.params[0]); + throw ParserException( + token.mark, std::string(ErrorMsg::YAML_VERSION) + token.params[0]); } - + if (m_pDirectives->version.major > 1) { - throw ParserException(token.mark, ErrorMsg::YAML_MAJOR_VERSION); + throw ParserException(token.mark, ErrorMsg::YAML_MAJOR_VERSION); } - - m_pDirectives->version.isDefault = false; - // TODO: warning on major == 1, minor > 2? -} - -void Parser::HandleTagDirective(const Token& token) { - if (token.params.size() != 2) - throw ParserException(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS); - - const std::string& handle = token.params[0]; - const std::string& prefix = token.params[1]; + + m_pDirectives->version.isDefault = false; + // TODO: warning on major == 1, minor > 2? +} + +void Parser::HandleTagDirective(const Token& token) { + if (token.params.size() != 2) + throw ParserException(token.mark, ErrorMsg::TAG_DIRECTIVE_ARGS); + + const std::string& handle = token.params[0]; + const std::string& prefix = token.params[1]; if (m_pDirectives->tags.find(handle) != m_pDirectives->tags.end()) { - throw ParserException(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE); + throw ParserException(token.mark, ErrorMsg::REPEATED_TAG_DIRECTIVE); } - - m_pDirectives->tags[handle] = prefix; -} - -void Parser::PrintTokens(std::ostream& out) { + + m_pDirectives->tags[handle] = prefix; +} + +void Parser::PrintTokens(std::ostream& out) { if (!m_pScanner.get()) { - return; + return; } - - while (1) { + + while (1) { if (m_pScanner->empty()) { - break; + break; } - - out << m_pScanner->peek() << "\n"; - m_pScanner->pop(); - } -} -} + + out << m_pScanner->peek() << "\n"; + m_pScanner->pop(); + } +} +} |