HoverRace  2.0
Parser.h
Go to the documentation of this file.
1 
2 // Parser.h
3 //
4 // Copyright (c) 2008, 2009, 2015-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <yaml.h>
25 
26 #include <exception>
27 
28 #include "Node.h"
29 #include "YamlExn.h"
30 
31 namespace HoverRace {
32 namespace Util {
33 namespace yaml {
34 
36 class ParserExn : public YamlExn
37 {
38  using SUPER = YamlExn;
39 
40 public:
41  ParserExn() : SUPER() { }
42  ParserExn(const char *const &s) : SUPER(s) { }
43  virtual ~ParserExn() noexcept { }
44 };
45 
48 {
49  using SUPER = ParserExn;
50 
51 public:
53  EmptyDocParserExn(const char *const &s) : SUPER(s) { }
54  virtual ~EmptyDocParserExn() noexcept { }
55 };
56 
58 class Parser
59 {
60 private:
61  Parser() = delete;
62 public:
63  Parser(FILE *file);
64  Parser(std::istream &is);
65  virtual ~Parser();
66 
67 protected:
68  void InitParser();
69  void InitStream();
70 
71 private:
72  void Cleanup();
73 
74 public:
75  Node *GetRootNode() const { return root; }
76 
77 private:
78  yaml_parser_t parser;
79  yaml_document_t *doc;
81 };
82 
83 } // namespace yaml
84 } // namespace Util
85 } // namespace HoverRace
86 
Wrapper for the LibYAML parser.
Definition: Parser.h:58
ParserExn(const char *const &s)
Definition: Parser.h:42
Base class for LibYAML document nodes.
Definition: Node.h:31
Exception for when the document is empty or missing the header.
Definition: Parser.h:47
yaml_parser_t parser
Definition: Parser.h:78
Definition: YamlExn.h:28
virtual ~EmptyDocParserExn() noexcept
Definition: Parser.h:54
EmptyDocParserExn()
Definition: Parser.h:52
Node * root
Definition: Parser.h:80
Standard exception thrown for parser errors.
Definition: Parser.h:36
Node * GetRootNode() const
Definition: Parser.h:75
ParserExn()
Definition: Parser.h:41
YamlExn()
Definition: YamlExn.h:33
EmptyDocParserExn(const char *const &s)
Definition: Parser.h:53
virtual ~ParserExn() noexcept
Definition: Parser.h:43
yaml_document_t * doc
Definition: Parser.h:79
Definition: Announcement.h:24
Definition: Symbol.h:253