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

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

#include <test_suite_event_handler.hpp>

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

Public Types

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

Public Member Functions

void check_trailing_doc_token () const
 Check whether the current parse tokens are trailing on the previous doc, and raise an error if they are. More...
 
construction and resetting
 EventHandlerYamlStd ()
 
 EventHandlerYamlStd (Callbacks const &cb)
 
 EventHandlerYamlStd (EventSink *sink, Callbacks const &cb)
 
 EventHandlerYamlStd (EventSink *sink)
 
void reset ()
 
parse events
void start_parse (const char *filename, detail::pfn_relocate_arena relocate_arena, void *relocate_arena_data)
 
void finish_parse ()
 
void cancel_parse ()
 
YAML stream events
void begin_stream ()
 
void end_stream ()
 
YAML document events
void begin_doc ()
 implicit doc start (without —) More...
 
void end_doc ()
 implicit doc end (without ...) More...
 
void begin_doc_expl ()
 explicit doc start, with — More...
 
void end_doc_expl ()
 explicit doc end, with ... More...
 
YAML map functions
void begin_map_key_flow ()
 
void begin_map_key_block ()
 
void begin_map_val_flow ()
 
void begin_map_val_block ()
 
void end_map ()
 
YAML seq events
void begin_seq_key_flow ()
 
void begin_seq_key_block ()
 
void begin_seq_val_flow ()
 
void begin_seq_val_block ()
 
void end_seq ()
 
YAML structure events
void add_sibling ()
 
void actually_val_is_first_key_of_new_map_flow ()
 set the previous val as the first key of a new map, with flow style. More...
 
void actually_val_is_first_key_of_new_map_block ()
 like its flow counterpart, but this function can only be called after the end of a flow-val at root or doc level. More...
 
YAML scalar events
void set_key_scalar_plain (csubstr scalar)
 
void set_val_scalar_plain (csubstr scalar)
 
void set_key_scalar_dquoted (csubstr scalar)
 
void set_val_scalar_dquoted (csubstr scalar)
 
void set_key_scalar_squoted (csubstr scalar)
 
void set_val_scalar_squoted (csubstr scalar)
 
void set_key_scalar_literal (csubstr scalar)
 
void set_val_scalar_literal (csubstr scalar)
 
void set_key_scalar_folded (csubstr scalar)
 
void set_val_scalar_folded (csubstr scalar)
 
void mark_key_scalar_unfiltered ()
 
void mark_val_scalar_unfiltered ()
 
YAML anchor/reference events
void set_key_anchor (csubstr anchor)
 
void set_val_anchor (csubstr anchor)
 
void set_key_ref (csubstr ref)
 
void set_val_ref (csubstr ref)
 
YAML tag events
void set_key_tag (csubstr tag)
 
void set_val_tag (csubstr tag)
 
YAML directive events
void add_directive (csubstr directive)
 
YAML arena events
substr alloc_arena (size_t len)
 
substr alloc_arena (size_t len, substr *relocated)
 

Public Attributes

detail::stack< statem_stack
 
statem_curr
 current stack level: top of the stack. cached here for easier access. More...
 
statem_parent
 parent of the current stack level. More...
 
pfn_relocate_arena m_relocate_arena
 callback when the arena gets relocated More...
 
void * m_relocate_arena_data
 

Protected Member Functions

void _stack_start_parse (const char *filename, pfn_relocate_arena relocate_arena, void *relocate_arena_data)
 
void _stack_finish_parse ()
 
void _stack_reset_root ()
 
void _stack_reset_non_root ()
 
void _stack_push ()
 
void _stack_pop ()
 
bool _stack_should_push_on_begin_doc () const
 
bool _stack_should_pop_on_end_doc () const
 
void _stack_relocate_to_new_arena (csubstr prev, substr curr)
 
substr _stack_relocate_to_new_arena (csubstr s, csubstr prev, substr curr)
 

Detailed Description

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

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

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

Definition at line 49 of file test_suite_event_handler.hpp.

Member Typedef Documentation

◆ state

◆ EventSink

Definition at line 58 of file test_suite_event_handler.hpp.

◆ pfn_relocate_arena

Constructor & Destructor Documentation

◆ EventHandlerYamlStd() [1/4]

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

Definition at line 85 of file test_suite_event_handler.hpp.

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

◆ EventHandlerYamlStd() [2/4]

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

Definition at line 86 of file test_suite_event_handler.hpp.

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

◆ EventHandlerYamlStd() [3/4]

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

Definition at line 87 of file test_suite_event_handler.hpp.

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

◆ EventHandlerYamlStd() [4/4]

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

Definition at line 91 of file test_suite_event_handler.hpp.

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

Member Function Documentation

◆ reset()

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

Definition at line 93 of file test_suite_event_handler.hpp.

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

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

◆ start_parse()

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

Definition at line 116 of file test_suite_event_handler.hpp.

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

◆ finish_parse()

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

Definition at line 121 of file test_suite_event_handler.hpp.

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

◆ cancel_parse()

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

Definition at line 128 of file test_suite_event_handler.hpp.

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

◆ begin_stream()

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

Definition at line 142 of file test_suite_event_handler.hpp.

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

◆ end_stream()

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

Definition at line 147 of file test_suite_event_handler.hpp.

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

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 161 of file test_suite_event_handler.hpp.

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

References c4::yml::DOC.

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 174 of file test_suite_event_handler.hpp.

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

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 186 of file test_suite_event_handler.hpp.

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

References c4::yml::DOC.

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 199 of file test_suite_event_handler.hpp.

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

◆ begin_map_key_flow()

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

Definition at line 218 of file test_suite_event_handler.hpp.

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

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

◆ begin_map_key_block()

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

Definition at line 228 of file test_suite_event_handler.hpp.

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

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

◆ begin_map_val_flow()

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

Definition at line 239 of file test_suite_event_handler.hpp.

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

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

◆ begin_map_val_block()

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

Definition at line 249 of file test_suite_event_handler.hpp.

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

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

◆ end_map()

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

Definition at line 260 of file test_suite_event_handler.hpp.

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

◆ begin_seq_key_flow()

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

Definition at line 273 of file test_suite_event_handler.hpp.

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

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

◆ begin_seq_key_block()

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

Definition at line 283 of file test_suite_event_handler.hpp.

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

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

◆ begin_seq_val_flow()

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

Definition at line 294 of file test_suite_event_handler.hpp.

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

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

◆ begin_seq_val_block()

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

Definition at line 304 of file test_suite_event_handler.hpp.

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

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

◆ end_seq()

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

Definition at line 315 of file test_suite_event_handler.hpp.

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

◆ add_sibling()

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

Definition at line 328 of file test_suite_event_handler.hpp.

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

◆ actually_val_is_first_key_of_new_map_flow()

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

set the previous val as the first key of a new map, with flow style.

See the documentation for Event Handlers, which has important notes about this event.

Definition at line 340 of file test_suite_event_handler.hpp.

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

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

◆ actually_val_is_first_key_of_new_map_block()

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

like its flow counterpart, but this function can only be called after the end of a flow-val at root or doc level.

See the documentation for Event Handlers, which has important notes about this event.

Definition at line 362 of file test_suite_event_handler.hpp.

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

References c4::yml::npos.

◆ set_key_scalar_plain()

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

Definition at line 396 of file test_suite_event_handler.hpp.

397  {
398  _c4dbgpf("node[{}]: set key scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
399  _send_key_scalar_(scalar, ':');
400  _enable_(KEY|KEY_PLAIN);
401  }
@ KEY
is member of a map, must have non-empty key
Definition: node_type.hpp:33
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:65
id_type node_id
don't hold a pointer to the node as it will be relocated during tree resizes

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

◆ set_val_scalar_plain()

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

Definition at line 402 of file test_suite_event_handler.hpp.

403  {
404  _c4dbgpf("node[{}]: set val scalar plain: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
405  _send_val_scalar_(scalar, ':');
406  _enable_(VAL|VAL_PLAIN);
407  }
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)
Definition: node_type.hpp:66

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

◆ set_key_scalar_dquoted()

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

Definition at line 410 of file test_suite_event_handler.hpp.

411  {
412  _c4dbgpf("node[{}]: set key scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
413  _send_key_scalar_(scalar, '"');
414  _enable_(KEY|KEY_DQUO);
415  }
@ KEY_DQUO
mark key scalar as double quoted "
Definition: node_type.hpp:63

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

◆ set_val_scalar_dquoted()

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

Definition at line 416 of file test_suite_event_handler.hpp.

417  {
418  _c4dbgpf("node[{}]: set val scalar dquot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
419  _send_val_scalar_(scalar, '"');
420  _enable_(VAL|VAL_DQUO);
421  }
@ VAL_DQUO
mark val scalar as double quoted "
Definition: node_type.hpp:64

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

◆ set_key_scalar_squoted()

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

Definition at line 424 of file test_suite_event_handler.hpp.

425  {
426  _c4dbgpf("node[{}]: set key scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
427  _send_key_scalar_(scalar, '\'');
428  _enable_(KEY|KEY_SQUO);
429  }
@ KEY_SQUO
mark key scalar as single quoted '
Definition: node_type.hpp:61

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

◆ set_val_scalar_squoted()

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

Definition at line 430 of file test_suite_event_handler.hpp.

431  {
432  _c4dbgpf("node[{}]: set val scalar squot: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
433  _send_val_scalar_(scalar, '\'');
434  _enable_(VAL|VAL_SQUO);
435  }
@ VAL_SQUO
mark val scalar as single quoted '
Definition: node_type.hpp:62

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

◆ set_key_scalar_literal()

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

Definition at line 438 of file test_suite_event_handler.hpp.

439  {
440  _c4dbgpf("node[{}]: set key scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
441  _send_key_scalar_(scalar, '|');
442  _enable_(KEY|KEY_LITERAL);
443  }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
Definition: node_type.hpp:57

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

◆ set_val_scalar_literal()

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

Definition at line 444 of file test_suite_event_handler.hpp.

445  {
446  _c4dbgpf("node[{}]: set val scalar literal: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
447  _send_val_scalar_(scalar, '|');
448  _enable_(VAL|VAL_LITERAL);
449  }
@ VAL_LITERAL
mark val scalar as multiline, block literal |
Definition: node_type.hpp:58

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

◆ set_key_scalar_folded()

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

Definition at line 452 of file test_suite_event_handler.hpp.

453  {
454  _c4dbgpf("node[{}]: set key scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
455  _send_key_scalar_(scalar, '>');
456  _enable_(KEY|KEY_FOLDED);
457  }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
Definition: node_type.hpp:59

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

◆ set_val_scalar_folded()

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

Definition at line 458 of file test_suite_event_handler.hpp.

459  {
460  _c4dbgpf("node[{}]: set val scalar folded: [{}]~~~{}~~~ ({})", m_curr->node_id, scalar.len, scalar, reinterpret_cast<void const*>(scalar.str));
461  _send_val_scalar_(scalar, '>');
462  _enable_(VAL|VAL_FOLDED);
463  }
@ VAL_FOLDED
mark val scalar as multiline, block folded >
Definition: node_type.hpp:60

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

◆ mark_key_scalar_unfiltered()

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

Definition at line 466 of file test_suite_event_handler.hpp.

467  {
468  C4_NOT_IMPLEMENTED();
469  }

◆ mark_val_scalar_unfiltered()

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

Definition at line 470 of file test_suite_event_handler.hpp.

471  {
472  C4_NOT_IMPLEMENTED();
473  }

◆ set_key_anchor()

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

Definition at line 482 of file test_suite_event_handler.hpp.

483  {
484  _c4dbgpf("node[{}]: set key anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
485  if(C4_UNLIKELY(_has_any_(KEYANCH)))
486  _RYML_CB_ERR_(m_stack.m_callbacks, "key cannot have both anchor and ref", m_curr->pos);
487  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
488  _enable_(KEYANCH);
489  m_curr->ev_data.m_key.anchor = anchor;
490  }
@ KEYANCH
the key has an &anchor
Definition: node_type.hpp:41
NodeScalar m_key
Definition: tree.hpp:225
csubstr anchor
Definition: tree.hpp:108

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

◆ set_val_anchor()

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

Definition at line 491 of file test_suite_event_handler.hpp.

492  {
493  _c4dbgpf("node[{}]: set val anchor: [{}]~~~{}~~~", m_curr->node_id, anchor.len, anchor);
494  if(C4_UNLIKELY(_has_any_(VALREF)))
495  _RYML_CB_ERR_(m_stack.m_callbacks, "val cannot have both anchor and ref", m_curr->pos);
496  _RYML_CB_ASSERT(m_stack.m_callbacks, !anchor.begins_with('&'));
497  _enable_(VALANCH);
498  m_curr->ev_data.m_val.anchor = anchor;
499  }
@ VALANCH
the val has an &anchor
Definition: node_type.hpp:42
@ VALREF
a *reference: the val references an &anchor
Definition: node_type.hpp:40
NodeScalar m_val
Definition: tree.hpp:226

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

◆ set_key_ref()

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

Definition at line 501 of file test_suite_event_handler.hpp.

502  {
503  _c4dbgpf("node[{}]: set key ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
504  if(C4_UNLIKELY(_has_any_(KEYANCH)))
505  _RYML_CB_ERR_(m_stack.m_callbacks, "key cannot have both anchor and ref", m_curr->pos);
506  _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*'));
507  _enable_(KEY|KEYREF);
508  _send_("=ALI ");
509  _send_(ref);
510  _send_('\n');
511  }
@ KEYREF
a *reference: the key references an &anchor
Definition: node_type.hpp:39

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

◆ set_val_ref()

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

Definition at line 512 of file test_suite_event_handler.hpp.

513  {
514  _c4dbgpf("node[{}]: set val ref: [{}]~~~{}~~~", m_curr->node_id, ref.len, ref);
515  if(C4_UNLIKELY(_has_any_(VALANCH)))
516  _RYML_CB_ERR_(m_stack.m_callbacks, "val cannot have both anchor and ref", m_curr->pos);
517  _RYML_CB_ASSERT(m_stack.m_callbacks, ref.begins_with('*'));
518  _enable_(VAL|VALREF);
519  _send_("=ALI ");
520  _send_(ref);
521  _send_('\n');
522  }

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

◆ set_key_tag()

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

Definition at line 531 of file test_suite_event_handler.hpp.

532  {
533  _c4dbgpf("node[{}]: set key tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
534  _enable_(KEYTAG);
535  m_curr->ev_data.m_key.tag = _transform_directive(tag, &m_key_tag_buf);
536  }
@ KEYTAG
the key has a tag
Definition: node_type.hpp:43

References c4::yml::KEYTAG.

◆ set_val_tag()

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

Definition at line 537 of file test_suite_event_handler.hpp.

538  {
539  _c4dbgpf("node[{}]: set val tag: [{}]~~~{}~~~", m_curr->node_id, tag.len, tag);
540  _enable_(VALTAG);
541  m_curr->ev_data.m_val.tag = _transform_directive(tag, &m_val_tag_buf);
542  }
@ VALTAG
the val has a tag
Definition: node_type.hpp:44

References c4::yml::VALTAG.

◆ add_directive()

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

Definition at line 551 of file test_suite_event_handler.hpp.

552  {
553  _RYML_CB_ASSERT(m_stack.m_callbacks, directive.begins_with('%'));
554  if(directive.begins_with("%TAG"))
555  {
556  const id_type pos = _num_tag_directives();
557  if(C4_UNLIKELY(pos >= RYML_MAX_TAG_DIRECTIVES))
558  _RYML_CB_ERR_(m_stack.m_callbacks, "too many directives", m_curr->pos);
559  if(C4_UNLIKELY(!m_tag_directives[pos].create_from_str(directive)))
560  _RYML_CB_ERR_(m_stack.m_callbacks, "failed to add directive", m_curr->pos);
561  }
562  else if(directive.begins_with("%YAML"))
563  {
564  _c4dbgpf("%YAML directive! ignoring...: {}", directive);
565  if(C4_UNLIKELY(m_has_yaml_directive))
566  _RYML_CB_ERR_(m_stack.m_callbacks, "multiple yaml directives", m_curr->pos);
567  m_has_yaml_directive = true;
568  }
569  else
570  {
571  _c4dbgpf("unknown directive! ignoring... {}", directive);
572  }
573  }
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition: tag.hpp:19

References RYML_MAX_TAG_DIRECTIVES.

◆ alloc_arena() [1/2]

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

Definition at line 582 of file test_suite_event_handler.hpp.

583  {
584  const size_t sz = m_arena.size();
585  csubstr prev = m_arena;
586  m_arena.resize(sz + len);
587  substr out = to_substr(m_arena).sub(sz);
588  substr curr = to_substr(m_arena);
589  if(curr.str != prev.str)
590  _stack_relocate_to_new_arena(prev, curr);
591  return out;
592  }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2187

References c4::to_substr().

◆ alloc_arena() [2/2]

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

Definition at line 594 of file test_suite_event_handler.hpp.

595  {
596  csubstr prev = m_arena;
597  if(!prev.is_super(*relocated))
598  return alloc_arena(len);
599  substr out = alloc_arena(len);
600  substr curr = to_substr(m_arena);
601  if(curr.str != prev.str)
602  *relocated = _stack_relocate_to_new_arena(*relocated, prev, curr);
603  return out;
604  }

References c4::to_substr().

◆ _stack_start_parse()

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

Definition at line 58 of file event_handler_stack.hpp.

59  {
60  _RYML_CB_ASSERT(m_stack.m_callbacks, m_curr != nullptr);
61  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena != nullptr);
62  _RYML_CB_ASSERT(m_stack.m_callbacks, relocate_arena_data != nullptr);
63  m_curr->start_parse(filename, m_curr->node_id);
64  m_relocate_arena = relocate_arena;
65  m_relocate_arena_data = relocate_arena_data;
66  }
pfn_relocate_arena m_relocate_arena
callback when the arena gets relocated
void start_parse(const char *file, id_type node_id_)

◆ _stack_finish_parse()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_finish_parse ( )
inlineprotectedinherited

Definition at line 68 of file event_handler_stack.hpp.

69  {
70  }

◆ _stack_reset_root()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_reset_root ( )
inlineprotectedinherited

Definition at line 74 of file event_handler_stack.hpp.

75  {
76  m_stack.clear();
77  m_stack.push({});
78  m_parent = nullptr;
79  m_curr = &m_stack.top();
80  }

◆ _stack_reset_non_root()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_reset_non_root ( )
inlineprotectedinherited

Definition at line 82 of file event_handler_stack.hpp.

83  {
84  m_stack.clear();
85  m_stack.push({}); // parent
86  m_stack.push({}); // node
87  m_parent = &m_stack.top(1);
88  m_curr = &m_stack.top();
89  }

◆ _stack_push()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_push ( )
inlineprotectedinherited

Definition at line 91 of file event_handler_stack.hpp.

92  {
93  m_stack.push_top();
94  m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push
95  m_curr = &m_stack.top();
97  }

◆ _stack_pop()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_pop ( )
inlineprotectedinherited

Definition at line 99 of file event_handler_stack.hpp.

100  {
101  _RYML_CB_ASSERT(m_stack.m_callbacks, m_parent);
102  _RYML_CB_ASSERT(m_stack.m_callbacks, m_stack.size() > 1);
104  m_stack.pop();
105  m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr;
106  m_curr = &m_stack.top();
107  #ifdef RYML_DBG
108  if(m_parent)
109  _c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
110  else
111  _c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id);
112  #endif
113  }
void reset_before_pop(ParserState const &to_pop)

◆ _stack_should_push_on_begin_doc()

bool c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_should_push_on_begin_doc ( ) const
inlineprotectedinherited

Definition at line 120 of file event_handler_stack.hpp.

121  {
122  const bool is_root = (m_stack.size() == 1u);
123  return is_root && (_has_any_(DOC|VAL|MAP|SEQ) || m_curr->has_children);
124  }

◆ _stack_should_pop_on_end_doc()

bool c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_should_pop_on_end_doc ( ) const
inlineprotectedinherited

Definition at line 126 of file event_handler_stack.hpp.

127  {
128  const bool is_root = (m_stack.size() == 1u);
129  return !is_root && _has_any_(DOC);
130  }

◆ _stack_relocate_to_new_arena() [1/2]

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_relocate_to_new_arena ( csubstr  prev,
substr  curr 
)
inlineprotectedinherited

Definition at line 134 of file event_handler_stack.hpp.

135  {
136  for(state &st : m_stack)
137  {
138  if(st.line_contents.rem.is_sub(prev))
139  st.line_contents.rem = _stack_relocate_to_new_arena(st.line_contents.rem, prev, curr);
140  if(st.line_contents.full.is_sub(prev))
141  st.line_contents.full = _stack_relocate_to_new_arena(st.line_contents.full, prev, curr);
142  if(st.line_contents.stripped.is_sub(prev))
143  st.line_contents.stripped = _stack_relocate_to_new_arena(st.line_contents.stripped, prev, curr);
144  }
145  _RYML_CB_ASSERT(m_stack.m_callbacks, m_relocate_arena != nullptr);
146  _RYML_CB_ASSERT(m_stack.m_callbacks, m_relocate_arena_data != nullptr);
148  }

◆ _stack_relocate_to_new_arena() [2/2]

substr c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::_stack_relocate_to_new_arena ( csubstr  s,
csubstr  prev,
substr  curr 
)
inlineprotectedinherited

Definition at line 150 of file event_handler_stack.hpp.

151  {
152  _RYML_CB_ASSERT(m_stack.m_callbacks, prev.is_super(s));
153  auto pos = s.str - prev.str;
154  substr out = {curr.str + pos, s.len};
155  _RYML_CB_ASSERT(m_stack.m_callbacks, curr.is_super(out));
156  return out;
157  }

◆ check_trailing_doc_token()

void c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::check_trailing_doc_token ( ) const
inlineinherited

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

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

Definition at line 165 of file event_handler_stack.hpp.

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

Member Data Documentation

◆ m_stack

Definition at line 45 of file event_handler_stack.hpp.

◆ m_curr

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

Definition at line 46 of file event_handler_stack.hpp.

◆ m_parent

parent of the current stack level.

Definition at line 47 of file event_handler_stack.hpp.

◆ m_relocate_arena

callback when the arena gets relocated

Definition at line 48 of file event_handler_stack.hpp.

◆ m_relocate_arena_data

void* c4::yml::EventHandlerStack< EventHandlerYamlStd , EventHandlerYamlStdState >::m_relocate_arena_data
inherited

Definition at line 49 of file event_handler_stack.hpp.


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