rapidyaml  0.12.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 33 of file event_handler_tree.hpp.

Member Typedef Documentation

◆ state

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

Definition at line 39 of file event_handler_tree.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
requires_strings_on_buffers 

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

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

◆ EventHandlerTree() [3/3]

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

Definition at line 68 of file event_handler_tree.hpp.

68  : EventHandlerStack(tree->callbacks()), m_tree(tree), m_curr_doc()
69  {
70  reset(tree, id);
71  }
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 73 of file event_handler_tree.hpp.

74  {
75  if(C4_UNLIKELY(!tree))
76  _RYML_ERR_BASIC_(m_stack.m_callbacks, "null tree");
77  if(C4_UNLIKELY(id >= tree->capacity()))
78  _RYML_ERR_BASIC_(tree->callbacks(), "invalid node");
79  if(C4_UNLIKELY(!tree->is_root(id)))
80  if(C4_UNLIKELY(tree->is_map(tree->parent(id))))
81  if(C4_UNLIKELY(!tree->has_key(id)))
82  _RYML_ERR_BASIC_(tree->callbacks(), "destination node belongs to a map and has no key");
83  m_tree = tree;
84  if(m_tree->is_root(id))
85  {
87  _reset_parser_state(m_curr, id, m_tree->root_id());
88  }
89  else
90  {
92  _reset_parser_state(m_parent, id, m_tree->parent(id));
93  _reset_parser_state(m_curr, id, id);
94  }
95  m_curr_doc = m_tree->ancestor_doc(id);
96  m_tag_cache.clear();
97  }
state * m_curr
current stack level: top of the stack. cached here for easier access.

References c4::yml::Tree::callbacks(), c4::yml::Tree::capacity(), c4::yml::TagCache::clear(), c4::yml::Tree::has_key(), c4::yml::Tree::is_map(), c4::yml::Tree::is_root(), and c4::yml::Tree::parent().

◆ callbacks()

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

Definition at line 99 of file event_handler_tree.hpp.

99 { return m_stack.m_callbacks; }

◆ tag_directives()

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

Definition at line 101 of file event_handler_tree.hpp.

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

◆ tag_cache()

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

Definition at line 102 of file event_handler_tree.hpp.

102 { return m_tag_cache; }

◆ start_parse()

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

Definition at line 111 of file event_handler_tree.hpp.

112  {
113  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree != nullptr);
114  this->_stack_start_parse(filename, ymlsrc);
115  }

◆ finish_parse()

void c4::yml::EventHandlerTree::finish_parse ( )
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_finish_parse();
121  /* This pointer is temporary. Remember that:
122  *
123  * - this handler object may be held by the user
124  * - it may be used with a temporary tree inside the parse function
125  * - when the parse function returns the temporary tree, its address
126  * will change
127  *
128  * As a result, the user could try to read the tree from m_tree, and
129  * end up reading the stale temporary object.
130  *
131  * So it is better to clear it here; then the user will get an obvious
132  * segfault if reading from m_tree. */
133  m_tree = nullptr;
134  }

◆ cancel_parse()

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

Definition at line 136 of file event_handler_tree.hpp.

137  {
138  m_tree = nullptr;
139  }

◆ begin_stream()

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

Definition at line 148 of file event_handler_tree.hpp.

148 { /* nothing to do */ }

◆ end_stream()

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

Definition at line 150 of file event_handler_tree.hpp.

150 { /* nothing to do */ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 160 of file event_handler_tree.hpp.

161  {
162  _c4dbgp("begin_doc");
164  {
165  _c4dbgp("push!");
166  _set_root_as_stream();
167  _push();
168  _enable_(DOC);
169  }
170  m_curr_doc = m_curr->node_id;
171  }
@ DOC
a document
Definition: node_type.hpp:41

References c4::yml::DOC.

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 173 of file event_handler_tree.hpp.

174  {
175  _c4dbgp("end_doc");
176  m_curr_doc = m_tree->size();
178  {
179  _remove_speculative();
180  _c4dbgp("pop!");
181  _pop();
182  }
183  }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 186 of file event_handler_tree.hpp.

187  {
188  _c4dbgp("begin_doc_expl");
189  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->root_id() == m_curr->node_id, m_tree, m_curr->node_id);
190  if(m_tree->is_stream(m_tree->root_id())) //if(_should_push_on_begin_doc())
191  {
192  _c4dbgp("push!");
193  _push();
194  }
195  else
196  {
197  _c4dbgp("ensure stream");
198  _set_root_as_stream();
199  const id_type root = m_tree->root_id();
200  const id_type first = m_tree->first_child(root);
201  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->is_stream(root), m_tree, root);
202  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->num_children(root) == 1u, m_tree, root);
203  if(m_tree->is_container(first) || m_tree->is_val(first))
204  {
205  _c4dbgp("push!");
206  _push();
207  #ifdef RYML_WITH_COMMENTS
208  m_tree->_p(root)->m_first_comment = NONE;
209  m_tree->_p(root)->m_last_comment = NONE;
210  #endif
211  }
212  else
213  {
214  _c4dbgp("tweak");
215  _push();
216  _remove_speculative();
217  m_curr->node_id = m_tree->last_child(root);
218  m_curr->tr_data = m_tree->_p(m_curr->node_id);
219  }
220  }
221  _enable_(DOC);
222  m_curr_doc = m_curr->node_id;
223  }
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

References c4::yml::DOC, and c4::yml::NONE.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 225 of file event_handler_tree.hpp.

226  {
227  _c4dbgp("end_doc_expl");
228  m_curr_doc = m_tree->size();
229  _remove_speculative();
231  {
232  _c4dbgp("pop!");
233  _pop();
234  }
235  }

◆ begin_map_key_flow()

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

Definition at line 244 of file event_handler_tree.hpp.

245  {
246  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
247  }

◆ begin_map_key_block()

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

Definition at line 248 of file event_handler_tree.hpp.

249  {
250  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
251  }

◆ begin_map_val_flow()

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

Definition at line 253 of file event_handler_tree.hpp.

254  {
255  _c4dbgpf("node[{}]: begin_map_val_flow", m_curr->node_id);
256  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
257  _enable_(MAP|FLOW_SL);
258  _save_loc();
259  _push();
260  }
#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

References _has_any_, c4::yml::FLOW_SL, c4::yml::MAP, and c4::yml::VAL.

◆ begin_map_val_block()

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

Definition at line 261 of file event_handler_tree.hpp.

262  {
263  _c4dbgpf("node[{}]: begin_map_val_block", m_curr->node_id);
264  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
265  _enable_(MAP|BLOCK);
266  _save_loc();
267  _push();
268  }
@ BLOCK
mark container with block style (seqs as '- val ', maps as 'key: val')
Definition: node_type.hpp:62

References _has_any_, c4::yml::BLOCK, c4::yml::MAP, and c4::yml::VAL.

◆ end_map_block()

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

Definition at line 270 of file event_handler_tree.hpp.

271  {
272  _c4dbgpf("node[{}]: end_map_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
273  _pop();
274  }

◆ end_map_flow()

void c4::yml::EventHandlerTree::end_map_flow ( bool  multiline)
inline

Definition at line 276 of file event_handler_tree.hpp.

277  {
278  _c4dbgpf("node[{}]: end_map. multiline={} startline={} endline={}", m_parent->node_id, multiline, m_parent->pos.line, m_curr->pos.line);
279  _pop();
280  if(multiline)
281  {
282  _disable_(FLOW_SL);
283  _enable_(FLOW_ML);
284  }
285  }
@ FLOW_ML
mark container with multi-line flow style (seqs as '[ val1, val2 ], maps as '{ key: val,...
Definition: node_type.hpp:61

References c4::yml::FLOW_ML, and c4::yml::FLOW_SL.

◆ begin_seq_key_flow()

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

Definition at line 294 of file event_handler_tree.hpp.

295  {
296  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
297  }

◆ begin_seq_key_block()

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

Definition at line 298 of file event_handler_tree.hpp.

299  {
300  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
301  }

◆ begin_seq_val_flow()

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

Definition at line 303 of file event_handler_tree.hpp.

304  {
305  _c4dbgpf("node[{}]: begin_seq_val_flow", m_curr->node_id);
306  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
307  _enable_(SEQ|FLOW_SL);
308  _save_loc();
309  _push();
310  }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:40

References _has_any_, c4::yml::FLOW_SL, c4::yml::SEQ, and c4::yml::VAL.

◆ begin_seq_val_block()

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

Definition at line 311 of file event_handler_tree.hpp.

312  {
313  _c4dbgpf("node[{}]: begin_seq_val_block", m_curr->node_id);
314  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
315  _enable_(SEQ|BLOCK);
316  _save_loc();
317  _push();
318  }

References _has_any_, c4::yml::BLOCK, c4::yml::SEQ, and c4::yml::VAL.

◆ end_seq_block()

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

Definition at line 320 of file event_handler_tree.hpp.

321  {
322  _c4dbgpf("node[{}]: end_seq_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
323  _pop();
324  }

◆ end_seq_flow()

void c4::yml::EventHandlerTree::end_seq_flow ( bool  multiline)
inline

Definition at line 326 of file event_handler_tree.hpp.

327  {
328  _c4dbgpf("node[{}]: end_seq. multiline={} startline={} endline={}", m_parent->node_id, multiline, m_parent->pos.line, m_curr->pos.line);
329  _pop();
330  if(multiline)
331  {
332  _disable_(FLOW_SL);
333  _enable_(FLOW_ML);
334  }
335  }

References c4::yml::FLOW_ML, and c4::yml::FLOW_SL.

◆ add_sibling()

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

Definition at line 344 of file event_handler_tree.hpp.

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

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

362  {
363  if(C4_UNLIKELY(m_tree->is_container(m_curr->node_id)))
364  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
365  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
366  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id), m_tree, m_parent->node_id);
367  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id), m_tree, m_curr->node_id);
368  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id), m_tree, m_curr->node_id);
369  const NodeData tmp = _val2key_(*m_curr->tr_data);
370  _disable_(_VALMASK|VAL_STYLE|VALNIL);
371  m_curr->tr_data->m_val = {};
373  m_curr->tr_data->m_type = tmp.m_type;
374  m_curr->tr_data->m_key = tmp.m_key;
375  }
@ 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

References c4::yml::_VALMASK, c4::yml::NodeData::m_key, c4::yml::NodeData::m_type, c4::yml::VAL_STYLE, and c4::yml::VALNIL.

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

384  {
385  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
386  }

◆ set_key_scalar_plain_empty()

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

Definition at line 396 of file event_handler_tree.hpp.

397  {
398  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
399  m_curr->tr_data->m_key.scalar = {};
400  _enable_(KEY|KEY_PLAIN|KEYNIL);
401  }
@ 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

References c4::yml::KEY, c4::yml::KEY_PLAIN, and c4::yml::KEYNIL.

◆ set_val_scalar_plain_empty()

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

Definition at line 402 of file event_handler_tree.hpp.

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

References c4::yml::VAL, c4::yml::VAL_PLAIN, and c4::yml::VALNIL.

◆ set_key_scalar_plain()

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

Definition at line 409 of file event_handler_tree.hpp.

410  {
411  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
412  m_curr->tr_data->m_key.scalar = scalar;
413  _enable_(KEY|KEY_PLAIN);
414  }

References c4::yml::KEY, and c4::yml::KEY_PLAIN.

◆ set_val_scalar_plain()

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

Definition at line 415 of file event_handler_tree.hpp.

416  {
417  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
418  m_curr->tr_data->m_val.scalar = scalar;
419  _enable_(VAL|VAL_PLAIN);
420  }

References c4::yml::VAL, and c4::yml::VAL_PLAIN.

◆ set_key_scalar_dquoted()

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

Definition at line 423 of file event_handler_tree.hpp.

424  {
425  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
426  m_curr->tr_data->m_key.scalar = scalar;
427  _enable_(KEY|KEY_DQUO);
428  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:69

References c4::yml::KEY, and c4::yml::KEY_DQUO.

◆ set_val_scalar_dquoted()

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

Definition at line 429 of file event_handler_tree.hpp.

430  {
431  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
432  m_curr->tr_data->m_val.scalar = scalar;
433  _enable_(VAL|VAL_DQUO);
434  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:70

References c4::yml::VAL, and c4::yml::VAL_DQUO.

◆ set_key_scalar_squoted()

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

Definition at line 437 of file event_handler_tree.hpp.

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

References c4::yml::KEY, and c4::yml::KEY_SQUO.

◆ set_val_scalar_squoted()

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

Definition at line 443 of file event_handler_tree.hpp.

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

References c4::yml::VAL, and c4::yml::VAL_SQUO.

◆ set_key_scalar_literal()

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

Definition at line 451 of file event_handler_tree.hpp.

452  {
453  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
454  m_curr->tr_data->m_key.scalar = scalar;
455  _enable_(KEY|KEY_LITERAL);
456  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:63

References c4::yml::KEY, and c4::yml::KEY_LITERAL.

◆ set_val_scalar_literal()

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

Definition at line 457 of file event_handler_tree.hpp.

458  {
459  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
460  m_curr->tr_data->m_val.scalar = scalar;
461  _enable_(VAL|VAL_LITERAL);
462  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:64

References c4::yml::VAL, and c4::yml::VAL_LITERAL.

◆ set_key_scalar_folded()

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

Definition at line 465 of file event_handler_tree.hpp.

466  {
467  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
468  m_curr->tr_data->m_key.scalar = scalar;
469  _enable_(KEY|KEY_FOLDED);
470  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:65

References c4::yml::KEY, and c4::yml::KEY_FOLDED.

◆ set_val_scalar_folded()

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

Definition at line 471 of file event_handler_tree.hpp.

472  {
473  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
474  m_curr->tr_data->m_val.scalar = scalar;
475  _enable_(VAL|VAL_FOLDED);
476  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:66

References c4::yml::VAL, and c4::yml::VAL_FOLDED.

◆ mark_key_scalar_unfiltered()

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

Definition at line 479 of file event_handler_tree.hpp.

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

References c4::yml::KEY_UNFILT.

◆ mark_val_scalar_unfiltered()

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

Definition at line 483 of file event_handler_tree.hpp.

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

References c4::yml::VAL_UNFILT.

◆ set_key_anchor()

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

Definition at line 495 of file event_handler_tree.hpp.

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

References _has_any_, c4::yml::KEYANCH, and c4::yml::KEYREF.

◆ set_val_anchor()

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

Definition at line 504 of file event_handler_tree.hpp.

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

References _has_any_, c4::yml::VALANCH, and c4::yml::VALREF.

◆ set_key_ref()

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

Definition at line 514 of file event_handler_tree.hpp.

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

References _has_any_, c4::yml::KEY, c4::yml::KEYANCH, and c4::yml::KEYREF.

◆ set_val_ref()

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

Definition at line 525 of file event_handler_tree.hpp.

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

References _has_any_, c4::yml::VAL, c4::yml::VALANCH, and c4::yml::VALREF.

◆ set_key_tag()

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

Definition at line 544 of file event_handler_tree.hpp.

545  {
546  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
547  _enable_(KEYTAG);
548  m_curr->tr_data->m_key.tag = tag;
549  }
@ KEYTAG
the key has a tag
Definition: node_type.hpp:47

References c4::yml::KEYTAG.

◆ set_val_tag()

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

Definition at line 550 of file event_handler_tree.hpp.

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

References c4::yml::VALTAG.

◆ add_directive_yaml()

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

Definition at line 564 of file event_handler_tree.hpp.

565  {
566  _c4dbgpf("%YAML directive! version={}", yaml_version);
567  (void)yaml_version;
568  }

◆ add_directive_tag()

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

Definition at line 570 of file event_handler_tree.hpp.

571  {
572  _c4dbgpf("%TAG directive! handle={} prefix={} id={}", handle, prefix, m_curr_doc);
573  if(C4_UNLIKELY(!m_tree->m_tag_directives.add(handle, prefix, m_curr_doc)))
574  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "too many %TAG directives");
575  }

◆ arena()

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

Definition at line 584 of file event_handler_tree.hpp.

585  {
586  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
587  return m_tree->m_arena.first(m_tree->m_arena_pos);
588  }

◆ arena_rem()

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

Definition at line 589 of file event_handler_tree.hpp.

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

◆ alloc_arena()

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

Definition at line 594 of file event_handler_tree.hpp.

595  {
596  return m_tree->alloc_arena(len);
597  }

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