rapidyaml  0.9.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 32 of file event_handler_tree.hpp.

Member Typedef Documentation

◆ state

◆ pfn_relocate_arena

Constructor & Destructor Documentation

◆ EventHandlerTree() [1/3]

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

Definition at line 65 of file event_handler_tree.hpp.

65 : 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 66 of file event_handler_tree.hpp.

66 : 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 67 of file event_handler_tree.hpp.

67  : EventHandlerStack(tree->callbacks()), m_tree(tree), m_id(id), m_num_directives(), m_yaml_directive()
68  {
69  reset(tree, id);
70  }
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 72 of file event_handler_tree.hpp.

73  {
74  if(C4_UNLIKELY(!tree))
75  _RYML_CB_ERR(m_stack.m_callbacks, "null tree");
76  if(C4_UNLIKELY(id >= tree->capacity()))
77  _RYML_CB_ERR(tree->callbacks(), "invalid node");
78  if(C4_UNLIKELY(!tree->is_root(id)))
79  if(C4_UNLIKELY(tree->is_map(tree->parent(id))))
80  if(C4_UNLIKELY(!tree->has_key(id)))
81  _RYML_CB_ERR(tree->callbacks(), "destination node belongs to a map and has no key");
82  m_tree = tree;
83  m_id = id;
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_num_directives = 0;
96  m_yaml_directive = false;
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::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 106 of file event_handler_tree.hpp.

107  {
108  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree != nullptr);
109  this->_stack_start_parse(filename, relocate_arena, relocate_arena_data);
110  }
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 112 of file event_handler_tree.hpp.

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

◆ cancel_parse()

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

Definition at line 133 of file event_handler_tree.hpp.

134  {
135  m_tree = nullptr;
136  }

◆ begin_stream()

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

Definition at line 145 of file event_handler_tree.hpp.

145 { /*nothing to do*/ }

◆ end_stream()

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

Definition at line 147 of file event_handler_tree.hpp.

147 { /*nothing to do*/ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 157 of file event_handler_tree.hpp.

158  {
159  _c4dbgp("begin_doc");
161  {
162  _c4dbgp("push!");
163  _set_root_as_stream();
164  _push();
165  _enable_(DOC);
166  }
167  }
@ DOC
a document
Definition: node_type.hpp:37

References c4::yml::DOC.

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 169 of file event_handler_tree.hpp.

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

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 181 of file event_handler_tree.hpp.

182  {
183  _c4dbgp("begin_doc_expl");
184  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->root_id() == m_curr->node_id);
185  if(!m_tree->is_stream(m_tree->root_id())) //if(_should_push_on_begin_doc())
186  {
187  _c4dbgp("ensure stream");
188  _set_root_as_stream();
189  id_type first = m_tree->first_child(m_tree->root_id());
190  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->is_stream(m_tree->root_id()));
191  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->num_children(m_tree->root_id()) == 1u);
192  if(m_tree->has_children(first) || m_tree->is_val(first))
193  {
194  _c4dbgp("push!");
195  _push();
196  }
197  else
198  {
199  _c4dbgp("tweak");
200  _push();
201  _remove_speculative();
202  m_curr->node_id = m_tree->last_child(m_tree->root_id());
203  m_curr->tr_data = m_tree->_p(m_curr->node_id);
204  }
205  }
206  else
207  {
208  _c4dbgp("push!");
209  _push();
210  }
211  _enable_(DOC);
212  }
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
id_type node_id
don't hold a pointer to the node as it will be relocated during tree resizes

References c4::yml::DOC.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 214 of file event_handler_tree.hpp.

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

◆ begin_map_key_flow()

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

Definition at line 233 of file event_handler_tree.hpp.

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

◆ begin_map_key_block()

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

Definition at line 237 of file event_handler_tree.hpp.

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

◆ begin_map_val_flow()

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

Definition at line 242 of file event_handler_tree.hpp.

243  {
244  _c4dbgpf("node[{}]: begin_map_val_flow", m_curr->node_id);
245  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
246  _enable_(MAP|FLOW_SL);
247  _save_loc();
248  _push();
249  }
#define _has_any_(bits)
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:35
@ FLOW_SL
mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,...
Definition: node_type.hpp:56
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition: node_type.hpp:34

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

251  {
252  _c4dbgpf("node[{}]: begin_map_val_block", m_curr->node_id);
253  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
254  _enable_(MAP|BLOCK);
255  _save_loc();
256  _push();
257  }
@ BLOCK
mark container with block style (seqs as '- val ', maps as 'key: val')
Definition: node_type.hpp:58

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

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

◆ begin_seq_key_flow()

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

Definition at line 272 of file event_handler_tree.hpp.

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

◆ begin_seq_key_block()

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

Definition at line 276 of file event_handler_tree.hpp.

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

◆ begin_seq_val_flow()

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

Definition at line 281 of file event_handler_tree.hpp.

282  {
283  _c4dbgpf("node[{}]: begin_seq_val_flow", m_curr->node_id);
284  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
285  _enable_(SEQ|FLOW_SL);
286  _save_loc();
287  _push();
288  }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:36

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

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

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

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

◆ add_sibling()

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

Definition at line 311 of file event_handler_tree.hpp.

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

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

