rapidyaml  0.11.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

using pfn_relocate_arena = detail::pfn_relocate_arena
 
types
using state = EventHandlerTreeState
 

Public Member Functions

void check_trailing_doc_token () const
 Check whether the current parse tokens are trailing on the previous doc, and raise an error if they are. More...
 
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
 
parse events
void start_parse (const char *filename, csubstr ymlsrc, detail::pfn_relocate_arena relocate_arena, void *relocate_arena_data)
 
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) noexcept
 
void set_val_tag (csubstr tag) noexcept
 
YAML directive events
void add_directive (csubstr directive)
 
arena functions
substr alloc_arena (size_t len)
 
substr alloc_arena (size_t len, substr *relocated)
 

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...
 
pfn_relocate_arena m_relocate_arena
 callback when the arena gets relocated More...
 
void * m_relocate_arena_data
 
csubstr m_src
 

Protected Member Functions

void _stack_start_parse (const char *filename, csubstr ymlsrc, pfn_relocate_arena relocate_arena, void *relocate_arena_data)
 
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
 
void _stack_relocate_to_new_arena (csubstr prev, substr curr)
 
substr _stack_relocate_to_new_arena (csubstr s, csubstr prev, substr curr)
 

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.

◆ pfn_relocate_arena

Definition at line 47 of file event_handler_stack.hpp.

Constructor & Destructor Documentation

◆ EventHandlerTree() [1/3]

c4::yml::EventHandlerTree::EventHandlerTree ( )
inline

Definition at line 66 of file event_handler_tree.hpp.

66 : EventHandlerStack(), m_tree(), m_id(NONE), m_num_directives(), m_yaml_directive() {}
@ NONE
an index to none
Definition: common.hpp:251

◆ 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_id(NONE), m_num_directives(), m_yaml_directive() {}

◆ 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_id(id), m_num_directives(), m_yaml_directive()
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  m_id = id;
85  if(m_tree->is_root(id))
86  {
88  _reset_parser_state(m_curr, id, m_tree->root_id());
89  }
90  else
91  {
93  _reset_parser_state(m_parent, id, m_tree->parent(id));
94  _reset_parser_state(m_curr, id, id);
95  }
96  m_num_directives = 0;
97  m_yaml_directive = false;
98  }
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::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 100 of file event_handler_tree.hpp.

100 { return m_stack.m_callbacks; }

◆ start_parse()

void c4::yml::EventHandlerTree::start_parse ( const char *  filename,
csubstr  ymlsrc,
detail::pfn_relocate_arena  relocate_arena,
void *  relocate_arena_data 
)
inline

Definition at line 108 of file event_handler_tree.hpp.

109  {
110  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree != nullptr);
111  this->_stack_start_parse(filename, ymlsrc, relocate_arena, relocate_arena_data);
112  }
void _stack_start_parse(const char *filename, csubstr ymlsrc, pfn_relocate_arena relocate_arena, void *relocate_arena_data)

◆ finish_parse()

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

Definition at line 114 of file event_handler_tree.hpp.

115  {
116  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree != nullptr);
117  if(m_num_directives && !m_tree->is_stream(m_tree->root_id()))
118  _RYML_ERR_BASIC_(m_stack.m_callbacks, "directives cannot be used without a document");
119  this->_stack_finish_parse();
120  /* This pointer is temporary. Remember that:
121  *
122  * - this handler object may be held by the user
123  * - it may be used with a temporary tree inside the parse function
124  * - when the parse function returns the temporary tree, its address
125  * will change
126  *
127  * As a result, the user could try to read the tree from m_tree, and
128  * end up reading the stale temporary object.
129  *
130  * So it is better to clear it here; then the user will get an obvious
131  * segfault if reading from m_tree. */
132  m_tree = nullptr;
133  }

◆ cancel_parse()

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

Definition at line 135 of file event_handler_tree.hpp.

136  {
137  m_tree = nullptr;
138  }

◆ begin_stream()

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

Definition at line 147 of file event_handler_tree.hpp.

147 { /*nothing to do*/ }

◆ end_stream()

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

Definition at line 149 of file event_handler_tree.hpp.

