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

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

◆ cancel_parse()

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

Definition at line 132 of file event_handler_tree.hpp.

133  {
134  m_tree = nullptr;
135  }

◆ begin_stream()

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

Definition at line 144 of file event_handler_tree.hpp.

144 { /*nothing to do*/ }

◆ end_stream()

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

Definition at line 146 of file event_handler_tree.hpp.

146 { /*nothing to do*/ }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 156 of file event_handler_tree.hpp.

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

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

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 180 of file event_handler_tree.hpp.

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

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

◆ begin_map_key_flow()

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

Definition at line 232 of file event_handler_tree.hpp.

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

◆ begin_map_key_block()

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

Definition at line 236 of file event_handler_tree.hpp.

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

◆ begin_map_val_flow()

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

Definition at line 241 of file event_handler_tree.hpp.

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

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

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

◆ begin_seq_key_flow()

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

Definition at line 271 of file event_handler_tree.hpp.

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

◆ begin_seq_key_block()

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

Definition at line 275 of file event_handler_tree.hpp.

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

◆ begin_seq_val_flow()

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

Definition at line 280 of file event_handler_tree.hpp.

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

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

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

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

◆ add_sibling()

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

Definition at line 310 of file event_handler_tree.hpp.

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

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

328  {
329  if(C4_UNLIKELY(m_tree->is_container(m_curr->node_id)))
330  _RYML_CB_ERR_(m_stack.m_callbacks, "ryml trees cannot handle containers as keys", m_curr->pos);
331  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
332  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree->is_seq(m_parent->node_id));
333  _RYML_CB_ASSERT(m_stack.m_callbacks, !m_tree->is_container(m_curr->node_id));
334  _RYML_CB_ASSERT(m_stack.m_callbacks, !m_tree->has_key(m_curr->node_id));
335  const NodeData tmp = _val2key_(*m_curr->tr_data);
336  _disable_(_VALMASK|VAL_STYLE);
337  m_curr->tr_data->m_val = {};
339  m_curr->tr_data->m_type = tmp.m_type;
340  m_curr->tr_data->m_key = tmp.m_key;
341  }
@ 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:223
NodeScalar m_key
Definition: tree.hpp:225
NodeScalar m_val
Definition: tree.hpp:226

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

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

◆ set_key_scalar_plain()

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

Definition at line 362 of file event_handler_tree.hpp.

363  {
364  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
365  m_curr->tr_data->m_key.scalar = scalar;
366  _enable_(KEY|KEY_PLAIN);
367  }
@ 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:107

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

369  {
370  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
371  m_curr->tr_data->m_val.scalar = scalar;
372  _enable_(VAL|VAL_PLAIN);
373  }
@ 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 376 of file event_handler_tree.hpp.

377  {
378  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
379  m_curr->tr_data->m_key.scalar = scalar;
380  _enable_(KEY|KEY_DQUO);
381  }
@ 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 382 of file event_handler_tree.hpp.

383  {
384  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
385  m_curr->tr_data->m_val.scalar = scalar;
386  _enable_(VAL|VAL_DQUO);
387  }
@ 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 390 of file event_handler_tree.hpp.

391  {
392  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
393  m_curr->tr_data->m_key.scalar = scalar;
394  _enable_(KEY|KEY_SQUO);
395  }
@ 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 396 of file event_handler_tree.hpp.

397  {
398  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
399  m_curr->tr_data->m_val.scalar = scalar;
400  _enable_(VAL|VAL_SQUO);
401  }
@ 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 404 of file event_handler_tree.hpp.

405  {
406  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
407  m_curr->tr_data->m_key.scalar = scalar;
408  _enable_(KEY|KEY_LITERAL);
409  }
@ 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 410 of file event_handler_tree.hpp.

411  {
412  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
413  m_curr->tr_data->m_val.scalar = scalar;
414  _enable_(VAL|VAL_LITERAL);
415  }
@ 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 418 of file event_handler_tree.hpp.

419  {
420  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
421  m_curr->tr_data->m_key.scalar = scalar;
422  _enable_(KEY|KEY_FOLDED);
423  }
@ 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 424 of file event_handler_tree.hpp.

425  {
426  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
427  m_curr->tr_data->m_val.scalar = scalar;
428  _enable_(VAL|VAL_FOLDED);
429  }
@ 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 432 of file event_handler_tree.hpp.

433  {
434  _enable_(KEY_UNFILT);
435  }
@ 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 436 of file event_handler_tree.hpp.

437  {
438  _enable_(VAL_UNFILT);
439  }
@ 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 448 of file event_handler_tree.hpp.

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

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

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

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

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

481  {
482  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
483  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
484  if(C4_UNLIKELY(_has_any_(VALANCH)))
485  _RYML_CB_ERR_(m_tree->callbacks(), "val cannot have both anchor and ref", m_curr->pos);
486  _RYML_CB_ASSERT(m_tree->callbacks(), ref.begins_with('*'));
487  _enable_(VAL|VALREF);
488  m_curr->tr_data->m_val.anchor = ref.sub(1);
489  m_curr->tr_data->m_val.scalar = ref;
490  }

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

500  {
501  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
502  _enable_(KEYTAG);
503  m_curr->tr_data->m_key.tag = tag;
504  }
@ 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 505 of file event_handler_tree.hpp.

506  {
507  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
508  _enable_(VALTAG);
509  m_curr->tr_data->m_val.tag = tag;
510  }
@ 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 519 of file event_handler_tree.hpp.

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

◆ alloc_arena() [1/2]

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

Definition at line 549 of file event_handler_tree.hpp.

550  {
551  _RYML_CB_ASSERT(m_stack.m_callbacks, m_tree);
552  csubstr prev = m_tree->arena();
553  substr out = m_tree->alloc_arena(len);
554  substr curr = m_tree->arena();
555  if(curr.str != prev.str)
556  _stack_relocate_to_new_arena(prev, curr);
557  return out;
558  }

◆ alloc_arena() [2/2]

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

Definition at line 560 of file event_handler_tree.hpp.

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

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