Free Electron
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
parser.h
1 #ifndef PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 
4 #if defined(_MSC_VER) || \
5  (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6  (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 #pragma once
8 #endif
9 
10 #include <ios>
11 #include <memory>
12 
13 #include "yaml-cpp/dll.h"
14 
15 namespace YAML {
16 class EventHandler;
17 class Node;
18 class Scanner;
19 struct Directives;
20 struct Token;
21 
22 /**
23  * A parser turns a stream of bytes into one stream of "events" per YAML
24  * document in the input stream.
25  */
26 class YAML_CPP_API Parser {
27  public:
28  /** Constructs an empty parser (with no input. */
29  Parser();
30 
31  Parser(const Parser&) = delete;
32  Parser(Parser&&) = delete;
33  Parser& operator=(const Parser&) = delete;
34  Parser& operator=(Parser&&) = delete;
35 
36  /**
37  * Constructs a parser from the given input stream. The input stream must
38  * live as long as the parser.
39  */
40  explicit Parser(std::istream& in);
41 
42  ~Parser();
43 
44  /** Evaluates to true if the parser has some valid input to be read. */
45  explicit operator bool() const;
46 
47  /**
48  * Resets the parser with the given input stream. Any existing state is
49  * erased.
50  */
51  void Load(std::istream& in);
52 
53  /**
54  * Handles the next document by calling events on the {@code eventHandler}.
55  *
56  * @throw a ParserException on error.
57  * @return false if there are no more documents
58  */
59  bool HandleNextDocument(EventHandler& eventHandler);
60 
61  void PrintTokens(std::ostream& out);
62 
63  private:
64  /**
65  * Reads any directives that are next in the queue, setting the internal
66  * {@code m_pDirectives} state.
67  */
68  void ParseDirectives();
69 
70  void HandleDirective(const Token& token);
71 
72  /**
73  * Handles a "YAML" directive, which should be of the form 'major.minor' (like
74  * a version number).
75  */
76  void HandleYamlDirective(const Token& token);
77 
78  /**
79  * Handles a "TAG" directive, which should be of the form 'handle prefix',
80  * where 'handle' is converted to 'prefix' in the file.
81  */
82  void HandleTagDirective(const Token& token);
83 
84  private:
85  std::unique_ptr<Scanner> m_pScanner;
86  std::unique_ptr<Directives> m_pDirectives;
87 };
88 } // namespace YAML
89 
90 #endif // PARSER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
A parser turns a stream of bytes into one stream of "events" per YAML document in the input stream...
Definition: parser.h:26
Definition: anchor.h:12