rapidyaml  0.13.0
parse and emit YAML, and do it fast
c4::yml::EventHandlerTree Struct Reference

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

#include <event_handler_tree.hpp>

Inheritance diagram for c4::yml::EventHandlerTree:
c4::yml::EventHandlerStack< EventHandlerTree, EventHandlerTreeState >

Public Types

types
enum  { requires_strings_on_buffers = false }
 
using state = EventHandlerTreeState
 

Public Member Functions

construction and resetting
 EventHandlerTree ()
 
 EventHandlerTree (Callbacks const &cb)
 
 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 —) More...
 
void end_doc ()
 implicit doc end (without ...) More...
 
void begin_doc_expl ()
 explicit doc start, with — More...
 
void end_doc_expl ()
 explicit doc end, with ... More...
 
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)
 
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)
 
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. More...
 
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. More...
 
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. More...
 
statem_parent
 parent of the current stack level. More...
 
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 ( )
inline

◆ EventHandlerTree() [2/3]

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

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_(m_stack.m_callbacks, "null tree");
83  if(C4_UNLIKELY(id >= tree->capacity()))
84  _RYML_ERR_BASIC_(tree->callbacks(), "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_(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  }
state * m_curr
current stack level: top of the stack. cached here for easier access.

◆ 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; }

◆ 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_(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_(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  _enable_(DOC);
175  }
176  m_curr_doc = m_curr->node_id;
177  }
@ DOC
a document
Definition: node_type.hpp:41

◆ 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_(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_(m_stack.m_callbacks, m_tree->is_stream(root), m_tree, root);
208  _RYML_ASSERT_VISIT_(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  _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:244
@ NONE
an index to none
Definition: common.hpp:251

◆ 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_(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_(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_(m_stack.m_callbacks, !_has_any_(VAL));
263  _enable_(MAP|FLOW_SL);
264  _save_loc();
265  _push();
266  }
#define _has_any_(bits)
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:39
@ FLOW_SL
mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,...
Definition: node_type.hpp:60
@ 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:38

◆ 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_(m_stack.m_callbacks, !_has_any_(VAL));
271  _enable_(MAP|BLOCK);
272  _save_loc();
273  _push();
274  }
@ BLOCK
mark container with block style (seqs as '- val ', maps as 'key: val')
Definition: node_type.hpp:62

◆ 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)
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  _disable_(FLOW_SL);
289  _enable_(FLOW_ML);
290  }
291  }
@ FLOW_ML
mark container with multi-line flow style (seqs as '[ val1, val2 ], maps as '{ key: val,...
Definition: node_type.hpp:61

◆ 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_(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_(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_(m_stack.m_callbacks, !_has_any_(VAL));
313  _enable_(SEQ|FLOW_SL);
314  _save_loc();
315  _push();
316  }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:40

◆ 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_(m_stack.m_callbacks, !_has_any_(VAL));
321  _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)
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  _disable_(FLOW_SL);
339  _enable_(FLOW_ML);
340  }
341  }

◆ add_sibling()

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

Definition at line 350 of file event_handler_tree.hpp.

351  {
352  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
353  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
354  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->has_children(m_parent->node_id), m_tree, m_parent->node_id);
355  NodeData const* const prev = m_tree->m_buf; // watchout against relocation of the tree nodes
356  _set_state_(m_curr, m_tree->_append_child__unprotected(m_parent->node_id));
357  if(prev != m_tree->m_buf)
358  _refresh_after_relocation();
359  _c4dbgpf("node[{}]: added sibling={} prev={}", m_parent->node_id, m_curr->node_id, m_tree->prev_sibling(m_curr->node_id));
360  }

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

368  {
369  if(C4_UNLIKELY(m_tree->is_container(m_curr->node_id)))
370  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
371  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
372  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id), m_tree, m_parent->node_id);
373  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id), m_tree, m_curr->node_id);
374  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id), m_tree, m_curr->node_id);
375  const NodeData tmp = _val2key_(*m_curr->tr_data);
376  _disable_(_VALMASK|VAL_STYLE|VALNIL);
377  m_curr->tr_data->m_val = {};
379  m_curr->tr_data->m_type = tmp.m_type;
380  m_curr->tr_data->m_key = tmp.m_key;
381  }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:50
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
Definition: node_type.hpp:93

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