149 { /*nothing to do*/ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 159 of file event_handler_tree.hpp.

160  {
161  _c4dbgp("begin_doc");
163  {
164  _c4dbgp("push!");
165  _set_root_as_stream();
166  _push();
167  _enable_(DOC);
168  }
169  }
@ DOC
a document
Definition: node_type.hpp:40

References c4::yml::DOC.

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 171 of file event_handler_tree.hpp.

172  {
173  _c4dbgp("end_doc");
175  {
176  _remove_speculative();
177  _c4dbgp("pop!");
178  _pop();
179  }
180  }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 183 of file event_handler_tree.hpp.

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

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

222  {
223  _c4dbgp("end_doc_expl");
224  _remove_speculative();
226  {
227  _c4dbgp("pop!");
228  _pop();
229  }
230  m_yaml_directive = false;
231  }

◆ begin_map_key_flow()

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

Definition at line 240 of file event_handler_tree.hpp.

241  {
242  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
243  }

◆ begin_map_key_block()

void c4::yml::EventHandlerTree::begin_map_key_block ( )
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_val_flow()

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

Definition at line 249 of file event_handler_tree.hpp.

250  {
251  _c4dbgpf("node[{}]: begin_map_val_flow", m_curr->node_id);
252  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
253  _enable_(MAP|FLOW_SL);
254  _save_loc();
255  _push();
256  }
#define _has_any_(bits)
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:38
@ FLOW_SL
mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,...
Definition: node_type.hpp:59
@ 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:37

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

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

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

267  {
268  _c4dbgpf("node[{}]: end_map_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
269  _pop();
270  }

◆ end_map_flow()

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

Definition at line 272 of file event_handler_tree.hpp.

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

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

291  {
292  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
293  }

◆ begin_seq_key_block()

void c4::yml::EventHandlerTree::begin_seq_key_block ( )
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_val_flow()

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

Definition at line 299 of file event_handler_tree.hpp.

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

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

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

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

317  {
318  _c4dbgpf("node[{}]: end_seq_block", m_parent->node_id, m_parent->pos.line, m_curr->pos.line);
319  _pop();
320  }

◆ end_seq_flow()

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

Definition at line 322 of file event_handler_tree.hpp.

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

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

◆ add_sibling()

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

Definition at line 340 of file event_handler_tree.hpp.

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

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

358  {
359  if(C4_UNLIKELY(m_tree->is_container(m_curr->node_id)))
360  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
361  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
362  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id), m_tree, m_parent->node_id);
363  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id), m_tree, m_curr->node_id);
364  _RYML_ASSERT_VISIT_(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id), m_tree, m_curr->node_id);
365  const NodeData tmp = _val2key_(*m_curr->tr_data);
366  _disable_(_VALMASK|VAL_STYLE|VALNIL);
367  m_curr->tr_data->m_val = {};
369  m_curr->tr_data->m_type = tmp.m_type;
370  m_curr->tr_data->m_key = tmp.m_key;
371  }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:49
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
Definition: node_type.hpp:92

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

380  {
381  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "ryml trees cannot handle containers as keys");
382  }

◆ set_key_scalar_plain_empty()

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

Definition at line 392 of file event_handler_tree.hpp.

393  {
394  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
395  m_curr->tr_data->m_key.scalar = {};
396  _enable_(KEY|KEY_PLAIN|KEYNIL);
397  }
@ KEY
is member of a map
Definition: node_type.hpp:36
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:70
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:48

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

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

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

406  {
407  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
408  m_curr->tr_data->m_key.scalar = scalar;
409  _enable_(KEY|KEY_PLAIN);
410  }

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

412  {
413  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
414  m_curr->tr_data->m_val.scalar = scalar;
415  _enable_(VAL|VAL_PLAIN);
416  }

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

420  {
421  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
422  m_curr->tr_data->m_key.scalar = scalar;
423  _enable_(KEY|KEY_DQUO);
424  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:68

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

426  {
427  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
428  m_curr->tr_data->m_val.scalar = scalar;
429  _enable_(VAL|VAL_DQUO);
430  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:69

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

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

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

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

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

448  {
449  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
450  m_curr->tr_data->m_key.scalar = scalar;
451  _enable_(KEY|KEY_LITERAL);
452  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:62

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

454  {
455  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
456  m_curr->tr_data->m_val.scalar = scalar;
457  _enable_(VAL|VAL_LITERAL);
458  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:63

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

462  {
463  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
464  m_curr->tr_data->m_key.scalar = scalar;
465  _enable_(KEY|KEY_FOLDED);
466  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:64

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

468  {
469  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
470  m_curr->tr_data->m_val.scalar = scalar;
471  _enable_(VAL|VAL_FOLDED);
472  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:65

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

476  {
477  _enable_(KEY_UNFILT);
478  }
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:54

References c4::yml::KEY_UNFILT.

◆ mark_val_scalar_unfiltered()

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

Definition at line 479 of file event_handler_tree.hpp.

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

References c4::yml::VAL_UNFILT.

◆ set_key_anchor()

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

Definition at line 491 of file event_handler_tree.hpp.

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

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

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

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

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

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

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

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)
inlinenoexcept

Definition at line 540 of file event_handler_tree.hpp.

541  {
542  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
543  _enable_(KEYTAG);
544  m_curr->tr_data->m_key.tag = tag;
545  }
@ KEYTAG
the key has a tag
Definition: node_type.hpp:46

References c4::yml::KEYTAG.

◆ set_val_tag()

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

Definition at line 546 of file event_handler_tree.hpp.

547  {
548  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
549  _enable_(VALTAG);
550  m_curr->tr_data->m_val.tag = tag;
551  }
@ VALTAG
the val has a tag
Definition: node_type.hpp:47

References c4::yml::VALTAG.

◆ add_directive()

void c4::yml::EventHandlerTree::add_directive ( csubstr  directive)
inline

Definition at line 560 of file event_handler_tree.hpp.

561  {
562  _c4dbgpf("% directive! {}", directive);
563  _RYML_ASSERT_PARSE_(m_tree->callbacks(), directive.begins_with('%'), m_curr->pos);
564  if(directive.begins_with("%TAG"))
565  {
566  if(C4_UNLIKELY(!m_tree->add_tag_directive(directive)))
567  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "failed to add directive");
568  }
569  else if(directive.begins_with("%YAML"))
570  {
571  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
572  if(C4_UNLIKELY(m_yaml_directive))
573  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "multiple yaml directives");
574  m_yaml_directive = true;
575  }
576  else
577  {
578  _c4dbgpf("unknown directive! ignoring... {}", directive);
579  }
580  ++m_num_directives;
581  }

◆ alloc_arena() [1/2]

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

Definition at line 590 of file event_handler_tree.hpp.

591  {
592  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
593  csubstr prev = m_tree->arena();
594  substr out = m_tree->alloc_arena(len);
595  substr curr = m_tree->arena();
596  if(curr.str != prev.str)
597  _stack_relocate_to_new_arena(prev, curr);
598  return out;
599  }

◆ alloc_arena() [2/2]

substr c4::yml::EventHandlerTree::alloc_arena ( size_t  len,
substr *  relocated 
)
inline

Definition at line 601 of file event_handler_tree.hpp.

602  {
603  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_tree);
604  csubstr prev = m_tree->arena();
605  if(!prev.is_super(*relocated))
606  return alloc_arena(len);
607  substr out = alloc_arena(len);
608  substr curr = m_tree->arena();
609  if(curr.str != prev.str)
610  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
611  return out;
612  }

◆ _stack_start_parse()

void c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::_stack_start_parse ( const char *  filename,
csubstr  ymlsrc,
pfn_relocate_arena  relocate_arena,
void *  relocate_arena_data 
)
inlineprotectedinherited

Definition at line 65 of file event_handler_stack.hpp.

66  {
67  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_curr != nullptr);
68  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, relocate_arena != nullptr);
69  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, relocate_arena_data != nullptr);
70  m_curr->start_parse(filename, m_curr->node_id);
71  m_relocate_arena = relocate_arena;
72  m_relocate_arena_data = relocate_arena_data;
73  m_src = ymlsrc;
74  }
pfn_relocate_arena m_relocate_arena
callback when the arena gets relocated

◆ _stack_finish_parse()

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

Definition at line 76 of file event_handler_stack.hpp.

77  {
78  m_src = {};
79  }

◆ _stack_reset_root()

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

Definition at line 83 of file event_handler_stack.hpp.

