rapidyaml  0.9.0
parse and emit YAML, and do it fast
c4::yml::EventHandlerYamlStd Struct Reference

The event handler producing standard YAML events as used in the YAML test suite. More...

#include <test_suite_event_handler.hpp>

Inheritance diagram for c4::yml::EventHandlerYamlStd:
c4::yml::EventHandlerStack< EventHandlerYamlStd, EventHandlerYamlStdState >

Public Types

using pfn_relocate_arena = detail::pfn_relocate_arena
 
types
using state = EventHandlerYamlStdState
 
using EventSink = extra::string
 

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
 EventHandlerYamlStd ()
 
 EventHandlerYamlStd (Callbacks const &cb)
 
 EventHandlerYamlStd (EventSink *sink, Callbacks const &cb)
 
 EventHandlerYamlStd (EventSink *sink)
 
void reset ()
 
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 ()
 
void end_stream ()
 
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 functions
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)
 
void set_val_scalar_plain (csubstr scalar)
 
void set_key_scalar_dquoted (csubstr scalar)
 
void set_val_scalar_dquoted (csubstr scalar)
 
void set_key_scalar_squoted (csubstr scalar)
 
void set_val_scalar_squoted (csubstr scalar)
 
void set_key_scalar_literal (csubstr scalar)
 
void set_val_scalar_literal (csubstr scalar)
 
void set_key_scalar_folded (csubstr scalar)
 
void set_val_scalar_folded (csubstr scalar)
 
void mark_key_scalar_unfiltered ()
 
void mark_val_scalar_unfiltered ()
 
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)
 
void set_val_tag (csubstr tag)
 
YAML directive events
void add_directive (csubstr directive)
 
YAML arena events
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 producing standard YAML events as used in the YAML test suite.

See the documentation for Event Handlers, which has important notes about the event model used by rapidyaml.

This class is used only in the CI of this project, and in the application used as part of the standard YAML playground. It is not part of the library and is not installed. *

Definition at line 49 of file test_suite_event_handler.hpp.

Member Typedef Documentation

◆ state

◆ EventSink

Definition at line 58 of file test_suite_event_handler.hpp.

◆ pfn_relocate_arena

Constructor & Destructor Documentation

◆ EventHandlerYamlStd() [1/4]

c4::yml::EventHandlerYamlStd::EventHandlerYamlStd ( )
inline

Definition at line 85 of file test_suite_event_handler.hpp.

85 : EventHandlerStack(), m_sink(), m_val_buffers(), m_key_tag_buf(), m_val_tag_buf(), m_tag_directives(), m_has_yaml_directive(), m_arena(), m_has_docs() {}

◆ EventHandlerYamlStd() [2/4]

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

Definition at line 86 of file test_suite_event_handler.hpp.

86 : EventHandlerStack(cb), m_sink(), m_val_buffers(), m_key_tag_buf(), m_val_tag_buf(), m_tag_directives(), m_has_yaml_directive(), m_arena(), m_has_docs() {}

◆ EventHandlerYamlStd() [3/4]

c4::yml::EventHandlerYamlStd::EventHandlerYamlStd ( EventSink sink,
Callbacks const &  cb 
)
inline

Definition at line 87 of file test_suite_event_handler.hpp.

87  : EventHandlerStack(cb), m_sink(sink), m_val_buffers(), m_key_tag_buf(), m_val_tag_buf(), m_tag_directives(), m_has_yaml_directive(), m_arena(), m_has_docs()
88  {
89  reset();
90  }

◆ EventHandlerYamlStd() [4/4]

c4::yml::EventHandlerYamlStd::EventHandlerYamlStd ( EventSink sink)
inline

Definition at line 91 of file test_suite_event_handler.hpp.

Callbacks const & get_callbacks()
get the global callbacks
Definition: common.cpp:118

Member Function Documentation

◆ reset()

void c4::yml::EventHandlerYamlStd::reset ( )
inline

Definition at line 93 of file test_suite_event_handler.hpp.

94  {
96  m_curr->flags |= RUNK|RTOP;
97  m_has_yaml_directive = false;
98  for(TagDirective &td : m_tag_directives)
99  td = {};
100  m_val_buffers.clear();
101  m_val_buffers.resize((size_t)m_stack.size());
102  m_arena.clear();
103  m_arena.reserve(1024);
104  m_key_tag_buf.resize(256);
105  m_val_tag_buf.resize(256);
106  m_has_docs = false;
107  }
@ RTOP
reading at top level
@ RUNK
reading unknown state (when starting): must determine whether scalar, map or seq
state * m_curr
current stack level: top of the stack. cached here for easier access.

References c4::yml::RTOP, and c4::yml::RUNK.

◆ start_parse()

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

Definition at line 116 of file test_suite_event_handler.hpp.

117  {
118  this->_stack_start_parse(filename, relocate_arena, relocate_arena_data);
119  }
void _stack_start_parse(const char *filename, pfn_relocate_arena relocate_arena, void *relocate_arena_data)

◆ finish_parse()

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

Definition at line 121 of file test_suite_event_handler.hpp.

122  {
123  if((_num_tag_directives() || m_has_yaml_directive) && !m_has_docs)
124  _RYML_CB_ERR_(m_stack.m_callbacks, "directives cannot be used without a document", {});
125  this->_stack_finish_parse();
126  }

◆ cancel_parse()

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

Definition at line 128 of file test_suite_event_handler.hpp.

129  {
130  while(m_stack.size() > 1)
131  _pop();
132  _buf_flush_();
133  }

◆ begin_stream()

void c4::yml::EventHandlerYamlStd::begin_stream ( )
inline

Definition at line 142 of file test_suite_event_handler.hpp.

143  {
144  _send_("+STR\n");
145  }

◆ end_stream()

void c4::yml::EventHandlerYamlStd::end_stream ( )
inline

Definition at line 147 of file test_suite_event_handler.hpp.

148  {
149  _send_("-STR\n");
150  _buf_flush_();
151  }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 161 of file test_suite_event_handler.hpp.

162  {
163  _c4dbgp("begin_doc");
165  {
166  _c4dbgp("push!");
167  _push();
168  _enable_(DOC);
169  }
170  _send_("+DOC\n");
171  m_has_docs = true;
172  }
@ DOC
a document
Definition: node_type.hpp:37

References c4::yml::DOC.

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 174 of file test_suite_event_handler.hpp.

175  {
176  _c4dbgp("end_doc");
177  _send_("-DOC\n");
179  {
180  _c4dbgp("pop!");
181  _pop();
182  }
183  }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 186 of file test_suite_event_handler.hpp.

187  {
188  _c4dbgp("begin_doc_expl");
190  {
191  _c4dbgp("push!");
192  _push();
193  }
194  _send_("+DOC ---\n");
195  _enable_(DOC);
196  m_has_docs = true;
197  }

References c4::yml::DOC.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 199 of file test_suite_event_handler.hpp.

200  {
201  _c4dbgp("end_doc_expl");
202  _send_("-DOC ...\n");
204  {
205  _c4dbgp("pop!");
206  _pop();
207  }
208  m_has_yaml_directive = false;
209  }

◆ begin_map_key_flow()

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

Definition at line 218 of file test_suite_event_handler.hpp.

219  {
220  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
221  _send_("+MAP {}");
222  _send_key_props_();
223  _send_('\n');
224  _mark_parent_with_children_();
225  _enable_(MAP|FLOW_SL);
226  _push();
227  }
#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_key_block()

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

Definition at line 228 of file test_suite_event_handler.hpp.

229  {
230  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
231  _send_("+MAP");
232  _send_key_props_();
233  _send_('\n');
234  _mark_parent_with_children_();
235  _enable_(MAP|BLOCK);
236  _push();
237  }
@ 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.

◆ begin_map_val_flow()

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

Definition at line 239 of file test_suite_event_handler.hpp.

240  {
241  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
242  _send_("+MAP {}");
243  _send_val_props_();
244  _send_('\n');
245  _mark_parent_with_children_();
246  _enable_(MAP|FLOW_SL);
247  _push();
248  }

References _has_any_, c4::yml::FLOW_SL, c4::yml::MAP, and c4::yml::VAL.

◆ begin_map_val_block()

void c4::yml::EventHandlerYamlStd::begin_map_val_block ( )
inline

Definition at line 249 of file test_suite_event_handler.hpp.

250  {
251  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
252  _send_("+MAP");
253  _send_val_props_();
254  _send_('\n');
255  _mark_parent_with_children_();
256  _enable_(MAP|BLOCK);
257  _push();
258  }

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

◆ end_map()

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

Definition at line 260 of file test_suite_event_handler.hpp.

261  {
262  _pop();
263  _send_("-MAP\n");
264  }

◆ begin_seq_key_flow()

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

Definition at line 273 of file test_suite_event_handler.hpp.

274  {
275  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
276  _send_("+SEQ []");
277  _send_key_props_();
278  _send_('\n');
279  _mark_parent_with_children_();
280  _enable_(SEQ|FLOW_SL);
281  _push();
282  }
@ 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_key_block()

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

Definition at line 283 of file test_suite_event_handler.hpp.

284  {
285  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
286  _send_("+SEQ");
287  _send_key_props_();
288  _send_('\n');
289  _mark_parent_with_children_();
290  _enable_(SEQ|BLOCK);
291  _push();
292  }

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

◆ begin_seq_val_flow()

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

Definition at line 294 of file test_suite_event_handler.hpp.

295  {
296  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
297  _send_("+SEQ []");
298  _send_val_props_();
299  _send_('\n');
300  _mark_parent_with_children_();
301  _enable_(SEQ|FLOW_SL);
302  _push();
303  }

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

◆ begin_seq_val_block()

void c4::yml::EventHandlerYamlStd::begin_seq_val_block ( )
inline

Definition at line 304 of file test_suite_event_handler.hpp.

305  {
306  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
307  _send_("+SEQ");
308  _send_val_props_();
309  _send_('\n');
310  _mark_parent_with_children_();
311  _enable_(SEQ|BLOCK);
312  _push();
313  }

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

◆ end_seq()

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

Definition at line 315 of file test_suite_event_handler.hpp.

316  {
317  _pop();
318  _send_("-SEQ\n"); // before popping
319  }

◆ add_sibling()

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

Definition at line 328 of file test_suite_event_handler.hpp.

329  {
330  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
331  _buf_flush_to_(m_curr->level, m_parent->level);
332  m_curr->ev_data = {};
333  }

◆ actually_val_is_first_key_of_new_map_flow()

void c4::yml::EventHandlerYamlStd::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 340 of file test_suite_event_handler.hpp.

341  {
342  // ensure we have a temporary buffer to save the current val
343  const id_type tmp = m_curr->level + id_type(2);
344  _buf_ensure_(tmp + id_type(2));
345  // save the current val to the temporary buffer
346  _buf_flush_to_(m_curr->level, tmp);
347  _disable_(_VALMASK|VAL_STYLE);
348  // create the map.
349  // this will push a new level, and tmp is one further
351  _RYML_CB_ASSERT(m_stack.m_callbacks, tmp != m_curr->level);
352  // now move the saved val as the first key
353  _buf_flush_to_(tmp, m_curr->level);
354  }
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
Definition: node_type.hpp:89
@ _VALMASK
Definition: node_type.hpp:98
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:253

References c4::yml::_VALMASK, and c4::yml::VAL_STYLE.

◆ actually_val_is_first_key_of_new_map_block()

void c4::yml::EventHandlerYamlStd::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 362 of file test_suite_event_handler.hpp.

363  {
364  EventSink &sink = _buf_();
365  substr full = sink;(void)full;
366  // interpolate +MAP\n after the last +DOC\n
367  _RYML_CB_ASSERT(m_stack.m_callbacks, full.len);
368  _RYML_CB_ASSERT(m_stack.m_callbacks, !full.count('\r'));
369  size_t docpos = sink.find_last("+DOC\n");
370  if(docpos != npos)
371  {
372  _RYML_CB_ASSERT(m_stack.m_callbacks, (m_stack.size() == 1u) ? (docpos >= 5u) : (docpos == 0u));
373  _RYML_CB_ASSERT(m_stack.m_callbacks, docpos + 5u < full.len);
374  sink.insert("+MAP\n", docpos + 5u);
375  }
376  else
377  {
378  // ... or interpolate +MAP\n after the last +DOC ---\n
379  docpos = sink.find_last("+DOC ---\n");
380  _RYML_CB_ASSERT(m_stack.m_callbacks, docpos != npos);
381  _RYML_CB_ASSERT(m_stack.m_callbacks, (m_stack.size() == 1u) ? (docpos >= 5u) : (docpos == 0u));
382  _RYML_CB_ASSERT(m_stack.m_callbacks, docpos + 9u < full.len);
383  sink.insert("+MAP\n", docpos + 9u);
384  }
385  _push();
386  }
@ npos
a null string position
Definition: common.hpp:267

References c4::yml::npos.

◆ set_key_scalar_plain_empty()

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

Definition at line 396 of file test_suite_event_handler.hpp.

397  {
398  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
399  _send_key_scalar_({}, ':');
400  _enable_(KEY|KEY_PLAIN|KEYNIL);
401  }
@ 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
id_type node_id
don't hold a pointer to the node as it will be relocated during tree resizes

References c4::yml::KEY, c4::yml::KEY_PLAIN, and c4::yml::KEYNIL.

◆ set_val_scalar_plain_empty()

void c4::yml::EventHandlerYamlStd::set_val_scalar_plain_empty ( )
inlinenoexcept

Definition at line 402 of file test_suite_event_handler.hpp.

403  {
404  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
405  _send_val_scalar_({}, ':');
406  _enable_(VAL|VAL_PLAIN|VALNIL);
407  }
@ 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::EventHandlerYamlStd::set_key_scalar_plain ( csubstr  scalar)
inline

Definition at line 409 of file test_suite_event_handler.hpp.

410  {
411  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
412  _send_key_scalar_(scalar, ':');
413  _enable_(KEY|KEY_PLAIN);
414  }

References c4::yml::KEY, and c4::yml::KEY_PLAIN.

◆ set_val_scalar_plain()

void c4::yml::EventHandlerYamlStd::set_val_scalar_plain ( csubstr  scalar)
inline

Definition at line 415 of file test_suite_event_handler.hpp.

416  {
417  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
418  _send_val_scalar_(scalar, ':');
419  _enable_(VAL|VAL_PLAIN);
420  }

References c4::yml::VAL, and c4::yml::VAL_PLAIN.

◆ set_key_scalar_dquoted()

void c4::yml::EventHandlerYamlStd::set_key_scalar_dquoted ( csubstr  scalar)
inline

Definition at line 423 of file test_suite_event_handler.hpp.

424  {
425  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
426  _send_key_scalar_(scalar, '"');
427  _enable_(KEY|KEY_DQUO);
428  }
@ 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::EventHandlerYamlStd::set_val_scalar_dquoted ( csubstr  scalar)
inline

Definition at line 429 of file test_suite_event_handler.hpp.

430  {
431  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
432  _send_val_scalar_(scalar, '"');
433  _enable_(VAL|VAL_DQUO);
434  }
@ 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::EventHandlerYamlStd::set_key_scalar_squoted ( csubstr  scalar)
inline

Definition at line 437 of file test_suite_event_handler.hpp.

438  {
439  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
440  _send_key_scalar_(scalar, '\'');
441  _enable_(KEY|KEY_SQUO);
442  }
@ 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::EventHandlerYamlStd::set_val_scalar_squoted ( csubstr  scalar)
inline

Definition at line 443 of file test_suite_event_handler.hpp.

444  {
445  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
446  _send_val_scalar_(scalar, '\'');
447  _enable_(VAL|VAL_SQUO);
448  }
@ 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::EventHandlerYamlStd::set_key_scalar_literal ( csubstr  scalar)
inline

Definition at line 451 of file test_suite_event_handler.hpp.

452  {
453  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
454  _send_key_scalar_(scalar, '|');
455  _enable_(KEY|KEY_LITERAL);
456  }
@ 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::EventHandlerYamlStd::set_val_scalar_literal ( csubstr  scalar)
inline

Definition at line 457 of file test_suite_event_handler.hpp.

458  {
459  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
460  _send_val_scalar_(scalar, '|');
461  _enable_(VAL|VAL_LITERAL);
462  }
@ 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::EventHandlerYamlStd::set_key_scalar_folded ( csubstr  scalar)
inline

Definition at line 465 of file test_suite_event_handler.hpp.

466  {
467  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
468  _send_key_scalar_(scalar, '>');
469  _enable_(KEY|KEY_FOLDED);
470  }
@ 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::EventHandlerYamlStd::set_val_scalar_folded ( csubstr  scalar)
inline

Definition at line 471 of file test_suite_event_handler.hpp.

472  {
473  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
474  _send_val_scalar_(scalar, '>');
475  _enable_(VAL|VAL_FOLDED);
476  }
@ 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::EventHandlerYamlStd::mark_key_scalar_unfiltered ( )
inline

Definition at line 479 of file test_suite_event_handler.hpp.

480  {
481  C4_NOT_IMPLEMENTED();
482  }

◆ mark_val_scalar_unfiltered()

void c4::yml::EventHandlerYamlStd::mark_val_scalar_unfiltered ( )
inline

Definition at line 483 of file test_suite_event_handler.hpp.

484  {
485  C4_NOT_IMPLEMENTED();
486  }

◆ set_key_anchor()

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

Definition at line 495 of file test_suite_event_handler.hpp.

496  {
497  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
498  if(C4_UNLIKELY(_has_any_(KEYANCH)))
499  _RYML_CB_ERR_(m_stack.m_callbacks, "key cannot have both anchor and ref", m_curr->pos);
500  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
501  _enable_(KEYANCH);
502  m_curr->ev_data.m_key.anchor = anchor;
503  }
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:41
NodeScalar m_key
Definition: tree.hpp:184
csubstr anchor
Definition: tree.hpp:67

References _has_any_, and c4::yml::KEYANCH.

◆ set_val_anchor()

void c4::yml::EventHandlerYamlStd::set_val_anchor ( csubstr  anchor)
inline

Definition at line 504 of file test_suite_event_handler.hpp.

505  {
506  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
507  if(C4_UNLIKELY(_has_any_(VALREF)))
508  _RYML_CB_ERR_(m_stack.m_callbacks, "val cannot have both anchor and ref", m_curr->pos);
509  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
510  _enable_(VALANCH);
511  m_curr->ev_data.m_val.anchor = anchor;
512  }
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:42
@ VALREF
a *reference: the val references an &anchor
Definition: node_type.hpp:40
NodeScalar m_val
Definition: tree.hpp:185

References _has_any_, c4::yml::VALANCH, and c4::yml::VALREF.

◆ set_key_ref()

void c4::yml::EventHandlerYamlStd::set_key_ref ( csubstr  ref)
inline

Definition at line 514 of file test_suite_event_handler.hpp.

515  {
516  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
517  if(C4_UNLIKELY(_has_any_(KEYANCH)))
518  _RYML_CB_ERR_(m_stack.m_callbacks, "key cannot have both anchor and ref", m_curr->pos);
519  _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*'));
520  _enable_(KEY|KEYREF);
521  _send_("=ALI ");
522  _send_(ref);
523  _send_('\n');
524  }
@ KEYREF
a *reference: the key references an &anchor
Definition: node_type.hpp:39

References _has_any_, c4::yml::KEY, c4::yml::KEYANCH, and c4::yml::KEYREF.

◆ set_val_ref()

void c4::yml::EventHandlerYamlStd::set_val_ref ( csubstr  ref)
inline

Definition at line 525 of file test_suite_event_handler.hpp.

526  {
527  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
528  if(C4_UNLIKELY(_has_any_(VALANCH)))
529  _RYML_CB_ERR_(m_stack.m_callbacks, "val cannot have both anchor and ref", m_curr->pos);
530  _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*'));
531  _enable_(VAL|VALREF);
532  _send_("=ALI ");
533  _send_(ref);
534  _send_('\n');
535  }

References _has_any_, c4::yml::VAL, c4::yml::VALANCH, and c4::yml::VALREF.

◆ set_key_tag()

void c4::yml::EventHandlerYamlStd::set_key_tag ( csubstr  tag)
inline

Definition at line 544 of file test_suite_event_handler.hpp.

545  {
546  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
547  _enable_(KEYTAG);
548  m_curr->ev_data.m_key.tag = _transform_directive(tag, &m_key_tag_buf);
549  }
@ KEYTAG
the key has a tag
Definition: node_type.hpp:43

References c4::yml::KEYTAG.

◆ set_val_tag()

void c4::yml::EventHandlerYamlStd::set_val_tag ( csubstr  tag)
inline

Definition at line 550 of file test_suite_event_handler.hpp.

551  {
552  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
553  _enable_(VALTAG);
554  m_curr->ev_data.m_val.tag = _transform_directive(tag, &m_val_tag_buf);
555  }
@ VALTAG
the val has a tag
Definition: node_type.hpp:44

References c4::yml::VALTAG.

◆ add_directive()

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

Definition at line 564 of file test_suite_event_handler.hpp.

565  {
566  _RYML_CB_ASSERT(m_stack.m_callbacks, directive.begins_with('%'));
567  if(directive.begins_with("%TAG"))
568  {
569  const id_type pos = _num_tag_directives();
570  if(C4_UNLIKELY(pos >= RYML_MAX_TAG_DIRECTIVES))
571  _RYML_CB_ERR_(m_stack.m_callbacks, "too many directives", m_curr->pos);
572  if(C4_UNLIKELY(!m_tag_directives[pos].create_from_str(directive)))
573  _RYML_CB_ERR_(m_stack.m_callbacks, "failed to add directive", m_curr->pos);
574  }
575  else if(directive.begins_with("%YAML"))
576  {
577  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
578  if(C4_UNLIKELY(m_has_yaml_directive))
579  _RYML_CB_ERR_(m_stack.m_callbacks, "multiple yaml directives", m_curr->pos);
580  m_has_yaml_directive = true;
581  }
582  else
583  {
584  _c4dbgpf("unknown directive! ignoring... {}", directive);
585  }
586  }
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition: tag.hpp:19

References RYML_MAX_TAG_DIRECTIVES.

◆ alloc_arena() [1/2]

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

Definition at line 595 of file test_suite_event_handler.hpp.

596  {
597  const size_t sz = m_arena.size();
598  csubstr prev = m_arena;
599  m_arena.resize(sz + len);
600  substr out = to_substr(m_arena).sub(sz);
601  substr curr = to_substr(m_arena);
602  if(curr.str != prev.str)
603  _stack_relocate_to_new_arena(prev, curr);
604  return out;
605  }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2184

References c4::to_substr().

◆ alloc_arena() [2/2]

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

Definition at line 607 of file test_suite_event_handler.hpp.

608  {
609  csubstr prev = m_arena;
610  if(!prev.is_super(*relocated))
611  return alloc_arena(len);
612  substr out = alloc_arena(len);
613  substr curr = to_substr(m_arena);
614  if(curr.str != prev.str)
615  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
616  return out;
617  }

References c4::to_substr().

◆ _stack_start_parse()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_finish_parse ( )
inlineprotectedinherited

Definition at line 74 of file event_handler_stack.hpp.

75  {
76  }

◆ _stack_reset_root()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::_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< EventHandlerYamlStd , EventHandlerYamlStdState >::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< EventHandlerYamlStd , EventHandlerYamlStdState >::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: