@@ -26,40 +26,38 @@ void Parser::Load(std::istream& in) {
2626 m_pDirectives.reset (new Directives);
2727}
2828
29- // HandleNextDocument
30- // . Handles the next document
31- // . Throws a ParserException on error.
32- // . Returns false if there are no more documents
3329bool Parser::HandleNextDocument (EventHandler& eventHandler) {
3430 if (!m_pScanner.get ())
3531 return false ;
3632
3733 ParseDirectives ();
38- if (m_pScanner->empty ())
34+ if (m_pScanner->empty ()) {
3935 return false ;
36+ }
4037
4138 SingleDocParser sdp (*m_pScanner, *m_pDirectives);
4239 sdp.HandleDocument (eventHandler);
4340 return true ;
4441}
4542
46- // ParseDirectives
47- // . Reads any directives that are next in the queue.
4843void Parser::ParseDirectives () {
4944 bool readDirective = false ;
5045
5146 while (1 ) {
52- if (m_pScanner->empty ())
47+ if (m_pScanner->empty ()) {
5348 break ;
49+ }
5450
5551 Token& token = m_pScanner->peek ();
56- if (token.type != Token::DIRECTIVE )
52+ if (token.type != Token::DIRECTIVE ) {
5753 break ;
54+ }
5855
5956 // we keep the directives from the last document if none are specified;
6057 // but if any directives are specific, then we reset them
61- if (!readDirective)
58+ if (!readDirective) {
6259 m_pDirectives.reset (new Directives);
60+ }
6361
6462 readDirective = true ;
6563 HandleDirective (token);
@@ -68,58 +66,61 @@ void Parser::ParseDirectives() {
6866}
6967
7068void Parser::HandleDirective (const Token& token) {
71- if (token.value == " YAML" )
69+ if (token.value == " YAML" ) {
7270 HandleYamlDirective (token);
73- else if (token.value == " TAG" )
71+ } else if (token.value == " TAG" ) {
7472 HandleTagDirective (token);
73+ }
7574}
7675
77- // HandleYamlDirective
78- // . Should be of the form 'major.minor' (like a version number)
7976void Parser::HandleYamlDirective (const Token& token) {
80- if (token.params .size () != 1 )
77+ if (token.params .size () != 1 ) {
8178 throw ParserException (token.mark , ErrorMsg::YAML_DIRECTIVE_ARGS );
79+ }
8280
83- if (!m_pDirectives->version .isDefault )
81+ if (!m_pDirectives->version .isDefault ) {
8482 throw ParserException (token.mark , ErrorMsg::REPEATED_YAML_DIRECTIVE );
83+ }
8584
8685 std::stringstream str (token.params [0 ]);
8786 str >> m_pDirectives->version .major ;
8887 str.get ();
8988 str >> m_pDirectives->version .minor ;
90- if (!str || str.peek () != EOF )
89+ if (!str || str.peek () != EOF ) {
9190 throw ParserException (
9291 token.mark , std::string (ErrorMsg::YAML_VERSION ) + token.params [0 ]);
92+ }
9393
94- if (m_pDirectives->version .major > 1 )
94+ if (m_pDirectives->version .major > 1 ) {
9595 throw ParserException (token.mark , ErrorMsg::YAML_MAJOR_VERSION );
96+ }
9697
9798 m_pDirectives->version .isDefault = false ;
9899 // TODO: warning on major == 1, minor > 2?
99100}
100101
101- // HandleTagDirective
102- // . Should be of the form 'handle prefix', where 'handle' is converted to
103- // 'prefix' in the file.
104102void Parser::HandleTagDirective (const Token& token) {
105103 if (token.params .size () != 2 )
106104 throw ParserException (token.mark , ErrorMsg::TAG_DIRECTIVE_ARGS );
107105
108106 const std::string& handle = token.params [0 ];
109107 const std::string& prefix = token.params [1 ];
110- if (m_pDirectives->tags .find (handle) != m_pDirectives->tags .end ())
108+ if (m_pDirectives->tags .find (handle) != m_pDirectives->tags .end ()) {
111109 throw ParserException (token.mark , ErrorMsg::REPEATED_TAG_DIRECTIVE );
110+ }
112111
113112 m_pDirectives->tags [handle] = prefix;
114113}
115114
116115void Parser::PrintTokens (std::ostream& out) {
117- if (!m_pScanner.get ())
116+ if (!m_pScanner.get ()) {
118117 return ;
118+ }
119119
120120 while (1 ) {
121- if (m_pScanner->empty ())
121+ if (m_pScanner->empty ()) {
122122 break ;
123+ }
123124
124125 out << m_pScanner->peek () << " \n " ;
125126 m_pScanner->pop ();
0 commit comments