rapidyaml  0.10.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)
 
parse events
void start_parse (const char *filename, 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 ()
 
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 ()
 
YAML structure events
void add_sibling ()
 
void actually_val_is_first_key_of_new_map_flow ()
 set 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
 

Protected Member Functions

void _stack_start_parse (const char *filename, 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:260

◆ 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_CB_ERR(m_stack.m_callbacks, "null tree");
77  if(C4_UNLIKELY(id >= tree->capacity()))
78  _RYML_CB_ERR(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_CB_ERR(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().

◆ start_parse()

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

Definition at line 107 of file event_handler_tree.hpp.

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

◆ finish_parse()

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

Definition at line 113 of file event_handler_tree.hpp.

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

◆ cancel_parse()

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

Definition at line 134 of file event_handler_tree.hpp.

135  {
136  m_tree = nullptr;
137  }

◆ begin_stream()

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

Definition at line 146 of file event_handler_tree.hpp.

146 { /*nothing to do*/ }

◆ end_stream()

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

Definition at line 148 of file event_handler_tree.hpp.

148 { /*nothing to do*/ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 158 of file event_handler_tree.hpp.

159  {
160  _c4dbgp("begin_doc");
162  {
163  _c4dbgp("push!");
164  _set_root_as_stream();
165  _push();
166  _enable_(DOC);
167  }
168  }
@ 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 170 of file event_handler_tree.hpp.

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

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 182 of file event_handler_tree.hpp.

183  {
184  _c4dbgp("begin_doc_expl");
185  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->root_id() == m_curr->node_id);
186  if(!m_tree->is_stream(m_tree->root_id())) //if(_should_push_on_begin_doc())
187  {
188  _c4dbgp("ensure stream");
189  _set_root_as_stream();
190  id_type first = m_tree->first_child(m_tree->root_id());
191  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->is_stream(m_tree->root_id()));
192  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->num_children(m_tree->root_id()) == 1u);
193  if(m_tree->has_children(first) || m_tree->is_val(first))
194  {
195  _c4dbgp("push!");
196  _push();
197  }
198  else
199  {
200  _c4dbgp("tweak");
201  _push();
202  _remove_speculative();
203  m_curr->node_id = m_tree->last_child(m_tree->root_id());
204  m_curr->tr_data = m_tree->_p(m_curr->node_id);
205  }
206  }
207  else
208  {
209  _c4dbgp("push!");
210  _push();
211  }
212  _enable_(DOC);
213  }
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:253

References c4::yml::DOC.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 215 of file event_handler_tree.hpp.

216  {
217  _c4dbgp("end_doc_expl");
218  _remove_speculative();
220  {
221  _c4dbgp("pop!");
222  _pop();
223  }
224  m_yaml_directive = false;
225  }

◆ begin_map_key_flow()

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

Definition at line 234 of file event_handler_tree.hpp.

235  {
236  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
237  }

◆ begin_map_key_block()

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

Definition at line 238 of file event_handler_tree.hpp.

239  {
240  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
241  }

◆ begin_map_val_flow()

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

Definition at line 243 of file event_handler_tree.hpp.

244  {
245  _c4dbgpf("node[{}]: begin_map_val_flow", m_curr->node_id);
246  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
247  _enable_(MAP|FLOW_SL);
248  _save_loc();
249  _push();
250  }
#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 251 of file event_handler_tree.hpp.

252  {
253  _c4dbgpf("node[{}]: begin_map_val_block", m_curr->node_id);
254  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
255  _enable_(MAP|BLOCK);
256  _save_loc();
257  _push();
258  }
@ 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()

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

Definition at line 260 of file event_handler_tree.hpp.

261  {
262  _pop();
263  _c4dbgpf("node[{}]: end_map_val", m_curr->node_id);
264  }

◆ begin_seq_key_flow()

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

Definition at line 273 of file event_handler_tree.hpp.

274  {
275  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
276  }

◆ begin_seq_key_block()

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

Definition at line 277 of file event_handler_tree.hpp.

278  {
279  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
280  }

◆ begin_seq_val_flow()

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

Definition at line 282 of file event_handler_tree.hpp.

283  {
284  _c4dbgpf("node[{}]: begin_seq_val_flow", m_curr->node_id);
285  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
286  _enable_(SEQ|FLOW_SL);
287  _save_loc();
288  _push();
289  }
@ 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 290 of file event_handler_tree.hpp.

291  {
292  _c4dbgpf("node[{}]: begin_seq_val_block", m_curr->node_id);
293  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
294  _enable_(SEQ|BLOCK);
295  _save_loc();
296  _push();
297  }

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

◆ end_seq()

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

Definition at line 299 of file event_handler_tree.hpp.

300  {
301  _pop();
302  _c4dbgpf("node[{}]: end_seq_val", m_curr->node_id);
303  }

◆ add_sibling()

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

Definition at line 312 of file event_handler_tree.hpp.

313  {
314  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
315  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
316  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->has_children(m_parent->node_id));
317  NodeData const* prev = m_tree->m_buf; // watchout against relocation of the tree nodes
318  _set_state_(m_curr, m_tree->_append_child__unprotected(m_parent->node_id));
319  if(prev != m_tree->m_buf)
320  _refresh_after_relocation();
321  _c4dbgpf("node[{}]: added sibling={} prev={}", m_parent->node_id, m_curr->node_id, m_tree->prev_sibling(m_curr->node_id));
322  }

◆ actually_val_is_first_key_of_new_map_flow()

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

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

330  {
331  if(C4_UNLIKELY(m_tree->is_container(m_curr->node_id)))
332  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
333  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
334  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id));
335  _RYML_CB_ASSERT(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id));
336  _RYML_CB_ASSERT(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id));
337  const NodeData tmp = _val2key_(*m_curr->tr_data);
338  _disable_(_VALMASK|VAL_STYLE);
339  m_curr->tr_data->m_val = {};
341  m_curr->tr_data->m_type = tmp.m_type;
342  m_curr->tr_data->m_key = tmp.m_key;
343  }
@ 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, and c4::yml::VAL_STYLE.

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