390  {
391  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
392  }

◆ set_key_scalar_plain_empty()

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

Definition at line 402 of file event_handler_tree.hpp.

403  {
404  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
405  m_curr->tr_data->m_key.scalar = {};
406  _enable_(KEY|KEY_PLAIN|KEYNIL);
407  }
@ KEY
is member of a map
Definition: node_type.hpp:37
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:71
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:49

◆ set_val_scalar_plain_empty()

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

Definition at line 408 of file event_handler_tree.hpp.

409  {
410  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
411  m_curr->tr_data->m_val.scalar = {};
412  _enable_(VAL|VAL_PLAIN|VALNIL);
413  }
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:72

◆ set_key_scalar_plain()

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

Definition at line 415 of file event_handler_tree.hpp.

416  {
417  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
418  m_curr->tr_data->m_key.scalar = scalar;
419  _enable_(KEY|KEY_PLAIN);
420  }

◆ set_val_scalar_plain()

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

Definition at line 421 of file event_handler_tree.hpp.

422  {
423  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
424  m_curr->tr_data->m_val.scalar = scalar;
425  _enable_(VAL|VAL_PLAIN);
426  }

◆ set_key_scalar_dquoted()

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

Definition at line 429 of file event_handler_tree.hpp.

430  {
431  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
432  m_curr->tr_data->m_key.scalar = scalar;
433  _enable_(KEY|KEY_DQUO);
434  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:69

◆ set_val_scalar_dquoted()

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

Definition at line 435 of file event_handler_tree.hpp.

436  {
437  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
438  m_curr->tr_data->m_val.scalar = scalar;
439  _enable_(VAL|VAL_DQUO);
440  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:70

◆ set_key_scalar_squoted()

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

Definition at line 443 of file event_handler_tree.hpp.

444  {
445  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
446  m_curr->tr_data->m_key.scalar = scalar;
447  _enable_(KEY|KEY_SQUO);
448  }
@ KEY_SQUO
mark key scalar as single quoted '
Definition: node_type.hpp:67

◆ set_val_scalar_squoted()

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

Definition at line 449 of file event_handler_tree.hpp.

450  {
451  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
452  m_curr->tr_data->m_val.scalar = scalar;
453  _enable_(VAL|VAL_SQUO);
454  }
@ VAL_SQUO
mark val scalar as single quoted '
Definition: node_type.hpp:68

◆ set_key_scalar_literal()

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

Definition at line 457 of file event_handler_tree.hpp.

458  {
459  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
460  m_curr->tr_data->m_key.scalar = scalar;
461  _enable_(KEY|KEY_LITERAL);
462  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:63

◆ set_val_scalar_literal()

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

Definition at line 463 of file event_handler_tree.hpp.

464  {
465  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
466  m_curr->tr_data->m_val.scalar = scalar;
467  _enable_(VAL|VAL_LITERAL);
468  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:64

◆ set_key_scalar_folded()

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

Definition at line 471 of file event_handler_tree.hpp.

472  {
473  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
474  m_curr->tr_data->m_key.scalar = scalar;
475  _enable_(KEY|KEY_FOLDED);
476  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:65

◆ set_val_scalar_folded()

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

Definition at line 477 of file event_handler_tree.hpp.

478  {
479  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
480  m_curr->tr_data->m_val.scalar = scalar;
481  _enable_(VAL|VAL_FOLDED);
482  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:66

◆ mark_key_scalar_unfiltered()

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

Definition at line 485 of file event_handler_tree.hpp.

486  {
487  _enable_(KEY_UNFILT);
488  }
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:55

◆ mark_val_scalar_unfiltered()

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

Definition at line 489 of file event_handler_tree.hpp.

490  {
491  _enable_(VAL_UNFILT);
492  }
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:56

◆ set_key_anchor()

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

Definition at line 501 of file event_handler_tree.hpp.

502  {
503  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
504  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
505  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !_has_any_(KEYREF));
506  _RYML_ASSERT_PARSE_(m_tree->callbacks(), !anchor.begins_with('&'), m_curr->pos);
507  _enable_(KEYANCH);
508  m_curr->tr_data->m_key.anchor = anchor;
509  }
@ KEYREF
a *reference: the key references an &anchor
Definition: node_type.hpp:43
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:45

◆ set_val_anchor()

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

Definition at line 510 of file event_handler_tree.hpp.

511  {
512  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
513  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
514  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !_has_any_(VALREF));
515  _RYML_ASSERT_PARSE_(m_tree->callbacks(), !anchor.begins_with('&'), m_curr->pos);
516  _enable_(VALANCH);
517  m_curr->tr_data->m_val.anchor = anchor;
518  }
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:46
@ VALREF
a *reference: the val references an &anchor
Definition: node_type.hpp:44

◆ set_key_ref()

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

Definition at line 520 of file event_handler_tree.hpp.

521  {
522  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
523  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
524  if(C4_UNLIKELY(_has_any_(KEYANCH)))
525  _RYML_ERR_PARSE_(m_tree->callbacks(), m_curr->pos, "key cannot have both anchor and ref");
526  _RYML_ASSERT_PARSE_(m_tree->callbacks(), ref.begins_with('*'), m_curr->pos);
527  _enable_(KEY|KEYREF);
528  m_curr->tr_data->m_key.anchor = ref.sub(1);
529  m_curr->tr_data->m_key.scalar = ref;
530  }

◆ set_val_ref()

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

Definition at line 531 of file event_handler_tree.hpp.

532  {
533  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
534  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
535  if(C4_UNLIKELY(_has_any_(VALANCH)))
536  _RYML_ERR_PARSE_(m_tree->callbacks(), m_curr->pos, "val cannot have both anchor and ref");
537  _RYML_ASSERT_PARSE_(m_tree->callbacks(), ref.begins_with('*'), m_curr->pos);
538  _enable_(VAL|VALREF);
539  m_curr->tr_data->m_val.anchor = ref.sub(1);
540  m_curr->tr_data->m_val.scalar = ref;
541  }

◆ set_key_tag()

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

Definition at line 550 of file event_handler_tree.hpp.

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

◆ set_val_tag()

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

Definition at line 556 of file event_handler_tree.hpp.

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

◆ add_directive_yaml()

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

Definition at line 570 of file event_handler_tree.hpp.

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

◆ add_directive_tag()

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

Definition at line 576 of file event_handler_tree.hpp.

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

◆ arena()

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

Definition at line 590 of file event_handler_tree.hpp.

591  {
592  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
593  return m_tree->m_arena.first(m_tree->m_arena_pos);
594  }

◆ arena_rem()

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

Definition at line 595 of file event_handler_tree.hpp.

596  {
597  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
598  return m_tree->m_arena.sub(m_tree->m_arena_pos);
599  }

◆ alloc_arena()

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

Definition at line 600 of file event_handler_tree.hpp.

601  {
602  return m_tree->alloc_arena(len);
603  }

◆ _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_(m_stack.m_callbacks, m_curr != nullptr);
61  m_curr->start_parse(filename, m_curr->node_id);
62  m_src = ymlsrc;
63  }

◆ _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  }

◆ _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  }

◆ _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  }

◆ _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  {
98  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
99  _RYML_ASSERT_BASIC_(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 || _has_any_(DOC|VAL|MAP|SEQ));
125  }

◆ _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 && _has_any_(DOC);
131  }

Member Data Documentation

◆ m_stack

detail::stack<state> c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::m_stack
inherited

Definition at line 46 of file event_handler_stack.hpp.

◆ 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.

◆ m_parent

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

parent of the current stack level.

Definition at line 48 of file event_handler_stack.hpp.

◆ 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: