Orcus
Loading...
Searching...
No Matches
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
13#include <memory>
14#include <cassert>
15
16namespace orcus { namespace yaml {
17
18namespace detail {
19
20enum class scope_t
21{
22 unset,
23 sequence,
24 map,
25 multi_line_string
26};
27
28enum class keyword_t
29{
30 unknown,
31 boolean_true,
32 boolean_false,
33 null
34};
35
36enum class parse_token_t
37{
38 unknown,
39
40 // handler tokens (tokens associated with handler events)
41
42 begin_parse,
43 end_parse,
44 begin_document,
45 end_document,
46 begin_sequence,
47 end_sequence,
48 begin_map,
49 end_map,
50 begin_map_key,
51 end_map_key,
52 string,
53 number,
54 boolean_true,
55 boolean_false,
56 null,
57
58 // non-handler tokens
59
60 begin_sequence_element
61};
62
63}
64
65class ORCUS_PSR_DLLPUBLIC parser_base : public ::orcus::parser_base
66{
67 struct impl;
68 std::unique_ptr<impl> mp_impl;
69
70protected:
71
72 // The entire line is empty.
73 static const size_t parse_indent_blank_line;
74
75 // End of stream has reached while parsing in the indent part of a line.
76 static const size_t parse_indent_end_of_stream;
77
78 static const size_t scope_empty;
79
80 struct key_value
81 {
82 std::string_view key;
83 std::string_view value;
84 };
85
86 parser_base() = delete;
87 parser_base(const parser_base&) = delete;
88 parser_base& operator=(const parser_base&) = delete;
89
90 parser_base(std::string_view content);
91 ~parser_base();
92
93 void push_parse_token(detail::parse_token_t t);
94
95 detail::parse_token_t get_last_parse_token() const;
96
106
112 size_t parse_indent();
113
118 std::string_view parse_to_end_of_line();
119
125
126 void reset_on_new_line();
127
128 size_t get_scope() const;
129
130 void push_scope(size_t scope_width);
131
132 void clear_scopes();
133
134 detail::scope_t get_scope_type() const;
135
136 void set_scope_type(detail::scope_t type);
137
143 size_t pop_scope();
144
145 void push_line_back(const char* p, size_t n);
146
147 std::string_view pop_line_front();
148
149 bool has_line_buffer() const;
150
151 size_t get_line_buffer_count() const;
152
153 std::string_view merge_line_buffer();
154
161 const char* get_doc_hash() const;
162
170 void set_doc_hash(const char* hash);
171
172 detail::keyword_t parse_keyword(const char* p, size_t len);
173
174 key_value parse_key_value(const char* p, size_t len);
175
176 std::string_view parse_single_quoted_string_value(const char*& p, size_t max_length);
177
178 std::string_view parse_double_quoted_string_value(const char*& p, size_t max_length);
179
180 void skip_blanks(const char*& p, size_t len);
181
182 void start_literal_block();
183
184 bool in_literal_block() const;
185
186 void handle_line_in_literal(size_t indent);
187
188 void handle_line_in_multi_line_string();
189};
190
191}}
192
193#endif
194
195/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition parser_base.hpp:23
std::string_view parse_to_end_of_line()
const char * get_doc_hash() const
void set_doc_hash(const char *hash)
size_t offset_last_char_of_line() const
Definition yaml_parser_base.hpp:81