329  {
330  if(C4_UNLIKELY(m_tree->is_container(m_curr->node_id)))
331  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
332  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
333  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id));
334  _RYML_CB_ASSERT(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id));
335  _RYML_CB_ASSERT(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id));
336  const NodeData tmp = _val2key_(*m_curr->tr_data);
337  _disable_(_VALMASK|VAL_STYLE);
338  m_curr->tr_data->m_val = {};
340  m_curr->tr_data->m_type = tmp.m_type;
341  m_curr->tr_data->m_key = tmp.m_key;
342  }
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
Definition: node_type.hpp:89
@ _VALMASK
Definition: node_type.hpp:98
NodeType m_type
Definition: tree.hpp:182
NodeScalar m_key
Definition: tree.hpp:184
NodeScalar m_val
Definition: tree.hpp:185

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

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

◆ set_key_scalar_plain_empty()

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

Definition at line 363 of file event_handler_tree.hpp.

364  {
365  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
366  m_curr->tr_data->m_key.scalar = {};
367  _enable_(KEY|KEY_PLAIN|KEYNIL);
368  }
@ KEY
is member of a map
Definition: node_type.hpp:33
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:67
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:45
csubstr scalar
Definition: tree.hpp:66

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

370  {
371  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
372  m_curr->tr_data->m_val.scalar = {};
373  _enable_(VAL|VAL_PLAIN|VALNIL);
374  }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:46
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:68

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

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

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

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

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

391  {
392  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
393  m_curr->tr_data->m_key.scalar = scalar;
394  _enable_(KEY|KEY_DQUO);
395  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:65

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

397  {
398  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
399  m_curr->tr_data->m_val.scalar = scalar;
400  _enable_(VAL|VAL_DQUO);
401  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:66

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

405  {
406  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
407  m_curr->tr_data->m_key.scalar = scalar;
408  _enable_(KEY|KEY_SQUO);
409  }
@ KEY_SQUO
mark key scalar as single quoted '
Definition: node_type.hpp:63

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

411  {
412  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
413  m_curr->tr_data->m_val.scalar = scalar;
414  _enable_(VAL|VAL_SQUO);
415  }
@ VAL_SQUO
mark val scalar as single quoted '
Definition: node_type.hpp:64

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

419  {
420  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
421  m_curr->tr_data->m_key.scalar = scalar;
422  _enable_(KEY|KEY_LITERAL);
423  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:59

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

425  {
426  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
427  m_curr->tr_data->m_val.scalar = scalar;
428  _enable_(VAL|VAL_LITERAL);
429  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:60

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

433  {
434  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
435  m_curr->tr_data->m_key.scalar = scalar;
436  _enable_(KEY|KEY_FOLDED);
437  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:61

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

439  {
440  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
441  m_curr->tr_data->m_val.scalar = scalar;
442  _enable_(VAL|VAL_FOLDED);
443  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:62

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

447  {
448  _enable_(KEY_UNFILT);
449  }
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:51

References c4::yml::KEY_UNFILT.

◆ mark_val_scalar_unfiltered()

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

Definition at line 450 of file event_handler_tree.hpp.

451  {
452  _enable_(VAL_UNFILT);
453  }
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:52

References c4::yml::VAL_UNFILT.

◆ set_key_anchor()

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

Definition at line 462 of file event_handler_tree.hpp.

463  {
464  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
465  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
466  if(C4_UNLIKELY(_has_any_(KEYREF)))
467  _RYML_CB_ERR_(m_tree->callbacks(), "key cannot have both anchor and ref", m_curr->pos);
468  _RYML_CB_ASSERT(m_tree->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:39
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:41
csubstr anchor
Definition: tree.hpp:67

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  if(C4_UNLIKELY(_has_any_(VALREF)))
477  _RYML_CB_ERR_(m_tree->callbacks(), "val cannot have both anchor and ref", m_curr->pos);
478  _RYML_CB_ASSERT(m_tree->callbacks(), !anchor.begins_with('&'));
479  _enable_(VALANCH);
480  m_curr->tr_data->m_val.anchor = anchor;
481  }
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:42
@ VALREF
a *reference: the val references an &anchor
Definition: node_type.hpp:40

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

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

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

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

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

514  {
515  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
516  _enable_(KEYTAG);
517  m_curr->tr_data->m_key.tag = tag;
518  }
@ KEYTAG
the key has a tag
Definition: node_type.hpp:43

References c4::yml::KEYTAG.

◆ set_val_tag()

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

Definition at line 519 of file event_handler_tree.hpp.

520  {
521  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
522  _enable_(VALTAG);
523  m_curr->tr_data->m_val.tag = tag;
524  }
@ VALTAG
the val has a tag
Definition: node_type.hpp:44

References c4::yml::VALTAG.

◆ add_directive()

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

Definition at line 533 of file event_handler_tree.hpp.

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

◆ alloc_arena() [1/2]

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

Definition at line 563 of file event_handler_tree.hpp.

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

◆ alloc_arena() [2/2]

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

Definition at line 574 of file event_handler_tree.hpp.

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

◆ _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
void start_parse(const char *file, id_type node_id_)

◆ _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();
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);
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  }
void reset_before_pop(ParserState const &to_pop)

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

Definition at line 51 of file event_handler_stack.hpp.

◆ m_curr

current stack level: top of the stack. cached here for easier access.

Definition at line 52 of file event_handler_stack.hpp.

◆ m_parent

parent of the current stack level.

Definition at line 53 of file event_handler_stack.hpp.

◆ m_relocate_arena

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: