rapidyaml  0.10.0
parse and emit YAML, and do it fast
c4::yml::extra::EventHandlerTestSuite Struct Reference

This event produces standard YAML events as used in the YAML test suite. More...

#include <event_handler_testsuite.hpp>

Inheritance diagram for c4::yml::extra::EventHandlerTestSuite:
c4::yml::EventHandlerStack< EventHandlerTestSuite, EventHandlerTestSuiteState >

Public Types

using pfn_relocate_arena = detail::pfn_relocate_arena
 
types
using state = EventHandlerTestSuiteState
 
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
 EventHandlerTestSuite ()
 
 EventHandlerTestSuite (Callbacks const &cb)
 
 EventHandlerTestSuite (EventSink *sink, Callbacks const &cb)
 
 EventHandlerTestSuite (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

This event produces 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 45 of file event_handler_testsuite.hpp.

Member Typedef Documentation

◆ state

using c4::yml::extra::EventHandlerTestSuite::state = EventHandlerTestSuiteState

Definition at line 52 of file event_handler_testsuite.hpp.

◆ EventSink

◆ pfn_relocate_arena

Definition at line 47 of file event_handler_stack.hpp.

Constructor & Destructor Documentation

◆ EventHandlerTestSuite() [1/4]

c4::yml::extra::EventHandlerTestSuite::EventHandlerTestSuite ( )
inline

Definition at line 81 of file event_handler_testsuite.hpp.

81 : 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() {}

◆ EventHandlerTestSuite() [2/4]

c4::yml::extra::EventHandlerTestSuite::EventHandlerTestSuite ( Callbacks const &  cb)
inline

Definition at line 82 of file event_handler_testsuite.hpp.

82 : 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() {}

◆ EventHandlerTestSuite() [3/4]

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

Definition at line 83 of file event_handler_testsuite.hpp.

83  : 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()
84  {
85  reset();
86  }

◆ EventHandlerTestSuite() [4/4]

c4::yml::extra::EventHandlerTestSuite::EventHandlerTestSuite ( EventSink sink)
inline

Definition at line 87 of file event_handler_testsuite.hpp.

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

Member Function Documentation

◆ reset()

void c4::yml::extra::EventHandlerTestSuite::reset ( )
inline

Definition at line 89 of file event_handler_testsuite.hpp.

90  {
92  m_curr->flags |= RUNK|RTOP;
93  m_has_yaml_directive = false;
94  for(TagDirective &td : m_tag_directives)
95  td = {};
96  m_val_buffers.clear();
97  m_val_buffers.resize((size_t)m_stack.size());
98  m_arena.clear();
99  m_arena.reserve(1024);
100  m_key_tag_buf.resize(256);
101  m_val_tag_buf.resize(256);
102  m_has_docs = false;
103  }
@ 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::extra::string::clear(), c4::yml::extra::string_vector::clear(), c4::yml::extra::string::reserve(), c4::yml::extra::string::resize(), c4::yml::extra::string_vector::resize(), c4::yml::RTOP, and c4::yml::RUNK.

◆ start_parse()

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

Definition at line 112 of file event_handler_testsuite.hpp.

113  {
114  this->_stack_start_parse(filename, relocate_arena, relocate_arena_data);
115  }
void _stack_start_parse(const char *filename, pfn_relocate_arena relocate_arena, void *relocate_arena_data)

◆ finish_parse()

void c4::yml::extra::EventHandlerTestSuite::finish_parse ( )
inline

Definition at line 117 of file event_handler_testsuite.hpp.

118  {
119  if((_num_tag_directives() || m_has_yaml_directive) && !m_has_docs)
120  _RYML_CB_ERR_(m_stack.m_callbacks, "directives cannot be used without a document", {});
121  this->_stack_finish_parse();
122  }

◆ cancel_parse()

void c4::yml::extra::EventHandlerTestSuite::cancel_parse ( )
inline

Definition at line 124 of file event_handler_testsuite.hpp.

125  {
126  while(m_stack.size() > 1)
127  _pop();
128  _buf_flush_();
129  }

◆ begin_stream()

void c4::yml::extra::EventHandlerTestSuite::begin_stream ( )
inline

Definition at line 138 of file event_handler_testsuite.hpp.

139  {
140  _send_("+STR\n");
141  }

◆ end_stream()

void c4::yml::extra::EventHandlerTestSuite::end_stream ( )
inline

Definition at line 143 of file event_handler_testsuite.hpp.

144  {
145  _send_("-STR\n");
146  _buf_flush_();
147  }

◆ begin_doc()

void c4::yml::extra::EventHandlerTestSuite::begin_doc ( )
inline

implicit doc start (without —)

Definition at line 157 of file event_handler_testsuite.hpp.

158  {
159  _c4dbgp("begin_doc");
161  {
162  _c4dbgp("push!");
163  _push();
164  _enable_(DOC);
165  }
166  _send_("+DOC\n");
167  m_has_docs = true;
168  }
@ DOC
a document
Definition: node_type.hpp:40

References c4::yml::DOC.

◆ end_doc()

void c4::yml::extra::EventHandlerTestSuite::end_doc ( )
inline

implicit doc end (without ...)

Definition at line 170 of file event_handler_testsuite.hpp.

171  {
172  _c4dbgp("end_doc");
173  _send_("-DOC\n");
175  {
176  _c4dbgp("pop!");
177  _pop();
178  }
179  }

◆ begin_doc_expl()

void c4::yml::extra::EventHandlerTestSuite::begin_doc_expl ( )
inline

explicit doc start, with —

Definition at line 182 of file event_handler_testsuite.hpp.

183  {
184  _c4dbgp("begin_doc_expl");
186  {
187  _c4dbgp("push!");
188  _push();
189  }
190  _send_("+DOC ---\n");
191  _enable_(DOC);
192  m_has_docs = true;
193  }

References c4::yml::DOC.

◆ end_doc_expl()

void c4::yml::extra::EventHandlerTestSuite::end_doc_expl ( )
inline

explicit doc end, with ...

Definition at line 195 of file event_handler_testsuite.hpp.

196  {
197  _c4dbgp("end_doc_expl");
198  _send_("-DOC ...\n");
200  {
201  _c4dbgp("pop!");
202  _pop();
203  }
204  m_has_yaml_directive = false;
205  }

◆ begin_map_key_flow()

void c4::yml::extra::EventHandlerTestSuite::begin_map_key_flow ( )
inline

Definition at line 214 of file event_handler_testsuite.hpp.

215  {
216  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
217  _send_("+MAP {}");
218  _send_key_props_();
219  _send_('\n');
220  _mark_parent_with_children_();
221  _enable_(MAP|FLOW_SL);
222  _push();
223  }
#define _has_any_(bits)
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:38
@ FLOW_SL
mark container with single-line flow style (seqs as '[val1,val2], maps as '{key: val,...
Definition: node_type.hpp:59
@ VAL
a scalar: has a scalar (ie string) value, possibly empty. must be a leaf node, and cannot be MAP or S...
Definition: node_type.hpp:37

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

◆ begin_map_key_block()

void c4::yml::extra::EventHandlerTestSuite::begin_map_key_block ( )
inline

Definition at line 224 of file event_handler_testsuite.hpp.

225  {
226  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
227  _send_("+MAP");
228  _send_key_props_();
229  _send_('\n');
230  _mark_parent_with_children_();
231  _enable_(MAP|BLOCK);
232  _push();
233  }
@ BLOCK
mark container with block style (seqs as '- val ', maps as 'key: val')
Definition: node_type.hpp:61

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

◆ begin_map_val_flow()

void c4::yml::extra::EventHandlerTestSuite::begin_map_val_flow ( )
inline

Definition at line 235 of file event_handler_testsuite.hpp.

236  {
237  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
238  _send_("+MAP {}");
239  _send_val_props_();
240  _send_('\n');
241  _mark_parent_with_children_();
242  _enable_(MAP|FLOW_SL);
243  _push();
244  }

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

◆ begin_map_val_block()

void c4::yml::extra::EventHandlerTestSuite::begin_map_val_block ( )
inline

Definition at line 245 of file event_handler_testsuite.hpp.

246  {
247  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
248  _send_("+MAP");
249  _send_val_props_();
250  _send_('\n');
251  _mark_parent_with_children_();
252  _enable_(MAP|BLOCK);
253  _push();
254  }

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

◆ end_map()

void c4::yml::extra::EventHandlerTestSuite::end_map ( )
inline

Definition at line 256 of file event_handler_testsuite.hpp.

257  {
258  _pop();
259  _send_("-MAP\n");
260  }

◆ begin_seq_key_flow()

void c4::yml::extra::EventHandlerTestSuite::begin_seq_key_flow ( )
inline

Definition at line 269 of file event_handler_testsuite.hpp.

270  {
271  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
272  _send_("+SEQ []");
273  _send_key_props_();
274  _send_('\n');
275  _mark_parent_with_children_();
276  _enable_(SEQ|FLOW_SL);
277  _push();
278  }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:39

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

◆ begin_seq_key_block()

void c4::yml::extra::EventHandlerTestSuite::begin_seq_key_block ( )
inline

Definition at line 279 of file event_handler_testsuite.hpp.

280  {
281  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
282  _send_("+SEQ");
283  _send_key_props_();
284  _send_('\n');
285  _mark_parent_with_children_();
286  _enable_(SEQ|BLOCK);
287  _push();
288  }

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

◆ begin_seq_val_flow()

void c4::yml::extra::EventHandlerTestSuite::begin_seq_val_flow ( )
inline

Definition at line 290 of file event_handler_testsuite.hpp.

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

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

◆ begin_seq_val_block()

void c4::yml::extra::EventHandlerTestSuite::begin_seq_val_block ( )
inline

Definition at line 300 of file event_handler_testsuite.hpp.

301  {
302  _RYML_CB_CHECK(m_stack.m_callbacks, !_has_any_(VAL));
303  _send_("+SEQ");
304  _send_val_props_();
305  _send_('\n');
306  _mark_parent_with_children_();
307  _enable_(SEQ|BLOCK);
308  _push();
309  }

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

◆ end_seq()

void c4::yml::extra::EventHandlerTestSuite::end_seq ( )
inline

Definition at line 311 of file event_handler_testsuite.hpp.

312  {
313  _pop();
314  _send_("-SEQ\n"); // before popping
315  }

◆ add_sibling()

void c4::yml::extra::EventHandlerTestSuite::add_sibling ( )
inline

Definition at line 324 of file event_handler_testsuite.hpp.

325  {
326  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
327  _buf_flush_to_(m_curr->level, m_parent->level);
328  m_curr->ev_data = {};
329  }

◆ actually_val_is_first_key_of_new_map_flow()

void c4::yml::extra::EventHandlerTestSuite::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 336 of file event_handler_testsuite.hpp.

337  {
338  // ensure we have a temporary buffer to save the current val
339  const id_type tmp = m_curr->level + id_type(2);
340  _buf_ensure_(tmp + id_type(2));
341  // save the current val to the temporary buffer
342  _buf_flush_to_(m_curr->level, tmp);
343  _disable_(_VALMASK|VAL_STYLE);
344  // create the map.
345  // this will push a new level, and tmp is one further
347  _RYML_CB_ASSERT(m_stack.m_callbacks, tmp != m_curr->level);
348  // now move the saved val as the first key
349  _buf_flush_to_(tmp, m_curr->level);
350  }
@ VAL_STYLE
mask of all the scalar styles for val (not container styles!)
Definition: node_type.hpp:92
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::extra::EventHandlerTestSuite::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 358 of file event_handler_testsuite.hpp.

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

References c4::yml::extra::string::find_last(), c4::yml::extra::string::insert(), and c4::yml::npos.

◆ set_key_scalar_plain_empty()

void c4::yml::extra::EventHandlerTestSuite::set_key_scalar_plain_empty ( )
inlinenoexcept

Definition at line 392 of file event_handler_testsuite.hpp.

393  {
394  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
395  _send_key_scalar_({}, ':');
396  _enable_(KEY|KEY_PLAIN|KEYNIL);
397  }
@ KEY
is member of a map
Definition: node_type.hpp:36
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:70
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition: node_type.hpp:48

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

◆ set_val_scalar_plain_empty()

void c4::yml::extra::EventHandlerTestSuite::set_val_scalar_plain_empty ( )
inlinenoexcept

Definition at line 398 of file event_handler_testsuite.hpp.

399  {
400  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
401  _send_val_scalar_({}, ':');
402  _enable_(VAL|VAL_PLAIN|VALNIL);
403  }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition: node_type.hpp:49
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:71

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

◆ set_key_scalar_plain()

void c4::yml::extra::EventHandlerTestSuite::set_key_scalar_plain ( csubstr  scalar)
inline

Definition at line 405 of file event_handler_testsuite.hpp.

406  {
407  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
408  _send_key_scalar_(scalar, ':');
409  _enable_(KEY|KEY_PLAIN);
410  }

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

◆ set_val_scalar_plain()

void c4::yml::extra::EventHandlerTestSuite::set_val_scalar_plain ( csubstr  scalar)
inline

Definition at line 411 of file event_handler_testsuite.hpp.

412  {
413  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
414  _send_val_scalar_(scalar, ':');
415  _enable_(VAL|VAL_PLAIN);
416  }

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

◆ set_key_scalar_dquoted()

void c4::yml::extra::EventHandlerTestSuite::set_key_scalar_dquoted ( csubstr  scalar)
inline

Definition at line 419 of file event_handler_testsuite.hpp.

420  {
421  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
422  _send_key_scalar_(scalar, '"');
423  _enable_(KEY|KEY_DQUO);
424  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:68

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

◆ set_val_scalar_dquoted()

void c4::yml::extra::EventHandlerTestSuite::set_val_scalar_dquoted ( csubstr  scalar)
inline

Definition at line 425 of file event_handler_testsuite.hpp.

426  {
427  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
428  _send_val_scalar_(scalar, '"');
429  _enable_(VAL|VAL_DQUO);
430  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:69

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

◆ set_key_scalar_squoted()

void c4::yml::extra::EventHandlerTestSuite::set_key_scalar_squoted ( csubstr  scalar)
inline

Definition at line 433 of file event_handler_testsuite.hpp.

434  {
435  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
436  _send_key_scalar_(scalar, '\'');
437  _enable_(KEY|KEY_SQUO);
438  }
@ KEY_SQUO
mark key scalar as single quoted '
Definition: node_type.hpp:66

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

◆ set_val_scalar_squoted()

void c4::yml::extra::EventHandlerTestSuite::set_val_scalar_squoted ( csubstr  scalar)
inline

Definition at line 439 of file event_handler_testsuite.hpp.

440  {
441  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
442  _send_val_scalar_(scalar, '\'');
443  _enable_(VAL|VAL_SQUO);
444  }
@ VAL_SQUO
mark val scalar as single quoted '
Definition: node_type.hpp:67

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

◆ set_key_scalar_literal()

void c4::yml::extra::EventHandlerTestSuite::set_key_scalar_literal ( csubstr  scalar)
inline

Definition at line 447 of file event_handler_testsuite.hpp.

448  {
449  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
450  _send_key_scalar_(scalar, '|');
451  _enable_(KEY|KEY_LITERAL);
452  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:62

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

◆ set_val_scalar_literal()

void c4::yml::extra::EventHandlerTestSuite::set_val_scalar_literal ( csubstr  scalar)
inline

Definition at line 453 of file event_handler_testsuite.hpp.

454  {
455  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
456  _send_val_scalar_(scalar, '|');
457  _enable_(VAL|VAL_LITERAL);
458  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:63

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

◆ set_key_scalar_folded()

void c4::yml::extra::EventHandlerTestSuite::set_key_scalar_folded ( csubstr  scalar)
inline

Definition at line 461 of file event_handler_testsuite.hpp.

462  {
463  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
464  _send_key_scalar_(scalar, '>');
465  _enable_(KEY|KEY_FOLDED);
466  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:64

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

◆ set_val_scalar_folded()

void c4::yml::extra::EventHandlerTestSuite::set_val_scalar_folded ( csubstr  scalar)
inline

Definition at line 467 of file event_handler_testsuite.hpp.

468  {
469  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
470  _send_val_scalar_(scalar, '>');
471  _enable_(VAL|VAL_FOLDED);
472  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:65

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

◆ mark_key_scalar_unfiltered()

void c4::yml::extra::EventHandlerTestSuite::mark_key_scalar_unfiltered ( )
inline

Definition at line 475 of file event_handler_testsuite.hpp.

476  {
477  // nothing to do here
478  }

◆ mark_val_scalar_unfiltered()

void c4::yml::extra::EventHandlerTestSuite::mark_val_scalar_unfiltered ( )
inline

Definition at line 479 of file event_handler_testsuite.hpp.

480  {
481  // nothing to do here
482  }

◆ set_key_anchor()

void c4::yml::extra::EventHandlerTestSuite::set_key_anchor ( csubstr  anchor)
inline

Definition at line 491 of file event_handler_testsuite.hpp.

492  {
493  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
494  _RYML_CB_ASSERT(m_stack.m_callbacks, !_has_any_(KEYREF));
495  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
496  _enable_(KEYANCH);
497  m_curr->ev_data.m_key.anchor = anchor;
498  }
@ KEYREF
a *reference: the key references an &anchor
Definition: node_type.hpp:42
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:44

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

◆ set_val_anchor()

void c4::yml::extra::EventHandlerTestSuite::set_val_anchor ( csubstr  anchor)
inline

Definition at line 499 of file event_handler_testsuite.hpp.

500  {
501  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
502  _RYML_CB_ASSERT(m_stack.m_callbacks, !_has_any_(VALREF));
503  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
504  _enable_(VALANCH);
505  m_curr->ev_data.m_val.anchor = anchor;
506  }
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:45
@ VALREF
a *reference: the val references an &anchor
Definition: node_type.hpp:43

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

◆ set_key_ref()

void c4::yml::extra::EventHandlerTestSuite::set_key_ref ( csubstr  ref)
inline

Definition at line 508 of file event_handler_testsuite.hpp.

509  {
510  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
511  if(C4_UNLIKELY(_has_any_(KEYANCH)))
512  _RYML_CB_ERR_(m_stack.m_callbacks, "key cannot have both anchor and ref", m_curr->pos);
513  _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*'));
514  _enable_(KEY|KEYREF);
515  _send_("=ALI ");
516  _send_(ref);
517  _send_('\n');
518  }

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

◆ set_val_ref()

void c4::yml::extra::EventHandlerTestSuite::set_val_ref ( csubstr  ref)
inline

Definition at line 519 of file event_handler_testsuite.hpp.

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

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

◆ set_key_tag()

void c4::yml::extra::EventHandlerTestSuite::set_key_tag ( csubstr  tag)
inline

Definition at line 538 of file event_handler_testsuite.hpp.

539  {
540  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
541  _enable_(KEYTAG);
542  m_curr->ev_data.m_key.tag = _transform_directive(tag, &m_key_tag_buf);
543  }
@ KEYTAG
the key has a tag
Definition: node_type.hpp:46

References c4::yml::KEYTAG.

◆ set_val_tag()

void c4::yml::extra::EventHandlerTestSuite::set_val_tag ( csubstr  tag)
inline

Definition at line 544 of file event_handler_testsuite.hpp.

545  {
546  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
547  _enable_(VALTAG);
548  m_curr->ev_data.m_val.tag = _transform_directive(tag, &m_val_tag_buf);
549  }
@ VALTAG
the val has a tag
Definition: node_type.hpp:47

References c4::yml::VALTAG.

◆ add_directive()

void c4::yml::extra::EventHandlerTestSuite::add_directive ( csubstr  directive)
inline

Definition at line 558 of file event_handler_testsuite.hpp.

559  {
560  _RYML_CB_ASSERT(m_stack.m_callbacks, directive.begins_with('%'));
561  if(directive.begins_with("%TAG"))
562  {
563  const id_type pos = _num_tag_directives();
564  if(C4_UNLIKELY(pos >= RYML_MAX_TAG_DIRECTIVES))
565  _RYML_CB_ERR_(m_stack.m_callbacks, "too many directives", m_curr->pos);
566  if(C4_UNLIKELY(!m_tag_directives[pos].create_from_str(directive)))
567  _RYML_CB_ERR_(m_stack.m_callbacks, "failed to add directive", m_curr->pos);
568  }
569  else if(directive.begins_with("%YAML"))
570  {
571  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
572  if(C4_UNLIKELY(m_has_yaml_directive))
573  _RYML_CB_ERR_(m_stack.m_callbacks, "multiple yaml directives", m_curr->pos);
574  m_has_yaml_directive = true;
575  }
576  else
577  {
578  _c4dbgpf("unknown directive! ignoring... {}", directive);
579  }
580  }
#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::extra::EventHandlerTestSuite::alloc_arena ( size_t  len)
inline

Definition at line 589 of file event_handler_testsuite.hpp.

590  {
591  const size_t sz = m_arena.size();
592  csubstr prev = m_arena;
593  m_arena.resize(sz + len);
594  substr out = to_substr(m_arena).sub(sz);
595  substr curr = to_substr(m_arena);
596  if(curr.str != prev.str)
597  _stack_relocate_to_new_arena(prev, curr);
598  return out;
599  }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2184

References c4::yml::extra::string::resize(), c4::yml::extra::string::size(), and c4::to_substr().

◆ alloc_arena() [2/2]

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

Definition at line 601 of file event_handler_testsuite.hpp.

602  {
603  csubstr prev = m_arena;
604  if(!prev.is_super(*relocated))
605  return alloc_arena(len);
606  substr out = alloc_arena(len);
607  substr curr = to_substr(m_arena);
608  if(curr.str != prev.str)
609  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
610  return out;
611  }

References c4::to_substr().

◆ _stack_start_parse()

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

Definition at line 64 of file event_handler_stack.hpp.

65  {
66  _RYML_CB_ASSERT(m_stack.m_callbacks, m_curr != nullptr);
67  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena != nullptr);
68  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena_data != nullptr);
69  m_curr->start_parse(filename, m_curr->node_id);
70  m_relocate_arena = relocate_arena;
71  m_relocate_arena_data = relocate_arena_data;
72  }
pfn_relocate_arena m_relocate_arena
callback when the arena gets relocated

◆ _stack_finish_parse()

void c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::_stack_finish_parse ( )
inlineprotectedinherited

Definition at line 74 of file event_handler_stack.hpp.

75  {
76  }

◆ _stack_reset_root()

void c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::_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< EventHandlerTestSuite , EventHandlerTestSuiteState >::_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< EventHandlerTestSuite , EventHandlerTestSuiteState >::_stack_push ( )
inlineprotectedinherited

Definition at line 97 of file event_handler_stack.hpp.

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

◆ _stack_pop()

void c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::_stack_pop ( )
inlineprotectedinherited

Definition at line 105 of file event_handler_stack.hpp.

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

◆ _stack_should_push_on_begin_doc()

bool c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::_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< EventHandlerTestSuite , EventHandlerTestSuiteState >::_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< EventHandlerTestSuite , EventHandlerTestSuiteState >::_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< EventHandlerTestSuite , EventHandlerTestSuiteState >::_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< EventHandlerTestSuite , EventHandlerTestSuiteState >::check_trailing_doc_token ( ) const
inlineinherited

Check whether the current parse tokens are trailing on the previous doc, and raise an error if they are.

This function is called by the parse engine (not the event handler) before a doc is started.

Definition at line 171 of file event_handler_stack.hpp.

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

Member Data Documentation

◆ m_stack

detail::stack<state> c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::m_stack
inherited

Definition at line 51 of file event_handler_stack.hpp.

◆ m_curr

state* c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::m_curr
inherited

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

Definition at line 52 of file event_handler_stack.hpp.

◆ m_parent

state* c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::m_parent
inherited

parent of the current stack level.

Definition at line 53 of file event_handler_stack.hpp.

◆ m_relocate_arena

pfn_relocate_arena c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::m_relocate_arena
inherited

callback when the arena gets relocated

Definition at line 54 of file event_handler_stack.hpp.

◆ m_relocate_arena_data

void* c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::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: