rapidyaml  0.11.1
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, csubstr src, 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_block ()
 
void end_map_flow (bool)
 
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_block ()
 
void end_seq_flow (bool)
 
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
 
csubstr m_src
 

Protected Member Functions

void _stack_start_parse (const char *filename, csubstr ymlsrc, 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 105 of file event_handler_testsuite.hpp.

105 : 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(), m_src() {}

◆ EventHandlerTestSuite() [2/4]

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

Definition at line 106 of file event_handler_testsuite.hpp.

106 : 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(), m_src() {}

◆ EventHandlerTestSuite() [3/4]

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

Definition at line 107 of file event_handler_testsuite.hpp.

107  : 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(), m_src()
108  {
109  reset();
110  }

◆ EventHandlerTestSuite() [4/4]

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

Definition at line 111 of file event_handler_testsuite.hpp.

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

Member Function Documentation

◆ reset()

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

Definition at line 113 of file event_handler_testsuite.hpp.

114  {
116  m_curr->flags |= RUNK|RTOP;
117  m_has_yaml_directive = false;
118  for(TagDirective &td : m_tag_directives)
119  td = {};
120  m_val_buffers.clear();
121  m_val_buffers.resize((size_t)m_stack.size());
122  m_arena.clear();
123  m_arena.reserve(1024);
124  m_key_tag_buf.resize(256);
125  m_val_tag_buf.resize(256);
126  m_has_docs = false;
127  m_src = {};
128  }
@ 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,
csubstr  src,
detail::pfn_relocate_arena  relocate_arena,
void *  relocate_arena_data 
)
inline

Definition at line 137 of file event_handler_testsuite.hpp.

138  {
139  this->_stack_start_parse(filename, src, relocate_arena, relocate_arena_data);
140  }
void _stack_start_parse(const char *filename, csubstr ymlsrc, pfn_relocate_arena relocate_arena, void *relocate_arena_data)

◆ finish_parse()

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

Definition at line 142 of file event_handler_testsuite.hpp.

143  {
144  if((_num_tag_directives() || m_has_yaml_directive) && !m_has_docs)
145  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "directives cannot be used without a document");
146  this->_stack_finish_parse();
147  }

◆ cancel_parse()

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

Definition at line 149 of file event_handler_testsuite.hpp.

150  {
151  while(m_stack.size() > 1)
152  _pop();
153  _buf_flush_();
154  }

◆ begin_stream()

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

Definition at line 163 of file event_handler_testsuite.hpp.

164  {
165  _send_("+STR\n");
166  }

◆ end_stream()

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

Definition at line 168 of file event_handler_testsuite.hpp.

169  {
170  _send_("-STR\n");
171  _buf_flush_();
172  }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 182 of file event_handler_testsuite.hpp.

183  {
184  _c4dbgp("begin_doc");
186  {
187  _c4dbgp("push!");
188  _push();
189  _enable_(DOC);
190  }
191  _send_("+DOC\n");
192  m_has_docs = true;
193  }
@ 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 195 of file event_handler_testsuite.hpp.

196  {
197  _c4dbgp("end_doc");
198  _send_("-DOC\n");
200  {
201  _c4dbgp("pop!");
202  _pop();
203  }
204  }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 207 of file event_handler_testsuite.hpp.

208  {
209  _c4dbgp("begin_doc_expl");
211  {
212  _c4dbgp("push!");
213  _push();
214  }
215  _send_("+DOC ---\n");
216  _enable_(DOC);
217  m_has_docs = true;
218  }

References c4::yml::DOC.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 220 of file event_handler_testsuite.hpp.

221  {
222  _c4dbgp("end_doc_expl");
223  _send_("-DOC ...\n");
225  {
226  _c4dbgp("pop!");
227  _pop();
228  }
229  m_has_yaml_directive = false;
230  }

◆ begin_map_key_flow()

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

Definition at line 239 of file event_handler_testsuite.hpp.

240  {
241  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
242  _send_("+MAP {}");
243  _send_key_props_();
244  _send_('\n');
245  _mark_parent_with_children_();
246  _enable_(MAP|FLOW_SL);
247  _push();
248  }
#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 249 of file event_handler_testsuite.hpp.

250  {
251  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
252  _send_("+MAP");
253  _send_key_props_();
254  _send_('\n');
255  _mark_parent_with_children_();
256  _enable_(MAP|BLOCK);
257  _push();
258  }
@ 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 260 of file event_handler_testsuite.hpp.

261  {
262  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
263  _send_("+MAP {}");
264  _send_val_props_();
265  _send_('\n');
266  _mark_parent_with_children_();
267  _enable_(MAP|FLOW_SL);
268  _push();
269  }

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 270 of file event_handler_testsuite.hpp.

271  {
272  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
273  _send_("+MAP");
274  _send_val_props_();
275  _send_('\n');
276  _mark_parent_with_children_();
277  _enable_(MAP|BLOCK);
278  _push();
279  }

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

◆ end_map_block()

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

Definition at line 281 of file event_handler_testsuite.hpp.

282  {
283  _pop();
284  _send_("-MAP\n");
285  }

◆ end_map_flow()

void c4::yml::extra::EventHandlerTestSuite::end_map_flow ( bool  )
inline

Definition at line 287 of file event_handler_testsuite.hpp.

288  {
289  _pop();
290  _send_("-MAP\n");
291  }

◆ begin_seq_key_flow()

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

Definition at line 300 of file event_handler_testsuite.hpp.

301  {
302  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
303  _send_("+SEQ []");
304  _send_key_props_();
305  _send_('\n');
306  _mark_parent_with_children_();
307  _enable_(SEQ|FLOW_SL);
308  _push();
309  }
@ 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 310 of file event_handler_testsuite.hpp.

311  {
312  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
313  _send_("+SEQ");
314  _send_key_props_();
315  _send_('\n');
316  _mark_parent_with_children_();
317  _enable_(SEQ|BLOCK);
318  _push();
319  }

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 321 of file event_handler_testsuite.hpp.

322  {
323  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
324  _send_("+SEQ []");
325  _send_val_props_();
326  _send_('\n');
327  _mark_parent_with_children_();
328  _enable_(SEQ|FLOW_SL);
329  _push();
330  }

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 331 of file event_handler_testsuite.hpp.

332  {
333  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
334  _send_("+SEQ");
335  _send_val_props_();
336  _send_('\n');
337  _mark_parent_with_children_();
338  _enable_(SEQ|BLOCK);
339  _push();
340  }

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

◆ end_seq_block()

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

Definition at line 342 of file event_handler_testsuite.hpp.

343  {
344  _pop();
345  _send_("-SEQ\n");
346  }

◆ end_seq_flow()

void c4::yml::extra::EventHandlerTestSuite::end_seq_flow ( bool  )
inline

Definition at line 348 of file event_handler_testsuite.hpp.

349  {
350  _pop();
351  _send_("-SEQ\n");
352  }

◆ add_sibling()

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

Definition at line 361 of file event_handler_testsuite.hpp.

362  {
363  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
364  _buf_flush_to_(m_curr->level, m_parent->level);
365  m_curr->ev_data = {};
366  }

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

374  {
375  _c4dbgpf("node[{}]: actually_val_is_first_key_of_new_map_flow", m_curr->node_id);
376  // ensure we have a temporary buffer to save the current val
377  const id_type tmp = m_curr->level + id_type(2);
378  _buf_ensure_(tmp + id_type(2));
379  // save the current val to the temporary buffer
380  _buf_flush_to_(m_curr->level, tmp);
381  _disable_(_VALMASK|VAL_STYLE);
382  // create the map.
383  // this will push a new level, and tmp is one further
385  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, tmp != m_curr->level);
386  // now move the saved val as the first key
387  _buf_flush_to_(tmp, m_curr->level);
388  }
@ 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:244

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

397  {
398  _c4dbgpf("node[{}]: actually_val_is_first_key_of_new_map_block", m_curr->node_id);
399  EventSink &sink = _buf_();
400  csubstr full = sink;(void)full;
401  // interpolate +MAP\n after the last +DOC\n
402  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, full.len);
403  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !full.count('\r'));
404  size_t docpos = sink.find_last("+DOC\n");
405  if(docpos != npos)
406  {
407  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, (m_stack.size() == 1u) ? (docpos >= 5u) : (docpos == 0u));
408  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, docpos + 5u < full.len);
409  sink.insert("+MAP\n", docpos + 5u);
410  }
411  else
412  {
413  // ... or interpolate +MAP\n after the last +DOC ---\n
414  docpos = sink.find_last("+DOC ---\n");
415  if(docpos != npos)
416  {
417  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, (m_stack.size() == 1u) ? (docpos >= 5u) : (docpos == 0u));
418  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, docpos + 9u < full.len);
419  sink.insert("+MAP\n", docpos + 9u);
420  }
421  else
422  {
423  sink.insert("+MAP\n", 0u);
424  }
425  }
426  _push();
427  }
@ npos
a null string position
Definition: common.hpp:258

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 437 of file event_handler_testsuite.hpp.

438  {
439  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
440  _send_key_scalar_({}, ':');
441  _enable_(KEY|KEY_PLAIN|KEYNIL);
442  }
@ 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 443 of file event_handler_testsuite.hpp.

444  {
445  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
446  _send_val_scalar_({}, ':');
447  _enable_(VAL|VAL_PLAIN|VALNIL);
448  }
@ 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 450 of file event_handler_testsuite.hpp.

451  {
452  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
453  _send_key_scalar_(scalar, ':');
454  _enable_(KEY|KEY_PLAIN);
455  }

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 456 of file event_handler_testsuite.hpp.

457  {
458  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
459  _send_val_scalar_(scalar, ':');
460  _enable_(VAL|VAL_PLAIN);
461  }

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 464 of file event_handler_testsuite.hpp.

465  {
466  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
467  _send_key_scalar_(scalar, '"');
468  _enable_(KEY|KEY_DQUO);
469  }
@ 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 470 of file event_handler_testsuite.hpp.

471  {
472  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
473  _send_val_scalar_(scalar, '"');
474  _enable_(VAL|VAL_DQUO);
475  }
@ 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 478 of file event_handler_testsuite.hpp.

479  {
480  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
481  _send_key_scalar_(scalar, '\'');
482  _enable_(KEY|KEY_SQUO);
483  }
@ 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 484 of file event_handler_testsuite.hpp.

485  {
486  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
487  _send_val_scalar_(scalar, '\'');
488  _enable_(VAL|VAL_SQUO);
489  }
@ 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 492 of file event_handler_testsuite.hpp.

493  {
494  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
495  _send_key_scalar_(scalar, '|');
496  _enable_(KEY|KEY_LITERAL);
497  }
@ 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 498 of file event_handler_testsuite.hpp.

499  {
500  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
501  _send_val_scalar_(scalar, '|');
502  _enable_(VAL|VAL_LITERAL);
503  }
@ 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 506 of file event_handler_testsuite.hpp.

507  {
508  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
509  _send_key_scalar_(scalar, '>');
510  _enable_(KEY|KEY_FOLDED);
511  }
@ 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 512 of file event_handler_testsuite.hpp.

513  {
514  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
515  _send_val_scalar_(scalar, '>');
516  _enable_(VAL|VAL_FOLDED);
517  }
@ 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 520 of file event_handler_testsuite.hpp.

521  {
522  // nothing to do here
523  }

◆ mark_val_scalar_unfiltered()

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

Definition at line 524 of file event_handler_testsuite.hpp.

525  {
526  // nothing to do here
527  }

◆ set_key_anchor()

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

Definition at line 536 of file event_handler_testsuite.hpp.

537  {
538  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
539  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !_has_any_(KEYREF));
540  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !anchor.begins_with('&'));
541  _enable_(KEYANCH);
542  m_curr->ev_data.m_key.anchor = anchor;
543  }
@ 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 544 of file event_handler_testsuite.hpp.

545  {
546  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
547  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !_has_any_(VALREF));
548  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !anchor.begins_with('&'));
549  _enable_(VALANCH);
550  m_curr->ev_data.m_val.anchor = anchor;
551  }
@ 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 553 of file event_handler_testsuite.hpp.

554  {
555  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
556  if(C4_UNLIKELY(_has_any_(KEYANCH)))
557  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "key cannot have both anchor and ref");
558  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, ref.begins_with('*'));
559  _enable_(KEY|KEYREF);
560  _send_("=ALI ");
561  _send_(ref);
562  _send_('\n');
563  }

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 564 of file event_handler_testsuite.hpp.

565  {
566  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
567  if(C4_UNLIKELY(_has_any_(VALANCH)))
568  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "val cannot have both anchor and ref");
569  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, ref.begins_with('*'));
570  _enable_(VAL|VALREF);
571  _send_("=ALI ");
572  _send_(ref);
573  _send_('\n');
574  }

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 583 of file event_handler_testsuite.hpp.

584  {
585  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
586  _enable_(KEYTAG);
587  m_curr->ev_data.m_key.tag = _transform_directive(tag, &m_key_tag_buf);
588  }
@ 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 589 of file event_handler_testsuite.hpp.

590  {
591  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
592  _enable_(VALTAG);
593  m_curr->ev_data.m_val.tag = _transform_directive(tag, &m_val_tag_buf);
594  }
@ 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 603 of file event_handler_testsuite.hpp.

604  {
605  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, directive.begins_with('%'));
606  if(directive.begins_with("%TAG"))
607  {
608  const id_type pos = _num_tag_directives();
609  if(C4_UNLIKELY(pos >= RYML_MAX_TAG_DIRECTIVES))
610  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "too many directives");
611  if(C4_UNLIKELY(!m_tag_directives[pos].create_from_str(directive)))
612  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "failed to add directive");
613  }
614  else if(directive.begins_with("%YAML"))
615  {
616  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
617  if(C4_UNLIKELY(m_has_yaml_directive))
618  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "multiple yaml directives");
619  m_has_yaml_directive = true;
620  }
621  else
622  {
623  _c4dbgpf("unknown directive! ignoring... {}", directive);
624  }
625  }
#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 634 of file event_handler_testsuite.hpp.

635  {
636  const size_t sz = m_arena.size();
637  csubstr prev = m_arena;
638  m_arena.resize(sz + len);
639  substr out = to_substr(m_arena).sub(sz);
640  substr curr = to_substr(m_arena);
641  if(curr.str != prev.str)
642  _stack_relocate_to_new_arena(prev, curr);
643  return out;
644  }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2208

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 646 of file event_handler_testsuite.hpp.

647  {
648  csubstr prev = m_arena;
649  if(!prev.is_super(*relocated))
650  return alloc_arena(len);
651  substr out = alloc_arena(len);
652  substr curr = to_substr(m_arena);
653  if(curr.str != prev.str)
654  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
655  return out;
656  }

References c4::to_substr().

◆ _stack_start_parse()

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

Definition at line 65 of file event_handler_stack.hpp.

66  {
67  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_curr != nullptr);
68  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, relocate_arena != nullptr);
69  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, relocate_arena_data != nullptr);
70  m_curr->start_parse(filename, m_curr->node_id);
71  m_relocate_arena = relocate_arena;
72  m_relocate_arena_data = relocate_arena_data;
73  m_src = ymlsrc;
74  }
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 76 of file event_handler_stack.hpp.

77  {
78  m_src = {};
79  }

◆ _stack_reset_root()

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

Definition at line 83 of file event_handler_stack.hpp.

84  {
85  m_stack.clear();
86  m_stack.push({});
87  m_parent = nullptr;
88  m_curr = &m_stack.top();
89  }

◆ _stack_reset_non_root()

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

Definition at line 91 of file event_handler_stack.hpp.

92  {
93  m_stack.clear();
94  m_stack.push({}); // parent
95  m_stack.push({}); // node
96  m_parent = &m_stack.top(1);
97  m_curr = &m_stack.top();
98  }

◆ _stack_push()

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

Definition at line 100 of file event_handler_stack.hpp.

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

◆ _stack_pop()

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

Definition at line 108 of file event_handler_stack.hpp.

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

◆ _stack_should_push_on_begin_doc()

bool c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::_stack_should_push_on_begin_doc ( ) const
inlineprotectedinherited

Definition at line 129 of file event_handler_stack.hpp.

130  {
131  const bool is_root = (m_stack.size() == 1u);
132  return is_root && (_has_any_(DOC|VAL|MAP|SEQ) || m_curr->has_children);
133  }

◆ _stack_should_pop_on_end_doc()

bool c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::_stack_should_pop_on_end_doc ( ) const
inlineprotectedinherited

Definition at line 135 of file event_handler_stack.hpp.

136  {
137  const bool is_root = (m_stack.size() == 1u);
138  return !is_root && _has_any_(DOC);
139  }

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

144  {
145  for(state &st : m_stack)
146  {
147  if(st.line_contents.rem.is_sub(prev))
148  st.line_contents.rem = _stack_relocate_to_new_arena(st.line_contents.rem, prev, curr);
149  if(st.line_contents.full.is_sub(prev))
150  st.line_contents.full = _stack_relocate_to_new_arena(st.line_contents.full, prev, curr);
151  }
152  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_relocate_arena != nullptr);
153  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_relocate_arena_data != nullptr);
155  }

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

158  {
159  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, prev.is_super(s));
160  auto pos = s.str - prev.str;
161  substr out = {curr.str + pos, s.len};
162  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, curr.is_super(out));
163  return out;
164  }

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

173  {
174  const bool is_root = (m_stack.size() == 1u);
175  const bool isndoc = (m_curr->flags & NDOC) != 0;
176  const bool suspicious = _has_any_(MAP|SEQ|VAL);
177  _c4dbgpf("target={} isroot={} suspicious={} ndoc={}", m_curr->node_id, is_root, suspicious, isndoc);
178  if((is_root || _has_any_(DOC)) && suspicious && !isndoc)
179  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "parse error");
180  }
@ 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.

◆ m_src

csubstr c4::yml::EventHandlerStack< EventHandlerTestSuite , EventHandlerTestSuiteState >::m_src
inherited

Definition at line 56 of file event_handler_stack.hpp.


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