352  {
353  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
354  }

◆ set_key_scalar_plain_empty()

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

Definition at line 364 of file event_handler_tree.hpp.

365  {
366  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
367  m_curr->tr_data->m_key.scalar = {};
368  _enable_(KEY|KEY_PLAIN|KEYNIL);
369  }
@ 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 370 of file event_handler_tree.hpp.

371  {
372  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
373  m_curr->tr_data->m_val.scalar = {};
374  _enable_(VAL|VAL_PLAIN|VALNIL);
375  }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:49
@ 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 377 of file event_handler_tree.hpp.

378  {
379  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
380  m_curr->tr_data->m_key.scalar = scalar;
381  _enable_(KEY|KEY_PLAIN);
382  }

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

384  {
385  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
386  m_curr->tr_data->m_val.scalar = scalar;
387  _enable_(VAL|VAL_PLAIN);
388  }

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

392  {
393  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
394  m_curr->tr_data->m_key.scalar = scalar;
395  _enable_(KEY|KEY_DQUO);
396  }
@ 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 397 of file event_handler_tree.hpp.

398  {
399  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
400  m_curr->tr_data->m_val.scalar = scalar;
401  _enable_(VAL|VAL_DQUO);
402  }
@ 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 405 of file event_handler_tree.hpp.

406  {
407  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
408  m_curr->tr_data->m_key.scalar = scalar;
409  _enable_(KEY|KEY_SQUO);
410  }
@ 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 411 of file event_handler_tree.hpp.

412  {
413  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
414  m_curr->tr_data->m_val.scalar = scalar;
415  _enable_(VAL|VAL_SQUO);
416  }
@ 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 419 of file event_handler_tree.hpp.

420  {
421  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
422  m_curr->tr_data->m_key.scalar = scalar;
423  _enable_(KEY|KEY_LITERAL);
424  }
@ 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 425 of file event_handler_tree.hpp.

426  {
427  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
428  m_curr->tr_data->m_val.scalar = scalar;
429  _enable_(VAL|VAL_LITERAL);
430  }
@ 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 433 of file event_handler_tree.hpp.

434  {
435  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
436  m_curr->tr_data->m_key.scalar = scalar;
437  _enable_(KEY|KEY_FOLDED);
438  }
@ 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 439 of file event_handler_tree.hpp.

440  {
441  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
442  m_curr->tr_data->m_val.scalar = scalar;
443  _enable_(VAL|VAL_FOLDED);
444  }
@ 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 447 of file event_handler_tree.hpp.

448  {
449  _enable_(KEY_UNFILT);
450  }
@ 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 451 of file event_handler_tree.hpp.

452  {
453  _enable_(VAL_UNFILT);
454  }
@ 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 463 of file event_handler_tree.hpp.

464  {
465  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
466  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
467  _RYML_CB_ASSERT(m_stack.m_callbacks, !_has_any_(KEYREF));
468  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
469  _enable_(KEYANCH);
470  m_curr->tr_data->m_key.anchor = anchor;
471  }
@ 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 472 of file event_handler_tree.hpp.

473  {
474  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
475  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
476  _RYML_CB_ASSERT(m_stack.m_callbacks, !_has_any_(VALREF));
477  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
478  _enable_(VALANCH);
479  m_curr->tr_data->m_val.anchor = anchor;
480  }
@ 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 482 of file event_handler_tree.hpp.

483  {
484  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
485  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
486  if(C4_UNLIKELY(_has_any_(KEYANCH)))
487  _RYML_CB_ERR_(m_tree->callbacks(), "key cannot have both anchor and ref", m_curr->pos);
488  _RYML_CB_ASSERT(m_tree->callbacks(), ref.begins_with('*'));
489  _enable_(KEY|KEYREF);
490  m_curr->tr_data->m_key.anchor = ref.sub(1);
491  m_curr->tr_data->m_key.scalar = ref;
492  }

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

494  {
495  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
496  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
497  if(C4_UNLIKELY(_has_any_(VALANCH)))
498  _RYML_CB_ERR_(m_tree->callbacks(), "val cannot have both anchor and ref", m_curr->pos);
499  _RYML_CB_ASSERT(m_tree->callbacks(), ref.begins_with('*'));
500  _enable_(VAL|VALREF);
501  m_curr->tr_data->m_val.anchor = ref.sub(1);
502  m_curr->tr_data->m_val.scalar = ref;
503  }

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

513  {
514  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
515  _enable_(KEYTAG);
516  m_curr->tr_data->m_key.tag = tag;
517  }
@ 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 518 of file event_handler_tree.hpp.

519  {
520  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
521  _enable_(VALTAG);
522  m_curr->tr_data->m_val.tag = tag;
523  }
@ 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 532 of file event_handler_tree.hpp.

533  {
534  _c4dbgpf("% directive! {}", directive);
535  _RYML_CB_ASSERT(m_tree->callbacks(), directive.begins_with('%'));
536  if(directive.begins_with("%TAG"))
537  {
538  if(C4_UNLIKELY(!m_tree->add_tag_directive(directive)))
539  _RYML_CB_ERR_(m_stack.m_callbacks, "failed to add directive", m_curr->pos);
540  }
541  else if(directive.begins_with("%YAML"))
542  {
543  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
544  if(C4_UNLIKELY(m_yaml_directive))
545  _RYML_CB_ERR_(m_stack.m_callbacks, "multiple yaml directives", m_curr->pos);
546  m_yaml_directive = true;
547  }
548  else
549  {
550  _c4dbgpf("unknown directive! ignoring... {}", directive);
551  }
552  ++m_num_directives;
553  }

◆ alloc_arena() [1/2]

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

Definition at line 562 of file event_handler_tree.hpp.

563  {
564  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
565  csubstr prev = m_tree->arena();
566  substr out = m_tree->alloc_arena(len);
567  substr curr = m_tree->arena();
568  if(curr.str != prev.str)
569  _stack_relocate_to_new_arena(prev, curr);
570  return out;
571  }

◆ alloc_arena() [2/2]

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

Definition at line 573 of file event_handler_tree.hpp.

574  {
575  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
576  csubstr prev = m_tree->arena();
577  if(!prev.is_super(*relocated))
578  return alloc_arena(len);
579  substr out = alloc_arena(len);
580  substr curr = m_tree->arena();
581  if(curr.str != prev.str)
582  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
583  return out;
584  }

◆ _stack_start_parse()

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

Definition at line 64 of file event_handler_stack.hpp.

65  {
66  _RYML_CB_ASSERT(m_stack.m_callbacks, m_curr != nullptr);
67  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena != nullptr);
68  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena_data != nullptr);
69  m_curr->start_parse(filename, m_curr->node_id);
70  m_relocate_arena = relocate_arena;
71  m_relocate_arena_data = relocate_arena_data;
72  }
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 74 of file event_handler_stack.hpp.

75  {
76  }

◆ _stack_reset_root()

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

Definition at line 80 of file event_handler_stack.hpp.

81  {
82  m_stack.clear();
83  m_stack.push({});
84  m_parent = nullptr;
85  m_curr = &m_stack.top();
86  }

◆ _stack_reset_non_root()

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

Definition at line 88 of file event_handler_stack.hpp.

89  {
90  m_stack.clear();
91  m_stack.push({}); // parent
92  m_stack.push({}); // node
93  m_parent = &m_stack.top(1);
94  m_curr = &m_stack.top();
95  }

◆ _stack_push()

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

Definition at line 97 of file event_handler_stack.hpp.

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

◆ _stack_pop()

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

Definition at line 105 of file event_handler_stack.hpp.

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

◆ _stack_should_push_on_begin_doc()

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

Definition at line 126 of file event_handler_stack.hpp.

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

◆ _stack_should_pop_on_end_doc()

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

Definition at line 132 of file event_handler_stack.hpp.

133  {
134  const bool is_root = (m_stack.size() == 1u);
135  return !is_root && _has_any_(DOC);
136  }

◆ _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 140 of file event_handler_stack.hpp.

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

◆ _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 156 of file event_handler_stack.hpp.

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

◆ 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 171 of file event_handler_stack.hpp.

172  {
173  const bool is_root = (m_stack.size() == 1u);
174  const bool isndoc = (m_curr->flags & NDOC) != 0;
175  const bool suspicious = _has_any_(MAP|SEQ|VAL);
176  _c4dbgpf("target={} isroot={} suspicious={} ndoc={}", m_curr->node_id, is_root, suspicious, isndoc);
177  if((is_root || _has_any_(DOC)) && suspicious && !isndoc)
178  _RYML_CB_ERR_(m_stack.m_callbacks, "parse error", m_curr->pos);
179  }
@ 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.


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