rapidyaml 0.16.0
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 43 of file event_handler_tree.hpp.

Member Typedef Documentation

◆ state

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

Definition at line 49 of file event_handler_tree.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
requires_strings_on_buffers 

Definition at line 50 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 77 of file event_handler_tree.hpp.

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

◆ EventHandlerTree() [3/3]

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

Definition at line 78 of file event_handler_tree.hpp.

78 : EventHandlerStack(tree->callbacks()), m_tree(tree), m_curr_doc()
79 {
80 reset(tree, id);
81 }
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 83 of file event_handler_tree.hpp.

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

Referenced by EventHandlerTree().

◆ callbacks()

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

Definition at line 109 of file event_handler_tree.hpp.

109{ 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 111 of file event_handler_tree.hpp.

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

◆ tag_cache()

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

Definition at line 112 of file event_handler_tree.hpp.

112{ return m_tag_cache; }

◆ start_parse()

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

Definition at line 121 of file event_handler_tree.hpp.

122 {
123 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree != nullptr);
124 this->_stack_start_parse(filename, ymlsrc);
125 }

◆ finish_parse()

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

Definition at line 127 of file event_handler_tree.hpp.

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

◆ cancel_parse()

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

Definition at line 146 of file event_handler_tree.hpp.

147 {
148 m_tree = nullptr;
149 }

◆ begin_stream()

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

Definition at line 158 of file event_handler_tree.hpp.

158{ /* nothing to do */ }

◆ end_stream()

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

Definition at line 160 of file event_handler_tree.hpp.

160{ /* nothing to do */ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 170 of file event_handler_tree.hpp.

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

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 183 of file event_handler_tree.hpp.

184 {
185 _c4dbgp("end_doc");
186 m_curr_doc = m_tree->size();
188 {
189 _remove_speculative();
190 _c4dbgp("pop!");
191 _pop();
192 }
193 }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 196 of file event_handler_tree.hpp.

197 {
198 _c4dbgp("begin_doc_expl");
199 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->root_id() == m_curr->node_id, m_tree, m_curr->node_id);
200 if(m_tree->is_stream(m_tree->root_id())) //if(_should_push_on_begin_doc())
201 {
202 _c4dbgp("push!");
203 _push();
204 }
205 else
206 {
207 _c4dbgp("ensure stream");
208 _set_root_as_stream();
209 const id_type root = m_tree->root_id();
210 const id_type first = m_tree->first_child(root);
211 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->is_stream(root), m_tree, root);
212 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->num_children(root) == 1u, m_tree, root);
213 if(m_tree->is_container(first) || m_tree->is_val(first))
214 {
215 _c4dbgp("push!");
216 _push();
217 #ifdef RYML_WITH_COMMENTS
218 m_tree->_p(root)->m_first_comment = NONE;
219 m_tree->_p(root)->m_last_comment = NONE;
220 #endif
221 }
222 else
223 {
224 _c4dbgp("tweak");
225 _push();
226 _remove_speculative();
227 m_curr->node_id = m_tree->last_child(root);
228 m_curr->tr_data = m_tree->_p(m_curr->node_id);
229 }
230 }
231 ryml_enable_(DOC);
232 m_curr_doc = m_curr->node_id;
233 }
@ NONE
an index to none
Definition common.hpp:131
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

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 235 of file event_handler_tree.hpp.

236 {
237 _c4dbgp("end_doc_expl");
238 m_curr_doc = m_tree->size();
239 _remove_speculative();
241 {
242 _c4dbgp("pop!");
243 _pop();
244 }
245 }

◆ begin_map_key_flow()

void c4::yml::EventHandlerTree::begin_map_key_flow ( )
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_key_block()

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

Definition at line 258 of file event_handler_tree.hpp.

259 {
260 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
261 }

◆ begin_map_val_flow()

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

Definition at line 263 of file event_handler_tree.hpp.

264 {
265 _c4dbgpf("node[{}]: begin_map_val_flow", m_curr->node_id);
266 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VAL));
267 ryml_enable_(MAP|FLOW_SL);
268 _save_loc();
269 _push();
270 }
@ 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 271 of file event_handler_tree.hpp.

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

◆ end_map_block()

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

Definition at line 280 of file event_handler_tree.hpp.

281 {
282 _c4dbgpf("node[{}]: end_map_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
283 _pop();
284 }

◆ end_map_flow()

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

Definition at line 286 of file event_handler_tree.hpp.

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

◆ begin_seq_key_flow()

void c4::yml::EventHandlerTree::begin_seq_key_flow ( )
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_key_block()

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

Definition at line 308 of file event_handler_tree.hpp.

309 {
310 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
311 }

◆ begin_seq_val_flow()

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

Definition at line 313 of file event_handler_tree.hpp.

314 {
315 _c4dbgpf("node[{}]: begin_seq_val_flow", m_curr->node_id);
316 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VAL));
317 ryml_enable_(SEQ|FLOW_SL);
318 _save_loc();
319 _push();
320 }
@ 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 321 of file event_handler_tree.hpp.

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

◆ end_seq_block()

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

Definition at line 330 of file event_handler_tree.hpp.

331 {
332 _c4dbgpf("node[{}]: end_seq_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
333 _pop();
334 }

◆ end_seq_flow()

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

Definition at line 336 of file event_handler_tree.hpp.

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

◆ add_sibling()

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

Definition at line 354 of file event_handler_tree.hpp.

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

◆ 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 377 of file event_handler_tree.hpp.

378 {
379 if C4_UNLIKELY(m_tree->is_container(m_curr->node_id))
380 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
381 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_parent);
382 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id), m_tree, m_parent->node_id);
383 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id), m_tree, m_curr->node_id);
384 RYML_ASSERT_VISIT_CB_(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id), m_tree, m_curr->node_id);
385 const NodeData tmp = _val2key_(*m_curr->tr_data);
386 ryml_disable_(VALMASK_|VAL_STYLE|VALNIL);
387 m_curr->tr_data->m_val = {};
389 m_curr->tr_data->m_type = tmp.m_type;
390 m_curr->tr_data->m_key = tmp.m_key;
391 }
@ 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 399 of file event_handler_tree.hpp.

400 {
401 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
402 }

◆ set_key_scalar_plain_empty()

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

Definition at line 412 of file event_handler_tree.hpp.

413 {
414 _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
415 m_curr->tr_data->m_key.scalar = {};
416 ryml_enable_(KEY|KEY_PLAIN|KEYNIL);
417 }
@ 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 418 of file event_handler_tree.hpp.

419 {
420 _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
421 m_curr->tr_data->m_val.scalar = {};
422 ryml_enable_(VAL|VAL_PLAIN|VALNIL);
423 }
@ 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 425 of file event_handler_tree.hpp.

426 {
427 _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
428 m_curr->tr_data->m_key.scalar = scalar;
429 ryml_enable_(KEY|KEY_PLAIN);
430 }

◆ set_val_scalar_plain()

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

Definition at line 431 of file event_handler_tree.hpp.

432 {
433 _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
434 m_curr->tr_data->m_val.scalar = scalar;
435 ryml_enable_(VAL|VAL_PLAIN);
436 }

◆ set_key_scalar_dquoted()

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

Definition at line 439 of file event_handler_tree.hpp.

440 {
441 _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
442 m_curr->tr_data->m_key.scalar = scalar;
443 ryml_enable_(KEY|KEY_DQUO);
444 }
@ 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 445 of file event_handler_tree.hpp.

446 {
447 _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
448 m_curr->tr_data->m_val.scalar = scalar;
449 ryml_enable_(VAL|VAL_DQUO);
450 }
@ 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 453 of file event_handler_tree.hpp.

454 {
455 _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
456 m_curr->tr_data->m_key.scalar = scalar;
457 ryml_enable_(KEY|KEY_SQUO);
458 }
@ 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 459 of file event_handler_tree.hpp.

460 {
461 _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
462 m_curr->tr_data->m_val.scalar = scalar;
463 ryml_enable_(VAL|VAL_SQUO);
464 }
@ 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 467 of file event_handler_tree.hpp.

468 {
469 _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
470 m_curr->tr_data->m_key.scalar = scalar;
471 ryml_enable_(KEY|KEY_LITERAL);
472 }
@ 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 473 of file event_handler_tree.hpp.

474 {
475 _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
476 m_curr->tr_data->m_val.scalar = scalar;
477 ryml_enable_(VAL|VAL_LITERAL);
478 }
@ 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 481 of file event_handler_tree.hpp.

482 {
483 _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
484 m_curr->tr_data->m_key.scalar = scalar;
485 ryml_enable_(KEY|KEY_FOLDED);
486 }
@ 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 487 of file event_handler_tree.hpp.

488 {
489 _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
490 m_curr->tr_data->m_val.scalar = scalar;
491 ryml_enable_(VAL|VAL_FOLDED);
492 }
@ 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 495 of file event_handler_tree.hpp.

496 {
497 ryml_enable_(KEY_UNFILT);
498 }
@ 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 499 of file event_handler_tree.hpp.

500 {
501 ryml_enable_(VAL_UNFILT);
502 }
@ 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 511 of file event_handler_tree.hpp.

512 {
513 _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
514 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
515 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(KEYREF));
516 RYML_ASSERT_PARSE_CB_(m_tree->callbacks(), !anchor.begins_with('&'), m_curr->pos);
517 ryml_enable_(KEYANCH);
518 m_curr->tr_data->m_key.anchor = anchor;
519 }
@ 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 520 of file event_handler_tree.hpp.

521 {
522 _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
523 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
524 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_hasany_(VALREF));
525 RYML_ASSERT_PARSE_CB_(m_tree->callbacks(), !anchor.begins_with('&'), m_curr->pos);
526 ryml_enable_(VALANCH);
527 m_curr->tr_data->m_val.anchor = anchor;
528 }
@ 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 530 of file event_handler_tree.hpp.

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

◆ set_val_ref()

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

Definition at line 539 of file event_handler_tree.hpp.

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

◆ set_key_tag()

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

Definition at line 556 of file event_handler_tree.hpp.

557 {
558 _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
559 ryml_enable_(KEYTAG);
560 m_curr->tr_data->m_key.tag = tag;
561 }
@ 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 562 of file event_handler_tree.hpp.

563 {
564 _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
565 ryml_enable_(VALTAG);
566 m_curr->tr_data->m_val.tag = tag;
567 }
@ 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 576 of file event_handler_tree.hpp.

577 {
578 _c4dbgpf("%YAML directive! version={}", yaml_version);
579 (void)yaml_version;
580 }

◆ add_directive_tag()

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

Definition at line 582 of file event_handler_tree.hpp.

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

◆ arena()

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

Definition at line 596 of file event_handler_tree.hpp.

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

◆ arena_rem()

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

Definition at line 601 of file event_handler_tree.hpp.

602 {
603 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_tree);
604 return m_tree->m_arena.sub(m_tree->m_arena_pos);
605 }

◆ alloc_arena()

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

Definition at line 606 of file event_handler_tree.hpp.

607 {
608 return m_tree->alloc_arena(len);
609 }

◆ _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/v0.16.0/src/c4/yml/event_handler_tree.hpp