Orcus
yaml_parser_base.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6  */
7 
8 #ifndef INCLUDED_ORCUS_YAML_PARSER_BASE_HPP
9 #define INCLUDED_ORCUS_YAML_PARSER_BASE_HPP
10 
11 #include "orcus/parser_base.hpp"
12 #include "orcus/pstring.hpp"
13 
14 #include <memory>
15 #include <cassert>
16 
17 namespace orcus { namespace yaml {
18 
19 class ORCUS_PSR_DLLPUBLIC parse_error : public ::orcus::parse_error
20 {
21 public:
22  parse_error(const std::string& msg);
23 
24  static void throw_with(const char* msg_before, char c, const char* msg_after);
25  static void throw_with(const char* msg_before, const char* p, size_t n, const char* msg_after);
26 };
27 
28 enum class scope_t
29 {
30  unset,
31  sequence,
32  map,
33  multi_line_string
34 };
35 
36 enum class keyword_t
37 {
38  unknown,
39  boolean_true,
40  boolean_false,
41  null
42 };
43 
44 class ORCUS_PSR_DLLPUBLIC parser_base : public ::orcus::parser_base
45 {
46  struct impl;
47  std::unique_ptr<impl> mp_impl;
48 
49 protected:
50 
51  // The entire line is empty.
52  static const size_t parse_indent_blank_line;
53 
54  // End of stream has reached while parsing in the indent part of a line.
55  static const size_t parse_indent_end_of_stream;
56 
57  static const size_t scope_empty;
58 
59  struct key_value
60  {
61  pstring key;
62  pstring value;
63  };
64 
65  parser_base() = delete;
66  parser_base(const parser_base&) = delete;
67  parser_base& operator=(const parser_base&) = delete;
68 
69  parser_base(const char* p, size_t n);
70  ~parser_base();
71 
77  size_t parse_indent();
78 
83  pstring parse_to_end_of_line();
84 
89  void skip_comment();
90 
91  size_t get_scope() const;
92 
93  void push_scope(size_t scope_width);
94 
95  scope_t get_scope_type() const;
96 
97  void set_scope_type(scope_t type);
98 
104  size_t pop_scope();
105 
106  void push_line_back(const char* p, size_t n);
107 
108  pstring pop_line_front();
109 
110  bool has_line_buffer() const;
111 
112  size_t get_line_buffer_count() const;
113 
114  pstring merge_line_buffer();
115 
122  const char* get_doc_hash() const;
123 
131  void set_doc_hash(const char* hash);
132 
133  keyword_t parse_keyword(const char* p, size_t len);
134 
135  key_value parse_key_value(const char* p, size_t len);
136 
137  pstring parse_single_quoted_string_value(const char*& p, size_t max_length);
138 
139  pstring parse_double_quoted_string_value(const char*& p, size_t max_length);
140 
141  void skip_blanks(const char*& p, size_t len);
142 
143  void start_literal_block();
144 
145  bool in_literal_block() const;
146 
147  void handle_line_in_literal(size_t indent);
148 
149  void handle_line_in_multi_line_string();
150 };
151 
152 }}
153 
154 #endif
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: yaml_parser_base.hpp:59
Definition: pstring.hpp:24
Definition: parser_base.hpp:34
Definition: yaml_parser_base.hpp:19
Definition: parser_base.hpp:20
Definition: base64.hpp:15
Definition: yaml_parser_base.hpp:44