rapidyaml  0.7.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 (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 31 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 64 of file event_handler_tree.hpp.

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

◆ EventHandlerTree() [2/3]

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

Definition at line 65 of file event_handler_tree.hpp.

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

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

72  {
73  if(C4_UNLIKELY(!tree))
74  _RYML_CB_ERR(m_stack.m_callbacks, "null tree");
75  if(C4_UNLIKELY(id >= tree->capacity()))
76  _RYML_CB_ERR(tree->callbacks(), "invalid node");
77  if(C4_UNLIKELY(!tree->is_root(id)))
78  if(C4_UNLIKELY(tree->is_map(tree->parent(id))))
79  if(C4_UNLIKELY(!tree->has_key(id)))
80  _RYML_CB_ERR(tree->callbacks(), "destination node belongs to a map and has no key");
81  m_tree = tree;
82  m_id = id;
83  if(m_tree->is_root(id))
84  {
86  _reset_parser_state(m_curr, id, m_tree->root_id());
87  }
88  else
89  {
91  _reset_parser_state(m_parent, id, m_tree->parent(id));
92  _reset_parser_state(m_curr, id, id);
93  }
94  m_num_directives = 0;
95  m_yaml_directive = false;
96  }
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 105 of file event_handler_tree.hpp.

106  {
107  this->_stack_start_parse(filename, relocate_arena, relocate_arena_data);
108  }
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 110 of file event_handler_tree.hpp.

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

◆ cancel_parse()

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

Definition at line 130 of file event_handler_tree.hpp.

131  {
132  m_tree = nullptr;
133  }

◆ begin_stream()

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

Definition at line 142 of file event_handler_tree.hpp.

142 { /*nothing to do*/ }

◆ end_stream()

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

Definition at line 144 of file event_handler_tree.hpp.

144 { /*nothing to do*/ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 154 of file event_handler_tree.hpp.

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

167  {
168  _c4dbgp("end_doc");
170  {
171  _remove_speculative();
172  _c4dbgp("pop!");
173  _pop();
174  }
175  }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 178 of file event_handler_tree.hpp.

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

212  {
213  _c4dbgp("end_doc_expl");
214  _remove_speculative();
216  {
217  _c4dbgp("pop!");
218  _pop();
219  }
220  m_yaml_directive = false;
221  }

◆ begin_map_key_flow()

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

Definition at line 230 of file event_handler_tree.hpp.

231  {
232  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
233  }

◆ begin_map_key_block()

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

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

Definition at line 239 of file event_handler_tree.hpp.

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

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

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

257  {
258  _pop();
259  _c4dbgpf("node[{}]: end_map_val", m_curr->node_id);
260  }

◆ begin_seq_key_flow()

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

Definition at line 269 of file event_handler_tree.hpp.

270  {
271  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
272  }

◆ begin_seq_key_block()

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

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

Definition at line 278 of file event_handler_tree.hpp.

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

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

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

296  {
297  _pop();
298  _c4dbgpf("node[{}]: end_seq_val", m_curr->node_id);
299  }

◆ add_sibling()

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

Definition at line 308 of file event_handler_tree.hpp.

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

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

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

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

347  {
348  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
349  }

◆ set_key_scalar_plain()

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

Definition at line 359 of file event_handler_tree.hpp.

360  {
361  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
362  m_curr->tr_data->m_key.scalar = scalar;
363  _enable_(KEY|KEY_PLAIN);
364  }
@ KEY
is member of a map, must have non-empty key
Definition: node_type.hpp:33
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:65
csubstr scalar
Definition: tree.hpp:103

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

366  {
367  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
368  m_curr->tr_data->m_val.scalar = scalar;
369  _enable_(VAL|VAL_PLAIN);
370  }
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:66

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

374  {
375  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
376  m_curr->tr_data->m_key.scalar = scalar;
377  _enable_(KEY|KEY_DQUO);
378  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:63

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

380  {
381  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
382  m_curr->tr_data->m_val.scalar = scalar;
383  _enable_(VAL|VAL_DQUO);
384  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:64

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

388  {
389  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
390  m_curr->tr_data->m_key.scalar = scalar;
391  _enable_(KEY|KEY_SQUO);
392  }
@ KEY_SQUO
mark key scalar as single quoted '
Definition: node_type.hpp:61

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

394  {
395  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
396  m_curr->tr_data->m_val.scalar = scalar;
397  _enable_(VAL|VAL_SQUO);
398  }
@ VAL_SQUO
mark val scalar as single quoted '
Definition: node_type.hpp:62

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

402  {
403  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
404  m_curr->tr_data->m_key.scalar = scalar;
405  _enable_(KEY|KEY_LITERAL);
406  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:57

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

408  {
409  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
410  m_curr->tr_data->m_val.scalar = scalar;
411  _enable_(VAL|VAL_LITERAL);
412  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:58

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

416  {
417  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
418  m_curr->tr_data->m_key.scalar = scalar;
419  _enable_(KEY|KEY_FOLDED);
420  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:59

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

422  {
423  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
424  m_curr->tr_data->m_val.scalar = scalar;
425  _enable_(VAL|VAL_FOLDED);
426  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:60

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

430  {
431  _enable_(KEY_UNFILT);
432  }
@ KEY_UNFILT
the key scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:49

References c4::yml::KEY_UNFILT.

◆ mark_val_scalar_unfiltered()

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

Definition at line 433 of file event_handler_tree.hpp.

434  {
435  _enable_(VAL_UNFILT);
436  }
@ VAL_UNFILT
the val scalar was left unfiltered; the parser was set not to filter.
Definition: node_type.hpp:50

References c4::yml::VAL_UNFILT.

◆ set_key_anchor()

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

Definition at line 445 of file event_handler_tree.hpp.

446  {
447  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
448  if(C4_UNLIKELY(_has_any_(KEYREF)))
449  _RYML_CB_ERR_(m_tree->callbacks(), "key cannot have both anchor and ref", m_curr->pos);
450  _RYML_CB_ASSERT(m_tree->callbacks(), !anchor.begins_with('&'));
451  _enable_(KEYANCH);
452  m_curr->tr_data->m_key.anchor = anchor;
453  }
@ 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:104

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

455  {
456  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
457  if(C4_UNLIKELY(_has_any_(VALREF)))
458  _RYML_CB_ERR_(m_tree->callbacks(), "val cannot have both anchor and ref", m_curr->pos);
459  _RYML_CB_ASSERT(m_tree->callbacks(), !anchor.begins_with('&'));
460  _enable_(VALANCH);
461  m_curr->tr_data->m_val.anchor = anchor;
462  }
@ 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 464 of file event_handler_tree.hpp.

465  {
466  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
467  if(C4_UNLIKELY(_has_any_(KEYANCH)))
468  _RYML_CB_ERR_(m_tree->callbacks(), "key cannot have both anchor and ref", m_curr->pos);
469  _RYML_CB_ASSERT(m_tree->callbacks(), ref.begins_with('*'));
470  _enable_(KEY|KEYREF);
471  m_curr->tr_data->m_key.anchor = ref.sub(1);
472  m_curr->tr_data->m_key.scalar = ref;
473  }

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

475  {
476  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
477  if(C4_UNLIKELY(_has_any_(VALANCH)))
478  _RYML_CB_ERR_(m_tree->callbacks(), "val cannot have both anchor and ref", m_curr->pos);
479  _RYML_CB_ASSERT(m_tree->callbacks(), ref.begins_with('*'));
480  _enable_(VAL|VALREF);
481  m_curr->tr_data->m_val.anchor = ref.sub(1);
482  m_curr->tr_data->m_val.scalar = ref;
483  }

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

493  {
494  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
495  _enable_(KEYTAG);
496  m_curr->tr_data->m_key.tag = tag;
497  }
@ 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 498 of file event_handler_tree.hpp.

499  {
500  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
501  _enable_(VALTAG);
502  m_curr->tr_data->m_val.tag = tag;
503  }
@ 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 512 of file event_handler_tree.hpp.

513  {
514  _c4dbgpf("% directive! {}", directive);
515  _RYML_CB_ASSERT(m_tree->callbacks(), directive.begins_with('%'));
516  if(directive.begins_with("%TAG"))
517  {
518  if(C4_UNLIKELY(!m_tree->add_tag_directive(directive)))
519  _RYML_CB_ERR_(m_stack.m_callbacks, "failed to add directive", m_curr->pos);
520  }
521  else if(directive.begins_with("%YAML"))
522  {
523  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
524  if(C4_UNLIKELY(m_yaml_directive))
525  _RYML_CB_ERR_(m_stack.m_callbacks, "multiple yaml directives", m_curr->pos);
526  m_yaml_directive = true;
527  }
528  else
529  {
530  _c4dbgpf("unknown directive! ignoring... {}", directive);
531  }
532  ++m_num_directives;
533  }

◆ alloc_arena() [1/2]

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

Definition at line 542 of file event_handler_tree.hpp.

543  {
544  csubstr prev = m_tree->arena();
545  substr out = m_tree->alloc_arena(len);
546  substr curr = m_tree->arena();
547  if(curr.str != prev.str)
548  _stack_relocate_to_new_arena(prev, curr);
549  return out;
550  }

◆ alloc_arena() [2/2]

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

Definition at line 552 of file event_handler_tree.hpp.

553  {
554  csubstr prev = m_tree->arena();
555  if(!prev.is_super(*relocated))
556  return alloc_arena(len);
557  substr out = alloc_arena(len);
558  substr curr = m_tree->arena();
559  if(curr.str != prev.str)
560  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
561  return out;
562  }

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

59  {
60  _RYML_CB_ASSERT(m_stack.m_callbacks, m_curr != nullptr);
61  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena != nullptr);
62  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena_data != nullptr);
63  m_curr->start_parse(filename, m_curr->node_id);
64  m_relocate_arena = relocate_arena;
65  m_relocate_arena_data = relocate_arena_data;
66  }
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 68 of file event_handler_stack.hpp.

69  {
70  }

◆ _stack_reset_root()

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

Definition at line 74 of file event_handler_stack.hpp.

75  {
76  m_stack.clear();
77  m_stack.push({});
78  m_parent = nullptr;
79  m_curr = &m_stack.top();
80  }

◆ _stack_reset_non_root()

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

Definition at line 82 of file event_handler_stack.hpp.

83  {
84  m_stack.clear();
85  m_stack.push({}); // parent
86  m_stack.push({}); // node
87  m_parent = &m_stack.top(1);
88  m_curr = &m_stack.top();
89  }

◆ _stack_push()

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

Definition at line 91 of file event_handler_stack.hpp.

92  {
93  m_stack.push_top();
94  m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push
95  m_curr = &m_stack.top();
97  }

◆ _stack_pop()

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

Definition at line 99 of file event_handler_stack.hpp.

100  {
101  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
102  _RYML_CB_ASSERT(m_stack.m_callbacks, m_stack.size() > 1);
104  m_stack.pop();
105  m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr;
106  m_curr = &m_stack.top();
107  #ifdef RYML_DBG
108  if(m_parent)
109  _c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
110  else
111  _c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id);
112  #endif
113  }
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 120 of file event_handler_stack.hpp.

121  {
122  const bool is_root = (m_stack.size() == 1u);
123  return is_root && (_has_any_(DOC|VAL|MAP|SEQ) || m_curr->has_children);
124  }

◆ _stack_should_pop_on_end_doc()

bool c4::yml::EventHandlerStack< EventHandlerTree , EventHandlerTreeState >::_stack_should_pop_on_end_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);
130  }

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

135  {
136  for(state &st : m_stack)
137  {
138  if(st.line_contents.rem.is_sub(prev))
139  st.line_contents.rem = _stack_relocate_to_new_arena(st.line_contents.rem, prev, curr);
140  if(st.line_contents.full.is_sub(prev))
141  st.line_contents.full = _stack_relocate_to_new_arena(st.line_contents.full, prev, curr);
142  if(st.line_contents.stripped.is_sub(prev))
143  st.line_contents.stripped = _stack_relocate_to_new_arena(st.line_contents.stripped, prev, curr);
144  }
145  _RYML_CB_ASSERT(m_stack.m_callbacks, m_relocate_arena != nullptr);
146  _RYML_CB_ASSERT(m_stack.m_callbacks, m_relocate_arena_data != nullptr);
148  }

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

151  {
152  _RYML_CB_ASSERT(m_stack.m_callbacks, prev.is_super(s));
153  auto pos = s.str - prev.str;
154  substr out = {curr.str + pos, s.len};
155  _RYML_CB_ASSERT(m_stack.m_callbacks, curr.is_super(out));
156  return out;
157  }

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

166  {
167  const bool is_root = (m_stack.size() == 1u);
168  const bool isndoc = (m_curr->flags & NDOC) != 0;
169  const bool suspicious = _has_any_(MAP|SEQ|VAL);
170  _c4dbgpf("target={} isroot={} suspicious={} ndoc={}", m_curr->node_id, is_root, suspicious, isndoc);
171  if((is_root || _has_any_(DOC)) && suspicious && !isndoc)
172  _RYML_CB_ERR_(m_stack.m_callbacks, "parse error", m_curr->pos);
173  }
@ NDOC
no document mode. a document has ended and another has not started yet.

Member Data Documentation

◆ m_stack

Definition at line 45 of file event_handler_stack.hpp.

◆ m_curr

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

Definition at line 46 of file event_handler_stack.hpp.

◆ m_parent

parent of the current stack level.

Definition at line 47 of file event_handler_stack.hpp.

◆ m_relocate_arena

callback when the arena gets relocated

Definition at line 48 of file event_handler_stack.hpp.

◆ m_relocate_arena_data

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

Definition at line 49 of file event_handler_stack.hpp.


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