rapidyaml  0.11.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, 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 82 of file event_handler_testsuite.hpp.

82 : 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 83 of file event_handler_testsuite.hpp.

83 : 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 84 of file event_handler_testsuite.hpp.

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

◆ EventHandlerTestSuite() [4/4]

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

Definition at line 88 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 90 of file event_handler_testsuite.hpp.

91  {
93  m_curr->flags |= RUNK|RTOP;
94  m_has_yaml_directive = false;
95  for(TagDirective &td : m_tag_directives)
96  td = {};
97  m_val_buffers.clear();
98  m_val_buffers.resize((size_t)m_stack.size());
99  m_arena.clear();
100  m_arena.reserve(1024);
101  m_key_tag_buf.resize(256);
102  m_val_tag_buf.resize(256);
103  m_has_docs = false;
104  m_src = {};
105  }
@ 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 114 of file event_handler_testsuite.hpp.

115  {
116  this->_stack_start_parse(filename, src, relocate_arena, relocate_arena_data);
117  }
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 119 of file event_handler_testsuite.hpp.

120  {
121  if((_num_tag_directives() || m_has_yaml_directive) && !m_has_docs)
122  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "directives cannot be used without a document");
123  this->_stack_finish_parse();
124  }

◆ cancel_parse()

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

Definition at line 126 of file event_handler_testsuite.hpp.

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

◆ begin_stream()

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

Definition at line 140 of file event_handler_testsuite.hpp.

141  {
142  _send_("+STR\n");
143  }

◆ end_stream()

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

Definition at line 145 of file event_handler_testsuite.hpp.

146  {
147  _send_("-STR\n");
148  _buf_flush_();
149  }

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 159 of file event_handler_testsuite.hpp.

160  {
161  _c4dbgp("begin_doc");
163  {
164  _c4dbgp("push!");
165  _push();
166  _enable_(DOC);
167  }
168  _send_("+DOC\n");
169  m_has_docs = true;
170  }
@ 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 172 of file event_handler_testsuite.hpp.

173  {
174  _c4dbgp("end_doc");
175  _send_("-DOC\n");
177  {
178  _c4dbgp("pop!");
179  _pop();
180  }
181  }

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 184 of file event_handler_testsuite.hpp.

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

References c4::yml::DOC.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 197 of file event_handler_testsuite.hpp.

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

◆ begin_map_key_flow()

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

Definition at line 216 of file event_handler_testsuite.hpp.

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

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

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

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

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

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

259  {
260  _pop();
261  _send_("-MAP\n");
262  }

◆ end_map_flow()

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

Definition at line 264 of file event_handler_testsuite.hpp.

265  {
266  _pop();
267  _send_("-MAP\n");
268  }

◆ begin_seq_key_flow()

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

Definition at line 277 of file event_handler_testsuite.hpp.

278  {
279  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
280  _send_("+SEQ []");
281  _send_key_props_();
282  _send_('\n');
283  _mark_parent_with_children_();
284  _enable_(SEQ|FLOW_SL);
285  _push();
286  }
@ 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 287 of file event_handler_testsuite.hpp.

288  {
289  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
290  _send_("+SEQ");
291  _send_key_props_();
292  _send_('\n');
293  _mark_parent_with_children_();
294  _enable_(SEQ|BLOCK);
295  _push();
296  }

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

299  {
300  _RYML_CHECK_BASIC_(m_stack.m_callbacks, !_has_any_(VAL));
301  _send_("+SEQ []");
302  _send_val_props_();
303  _send_('\n');
304  _mark_parent_with_children_();
305  _enable_(SEQ|FLOW_SL);
306  _push();
307  }

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

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

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

320  {
321  _pop();
322  _send_("-SEQ\n");
323  }

◆ end_seq_flow()

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

Definition at line 325 of file event_handler_testsuite.hpp.

326  {
327  _pop();
328  _send_("-SEQ\n");
329  }

◆ add_sibling()

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

Definition at line 338 of file event_handler_testsuite.hpp.

339  {
340  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, m_parent);
341  _buf_flush_to_(m_curr->level, m_parent->level);
342  m_curr->ev_data = {};
343  }

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

351  {
352  // ensure we have a temporary buffer to save the current val
353  const id_type tmp = m_curr->level + id_type(2);
354  _buf_ensure_(tmp + id_type(2));
355  // save the current val to the temporary buffer
356  _buf_flush_to_(m_curr->level, tmp);
357  _disable_(_VALMASK|VAL_STYLE);
358  // create the map.
359  // this will push a new level, and tmp is one further
361  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, tmp != m_curr->level);
362  // now move the saved val as the first key
363  _buf_flush_to_(tmp, m_curr->level);
364  }
@ 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 372 of file event_handler_testsuite.hpp.

373  {
374  EventSink &sink = _buf_();
375  substr full = sink;(void)full;
376  // interpolate +MAP\n after the last +DOC\n
377  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, full.len);
378  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !full.count('\r'));
379  size_t docpos = sink.find_last("+DOC\n");
380  if(docpos != npos)
381  {
382  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, (m_stack.size() == 1u) ? (docpos >= 5u) : (docpos == 0u));
383  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, docpos + 5u < full.len);
384  sink.insert("+MAP\n", docpos + 5u);
385  }
386  else
387  {
388  // ... or interpolate +MAP\n after the last +DOC ---\n
389  docpos = sink.find_last("+DOC ---\n");
390  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, docpos != npos);
391  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, (m_stack.size() == 1u) ? (docpos >= 5u) : (docpos == 0u));
392  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, docpos + 9u < full.len);
393  sink.insert("+MAP\n", docpos + 9u);
394  }
395  _push();
396  }
@ 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 406 of file event_handler_testsuite.hpp.

407  {
408  _c4dbgpf("node[{}]: set key scalar plain as empty", m_curr->node_id);
409  _send_key_scalar_({}, ':');
410  _enable_(KEY|KEY_PLAIN|KEYNIL);
411  }
@ 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 412 of file event_handler_testsuite.hpp.

413  {
414  _c4dbgpf("node[{}]: set val scalar plain as empty", m_curr->node_id);
415  _send_val_scalar_({}, ':');
416  _enable_(VAL|VAL_PLAIN|VALNIL);
417  }
@ 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 419 of file event_handler_testsuite.hpp.

420  {
421  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
422  _send_key_scalar_(scalar, ':');
423  _enable_(KEY|KEY_PLAIN);
424  }

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

426  {
427  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
428  _send_val_scalar_(scalar, ':');
429  _enable_(VAL|VAL_PLAIN);
430  }

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

434  {
435  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
436  _send_key_scalar_(scalar, '"');
437  _enable_(KEY|KEY_DQUO);
438  }
@ 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 439 of file event_handler_testsuite.hpp.

440  {
441  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
442  _send_val_scalar_(scalar, '"');
443  _enable_(VAL|VAL_DQUO);
444  }
@ 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 447 of file event_handler_testsuite.hpp.

448  {
449  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
450  _send_key_scalar_(scalar, '\'');
451  _enable_(KEY|KEY_SQUO);
452  }
@ 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 453 of file event_handler_testsuite.hpp.

454  {
455  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
456  _send_val_scalar_(scalar, '\'');
457  _enable_(VAL|VAL_SQUO);
458  }
@ 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 461 of file event_handler_testsuite.hpp.

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

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

476  {
477  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
478  _send_key_scalar_(scalar, '>');
479  _enable_(KEY|KEY_FOLDED);
480  }
@ 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 481 of file event_handler_testsuite.hpp.

482  {
483  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~", m_curr->node_id, scalar.len, scalar);
484  _send_val_scalar_(scalar, '>');
485  _enable_(VAL|VAL_FOLDED);
486  }
@ 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 489 of file event_handler_testsuite.hpp.

490  {
491  // nothing to do here
492  }

◆ mark_val_scalar_unfiltered()

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

Definition at line 493 of file event_handler_testsuite.hpp.

494  {
495  // nothing to do here
496  }

◆ set_key_anchor()

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

Definition at line 505 of file event_handler_testsuite.hpp.

506  {
507  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
508  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !_has_any_(KEYREF));
509  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !anchor.begins_with('&'));
510  _enable_(KEYANCH);
511  m_curr->ev_data.m_key.anchor = anchor;
512  }
@ 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 513 of file event_handler_testsuite.hpp.

514  {
515  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
516  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !_has_any_(VALREF));
517  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, !anchor.begins_with('&'));
518  _enable_(VALANCH);
519  m_curr->ev_data.m_val.anchor = anchor;
520  }
@ 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 522 of file event_handler_testsuite.hpp.

523  {
524  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
525  if(C4_UNLIKELY(_has_any_(KEYANCH)))
526  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "key cannot have both anchor and ref");
527  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, ref.begins_with('*'));
528  _enable_(KEY|KEYREF);
529  _send_("=ALI ");
530  _send_(ref);
531  _send_('\n');
532  }

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

534  {
535  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
536  if(C4_UNLIKELY(_has_any_(VALANCH)))
537  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "val cannot have both anchor and ref");
538  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, ref.begins_with('*'));
539  _enable_(VAL|VALREF);
540  _send_("=ALI ");
541  _send_(ref);
542  _send_('\n');
543  }

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

553  {
554  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
555  _enable_(KEYTAG);
556  m_curr->ev_data.m_key.tag = _transform_directive(tag, &m_key_tag_buf);
557  }
@ 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 558 of file event_handler_testsuite.hpp.

559  {
560  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
561  _enable_(VALTAG);
562  m_curr->ev_data.m_val.tag = _transform_directive(tag, &m_val_tag_buf);
563  }
@ 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 572 of file event_handler_testsuite.hpp.

573  {
574  _RYML_ASSERT_BASIC_(m_stack.m_callbacks, directive.begins_with('%'));
575  if(directive.begins_with("%TAG"))
576  {
577  const id_type pos = _num_tag_directives();
578  if(C4_UNLIKELY(pos >= RYML_MAX_TAG_DIRECTIVES))
579  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "too many directives");
580  if(C4_UNLIKELY(!m_tag_directives[pos].create_from_str(directive)))
581  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "failed to add directive");
582  }
583  else if(directive.begins_with("%YAML"))
584  {
585  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
586  if(C4_UNLIKELY(m_has_yaml_directive))
587  _RYML_ERR_PARSE_(m_stack.m_callbacks, m_curr->pos, "multiple yaml directives");
588  m_has_yaml_directive = true;
589  }
590  else
591  {
592  _c4dbgpf("unknown directive! ignoring... {}", directive);
593  }
594  }
#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 603 of file event_handler_testsuite.hpp.

604  {
605  const size_t sz = m_arena.size();
606  csubstr prev = m_arena;
607  m_arena.resize(sz + len);
608  substr out = to_substr(m_arena).sub(sz);
609  substr curr = to_substr(m_arena);
610  if(curr.str != prev.str)
611  _stack_relocate_to_new_arena(prev, curr);
612  return out;
613  }
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 615 of file event_handler_testsuite.hpp.

616  {
617  csubstr prev = m_arena;
618  if(!prev.is_super(*relocated))
619  return alloc_arena(len);
620  substr out = alloc_arena(len);
621  substr curr = to_substr(m_arena);
622  if(curr.str != prev.str)
623  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
624  return out;
625  }

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: