rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
c4::yml::EventHandlerTree Struct Reference

The event handler to create a ryml Tree. More...

#include <event_handler_tree.hpp>

Public Types

types
enum  { requires_strings_on_buffers = false }
using state = EventHandlerTreeState

Public Member Functions

construction and resetting
 EventHandlerTree () noexcept
 EventHandlerTree (Callbacks const &cb) noexcept
 EventHandlerTree (Tree *tree, id_type id)
void reset (Tree *tree, id_type id)
Callbacks const & callbacks () const
TagDirectivestag_directives ()
TagCachetag_cache ()
parse events
void start_parse (const char *filename, substr ymlsrc)
void finish_parse ()
void cancel_parse ()
YAML stream events
void begin_stream () const noexcept
void end_stream () const noexcept
YAML document events
void begin_doc ()
 implicit doc start (without —)
void end_doc ()
 implicit doc end (without ...)
void begin_doc_expl ()
 explicit doc start, with —
void end_doc_expl ()
 explicit doc end, with ...
YAML map events
void begin_map_key_flow ()
void begin_map_key_block ()
void begin_map_val_flow ()
void begin_map_val_block ()
void end_map_block ()
void end_map_flow (bool multiline, type_bits multiline_style=FLOW_ML1)
YAML seq events
void begin_seq_key_flow ()
void begin_seq_key_block ()
void begin_seq_val_flow ()
void begin_seq_val_block ()
void end_seq_block ()
void end_seq_flow (bool multiline, type_bits multiline_style=FLOW_ML1)
YAML structure events
void add_sibling ()
void actually_val_is_first_key_of_new_map_flow ()
 reset the previous val as the first key of a new map, with flow style.
void actually_val_is_first_key_of_new_map_block ()
 like its flow counterpart, but this function can only be called after the end of a flow-val at root or doc level.
YAML scalar events
void set_key_scalar_plain_empty () noexcept
void set_val_scalar_plain_empty () noexcept
void set_key_scalar_plain (csubstr scalar) noexcept
void set_val_scalar_plain (csubstr scalar) noexcept
void set_key_scalar_dquoted (csubstr scalar) noexcept
void set_val_scalar_dquoted (csubstr scalar) noexcept
void set_key_scalar_squoted (csubstr scalar) noexcept
void set_val_scalar_squoted (csubstr scalar) noexcept
void set_key_scalar_literal (csubstr scalar) noexcept
void set_val_scalar_literal (csubstr scalar) noexcept
void set_key_scalar_folded (csubstr scalar) noexcept
void set_val_scalar_folded (csubstr scalar) noexcept
void mark_key_scalar_unfiltered () noexcept
void mark_val_scalar_unfiltered () noexcept
YAML anchor/reference events
void set_key_anchor (csubstr anchor)
void set_val_anchor (csubstr anchor)
void set_key_ref (csubstr ref)
void set_val_ref (csubstr ref)
YAML tag events
void set_key_tag (csubstr tag)
void set_val_tag (csubstr tag)
YAML directive events
void add_directive_yaml (csubstr yaml_version)
void add_directive_tag (csubstr handle, csubstr prefix)
arena functions
substr arena ()
substr arena_rem ()
substr alloc_arena (size_t len)

Public Attributes

detail::stack< statem_stack
statem_curr
 current stack level: top of the stack. cached here for easier access.
statem_parent
 parent of the current stack level.
substr m_src

Protected Member Functions

void _stack_start_parse (const char *filename, substr ymlsrc)
void _stack_finish_parse ()
void _stack_reset_root ()
void _stack_reset_non_root ()
void _stack_push ()
void _stack_pop ()
bool _stack_should_push_on_begin_doc () const
bool _stack_should_pop_on_end_doc () const

Detailed Description

The event handler to create a ryml Tree.

See the documentation for Event Handlers, which has important notes about the event model used by rapidyaml.

Definition at line 39 of file event_handler_tree.hpp.

Member Typedef Documentation

◆ state

using c4::yml::EventHandlerTree::state = EventHandlerTreeState

Definition at line 45 of file event_handler_tree.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
requires_strings_on_buffers 

Definition at line 46 of file event_handler_tree.hpp.

Constructor & Destructor Documentation

◆ EventHandlerTree() [1/3]

c4::yml::EventHandlerTree::EventHandlerTree ( )
inlinenoexcept

◆ EventHandlerTree() [2/3]

c4::yml::EventHandlerTree::EventHandlerTree ( Callbacks const & cb)
inlinenoexcept

Definition at line 73 of file event_handler_tree.hpp.

73: EventHandlerStack(cb), m_tree(), m_curr_doc() {}

◆ EventHandlerTree() [3/3]

c4::yml::EventHandlerTree::EventHandlerTree ( Tree * tree,
id_type id )
inline

Definition at line 74 of file event_handler_tree.hpp.

74 : EventHandlerStack(tree->callbacks()), m_tree(tree), m_curr_doc()
75 {
76 reset(tree, id);
77 }
void reset(Tree *tree, id_type id)

Member Function Documentation

◆ reset()

void c4::yml::EventHandlerTree::reset ( Tree * tree,
id_type id )
inline

Definition at line 79 of file event_handler_tree.hpp.

80 {
81 if C4_UNLIKELY(!tree)
82 RYML_ERR_BASIC_CB_(m_stack.m_callbacks, "null tree");
83 if C4_UNLIKELY(id >= tree->capacity())
84 RYML_ERR_VISIT_CB_(tree->callbacks(), tree, id, "invalid node");
85 if C4_UNLIKELY(!tree->is_root(id))
86 if C4_UNLIKELY(tree->is_map(tree->parent(id)))
87 if C4_UNLIKELY(!tree->has_key(id))
88 RYML_ERR_BASIC_CB_(tree->callbacks(), "destination node belongs to a map and has no key");
89 m_tree = tree;
90 if(m_tree->is_root(id))
91 {
93 _reset_parser_state(m_curr, id, m_tree->root_id());
94 }
95 else
96 {
98 _reset_parser_state(m_parent, id, m_tree->parent(id));
99 _reset_parser_state(m_curr, id, id);
100 }
101 m_curr_doc = m_tree->ancestor_doc(id);
102 m_tag_cache.clear();
103 }
Callbacks const & callbacks() const

Referenced by EventHandlerTree().

◆ callbacks()

Callbacks const & c4::yml::EventHandlerTree::callbacks ( ) const
inline

Definition at line 105 of file event_handler_tree.hpp.

105{ return m_stack.m_callbacks; }

Referenced by EventHandlerTree(), and sample_error_visit_location().

◆ tag_directives()

TagDirectives & c4::yml::EventHandlerTree::tag_directives ( )
inline

Definition at line 107 of file event_handler_tree.hpp.

107{ return m_tree->m_tag_directives; } // NOLINT(readability-make-member-function-const)

◆ tag_cache()

TagCache & c4::yml::EventHandlerTree::tag_cache ( )
inline

Definition at line 108 of file event_handler_tree.hpp.

108{ return m_tag_cache; }

◆ start_parse()

void c4::yml::EventHandlerTree::start_parse ( const char * filename,
substr ymlsrc )
inline

Definition at line 117 of file event_handler_tree.hpp.

118 {
119 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree != nullptr);
120 this->_stack_start_parse(filename, ymlsrc);
121 }

◆ finish_parse()

void c4::yml::EventHandlerTree::finish_parse ( )
inline

Definition at line 123 of file event_handler_tree.hpp.

124 {
125 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree != nullptr);
126 this->_stack_finish_parse();
127 /* This pointer is temporary. Remember that:
128 *
129 * - this handler object may be held by the user
130 * - it may be used with a temporary tree inside the parse function
131 * - when the parse function returns the temporary tree, its address
132 * will change
133 *
134 * As a result, the user could try to read the tree from m_tree, and
135 * end up reading the stale temporary object.
136 *
137 * So it is better to clear it here; then the user will get an obvious
138 * segfault if reading from m_tree. */
139 m_tree = nullptr;
140 }

◆ cancel_parse()

void c4::yml::EventHandlerTree::cancel_parse ( )
inline

Definition at line 142 of file event_handler_tree.hpp.

143 {
144 m_tree = nullptr;
145 }

◆ begin_stream()

void c4::yml::EventHandlerTree::begin_stream ( ) const
inlinenoexcept

Definition at line 154 of file event_handler_tree.hpp.

154{ /* nothing to do */ }

◆ end_stream()

void c4::yml::EventHandlerTree::end_stream ( ) const
inlinenoexcept

Definition at line 156 of file event_handler_tree.hpp.

156{ /* nothing to do */ }

◆ begin_doc()

void c4::yml::EventHandlerTree::begin_doc ( )
inline

implicit doc start (without —)

Definition at line 166 of file event_handler_tree.hpp.

167 {
168 _c4dbgp("begin_doc");
170 {
171 _c4dbgp("push!");
172 _set_root_as_stream();
173 _push();
174 ryml_enable_(DOC);
175 }
176 m_curr_doc = m_curr->node_id;
177 }
@ DOC
a document
Definition node_type.hpp:37

◆ end_doc()

void c4::yml::EventHandlerTree::end_doc ( )
inline

implicit doc end (without ...)

Definition at line 179 of file event_handler_tree.hpp.

180 {
181 _c4dbgp("end_doc");
182 m_curr_doc = m_tree->size();
184 {
185 _remove_speculative();
186 _c4dbgp("pop!");
187 _pop();
188 }
189 }

◆ begin_doc_expl()

void c4::yml::EventHandlerTree::begin_doc_expl ( )
inline

explicit doc start, with —

Definition at line 192 of file event_handler_tree.hpp.

193 {
194 _c4dbgp("begin_doc_expl");
195 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->root_id() == m_curr->node_id, m_tree, m_curr->node_id);
196 if(m_tree->is_stream(m_tree->root_id())) //if(_should_push_on_begin_doc())
197 {
198 _c4dbgp("push!");
199 _push();
200 }
201 else
202 {
203 _c4dbgp("ensure stream");
204 _set_root_as_stream();
205 const id_type root = m_tree->root_id();
206 const id_type first = m_tree->first_child(root);
207 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->is_stream(root), m_tree, root);
208 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->num_children(root) == 1u, m_tree, root);
209 if(m_tree->is_container(first) || m_tree->is_val(first))
210 {
211 _c4dbgp("push!");
212 _push();
213 #ifdef RYML_WITH_COMMENTS
214 m_tree->_p(root)->m_first_comment = NONE;
215 m_tree->_p(root)->m_last_comment = NONE;
216 #endif
217 }
218 else
219 {
220 _c4dbgp("tweak");
221 _push();
222 _remove_speculative();
223 m_curr->node_id = m_tree->last_child(root);
224 m_curr->tr_data = m_tree->_p(m_curr->node_id);
225 }
226 }
227 ryml_enable_(DOC);
228 m_curr_doc = m_curr->node_id;
229 }
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition common.hpp:124
@ NONE
an index to none
Definition common.hpp:131

◆ end_doc_expl()

void c4::yml::EventHandlerTree::end_doc_expl ( )
inline

explicit doc end, with ...

Definition at line 231 of file event_handler_tree.hpp.

232 {
233 _c4dbgp("end_doc_expl");
234 m_curr_doc = m_tree->size();
235 _remove_speculative();
237 {
238 _c4dbgp("pop!");
239 _pop();
240 }
241 }

◆ begin_map_key_flow()

void c4::yml::EventHandlerTree::begin_map_key_flow ( )
inline

Definition at line 250 of file event_handler_tree.hpp.

251 {
252 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
253 }

◆ begin_map_key_block()

void c4::yml::EventHandlerTree::begin_map_key_block ( )
inline

Definition at line 254 of file event_handler_tree.hpp.

255 {
256 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
257 }

◆ begin_map_val_flow()

void c4::yml::EventHandlerTree::begin_map_val_flow ( )
inline

Definition at line 259 of file event_handler_tree.hpp.

260 {
261 _c4dbgpf("node[{}]: begin_map_val_flow", m_curr->node_id);
262 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VAL));
263 ryml_enable_(MAP|FLOW_SL);
264 _save_loc();
265 _push();
266 }
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition node_type.hpp:35
@ FLOW_SL
mark container with single-line flow style
Definition node_type.hpp:56
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition node_type.hpp:34

Referenced by actually_val_is_first_key_of_new_map_flow().

◆ begin_map_val_block()

void c4::yml::EventHandlerTree::begin_map_val_block ( )
inline

Definition at line 267 of file event_handler_tree.hpp.

268 {
269 _c4dbgpf("node[{}]: begin_map_val_block", m_curr->node_id);
270 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VAL));
271 ryml_enable_(MAP|BLOCK);
272 _save_loc();
273 _push();
274 }
@ BLOCK
mark container with block style

◆ end_map_block()

void c4::yml::EventHandlerTree::end_map_block ( )
inline

Definition at line 276 of file event_handler_tree.hpp.

277 {
278 _c4dbgpf("node[{}]: end_map_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
279 _pop();
280 }

◆ end_map_flow()

void c4::yml::EventHandlerTree::end_map_flow ( bool multiline,
type_bits multiline_style = FLOW_ML1 )
inline

Definition at line 282 of file event_handler_tree.hpp.

283 {
284 _c4dbgpf("node[{}]: end_map. multiline={} startline={} endline={}", m_parent->node_id, multiline, m_parent->pos.line, m_curr->pos.line);
285 _pop();
286 if(multiline)
287 {
288 ryml_disable_(FLOW_SL);
289 enable_(multiline_style);
290 }
291 }

◆ begin_seq_key_flow()

void c4::yml::EventHandlerTree::begin_seq_key_flow ( )
inline

Definition at line 300 of file event_handler_tree.hpp.

301 {
302 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
303 }

◆ begin_seq_key_block()

void c4::yml::EventHandlerTree::begin_seq_key_block ( )
inline

Definition at line 304 of file event_handler_tree.hpp.

305 {
306 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
307 }

◆ begin_seq_val_flow()

void c4::yml::EventHandlerTree::begin_seq_val_flow ( )
inline

Definition at line 309 of file event_handler_tree.hpp.

310 {
311 _c4dbgpf("node[{}]: begin_seq_val_flow", m_curr->node_id);
312 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VAL));
313 ryml_enable_(SEQ|FLOW_SL);
314 _save_loc();
315 _push();
316 }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition node_type.hpp:36

◆ begin_seq_val_block()

void c4::yml::EventHandlerTree::begin_seq_val_block ( )
inline

Definition at line 317 of file event_handler_tree.hpp.

318 {
319 _c4dbgpf("node[{}]: begin_seq_val_block", m_curr->node_id);
320 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VAL));
321 ryml_enable_(SEQ|BLOCK);
322 _save_loc();
323 _push();
324 }

◆ end_seq_block()

void c4::yml::EventHandlerTree::end_seq_block ( )
inline

Definition at line 326 of file event_handler_tree.hpp.

327 {
328 _c4dbgpf("node[{}]: end_seq_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
329 _pop();
330 }

◆ end_seq_flow()

void c4::yml::EventHandlerTree::end_seq_flow ( bool multiline,
type_bits multiline_style = FLOW_ML1 )
inline

Definition at line 332 of file event_handler_tree.hpp.

333 {
334 _c4dbgpf("node[{}]: end_seq. multiline={} startline={} endline={}", m_parent->node_id, multiline, m_parent->pos.line, m_curr->pos.line);
335 _pop();
336 if(multiline)
337 {
338 ryml_disable_(FLOW_SL);
339 enable_(multiline_style);
340 }
341 }

◆ add_sibling()

void c4::yml::EventHandlerTree::add_sibling ( )
inline

Definition at line 350 of file event_handler_tree.hpp.

351 {
352 #if defined(__GNUC__) && (__GNUC__ >= 6)
353 C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wnull-dereference")
354 #endif
355 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
356 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_parent);
357 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->has_children(m_parent->node_id), m_tree, m_parent->node_id);
358 NodeData const* const prev = m_tree->m_buf; // watchout against relocation of the tree nodes
359 _set_state_(m_curr, m_tree->_append_child__unprotected(m_parent->node_id));
360 if(prev != m_tree->m_buf)
361 _refresh_after_relocation();
362 _c4dbgpf("node[{}]: added sibling={} prev={}", m_parent->node_id, m_curr->node_id, m_tree->prev_sibling(m_curr->node_id));
363 #if defined(__GNUC__) && (__GNUC__ >= 6)
364 C4_SUPPRESS_WARNING_GCC_POP
365 #endif
366 }

◆ actually_val_is_first_key_of_new_map_flow()

void c4::yml::EventHandlerTree::actually_val_is_first_key_of_new_map_flow ( )
inline

reset the previous val as the first key of a new map, with flow style.

See the documentation for Event Handlers, which has important notes about this event.

Definition at line 373 of file event_handler_tree.hpp.

374 {
375 if C4_UNLIKELY(m_tree->is_container(m_curr->node_id))
376 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
377 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_parent);
378 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id), m_tree, m_parent->node_id);
379 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id), m_tree, m_curr->node_id);
380 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id), m_tree, m_curr->node_id);
381 const NodeData tmp = _val2key_(*m_curr->tr_data);
382 ryml_disable_(VALMASK_|VAL_STYLE|VALNIL);
383 m_curr->tr_data->m_val = {};
385 m_curr->tr_data->m_type = tmp.m_type;
386 m_curr->tr_data->m_key = tmp.m_key;
387 }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition node_type.hpp:46
@ VAL_STYLE
mask of VALQUO|VAL_PLAIN : all the val scalar styles for val (not container styles!...

◆ actually_val_is_first_key_of_new_map_block()

void c4::yml::EventHandlerTree::actually_val_is_first_key_of_new_map_block ( )
inline

like its flow counterpart, but this function can only be called after the end of a flow-val at root or doc level.

See the documentation for Event Handlers, which has important notes about this event.

Definition at line 395 of file event_handler_tree.hpp.

396 {
397 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
398 }

◆ set_key_scalar_plain_empty()

void c4::yml::EventHandlerTree::set_key_scalar_plain_empty ( )
inlinenoexcept

Definition at line 408 of file event_handler_tree.hpp.

409 {
410 _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
411 m_curr->tr_data->m_key.scalar = {};
412 ryml_enable_(KEY|KEY_PLAIN|KEYNIL);
413 }
@ KEY
the scalar to the left of : in a map's member
Definition node_type.hpp:33
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition node_type.hpp:45

◆ set_val_scalar_plain_empty()

void c4::yml::EventHandlerTree::set_val_scalar_plain_empty ( )
inlinenoexcept

Definition at line 414 of file event_handler_tree.hpp.

415 {
416 _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
417 m_curr->tr_data->m_val.scalar = {};
418 ryml_enable_(VAL|VAL_PLAIN|VALNIL);
419 }
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)

◆ set_key_scalar_plain()

void c4::yml::EventHandlerTree::set_key_scalar_plain ( csubstr scalar)
inlinenoexcept

Definition at line 421 of file event_handler_tree.hpp.

422 {
423 _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
424 m_curr->tr_data->m_key.scalar = scalar;
425 ryml_enable_(KEY|KEY_PLAIN);
426 }

◆ set_val_scalar_plain()

void c4::yml::EventHandlerTree::set_val_scalar_plain ( csubstr scalar)
inlinenoexcept

Definition at line 427 of file event_handler_tree.hpp.

428 {
429 _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
430 m_curr->tr_data->m_val.scalar = scalar;
431 ryml_enable_(VAL|VAL_PLAIN);
432 }

◆ set_key_scalar_dquoted()

void c4::yml::EventHandlerTree::set_key_scalar_dquoted ( csubstr scalar)
inlinenoexcept

Definition at line 435 of file event_handler_tree.hpp.

436 {
437 _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
438 m_curr->tr_data->m_key.scalar = scalar;
439 ryml_enable_(KEY|KEY_DQUO);
440 }
@ KEY_DQUO
mark key scalar as double quoted "

◆ set_val_scalar_dquoted()

void c4::yml::EventHandlerTree::set_val_scalar_dquoted ( csubstr scalar)
inlinenoexcept

Definition at line 441 of file event_handler_tree.hpp.

442 {
443 _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
444 m_curr->tr_data->m_val.scalar = scalar;
445 ryml_enable_(VAL|VAL_DQUO);
446 }
@ VAL_DQUO
mark val scalar as double quoted "

◆ set_key_scalar_squoted()

void c4::yml::EventHandlerTree::set_key_scalar_squoted ( csubstr scalar)
inlinenoexcept

Definition at line 449 of file event_handler_tree.hpp.

450 {
451 _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
452 m_curr->tr_data->m_key.scalar = scalar;
453 ryml_enable_(KEY|KEY_SQUO);
454 }
@ KEY_SQUO
mark key scalar as single quoted '

◆ set_val_scalar_squoted()

void c4::yml::EventHandlerTree::set_val_scalar_squoted ( csubstr scalar)
inlinenoexcept

Definition at line 455 of file event_handler_tree.hpp.

456 {
457 _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
458 m_curr->tr_data->m_val.scalar = scalar;
459 ryml_enable_(VAL|VAL_SQUO);
460 }
@ VAL_SQUO
mark val scalar as single quoted '

◆ set_key_scalar_literal()

void c4::yml::EventHandlerTree::set_key_scalar_literal ( csubstr scalar)
inlinenoexcept

Definition at line 463 of file event_handler_tree.hpp.

464 {
465 _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
466 m_curr->tr_data->m_key.scalar = scalar;
467 ryml_enable_(KEY|KEY_LITERAL);
468 }
@ KEY_LITERAL
mark key scalar as multiline, block literal |

◆ set_val_scalar_literal()

void c4::yml::EventHandlerTree::set_val_scalar_literal ( csubstr scalar)
inlinenoexcept

Definition at line 469 of file event_handler_tree.hpp.

470 {
471 _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
472 m_curr->tr_data->m_val.scalar = scalar;
473 ryml_enable_(VAL|VAL_LITERAL);
474 }
@ VAL_LITERAL
mark val scalar as multiline, block literal |

◆ set_key_scalar_folded()

void c4::yml::EventHandlerTree::set_key_scalar_folded ( csubstr scalar)
inlinenoexcept

Definition at line 477 of file event_handler_tree.hpp.

478 {
479 _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
480 m_curr->tr_data->m_key.scalar = scalar;
481 ryml_enable_(KEY|KEY_FOLDED);
482 }
@ KEY_FOLDED
mark key scalar as multiline, block folded >

◆ set_val_scalar_folded()

void c4::yml::EventHandlerTree::set_val_scalar_folded ( csubstr scalar)
inlinenoexcept

Definition at line 483 of file event_handler_tree.hpp.

484 {
485 _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
486 m_curr->tr_data->m_val.scalar = scalar;
487 ryml_enable_(VAL|VAL_FOLDED);
488 }
@ VAL_FOLDED
mark val scalar as multiline, block folded >

◆ mark_key_scalar_unfiltered()

void c4::yml::EventHandlerTree::mark_key_scalar_unfiltered ( )
inlinenoexcept

Definition at line 491 of file event_handler_tree.hpp.

492 {
493 ryml_enable_(KEY_UNFILT);
494 }
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition node_type.hpp:51

◆ mark_val_scalar_unfiltered()

void c4::yml::EventHandlerTree::mark_val_scalar_unfiltered ( )
inlinenoexcept

Definition at line 495 of file event_handler_tree.hpp.

496 {
497 ryml_enable_(VAL_UNFILT);
498 }
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
Definition node_type.hpp:52

◆ set_key_anchor()

void c4::yml::EventHandlerTree::set_key_anchor ( csubstr anchor)
inline

Definition at line 507 of file event_handler_tree.hpp.

508 {
509 _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
510 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
511 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(KEYREF));
512 RYML_ASSERT_PARSE_CB_(m_tree->callbacks(), !anchor.begins_with('&'), m_curr->pos);
513 ryml_enable_(KEYANCH);
514 m_curr->tr_data->m_key.anchor = anchor;
515 }
@ KEYREF
a *reference: the key references an &anchor
Definition node_type.hpp:39
@ KEYANCH
the key has an &anchor
Definition node_type.hpp:41

◆ set_val_anchor()

void c4::yml::EventHandlerTree::set_val_anchor ( csubstr anchor)
inline

Definition at line 516 of file event_handler_tree.hpp.

517 {
518 _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
519 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
520 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VALREF));
521 RYML_ASSERT_PARSE_CB_(m_tree->callbacks(), !anchor.begins_with('&'), m_curr->pos);
522 ryml_enable_(VALANCH);
523 m_curr->tr_data->m_val.anchor = anchor;
524 }
@ VALANCH
the val has an &anchor
Definition node_type.hpp:42
@ VALREF
a *reference: the val references an &anchor
Definition node_type.hpp:40

◆ set_key_ref()

void c4::yml::EventHandlerTree::set_key_ref ( csubstr ref)
inline

Definition at line 526 of file event_handler_tree.hpp.

527 {
528 _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
529 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, ref.begins_with('*'), m_curr->pos);
530 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, !ryml_hasany_(KEYANCH), m_curr->pos);
531 ryml_enable_(KEY|KEYREF);
532 m_curr->tr_data->m_key.anchor = ref.sub(1);
533 m_curr->tr_data->m_key.scalar = ref;
534 }

◆ set_val_ref()

void c4::yml::EventHandlerTree::set_val_ref ( csubstr ref)
inline

Definition at line 535 of file event_handler_tree.hpp.

536 {
537 _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
538 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, ref.begins_with('*'), m_curr->pos);
539 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, !ryml_hasany_(VALANCH), m_curr->pos);
540 ryml_enable_(VAL|VALREF);
541 m_curr->tr_data->m_val.anchor = ref.sub(1);
542 m_curr->tr_data->m_val.scalar = ref;
543 }

◆ set_key_tag()

void c4::yml::EventHandlerTree::set_key_tag ( csubstr tag)
inline

Definition at line 552 of file event_handler_tree.hpp.

553 {
554 _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
555 ryml_enable_(KEYTAG);
556 m_curr->tr_data->m_key.tag = tag;
557 }
@ KEYTAG
the key has a tag
Definition node_type.hpp:43

◆ set_val_tag()

void c4::yml::EventHandlerTree::set_val_tag ( csubstr tag)
inline

Definition at line 558 of file event_handler_tree.hpp.

559 {
560 _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
561 ryml_enable_(VALTAG);
562 m_curr->tr_data->m_val.tag = tag;
563 }
@ VALTAG
the val has a tag
Definition node_type.hpp:44

◆ add_directive_yaml()

void c4::yml::EventHandlerTree::add_directive_yaml ( csubstr yaml_version)
inline

Definition at line 572 of file event_handler_tree.hpp.

573 {
574 _c4dbgpf("%YAML directive! version={}", yaml_version);
575 (void)yaml_version;
576 }

◆ add_directive_tag()

void c4::yml::EventHandlerTree::add_directive_tag ( csubstr handle,
csubstr prefix )
inline

Definition at line 578 of file event_handler_tree.hpp.

579 {
580 _c4dbgpf("%TAG directive! handle={} prefix={} id={}", handle, prefix, m_curr_doc);
581 if C4_UNLIKELY(!m_tree->m_tag_directives.add(handle, prefix, m_curr_doc))
582 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "too many %TAG directives");
583 }

◆ arena()

substr c4::yml::EventHandlerTree::arena ( )
inline

Definition at line 592 of file event_handler_tree.hpp.

593 {
594 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
595 return m_tree->m_arena.first(m_tree->m_arena_pos);
596 }

◆ arena_rem()

substr c4::yml::EventHandlerTree::arena_rem ( )
inline

Definition at line 597 of file event_handler_tree.hpp.

598 {
599 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
600 return m_tree->m_arena.sub(m_tree->m_arena_pos);
601 }

◆ alloc_arena()

substr c4::yml::EventHandlerTree::alloc_arena ( size_t len)
inline

Definition at line 602 of file event_handler_tree.hpp.

603 {
604 return m_tree->alloc_arena(len);
605 }

◆ _stack_start_parse()

void c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_start_parse ( const char * filename,
substr ymlsrc )
inlineprotectedinherited

Definition at line 58 of file event_handler_stack.hpp.

59 {
60 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_curr != nullptr);
61 m_curr->start_parse(filename, m_curr->node_id);
62 m_src = ymlsrc;
63 }
Use this class a base of implementations of event handler to simplify the stack logic.

Referenced by c4::yml::EventHandlerTree::start_parse().

◆ _stack_finish_parse()

void c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_finish_parse ( )
inlineprotectedinherited

Definition at line 65 of file event_handler_stack.hpp.

66 {
67 }

Referenced by c4::yml::EventHandlerTree::finish_parse().

◆ _stack_reset_root()

void c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_reset_root ( )
inlineprotectedinherited

Definition at line 71 of file event_handler_stack.hpp.

72 {
73 m_stack.clear();
74 m_stack.push({});
75 m_parent = nullptr;
76 m_curr = &m_stack.top();
77 }

Referenced by c4::yml::EventHandlerTree::reset().

◆ _stack_reset_non_root()

void c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_reset_non_root ( )
inlineprotectedinherited

Definition at line 79 of file event_handler_stack.hpp.

80 {
81 m_stack.clear();
82 m_stack.push({}); // parent
83 m_stack.push({}); // node
84 m_parent = &m_stack.top(1);
85 m_curr = &m_stack.top();
86 }

Referenced by c4::yml::EventHandlerTree::reset().

◆ _stack_push()

void c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_push ( )
inlineprotectedinherited

Definition at line 88 of file event_handler_stack.hpp.

89 {
90 m_stack.push_top();
91 m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push
92 m_curr = &m_stack.top();
93 m_curr->reset_after_push();
94 }

◆ _stack_pop()

void c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_pop ( )
inlineprotectedinherited

Definition at line 96 of file event_handler_stack.hpp.

97 {
99 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_stack.size() > 1);
100 m_parent->reset_before_pop(*m_curr);
101 m_stack.pop();
102 m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr;
103 m_curr = &m_stack.top();
104 #ifdef RYML_DBG
105 if(m_parent)
106 _c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
107 else
108 _c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id);
109 #endif
110 }

◆ _stack_should_push_on_begin_doc()

bool c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_should_push_on_begin_doc ( ) const
inlineprotectedinherited

Definition at line 121 of file event_handler_stack.hpp.

122 {
123 const bool is_root = (m_stack.size() == 1u);
124 return is_root && (m_curr->has_children || ryml_has_any_(DOC|VAL|MAP|SEQ));
125 }
#define ryml_has_any_(bits)

Referenced by c4::yml::EventHandlerTree::begin_doc().

◆ _stack_should_pop_on_end_doc()

bool c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::_stack_should_pop_on_end_doc ( ) const
inlineprotectedinherited

Definition at line 127 of file event_handler_stack.hpp.

128 {
129 const bool is_root = (m_stack.size() == 1u);
130 return !is_root && ryml_has_any_(DOC);
131 }

Referenced by c4::yml::EventHandlerTree::end_doc(), and c4::yml::EventHandlerTree::end_doc_expl().

Member Data Documentation

◆ m_stack

◆ m_curr

state* c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::m_curr
inherited

current stack level: top of the stack. cached here for easier access.

Definition at line 47 of file event_handler_stack.hpp.

Referenced by c4::yml::EventHandlerTree::actually_val_is_first_key_of_new_map_block(), c4::yml::EventHandlerTree::actually_val_is_first_key_of_new_map_flow(), c4::yml::EventHandlerTree::add_directive_tag(), c4::yml::EventHandlerTree::add_sibling(), c4::yml::EventHandlerTree::begin_doc(), c4::yml::EventHandlerTree::begin_doc_expl(), c4::yml::EventHandlerTree::begin_map_key_block(), c4::yml::EventHandlerTree::begin_map_key_flow(), c4::yml::EventHandlerTree::begin_map_val_block(), c4::yml::EventHandlerTree::begin_map_val_flow(), c4::yml::EventHandlerTree::begin_seq_key_block(), c4::yml::EventHandlerTree::begin_seq_key_flow(), c4::yml::EventHandlerTree::begin_seq_val_block(), c4::yml::EventHandlerTree::begin_seq_val_flow(), c4::yml::EventHandlerTree::end_map_block(), c4::yml::EventHandlerTree::end_map_flow(), c4::yml::EventHandlerTree::end_seq_block(), c4::yml::EventHandlerTree::end_seq_flow(), c4::yml::EventHandlerTree::reset(), c4::yml::EventHandlerTree::set_key_anchor(), c4::yml::EventHandlerTree::set_key_ref(), c4::yml::EventHandlerTree::set_key_scalar_dquoted(), c4::yml::EventHandlerTree::set_key_scalar_folded(), c4::yml::EventHandlerTree::set_key_scalar_literal(), c4::yml::EventHandlerTree::set_key_scalar_plain(), c4::yml::EventHandlerTree::set_key_scalar_plain_empty(), c4::yml::EventHandlerTree::set_key_scalar_squoted(), c4::yml::EventHandlerTree::set_key_tag(), c4::yml::EventHandlerTree::set_val_anchor(), c4::yml::EventHandlerTree::set_val_ref(), c4::yml::EventHandlerTree::set_val_scalar_dquoted(), c4::yml::EventHandlerTree::set_val_scalar_folded(), c4::yml::EventHandlerTree::set_val_scalar_literal(), c4::yml::EventHandlerTree::set_val_scalar_plain(), c4::yml::EventHandlerTree::set_val_scalar_plain_empty(), c4::yml::EventHandlerTree::set_val_scalar_squoted(), and c4::yml::EventHandlerTree::set_val_tag().

◆ m_parent

◆ m_src

substr c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >::m_src
inherited

Definition at line 49 of file event_handler_stack.hpp.


The documentation for this struct was generated from the following file:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/event_handler_tree.hpp