84  {
85  m_stack.clear();
86  m_stack.push({});
87  m_parent = nullptr;
88  m_curr = &m_stack.top();
89  }

◆ _stack_reset_non_root()

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

Definition at line 91 of file event_handler_stack.hpp.

92  {
93  m_stack.clear();
94  m_stack.push({}); // parent
95  m_stack.push({}); // node
96  m_parent = &m_stack.top(1);
97  m_curr = &m_stack.top();
98  }

◆ _stack_push()

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

Definition at line 100 of file event_handler_stack.hpp.

101  {
102  m_stack.push_top();
103  m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push
104  m_curr = &m_stack.top();
105  m_curr->reset_after_push();
106  }

◆ _stack_pop()

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

Definition at line 108 of file event_handler_stack.hpp.

109  {
110  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
111  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_stack.size() > 1);
112  m_parent->reset_before_pop(*m_curr);
113  m_stack.pop();
114  m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr;
115  m_curr = &m_stack.top();
116  #ifdef RYML_DBG
117  if(m_parent)
118  _c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
119  else
120  _c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id);
121  #endif
122  }

◆ _stack_should_push_on_begin_doc()

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

Definition at line 129 of file event_handler_stack.hpp.

130  {
131  const bool is_root = (m_stack.size() == 1u);
132  return is_root && (_has_any_(DOC|VAL|MAP|SEQ) || m_curr->has_children);
133  }

◆ _stack_should_pop_on_end_doc()

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

Definition at line 135 of file event_handler_stack.hpp.

136  {
137  const bool is_root = (m_stack.size() == 1u);
138  return !is_root && _has_any_(DOC);
139  }

◆ _stack_relocate_to_new_arena() [1/2]

void c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::_stack_relocate_to_new_arena ( csubstr  prev,
substr  curr 
)
inlineprotectedinherited

Definition at line 143 of file event_handler_stack.hpp.

144  {
145  for(state &st : m_stack)
146  {
147  if(st.line_contents.rem.is_sub(prev))
148  st.line_contents.rem = _stack_relocate_to_new_arena(st.line_contents.rem, prev, curr);
149  if(st.line_contents.full.is_sub(prev))
150  st.line_contents.full = _stack_relocate_to_new_arena(st.line_contents.full, prev, curr);
151  }
152  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_relocate_arena != nullptr);
153  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_relocate_arena_data != nullptr);
155  }

◆ _stack_relocate_to_new_arena() [2/2]

substr c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::_stack_relocate_to_new_arena ( csubstr  s,
csubstr  prev,
substr  curr 
)
inlineprotectedinherited

Definition at line 157 of file event_handler_stack.hpp.

158  {
159  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, prev.is_super(s));
160  auto pos = s.str - prev.str;
161  substr out = {curr.str + pos, s.len};
162  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, curr.is_super(out));
163  return out;
164  }

◆ check_trailing_doc_token()

void c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::check_trailing_doc_token ( ) const
inlineinherited

Check whether the current parse tokens are trailing on the previous doc, and raise an error if they are.

This function is called by the parse engine (not the event handler) before a doc is started.

Definition at line 172 of file event_handler_stack.hpp.

173  {
174  const bool is_root = (m_stack.size() == 1u);
175  const bool isndoc = (m_curr->flags & NDOC) != 0;
176  const bool suspicious = _has_any_(MAP|SEQ|VAL);
177  _c4dbgpf("target={} isroot={} suspicious={} ndoc={}", m_curr->node_id, is_root, suspicious, isndoc);
178  if((is_root || _has_any_(DOC)) && suspicious && !isndoc)
179  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "parse error");
180  }
@ NDOC
no document mode. a document has ended and another has not started yet.

Member Data Documentation

◆ m_stack

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

Definition at line 51 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 52 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 53 of file event_handler_stack.hpp.

◆ m_relocate_arena

pfn_relocate_arena c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::m_relocate_arena
inherited

callback when the arena gets relocated

Definition at line 54 of file event_handler_stack.hpp.

◆ m_relocate_arena_data

void* c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::m_relocate_arena_data
inherited

Definition at line 55 of file event_handler_stack.hpp.

◆ m_src

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

Definition at line 56 of file event_handler_stack.hpp.


The documentation for this struct was generated from the following file: