rapidyaml 0.16.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
c4::yml::extra::EventHandlerInts Struct Reference

A parser event handler that creates a compact representation of the YAML tree in a contiguous buffer of integers. More...

#include <event_handler_ints.hpp>

Public Types

types
enum  { requires_strings_on_buffers = true }
using value_type = ievt::evt_bits
using state = EventHandlerIntsState

Public Member Functions

construction and resetting
 EventHandlerInts (c4::yml::Callbacks const &cb) noexcept
 EventHandlerInts () noexcept
void reset (substr str, substr arena, ievt::evt_bits *dst, evt_size dst_size)
evt_size required_size_events () const
 get the size needed for the event buffer from the previous parse
size_t required_size_arena () const
 get the size needed for the arena from the previous parse
bool fits_buffers () const
 Predicate to test if the event and arena buffers successfully accomodated all the parse events.
void reserve_arena (int)
TagDirectivestag_directives ()
TagCachetag_cache ()
parse events
void start_parse (const char *filename, substr src)
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 —)
void end_doc ()
 implicit doc end (without ...)
void begin_doc_expl ()
 explicit doc start, with —
void end_doc_expl ()
 explicit doc end, with ...
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, type_bits=FLOW_ML1)
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, type_bits=FLOW_ML1)
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.
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.
YAML scalar events
void set_key_scalar_plain_empty ()
void set_val_scalar_plain_empty ()
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_yaml (csubstr yaml_version)
void add_directive_tag (csubstr handle, csubstr prefix)
arena events
substr arena ()
substr arena_rem ()
substr alloc_arena (size_t len)
 this may fail, in which case an empty string is returned
implementation helpers
void _push ()
 push a new parent, add a child to the new parent, and set the child as the current node
void _pop ()
 end the current scope
template<c4::yml::type_bits bits>
void enable_ () noexcept
template<c4::yml::type_bits bits>
void disable_ () noexcept
template<c4::yml::type_bits bits>
bool has_any_ () const noexcept
evt_size _next (evt_size pos) const noexcept
evt_size _prev (evt_size pos) const noexcept
bool _is_sub_ (csubstr str) const noexcept
void _send_flag_only_ (ievt::evt_bits flags)
void _send_str_ (csubstr scalar, ievt::evt_bits flags)
void _mark_parent_with_children_ ()
csubstr _get_latest_empty_scalar () const
evt_size _find_last_bdoc (evt_size pos) const
evt_size _find_matching_open (ievt::evt_bits open, ievt::evt_bits close, evt_size pos) const
evt_size _extend_left_to_include_tag_and_or_anchor (evt_size pos) const

Public Attributes

detail::stack< statem_stack
statem_curr
 current stack level: top of the stack. cached here for easier access.
statem_parent
 parent of the current stack level.
substr m_src

Protected Member Functions

void _stack_start_parse (const char *filename, substr ymlsrc)
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

Detailed Description

A parser event handler that creates a compact representation of the YAML tree in a contiguous buffer of integers.

The integers are ievt::EventBits containing masks (to represent events), interleaved with offset+length (to represent strings in the source buffer).

For a description of the events, see Ints Event Handler

This handler must be initialized with the input source buffer, the output arena, and the output event buffer. This handler will not take ownership nor attempt to resize the output buffer. If the size required for the output buffer or arena are larger than their actual size, parsing goes all way to the end, determining the required buffer sizes without writing anything past the end of the respective buffer. After parsing is finished, the user must ensure that the buffer size was enough to accomodate all the data that needs to be written into it, or react accordingly (eg, throw an error, or resize the buffer then retry the parse).

A couple of functions will be helpful to do this. After parsing, EventHandlerInts::fits_buffers() must be used to verify that the output buffers were enough to accomodate the results. Then, EventHandlerInts::required_size_events() and EventHandlerInts::required_size_arena() can be used to retrieve to necessary information. To get an estimation of the number of events before parsing, see estimate_events_ints_size().

Typical code to parse YAML with this handler will look like this:

csubstr filename = ...;
substr src = ...;
// estimate the size required for the events buffer,
// overpredicting it to be safe.
int estimated_size = extra::estimate_events_ints_size(src);
// example with a vector
std::vector<int> evts;
// ensure we have a fighting chance to acommodate the events
evts.resize((size_t)estimated_size);
// arena to place scalars/tags that may have been extended after filtering
std::vector<char> arena;
arena.resize(src.len); // this is generally enough
// initialize the handler
handler.reset(src, arena, evts.data(), (int)evts.size());
// parse the YAML
parser.parse_in_place_ev(filename, src);
if(handler.fits_buffers()) // were the buffer sizes enough?
{
evts.resize((size_t)handler.required_size_events()); // trim the vector
...
}
else
{
// event size estimation underpredicted, or arena is too small!
// for the first case, open an issue at
// https://github.com/biojppm/rapidyaml/issues
error("buffer could not accomodate all the events");
// NOTE: see below for notes on doing a parse retry.
}
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
evt_size estimate_events_ints_size(csubstr src)
Read YAML source and, without undergoing a full parse, estimate the size of the integer buffer requir...
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2355
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2356
size_t len
the length of the substring
Definition substr.hpp:218
A parser event handler that creates a compact representation of the YAML tree in a contiguous buffer ...
evt_size required_size_events() const
get the size needed for the event buffer from the previous parse
bool fits_buffers() const
Predicate to test if the event and arena buffers successfully accomodated all the parse events.
void reset(substr str, substr arena, ievt::evt_bits *dst, evt_size dst_size)

The result of estimate_events_ints_size() (click to see more info) must be an overprediction: it overpredicts for every single case among the many hundreds covered in the unit tests. This is deliberate, and aims at ensuring that a retry parse is not needed. But conceivably, it may underpredict in some instances not found in the out tests. What to do then?

First, open an issue to allow the estimation to be improved! Second, there are two ways to handle this situation in code:

1) throw an error (as sketched above)

2) grow the buffer to the required size (see EventHandlerInts::required_size_events()), and then parse again

If your code must be able to handle any case including where the prediction undershoots before the estimate function is fixed (after you open the issue), that is, if you are considering a parse retry, there is something important that needs attention. The YAML source buffer is mutated in-place during the parse, and cannot be used to parse again. So if you want to retry, you need to keep a pristine copy of the source, and use it for the retry:

const std::string src = ...; // the YAML code to be parsed
std::string parsed_src = src; // this is where we will parse (filter during parsing)
std::vector<int> evts((size_t)estimated_size); // ensure we have a fighting change to acommodate the events
std::vector<char> arena(src.size()); // ensure we have a fighting change to acommodate the events
handler.reset(to_substr(parsed_src), to_substr(arena), evts.data(), (int)evts.size());
parser.parse_in_place_ev(filename, to_substr(parsed_src));
if(handler.fits_buffers()) // were the buffer sizes enough?
{
evts.resize((size_t)handler.required_size()); // trim the vector
...
}
else
{
evts.resize((size_t)handler.required_size_events()); // buffer size was not enough.
arena.resize(handler.required_size_arena()); // buffer size was not enough.
// copy again
parsed_src = src;
// retry parse
handler.reset(to_substr(parsed_src), to_substr(arena), evts.data(), (int)evts.size());
parser.parse_in_place_ev(filename, to_substr(parsed_src));
assert((size_t)handler.fits_buffers()); // must always be true
}
substr to_substr(char(&s)[N]) noexcept
Definition substr.hpp:2376
size_t size() const noexcept
Definition substr.hpp:358
C * data() noexcept
Definition substr.hpp:366
size_t required_size_arena() const
get the size needed for the arena from the previous parse

When bringing this to other programming languages, the semantics will be very similar to this.

Definition at line 460 of file event_handler_ints.hpp.

Member Typedef Documentation

◆ value_type

◆ state

using c4::yml::extra::EventHandlerInts::state = EventHandlerIntsState

Definition at line 467 of file event_handler_ints.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
requires_strings_on_buffers 

Definition at line 468 of file event_handler_ints.hpp.

Constructor & Destructor Documentation

◆ EventHandlerInts() [1/2]

c4::yml::extra::EventHandlerInts::EventHandlerInts ( c4::yml::Callbacks const & cb)
inlinenoexcept

◆ EventHandlerInts() [2/2]

c4::yml::extra::EventHandlerInts::EventHandlerInts ( )
inlinenoexcept

Definition at line 501 of file event_handler_ints.hpp.

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

Member Function Documentation

◆ reset()

void c4::yml::extra::EventHandlerInts::reset ( substr str,
substr arena,
ievt::evt_bits * dst,
evt_size dst_size )
inline

Definition at line 506 of file event_handler_ints.hpp.

507 {
510 m_curr->evt_type = {};
511 m_curr->evt_id = 0;
512 m_arena = arena;
513 m_arena_pos = 0;
514 m_src = str;
515 m_evt = dst;
516 m_evt_size = dst_size;
517 m_evt_pos = 0;
518 m_evt_prev = 0;
519 m_curr_doc = 0;
520 m_tag_directives.clear();
521 m_tag_cache.clear();
522 }
@ RTOP
reading at top level
@ RUNK
reading unknown state (when starting): must determine whether scalar, map or seq

Referenced by EventHandlerInts().

◆ required_size_events()

evt_size c4::yml::extra::EventHandlerInts::required_size_events ( ) const
inline

get the size needed for the event buffer from the previous parse

Warning
this is valid only until the next parse

Definition at line 526 of file event_handler_ints.hpp.

527 {
528 return m_evt_pos;
529 }

Referenced by IntsResult::resize_buffers().

◆ required_size_arena()

size_t c4::yml::extra::EventHandlerInts::required_size_arena ( ) const
inline

get the size needed for the arena from the previous parse

Warning
this is valid only until the next parse

Definition at line 533 of file event_handler_ints.hpp.

534 {
535 return m_arena_pos;
536 }

Referenced by IntsResult::resize_buffers().

◆ fits_buffers()

bool c4::yml::extra::EventHandlerInts::fits_buffers ( ) const
inline

Predicate to test if the event and arena buffers successfully accomodated all the parse events.

Warning
this is valid only until the next parse

Definition at line 542 of file event_handler_ints.hpp.

543 {
544 return m_evt_pos <= m_evt_size && m_arena_pos <= m_arena.len;
545 }

◆ reserve_arena()

void c4::yml::extra::EventHandlerInts::reserve_arena ( int )
inline

Definition at line 547 of file event_handler_ints.hpp.

548 {
549 // does not apply here
550 }

◆ tag_directives()

TagDirectives & c4::yml::extra::EventHandlerInts::tag_directives ( )
inline

Definition at line 552 of file event_handler_ints.hpp.

552{ return m_tag_directives; }

◆ tag_cache()

TagCache & c4::yml::extra::EventHandlerInts::tag_cache ( )
inline

Definition at line 553 of file event_handler_ints.hpp.

553{ return m_tag_cache; }

◆ start_parse()

void c4::yml::extra::EventHandlerInts::start_parse ( const char * filename,
substr src )
inline

Definition at line 562 of file event_handler_ints.hpp.

563 {
564 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, src.str == m_src.str);
565 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, src.len == m_src.len);
566 this->_stack_start_parse(filename, src);
567 }

◆ finish_parse()

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

◆ cancel_parse()

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

Definition at line 574 of file event_handler_ints.hpp.

575 {
576 while(m_stack.size() > 1)
577 _pop();
578 }

◆ begin_stream()

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

Definition at line 587 of file event_handler_ints.hpp.

588 {
590 }
@ BSTR
begin stream (+STR in test suite events)
void _send_flag_only_(ievt::evt_bits flags)

◆ end_stream()

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

Definition at line 592 of file event_handler_ints.hpp.

593 {
595 }
@ ESTR
end stream (-STR in test suite events)

◆ begin_doc()

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

implicit doc start (without —)

Definition at line 605 of file event_handler_ints.hpp.

606 {
607 _c4dbgpf("{}/{}: begin_doc", m_evt_pos, m_evt_size);
610 {
611 _c4dbgp("push!");
612 _push();
613 ryml_enable_(DOC);
614 }
615 }
@ DOC
a document
Definition node_type.hpp:37
@ BDOC
begin doc (+DOC in test suite events)
void _push()
push a new parent, add a child to the new parent, and set the child as the current node

◆ end_doc()

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

implicit doc end (without ...)

Definition at line 617 of file event_handler_ints.hpp.

618 {
619 _c4dbgpf("{}/{}: end_doc", m_evt_pos, m_evt_size);
622 {
623 _c4dbgp("pop!");
624 _pop();
625 }
626 ++m_curr_doc;
627 }
@ EDOC
end doc (-DOC in test suite events)

◆ begin_doc_expl()

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

explicit doc start, with —

Definition at line 630 of file event_handler_ints.hpp.

631 {
632 _c4dbgpf("{}/{}: begin_doc_expl", m_evt_pos, m_evt_size);
634 _c4dbgp("push!");
635 _push();
636 ryml_enable_(DOC);
637 }
@ EXPL
--- (with BDOC) or ... (with EDOC)

◆ end_doc_expl()

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

explicit doc end, with ...

Definition at line 639 of file event_handler_ints.hpp.

640 {
641 _c4dbgpf("{}/{}: end_doc_expl", m_evt_pos, m_evt_size);
644 {
645 _c4dbgp("pop!");
646 _pop();
647 }
648 ++m_curr_doc;
649 }

◆ begin_map_key_flow()

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

Definition at line 658 of file event_handler_ints.hpp.

659 {
660 _c4dbgpf("{}/{}: bmap key flow", m_evt_pos, m_evt_size);
664 _push();
665 }
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition node_type.hpp:35
@ KEY
the scalar to the left of : in a map's member
Definition node_type.hpp:33
@ FLOW_SL
mark container with single-line flow style
Definition node_type.hpp:56
@ BMAP
begin map (+MAP in test suite events)
@ FLOW
container: flow: [] for seqs or {} for maps

◆ begin_map_key_block()

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

Definition at line 666 of file event_handler_ints.hpp.

667 {
668 _c4dbgpf("{}/{}: bmap key block", m_evt_pos, m_evt_size);
672 _push();
673 }
@ BLOCK
mark container with block style

◆ begin_map_val_flow()

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

Definition at line 675 of file event_handler_ints.hpp.

676 {
677 _c4dbgpf("{}/{}: bmap flow", m_evt_pos, m_evt_size);
680 ryml_enable_(c4::yml::MAP|c4::yml::FLOW_SL);
681 _push();
682 }

◆ begin_map_val_block()

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

Definition at line 683 of file event_handler_ints.hpp.

684 {
685 _c4dbgpf("{}/{}: bmap block", m_evt_pos, m_evt_size);
688 ryml_enable_(c4::yml::MAP|c4::yml::BLOCK);
689 _push();
690 }

◆ end_map_block()

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

Definition at line 692 of file event_handler_ints.hpp.

693 {
694 _pop();
696 }
@ EMAP
end map (-MAP in test suite events)

◆ end_map_flow()

void c4::yml::extra::EventHandlerInts::end_map_flow ( bool ,
type_bits = FLOW_ML1 )
inline

Definition at line 698 of file event_handler_ints.hpp.

699 {
700 _pop();
702 }

◆ begin_seq_key_flow()

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

Definition at line 711 of file event_handler_ints.hpp.

712 {
713 _c4dbgpf("{}/{}: bseq key flow", m_evt_pos, m_evt_size);
717 _push();
718 }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition node_type.hpp:36
@ BSEQ
begin seq (+SEQ in test suite events)

◆ begin_seq_key_block()

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

Definition at line 719 of file event_handler_ints.hpp.

720 {
721 _c4dbgpf("{}/{}: bseq key block", m_evt_pos, m_evt_size);
725 _push();
726 }

◆ begin_seq_val_flow()

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

Definition at line 728 of file event_handler_ints.hpp.

729 {
730 _c4dbgpf("{}/{}: bseq flow", m_evt_pos, m_evt_size);
733 ryml_enable_(c4::yml::SEQ|c4::yml::FLOW_SL);
734 _push();
735 }

◆ begin_seq_val_block()

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

Definition at line 736 of file event_handler_ints.hpp.

737 {
738 _c4dbgpf("{}/{}: bseq block", m_evt_pos, m_evt_size);
741 ryml_enable_(c4::yml::SEQ|c4::yml::BLOCK);
742 _push();
743 }

◆ end_seq_block()

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

Definition at line 745 of file event_handler_ints.hpp.

746 {
747 _pop();
749 }
@ ESEQ
end seq (-SEQ in test suite events)

◆ end_seq_flow()

void c4::yml::extra::EventHandlerInts::end_seq_flow ( bool ,
type_bits = FLOW_ML1 )
inline

Definition at line 751 of file event_handler_ints.hpp.

752 {
753 _pop();
755 }

◆ add_sibling()

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

Definition at line 764 of file event_handler_ints.hpp.

765 {
766 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_parent);
767 m_curr->evt_type = {};
768 }

◆ set_key_scalar_plain_empty()

void c4::yml::extra::EventHandlerInts::set_key_scalar_plain_empty ( )
inline

Definition at line 778 of file event_handler_ints.hpp.

779 {
780 _c4dbgpf("{}/{}: set_key_scalar_plain_empty", m_evt_pos, m_evt_size);
783 }
@ KEY_PLAIN
mark key scalar as plain scalar (unquoted, even when multiline)
@ KEYNIL
the key is null (eg { : b} results in a null key)
Definition node_type.hpp:45
@ SCLR
scalar (=VAL in test suite events)
void _send_str_(csubstr scalar, ievt::evt_bits flags)

◆ set_val_scalar_plain_empty()

void c4::yml::extra::EventHandlerInts::set_val_scalar_plain_empty ( )
inline

Definition at line 784 of file event_handler_ints.hpp.

785 {
786 _c4dbgpf("{}/{}: set_val_scalar_plain_empty", m_evt_pos, m_evt_size);
789 }
@ VALNIL
the val is null (eg {a : } results in a null val)
Definition node_type.hpp:46
@ 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
@ VAL_PLAIN
mark val scalar as plain scalar (unquoted, even when multiline)

◆ set_key_scalar_plain()

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

Definition at line 792 of file event_handler_ints.hpp.

793 {
794 _c4dbgpf("{}/{}: set_key_scalar_plain: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
796 ryml_enable_(c4::yml::KEY|c4::yml::KEY_PLAIN);
797 }

◆ set_val_scalar_plain()

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

Definition at line 798 of file event_handler_ints.hpp.

799 {
800 _c4dbgpf("{}/{}: set_val_scalar_plain: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
802 ryml_enable_(c4::yml::VAL|c4::yml::VAL_PLAIN);
803 }

◆ set_key_scalar_dquoted()

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

Definition at line 806 of file event_handler_ints.hpp.

807 {
808 _c4dbgpf("{}/{}: set_key_scalar_dquo: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str?size_t(scalar.str-m_src.str):m_src.len, scalar.len, scalar.str?scalar:csubstr{});
810 ryml_enable_(c4::yml::KEY|c4::yml::KEY_DQUO);
811 }
@ KEY_DQUO
mark key scalar as double quoted "
@ DQUO
scalar: double-quoted ("")

◆ set_val_scalar_dquoted()

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

Definition at line 812 of file event_handler_ints.hpp.

813 {
814 _c4dbgpf("{}/{}: set_val_scalar_dquo: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str?size_t(scalar.str-m_src.str):m_src.len, scalar.len, scalar.str?scalar:csubstr{});
816 ryml_enable_(c4::yml::VAL|c4::yml::VAL_DQUO);
817 }
@ VAL_DQUO
mark val scalar as double quoted "

◆ set_key_scalar_squoted()

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

Definition at line 820 of file event_handler_ints.hpp.

821 {
822 _c4dbgpf("{}/{}: set_key_scalar_squo: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
824 ryml_enable_(c4::yml::KEY|c4::yml::KEY_SQUO);
825 }
@ KEY_SQUO
mark key scalar as single quoted '
@ SQUO
scalar: single-quoted (')

◆ set_val_scalar_squoted()

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

Definition at line 826 of file event_handler_ints.hpp.

827 {
828 _c4dbgpf("{}/{}: set_val_scalar_squo: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
830 ryml_enable_(c4::yml::VAL|c4::yml::VAL_SQUO);
831 }
@ VAL_SQUO
mark val scalar as single quoted '

◆ set_key_scalar_literal()

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

Definition at line 834 of file event_handler_ints.hpp.

835 {
836 _c4dbgpf("{}/{}: set_key_scalar_literal: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str?size_t(scalar.str-m_src.str):m_src.len, scalar.len, scalar.str?scalar:csubstr{});
839 }
@ KEY_LITERAL
mark key scalar as multiline, block literal |
@ LITL
scalar: block literal (|)

◆ set_val_scalar_literal()

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

Definition at line 840 of file event_handler_ints.hpp.

841 {
842 _c4dbgpf("{}/{}: set_val_scalar_literal: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str?size_t(scalar.str-m_src.str):m_src.len, scalar.len, scalar.str?scalar:csubstr{});
845 }
@ VAL_LITERAL
mark val scalar as multiline, block literal |

◆ set_key_scalar_folded()

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

Definition at line 848 of file event_handler_ints.hpp.

849 {
850 _c4dbgpf("{}/{}: set_key_scalar_folded: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str?size_t(scalar.str-m_src.str):m_src.len, scalar.len, scalar.str?scalar:csubstr{});
852 ryml_enable_(c4::yml::KEY|c4::yml::KEY_FOLDED);
853 }
@ KEY_FOLDED
mark key scalar as multiline, block folded >
@ FOLD
scalar: block folded (>)

◆ set_val_scalar_folded()

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

Definition at line 854 of file event_handler_ints.hpp.

855 {
856 _c4dbgpf("{}/{}: set_val_scalar_folded: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str?size_t(scalar.str-m_src.str):m_src.len, scalar.len, scalar.str?scalar:csubstr{});
858 ryml_enable_(c4::yml::VAL|c4::yml::VAL_FOLDED);
859 }
@ VAL_FOLDED
mark val scalar as multiline, block folded >

◆ mark_key_scalar_unfiltered()

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

Definition at line 862 of file event_handler_ints.hpp.

863 {
864 _c4dbgpf("{}/{}: mark_key_scalar_unfiltered", m_evt_pos, m_evt_size);
865 if(m_evt_pos < m_evt_size)
866 m_evt[m_evt_pos] |= ievt::UNFILT;
867 }
@ UNFILT
Special flag to mark a scalar as unfiltered (when the parser is set not to filter).

◆ mark_val_scalar_unfiltered()

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

Definition at line 868 of file event_handler_ints.hpp.

869 {
870 _c4dbgpf("{}/{}: mark_val_scalar_unfiltered", m_evt_pos, m_evt_size);
871 if(m_evt_pos < m_evt_size)
872 m_evt[m_evt_pos] |= ievt::UNFILT;
873 }

◆ set_key_anchor()

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

Definition at line 904 of file event_handler_ints.hpp.

905 {
906 _c4dbgpf("{}/{}: set_key_anchor: {}", m_evt_pos, m_evt_size, anchor);
907 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_has_any_(KEYREF));
908 ryml_enable_(c4::yml::KEYANCH);
909 if(m_evt_pos + 3 < m_evt_size)
910 {
911 m_evt[m_evt_pos] |= ievt::KEY_|ievt::ANCH;
912 _add_scalar_(m_evt_pos, anchor);
913 }
914 m_evt_prev = m_evt_pos;
915 m_evt_pos += 3;
916 }
#define ryml_has_any_(bits)
@ KEYREF
a *reference: the key references an &anchor
Definition node_type.hpp:39
@ KEYANCH
the key has an &anchor
Definition node_type.hpp:41

◆ set_val_anchor()

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

Definition at line 917 of file event_handler_ints.hpp.

918 {
919 _c4dbgpf("{}/{}: set_val_anchor: {}", m_evt_pos, m_evt_size, anchor);
920 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_has_any_(VALREF));
921 ryml_enable_(c4::yml::VALANCH);
922 if(m_evt_pos + 3 < m_evt_size)
923 {
924 m_evt[m_evt_pos] |= ievt::VAL_|ievt::ANCH;
925 _add_scalar_(m_evt_pos, anchor);
926 }
927 m_evt_prev = m_evt_pos;
928 m_evt_pos += 3;
929 }
@ VALANCH
the val has an &anchor
Definition node_type.hpp:42
@ VALREF
a *reference: the val references an &anchor
Definition node_type.hpp:40

◆ set_key_ref()

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

Definition at line 931 of file event_handler_ints.hpp.

932 {
933 _c4dbgpf("{}/{}: set_key_ref: {}", m_evt_pos, m_evt_size, ref);
934 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, ref.begins_with('*'), m_curr->pos);
935 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, !ryml_has_any_(KEYANCH), m_curr->pos);
936 ryml_enable_(c4::yml::KEY|c4::yml::KEYREF);
937 _send_str_(ref.sub(1), ievt::KEY_|ievt::ALIA); // skip the leading *
938 }

◆ set_val_ref()

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

Definition at line 939 of file event_handler_ints.hpp.

940 {
941 _c4dbgpf("{}/{}: set_val_ref: {}", m_evt_pos, m_evt_size, ref);
942 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, ref.begins_with('*'), m_curr->pos);
943 RYML_ASSERT_PARSE_CB_(m_stack.m_callbacks, !ryml_has_any_(VALANCH), m_curr->pos);
944 ryml_enable_(c4::yml::VAL|c4::yml::VALREF);
945 _send_str_(ref.sub(1), ievt::VAL_|ievt::ALIA); // skip the leading *
946 }

◆ set_key_tag()

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

Definition at line 955 of file event_handler_ints.hpp.

956 {
957 _c4dbgpf("{}/{}: set key tag [{}]~~~{}~~~", m_evt_pos, m_evt_size, tag.len, tag.str ? tag : csubstr("(arena full)"));
958 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, _is_sub_(tag));
959 ryml_enable_(c4::yml::KEYTAG);
961 }
@ KEYTAG
the key has a tag
Definition node_type.hpp:43
bool _is_sub_(csubstr str) const noexcept

◆ set_val_tag()

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

Definition at line 962 of file event_handler_ints.hpp.

963 {
964 _c4dbgpf("{}/{}: set val tag [{}]~~~{}~~~", m_evt_pos, m_evt_size, tag.len, tag.str ? tag : csubstr("(arena full)"));
965 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, _is_sub_(tag));
966 ryml_enable_(c4::yml::VALTAG);
968 }
@ VALTAG
the val has a tag
Definition node_type.hpp:44

◆ add_directive_yaml()

void c4::yml::extra::EventHandlerInts::add_directive_yaml ( csubstr yaml_version)
inline

Definition at line 977 of file event_handler_ints.hpp.

978 {
979 _c4dbgpf("{}/{}: %YAML directive! version={}", m_evt_pos, m_evt_size, yaml_version);
980 _send_str_(yaml_version, ievt::YAML);
981 }
@ YAML
yaml directive: \YAML <version>

◆ add_directive_tag()

void c4::yml::extra::EventHandlerInts::add_directive_tag ( csubstr handle,
csubstr prefix )
inline

Definition at line 983 of file event_handler_ints.hpp.

984 {
985 _c4dbgpf("{}/{}: %TAG directive! handle={} prefix={} doc_id={}", m_evt_pos, m_evt_size, handle, prefix, m_curr_doc);
986 if C4_UNLIKELY(!m_tag_directives.add(handle, prefix, m_curr_doc))
987 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "too many %TAG directives");
988 _send_str_(handle, ievt::TAGH);
989 _send_str_(prefix, ievt::TAGP);
990 }
@ TAGH
tag directive, handle: \TAG <handle> ........
@ TAGP
tag directive, prefix: \TAG ........ <prefix>

◆ actually_val_is_first_key_of_new_map_flow()

void c4::yml::extra::EventHandlerInts::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 1004 of file event_handler_ints.hpp.

1005 {
1006 _c4dbgpf("{}/{}: prev={} actually_val_is_first_key_of_new_map_flow", m_evt_pos, m_evt_size, m_evt_prev);
1007 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_evt_pos > 2);
1008 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_evt_prev > 0);
1009 // BEFORE
1010 // ... flag start len (free)
1011 // | |
1012 // prev curr
1013 // AFTER
1014 // ... BMAP flag start len (free)
1015 // | |
1016 // prev curr
1017 if(m_evt_pos < m_evt_size)
1018 {
1019 if(m_evt[m_evt_prev] & ievt::WSTR)
1020 {
1021 _c4dbgpf("{}/{}: WSTR", m_evt_pos, m_evt_size);
1022 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_evt_prev > 0);
1024 if(m_evt_pos + 1 < m_evt_size)
1025 {
1026 for(evt_size i = pos; i <= m_evt_prev; i = _next(i))
1027 {
1028 m_evt[i] |= ievt::KEY_;
1029 m_evt[i] &= ~ievt::VAL_;
1030 }
1031 evt_size num_move = m_evt_pos + 1 - pos;
1032 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, num_move > 0);
1033 memmove(m_evt + pos + 1, m_evt + pos, (size_t)num_move * sizeof(ievt::evt_bits));
1034 }
1035 m_evt[pos] = ievt::BMAP|ievt::FLOW|ievt::VAL_;
1036 // move PSTR to prev
1037 if(m_evt[pos + 1] & ievt::PSTR)
1038 {
1039 m_evt[pos ] |= ievt::PSTR;
1040 m_evt[pos + 1] &= ~ievt::PSTR;
1041 }
1042 }
1043 else
1044 {
1045 _c4dbgpf("{}/{}: container key", m_evt_pos, m_evt_size);
1046 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[m_evt_prev] & (ievt::EMAP|ievt::ESEQ)));
1047 evt_size pos;
1048 _c4dbgpf("{}/{}: find matching open for {}", m_evt_pos, m_evt_size, m_evt_prev);
1049 if((m_evt[m_evt_prev] & ievt::EMAP) == ievt::EMAP)
1050 {
1051 pos = _find_matching_open(ievt::BMAP, ievt::EMAP, m_evt_prev);
1052 }
1053 else
1054 {
1055 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[m_evt_prev] & ievt::ESEQ));
1056 pos = _find_matching_open(ievt::BSEQ, ievt::ESEQ, m_evt_prev);
1057 }
1058 _c4dbgpf("{}/{}: matching open for {}={}", m_evt_pos, m_evt_size, m_evt_prev, pos);
1059 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, pos >= 0); // internal error
1060 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_prev); // internal error
1061 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & ievt::ESEQ) == (m_evt[m_evt_prev] & ievt::BSEQ));
1062 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & ievt::EMAP) == (m_evt[m_evt_prev] & ievt::BMAP));
1063 // shift the array one position to the right, starting at pos
1064 evt_size posp1 = pos + 1;
1065 if(m_evt_pos + 1 < m_evt_size)
1066 {
1067 evt_size num_move = m_evt_pos + 1 - pos;
1068 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, num_move > 0);
1069 memmove(m_evt + posp1, m_evt + pos, (size_t)num_move * sizeof(ievt::evt_bits));
1070 }
1071 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, posp1 < m_evt_pos);
1072 // start the map
1073 m_evt[pos] = ievt::BMAP|ievt::FLOW|ievt::VAL_;
1074 // set next as key, not val
1075 m_evt[posp1] |= ievt::KEY_;
1076 m_evt[posp1] &= ~ievt::VAL_;
1077 // move PSTR to pos
1078 if(m_evt[posp1] & ievt::PSTR)
1079 {
1080 m_evt[pos] |= ievt::PSTR;
1081 m_evt[posp1] &= ~ievt::PSTR;
1082 }
1083 }
1084 }
1085 m_curr->evt_id = m_evt_pos - 2;
1086 ++m_evt_prev;
1087 ++m_evt_pos;
1088 ryml_enable_(c4::yml::MAP|c4::yml::FLOW_SL);
1089 _push();
1090 }
int32_t evt_size
data type for integer events size.
int32_t evt_bits
data type for integer events bits.
@ PSTR
Special flag to enable look-back in the event array. It signifies that the previous event has a strin...
@ WSTR
WithSTRing: mask of all events that encode a string following the event. For such events,...
evt_size _extend_left_to_include_tag_and_or_anchor(evt_size pos) const
evt_size _find_matching_open(ievt::evt_bits open, ievt::evt_bits close, evt_size pos) const
evt_size _next(evt_size pos) const noexcept

◆ actually_val_is_first_key_of_new_map_block()

void c4::yml::extra::EventHandlerInts::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 1098 of file event_handler_ints.hpp.

1099 {
1100 _c4dbgpf("{}/{}: prev={} actually_val_is_first_key_of_new_map_block", m_evt_pos, m_evt_size, m_evt_prev);
1101 if(m_evt_pos < m_evt_size)
1102 {
1103 // interpolate BMAP|VAL|BLCK after the last BDOC
1104 evt_size pos = _find_last_bdoc(m_evt_pos);
1105 if(pos >= 0)
1106 {
1107 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1108 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_pos);
1109 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & ievt::BDOC) == ievt::BDOC);
1110 if(m_evt_pos < m_evt_size)
1111 {
1112 ++pos; // add 1 to write after BDOC
1113 evt_size num_move = m_evt_pos - pos;
1114 evt_size posp1 = pos + 1;
1115 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, ((m_evt[pos] & ievt::BSEQ) == ievt::BSEQ) || ((m_evt[pos] & ievt::BMAP) == ievt::BMAP));
1116 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, num_move > 0);
1117 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, 0 == (m_evt[posp1] & ievt::PSTR));
1118 memmove(m_evt + posp1, m_evt + pos, (size_t)num_move * sizeof(ievt::evt_bits));
1119 m_evt[pos] = ievt::VAL_|ievt::BMAP|ievt::BLCK;
1120 m_evt[posp1] &= ~ievt::VAL_;
1121 m_evt[posp1] |= ievt::KEY_;
1122 }
1123 }
1124 }
1125 ++m_curr->evt_id;
1126 ++m_evt_prev;
1127 ++m_evt_pos;
1128 _push();
1129 }
evt_size _find_last_bdoc(evt_size pos) const

◆ arena()

substr c4::yml::extra::EventHandlerInts::arena ( )
inline

Definition at line 1138 of file event_handler_ints.hpp.

1139 {
1140 return m_arena.first(m_arena_pos < m_arena.len ? m_arena_pos : m_arena.len);
1141 }

Referenced by reset().

◆ arena_rem()

substr c4::yml::extra::EventHandlerInts::arena_rem ( )
inline

Definition at line 1142 of file event_handler_ints.hpp.

1143 {
1144 return C4_EXPECT(m_arena_pos <= m_arena.len, 1) ? m_arena.sub(m_arena_pos) : m_arena.last(0);
1145 }

Referenced by alloc_arena().

◆ alloc_arena()

substr c4::yml::extra::EventHandlerInts::alloc_arena ( size_t len)
inline

this may fail, in which case an empty string is returned

Definition at line 1147 of file event_handler_ints.hpp.

1148 {
1149 substr s = arena_rem();
1150 if C4_LIKELY(len <= s.len)
1151 s.len = len;
1152 else
1153 s.str = nullptr;
1154 m_arena_pos += len;
1155 return s;
1156 }

◆ _push()

void c4::yml::extra::EventHandlerInts::_push ( )
inline

◆ _pop()

void c4::yml::extra::EventHandlerInts::_pop ( )
inline

◆ enable_()

template<c4::yml::type_bits bits>
void c4::yml::extra::EventHandlerInts::enable_ ( )
inlinenoexcept

Definition at line 1179 of file event_handler_ints.hpp.

1180 {
1181 m_curr->evt_type |= bits;
1182 }

◆ disable_()

template<c4::yml::type_bits bits>
void c4::yml::extra::EventHandlerInts::disable_ ( )
inlinenoexcept

Definition at line 1183 of file event_handler_ints.hpp.

1184 {
1185 m_curr->evt_type &= ~bits;
1186 }

◆ has_any_()

template<c4::yml::type_bits bits>
bool c4::yml::extra::EventHandlerInts::has_any_ ( ) const
inlinenoexcept

Definition at line 1187 of file event_handler_ints.hpp.

1188 {
1189 return (m_curr->evt_type & bits) != c4::yml::type_bits(0);
1190 }
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition node_type.hpp:26

◆ _next()

evt_size c4::yml::extra::EventHandlerInts::_next ( evt_size pos) const
inlinenoexcept

Definition at line 1192 of file event_handler_ints.hpp.

1193 {
1194 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1195 return pos + ((m_evt[pos] & ievt::WSTR) ? 3 : 1);
1196 }

Referenced by actually_val_is_first_key_of_new_map_flow().

◆ _prev()

evt_size c4::yml::extra::EventHandlerInts::_prev ( evt_size pos) const
inlinenoexcept

Definition at line 1198 of file event_handler_ints.hpp.

1199 {
1200 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1201 return pos - ((m_evt[pos] & ievt::PSTR) ? 3 : 1);
1202 }

Referenced by _extend_left_to_include_tag_and_or_anchor(), and _find_matching_open().

◆ _is_sub_()

bool c4::yml::extra::EventHandlerInts::_is_sub_ ( csubstr str) const
inlinenoexcept

Definition at line 1204 of file event_handler_ints.hpp.

1205 {
1206 return (!str.str || str.is_sub(m_src) || str.is_sub(m_arena));
1207 }

Referenced by set_key_tag(), and set_val_tag().

◆ _send_flag_only_()

void c4::yml::extra::EventHandlerInts::_send_flag_only_ ( ievt::evt_bits flags)
inline

Definition at line 1209 of file event_handler_ints.hpp.

1210 {
1211 _c4dbgpf("{}/{}: flag only", m_evt_pos, m_evt_size);
1212 if(m_evt_pos < m_evt_size)
1213 m_evt[m_evt_pos] |= flags;
1214 m_curr->evt_id = m_evt_pos;
1215 m_evt_prev = m_evt_pos;
1216 ++m_evt_pos;
1217 if(m_evt_pos < m_evt_size)
1218 m_evt[m_evt_pos] = {};
1219 }

Referenced by begin_doc(), begin_doc_expl(), begin_map_key_block(), begin_map_key_flow(), begin_map_val_block(), begin_map_val_flow(), begin_seq_key_block(), begin_seq_key_flow(), begin_seq_val_block(), begin_seq_val_flow(), begin_stream(), end_doc(), end_doc_expl(), end_map_block(), end_map_flow(), end_seq_block(), end_seq_flow(), and end_stream().

◆ _send_str_()

void c4::yml::extra::EventHandlerInts::_send_str_ ( csubstr scalar,
ievt::evt_bits flags )
inline

Definition at line 1221 of file event_handler_ints.hpp.

1222 {
1223 _c4dbgpf("{}/{}: send str", m_evt_pos, m_evt_size);
1224 if(m_evt_pos + 3 < m_evt_size)
1225 {
1226 m_evt[m_evt_pos] |= flags;
1227 _add_scalar_(m_evt_pos, scalar);
1228 }
1229 m_curr->evt_id = m_evt_pos;
1230 m_evt_prev = m_evt_pos;
1231 m_evt_pos += 3;
1232 }

Referenced by add_directive_tag(), add_directive_yaml(), set_key_ref(), set_key_scalar_dquoted(), set_key_scalar_folded(), set_key_scalar_literal(), set_key_scalar_plain(), set_key_scalar_plain_empty(), set_key_scalar_squoted(), set_key_tag(), set_val_ref(), set_val_scalar_dquoted(), set_val_scalar_folded(), set_val_scalar_literal(), set_val_scalar_plain(), set_val_scalar_plain_empty(), set_val_scalar_squoted(), and set_val_tag().

◆ _mark_parent_with_children_()

void c4::yml::extra::EventHandlerInts::_mark_parent_with_children_ ( )
inline

◆ _get_latest_empty_scalar()

csubstr c4::yml::extra::EventHandlerInts::_get_latest_empty_scalar ( ) const
inline

Definition at line 1240 of file event_handler_ints.hpp.

1241 {
1242 // ideally we should search back in the latest event that has
1243 // a scalar, then select a zero-length scalar immediately
1244 // after that scalar. But this also works for now:
1245 return m_src.first(0);
1246 }

Referenced by set_key_scalar_plain_empty(), and set_val_scalar_plain_empty().

◆ _find_last_bdoc()

evt_size c4::yml::extra::EventHandlerInts::_find_last_bdoc ( evt_size pos) const
inline

Definition at line 1248 of file event_handler_ints.hpp.

1249 {
1250 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size); // it's safe to read from the array
1251 while(pos >= 0)
1252 {
1253 ievt::evt_bits e = m_evt[pos];
1254 if((e & ievt::BDOC) == ievt::BDOC)
1255 return pos;
1256 pos -= (e & ievt::PSTR) ? 3 : 1;
1257 }
1258 return -1; // LCOV_EXCL_LINE
1259 }

Referenced by actually_val_is_first_key_of_new_map_block().

◆ _find_matching_open()

evt_size c4::yml::extra::EventHandlerInts::_find_matching_open ( ievt::evt_bits open,
ievt::evt_bits close,
evt_size pos ) const
inline

Definition at line 1261 of file event_handler_ints.hpp.

1262 {
1263 _c4dbgpf("find_matching: start at {}", pos);
1264 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1265 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & close) == close);
1266 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & open) == (close & ~ievt::END_));
1267 pos = _prev(pos); // don't count the starting close token
1268 uint32_t count = 0;
1269 while(pos >= 0)
1270 {
1271 ievt::evt_bits e = m_evt[pos];
1272 _c4dbgpf("find_matching: pos={} count={} e={}", pos, count, m_evt[pos]);
1273 if((e & close) == close)
1274 {
1275 _c4dbgpf(".............: pos={} close! count={} e={}", pos, count, m_evt[pos]);
1276 ++count;
1277 }
1278 else if((e & open) == open)
1279 {
1280 _c4dbgpf(".............: pos={} open! count={} e={}", pos, count, m_evt[pos]);
1281 if(!count)
1282 return pos;
1283 else
1284 --count;
1285 }
1286 pos = _prev(pos);
1287 }
1288 _c4dbgpf("find_matching: not found!", 0); // LCOV_EXCL_LINE
1289 return -1; // LCOV_EXCL_LINE
1290 }
evt_size _prev(evt_size pos) const noexcept

Referenced by actually_val_is_first_key_of_new_map_flow().

◆ _extend_left_to_include_tag_and_or_anchor()

evt_size c4::yml::extra::EventHandlerInts::_extend_left_to_include_tag_and_or_anchor ( evt_size pos) const
inline

Definition at line 1292 of file event_handler_ints.hpp.

1293 {
1294 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1295 evt_size prev = _prev(pos);
1296 while((prev > 0) && (m_evt[prev] & (ievt::TAG_|ievt::ANCH)))
1297 {
1298 _c4dbgpf("{}/{}: {} is anchor/tag. extend to {}", m_evt_pos, m_evt_size, prev, prev);
1299 pos = prev;
1300 prev = _prev(prev);
1301 }
1302 return pos;
1303 }

Referenced by actually_val_is_first_key_of_new_map_flow().

◆ _stack_start_parse()

void c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_start_parse ( const char * filename,
substr ymlsrc )
inlineprotectedinherited

Definition at line 58 of file event_handler_stack.hpp.

59 {
60 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_curr != nullptr);
61 m_curr->start_parse(filename, m_curr->node_id);
62 m_src = ymlsrc;
63 }
Use this class a base of implementations of event handler to simplify the stack logic.

Referenced by c4::yml::extra::EventHandlerInts::start_parse().

◆ _stack_finish_parse()

void c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_finish_parse ( )
inlineprotectedinherited

Definition at line 65 of file event_handler_stack.hpp.

66 {
67 }

Referenced by c4::yml::extra::EventHandlerInts::finish_parse().

◆ _stack_reset_root()

void c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_reset_root ( )
inlineprotectedinherited

Definition at line 71 of file event_handler_stack.hpp.

72 {
73 m_stack.clear();
74 m_stack.push({});
75 m_parent = nullptr;
76 m_curr = &m_stack.top();
77 }

Referenced by c4::yml::extra::EventHandlerInts::reset().

◆ _stack_reset_non_root()

void c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_reset_non_root ( )
inlineprotectedinherited

Definition at line 79 of file event_handler_stack.hpp.

80 {
81 m_stack.clear();
82 m_stack.push({}); // parent
83 m_stack.push({}); // node
84 m_parent = &m_stack.top(1);
85 m_curr = &m_stack.top();
86 }

◆ _stack_push()

void c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_push ( )
inlineprotectedinherited

Definition at line 88 of file event_handler_stack.hpp.

89 {
90 m_stack.push_top();
91 m_parent = &m_stack.top(1); // don't use m_curr. watch out for relocations inside the prev push
92 m_curr = &m_stack.top();
93 m_curr->reset_after_push();
94 }

Referenced by c4::yml::extra::EventHandlerInts::_push().

◆ _stack_pop()

void c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_pop ( )
inlineprotectedinherited

Definition at line 96 of file event_handler_stack.hpp.

97 {
99 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_stack.size() > 1);
100 m_parent->reset_before_pop(*m_curr);
101 m_stack.pop();
102 m_parent = m_stack.size() > 1 ? &m_stack.top(1) : nullptr;
103 m_curr = &m_stack.top();
104 #ifdef RYML_DBG
105 if(m_parent)
106 _c4dbgpf("popped! top is now node={} (parent={})", m_curr->node_id, m_parent->node_id);
107 else
108 _c4dbgpf("popped! top is now node={} @ ROOT", m_curr->node_id);
109 #endif
110 }

Referenced by c4::yml::extra::EventHandlerInts::_pop().

◆ _stack_should_push_on_begin_doc()

bool c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_should_push_on_begin_doc ( ) const
inlineprotectedinherited

Definition at line 121 of file event_handler_stack.hpp.

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

Referenced by c4::yml::extra::EventHandlerInts::begin_doc().

◆ _stack_should_pop_on_end_doc()

bool c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::_stack_should_pop_on_end_doc ( ) const
inlineprotectedinherited

Definition at line 127 of file event_handler_stack.hpp.

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

Referenced by c4::yml::extra::EventHandlerInts::end_doc(), and c4::yml::extra::EventHandlerInts::end_doc_expl().

Member Data Documentation

◆ m_stack

◆ m_curr

◆ m_parent

state* c4::yml::EventHandlerStack< EventHandlerInts, EventHandlerIntsState >::m_parent
inherited

◆ m_src


The documentation for this struct was generated from the following file:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/v0.16.0/src_extra/c4/yml/extra/event_handler_ints.hpp