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
 ~EventHandlerInts () noexcept=default
 EventHandlerInts (EventHandlerInts &&)=default
 EventHandlerInts (EventHandlerInts const &)=delete
EventHandlerInts & operator= (EventHandlerInts &&)=default
EventHandlerInts & operator= (EventHandlerInts const &)=delete
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)
TagDirectives & tag_directives ()
TagCache & tag_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 with block style.
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
void enable_ (c4::yml::type_bits bits) noexcept
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
void actually_val_is_first_key_of_new_map_ (ievt::evt_bits sty, type_bits stack_bits)
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< state > m_stack
state * m_curr
 current stack level: top of the stack. cached here for easier access.
state * m_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/4]

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

◆ EventHandlerInts() [2/4]

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:101

◆ ~EventHandlerInts()

c4::yml::extra::EventHandlerInts::~EventHandlerInts ( )
defaultnoexcept

◆ EventHandlerInts() [3/4]

c4::yml::extra::EventHandlerInts::EventHandlerInts ( EventHandlerInts && )
default

◆ EventHandlerInts() [4/4]

c4::yml::extra::EventHandlerInts::EventHandlerInts ( EventHandlerInts const & )
delete

Member Function Documentation

◆ operator=() [1/2]

EventHandlerInts & c4::yml::extra::EventHandlerInts::operator= ( EventHandlerInts && )
default

◆ operator=() [2/2]

EventHandlerInts & c4::yml::extra::EventHandlerInts::operator= ( EventHandlerInts const & )
delete

◆ reset()

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

Definition at line 511 of file event_handler_ints.hpp.

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

Referenced by EventHandlerInts(), and reset().

◆ 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 531 of file event_handler_ints.hpp.

532 {
533 return m_evt_pos;
534 }

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 538 of file event_handler_ints.hpp.

539 {
540 return m_arena_pos;
541 }

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 547 of file event_handler_ints.hpp.

548 {
549 return m_evt_pos <= m_evt_size && m_arena_pos <= m_arena.len;
550 }

◆ reserve_arena()

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

Definition at line 552 of file event_handler_ints.hpp.

553 {
554 // does not apply here
555 }

◆ tag_directives()

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

Definition at line 557 of file event_handler_ints.hpp.

557{ return m_tag_directives; }

◆ tag_cache()

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

Definition at line 558 of file event_handler_ints.hpp.

558{ return m_tag_cache; }

◆ start_parse()

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

Definition at line 567 of file event_handler_ints.hpp.

568 {
569 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, src.str == m_src.str);
570 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, src.len == m_src.len);
571 this->_stack_start_parse(filename, src);
572 }

◆ finish_parse()

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

◆ cancel_parse()

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

Definition at line 579 of file event_handler_ints.hpp.

580 {
581 while(m_stack.size() > 1)
582 _pop();
583 }

◆ begin_stream()

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

Definition at line 592 of file event_handler_ints.hpp.

593 {
595 }
@ 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 597 of file event_handler_ints.hpp.

598 {
600 }
@ 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 610 of file event_handler_ints.hpp.

611 {
612 _c4dbgpf("{}/{}: begin_doc", m_evt_pos, m_evt_size);
615 {
616 _c4dbgp("push!");
617 _push();
618 ryml_enable_(DOC);
619 }
620 }
@ 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 622 of file event_handler_ints.hpp.

623 {
624 _c4dbgpf("{}/{}: end_doc", m_evt_pos, m_evt_size);
627 {
628 _c4dbgp("pop!");
629 _pop();
630 }
631 ++m_curr_doc;
632 }
@ 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 635 of file event_handler_ints.hpp.

636 {
637 _c4dbgpf("{}/{}: begin_doc_expl", m_evt_pos, m_evt_size);
639 _c4dbgp("push!");
640 _push();
641 ryml_enable_(DOC);
642 }
@ 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 644 of file event_handler_ints.hpp.

645 {
646 _c4dbgpf("{}/{}: end_doc_expl", m_evt_pos, m_evt_size);
649 {
650 _c4dbgp("pop!");
651 _pop();
652 }
653 ++m_curr_doc;
654 }

◆ begin_map_key_flow()

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

Definition at line 663 of file event_handler_ints.hpp.

664 {
665 _c4dbgpf("{}/{}: bmap key flow", m_evt_pos, m_evt_size);
669 _push();
670 }
@ 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 671 of file event_handler_ints.hpp.

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

◆ begin_map_val_flow()

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

Definition at line 680 of file event_handler_ints.hpp.

681 {
682 _c4dbgpf("{}/{}: bmap flow", m_evt_pos, m_evt_size);
685 ryml_enable_(c4::yml::MAP|c4::yml::FLOW_SL);
686 _push();
687 }

◆ begin_map_val_block()

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

Definition at line 688 of file event_handler_ints.hpp.

689 {
690 _c4dbgpf("{}/{}: bmap block", m_evt_pos, m_evt_size);
693 ryml_enable_(c4::yml::MAP|c4::yml::BLOCK);
694 _push();
695 }

◆ end_map_block()

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

Definition at line 697 of file event_handler_ints.hpp.

698 {
699 _pop();
701 }
@ 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 703 of file event_handler_ints.hpp.

704 {
705 _pop();
707 }

◆ begin_seq_key_flow()

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

Definition at line 716 of file event_handler_ints.hpp.

717 {
718 _c4dbgpf("{}/{}: bseq key flow", m_evt_pos, m_evt_size);
722 _push();
723 }
@ 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 724 of file event_handler_ints.hpp.

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

◆ begin_seq_val_flow()

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

Definition at line 733 of file event_handler_ints.hpp.

734 {
735 _c4dbgpf("{}/{}: bseq flow", m_evt_pos, m_evt_size);
738 ryml_enable_(c4::yml::SEQ|c4::yml::FLOW_SL);
739 _push();
740 }

◆ begin_seq_val_block()

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

Definition at line 741 of file event_handler_ints.hpp.

742 {
743 _c4dbgpf("{}/{}: bseq block", m_evt_pos, m_evt_size);
746 ryml_enable_(c4::yml::SEQ|c4::yml::BLOCK);
747 _push();
748 }

◆ end_seq_block()

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

Definition at line 750 of file event_handler_ints.hpp.

751 {
752 _pop();
754 }
@ 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 756 of file event_handler_ints.hpp.

757 {
758 _pop();
760 }

◆ add_sibling()

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

Definition at line 769 of file event_handler_ints.hpp.

770 {
771 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_parent);
772 m_curr->evt_type = {};
773 }

◆ set_key_scalar_plain_empty()

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

Definition at line 783 of file event_handler_ints.hpp.

784 {
785 _c4dbgpf("{}/{}: set_key_scalar_plain_empty", m_evt_pos, m_evt_size);
788 }
@ 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 789 of file event_handler_ints.hpp.

790 {
791 _c4dbgpf("{}/{}: set_val_scalar_plain_empty", m_evt_pos, m_evt_size);
794 }
@ 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 797 of file event_handler_ints.hpp.

798 {
799 _c4dbgpf("{}/{}: set_key_scalar_plain: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
801 ryml_enable_(c4::yml::KEY|c4::yml::KEY_PLAIN);
802 }

◆ set_val_scalar_plain()

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

Definition at line 803 of file event_handler_ints.hpp.

804 {
805 _c4dbgpf("{}/{}: set_val_scalar_plain: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
807 ryml_enable_(c4::yml::VAL|c4::yml::VAL_PLAIN);
808 }

◆ set_key_scalar_dquoted()

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

Definition at line 811 of file event_handler_ints.hpp.

812 {
813 _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{});
815 ryml_enable_(c4::yml::KEY|c4::yml::KEY_DQUO);
816 }
@ 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 817 of file event_handler_ints.hpp.

818 {
819 _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{});
821 ryml_enable_(c4::yml::VAL|c4::yml::VAL_DQUO);
822 }
@ 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 825 of file event_handler_ints.hpp.

826 {
827 _c4dbgpf("{}/{}: set_key_scalar_squo: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
829 ryml_enable_(c4::yml::KEY|c4::yml::KEY_SQUO);
830 }
@ 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 831 of file event_handler_ints.hpp.

832 {
833 _c4dbgpf("{}/{}: set_val_scalar_squo: @{} [{}]~~~{}~~~", m_evt_pos, m_evt_size, scalar.str-m_src.str, scalar.len, scalar);
835 ryml_enable_(c4::yml::VAL|c4::yml::VAL_SQUO);
836 }
@ 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 839 of file event_handler_ints.hpp.

840 {
841 _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{});
844 }
@ 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 845 of file event_handler_ints.hpp.

846 {
847 _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{});
850 }
@ 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 853 of file event_handler_ints.hpp.

854 {
855 _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{});
857 ryml_enable_(c4::yml::KEY|c4::yml::KEY_FOLDED);
858 }
@ 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 859 of file event_handler_ints.hpp.

860 {
861 _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{});
863 ryml_enable_(c4::yml::VAL|c4::yml::VAL_FOLDED);
864 }
@ 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 867 of file event_handler_ints.hpp.

868 {
869 _c4dbgpf("{}/{}: mark_key_scalar_unfiltered", m_evt_pos, m_evt_size);
870 if(m_evt_pos < m_evt_size)
871 m_evt[m_evt_pos] |= ievt::UNFILT;
872 }
@ 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 873 of file event_handler_ints.hpp.

874 {
875 _c4dbgpf("{}/{}: mark_val_scalar_unfiltered", m_evt_pos, m_evt_size);
876 if(m_evt_pos < m_evt_size)
877 m_evt[m_evt_pos] |= ievt::UNFILT;
878 }

◆ set_key_anchor()

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

Definition at line 909 of file event_handler_ints.hpp.

910 {
911 _c4dbgpf("{}/{}: set_key_anchor: {}", m_evt_pos, m_evt_size, anchor);
912 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_has_any_(KEYREF));
913 ryml_enable_(c4::yml::KEYANCH);
914 if(m_evt_pos + 3 < m_evt_size)
915 {
916 m_evt[m_evt_pos] |= ievt::KEY_|ievt::ANCH;
917 _add_scalar_(m_evt_pos, anchor);
918 }
919 m_evt_prev = m_evt_pos;
920 m_evt_pos += 3;
921 }
#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 922 of file event_handler_ints.hpp.

923 {
924 _c4dbgpf("{}/{}: set_val_anchor: {}", m_evt_pos, m_evt_size, anchor);
925 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, !ryml_has_any_(VALREF));
926 ryml_enable_(c4::yml::VALANCH);
927 if(m_evt_pos + 3 < m_evt_size)
928 {
929 m_evt[m_evt_pos] |= ievt::VAL_|ievt::ANCH;
930 _add_scalar_(m_evt_pos, anchor);
931 }
932 m_evt_prev = m_evt_pos;
933 m_evt_pos += 3;
934 }
@ 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 936 of file event_handler_ints.hpp.

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

◆ set_val_ref()

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

Definition at line 944 of file event_handler_ints.hpp.

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

◆ set_key_tag()

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

Definition at line 960 of file event_handler_ints.hpp.

961 {
962 _c4dbgpf("{}/{}: set key tag [{}]~~~{}~~~", m_evt_pos, m_evt_size, tag.len, tag.str ? tag : csubstr("(arena full)"));
963 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, _is_sub_(tag));
964 ryml_enable_(c4::yml::KEYTAG);
966 }
@ 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 967 of file event_handler_ints.hpp.

968 {
969 _c4dbgpf("{}/{}: set val tag [{}]~~~{}~~~", m_evt_pos, m_evt_size, tag.len, tag.str ? tag : csubstr("(arena full)"));
970 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, _is_sub_(tag));
971 ryml_enable_(c4::yml::VALTAG);
973 }
@ 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 982 of file event_handler_ints.hpp.

983 {
984 _c4dbgpf("{}/{}: %YAML directive! version={}", m_evt_pos, m_evt_size, yaml_version);
985 _send_str_(yaml_version, ievt::YAML);
986 }
@ YAML
yaml directive: \YAML <version>

◆ add_directive_tag()

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

Definition at line 988 of file event_handler_ints.hpp.

989 {
990 _c4dbgpf("{}/{}: %TAG directive! handle={} prefix={} doc_id={}", m_evt_pos, m_evt_size, handle, prefix, m_curr_doc);
991 if C4_UNLIKELY(!m_tag_directives.add(handle, prefix, m_curr_doc))
992 RYML_ERR_PARSE_CB_(m_stack.m_callbacks, m_curr->pos, "too many %TAG directives");
993 _send_str_(handle, ievt::TAGH);
994 _send_str_(prefix, ievt::TAGP);
995 }
@ 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 1009 of file event_handler_ints.hpp.

1010 {
1011 _c4dbgpf("{}/{}: prev={} actually_val_is_first_key_of_new_map_flow", m_evt_pos, m_evt_size, m_evt_prev);
1013 }
void actually_val_is_first_key_of_new_map_(ievt::evt_bits sty, type_bits stack_bits)

◆ 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 with block style.

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

Definition at line 1020 of file event_handler_ints.hpp.

1021 {
1022 _c4dbgpf("{}/{}: prev={} actually_val_is_first_key_of_new_map_block", m_evt_pos, m_evt_size, m_evt_prev);
1024 }

◆ arena()

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

Definition at line 1033 of file event_handler_ints.hpp.

1034 {
1035 return m_arena.first(m_arena_pos < m_arena.len ? m_arena_pos : m_arena.len);
1036 }

Referenced by reset().

◆ arena_rem()

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

Definition at line 1037 of file event_handler_ints.hpp.

1038 {
1039 return C4_EXPECT(m_arena_pos <= m_arena.len, 1) ? m_arena.sub(m_arena_pos) : m_arena.last(0);
1040 }

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 1042 of file event_handler_ints.hpp.

1043 {
1044 substr s = arena_rem();
1045 if C4_LIKELY(len <= s.len)
1046 s.len = len;
1047 else
1048 s.str = nullptr;
1049 m_arena_pos += len;
1050 return s;
1051 }

◆ _push()

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

◆ _pop()

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

◆ enable_() [1/2]

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

Definition at line 1074 of file event_handler_ints.hpp.

1075 {
1076 m_curr->evt_type |= bits;
1077 }

Referenced by actually_val_is_first_key_of_new_map_().

◆ enable_() [2/2]

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

Definition at line 1078 of file event_handler_ints.hpp.

1079 {
1080 m_curr->evt_type |= bits;
1081 }

◆ disable_()

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

Definition at line 1082 of file event_handler_ints.hpp.

1083 {
1084 m_curr->evt_type &= ~bits;
1085 }

◆ has_any_()

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

Definition at line 1086 of file event_handler_ints.hpp.

1087 {
1088 return (m_curr->evt_type & bits) != c4::yml::type_bits(0);
1089 }
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 1091 of file event_handler_ints.hpp.

1092 {
1093 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1094 return pos + ((m_evt[pos] & ievt::WSTR) ? 3 : 1);
1095 }
@ WSTR
WithSTRing: mask of all events that encode a string following the event. For such events,...

Referenced by actually_val_is_first_key_of_new_map_().

◆ _prev()

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

Definition at line 1097 of file event_handler_ints.hpp.

1098 {
1099 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1100 return pos - ((m_evt[pos] & ievt::PSTR) ? 3 : 1);
1101 }
@ PSTR
Special flag to enable look-back in the event array. It signifies that the previous event has a strin...

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 1103 of file event_handler_ints.hpp.

1104 {
1105 return (!str.str || str.is_sub(m_src) || str.is_sub(m_arena));
1106 }

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 1108 of file event_handler_ints.hpp.

1109 {
1110 _c4dbgpf("{}/{}: flag only", m_evt_pos, m_evt_size);
1111 if(m_evt_pos < m_evt_size)
1112 m_evt[m_evt_pos] |= flags;
1113 m_curr->evt_id = m_evt_pos;
1114 m_evt_prev = m_evt_pos;
1115 ++m_evt_pos;
1116 if(m_evt_pos < m_evt_size)
1117 m_evt[m_evt_pos] = {};
1118 }

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 1120 of file event_handler_ints.hpp.

1121 {
1122 _c4dbgpf("{}/{}: send str", m_evt_pos, m_evt_size);
1123 if(m_evt_pos + 3 < m_evt_size)
1124 {
1125 m_evt[m_evt_pos] |= flags;
1126 _add_scalar_(m_evt_pos, scalar);
1127 }
1128 m_curr->evt_id = m_evt_pos;
1129 m_evt_prev = m_evt_pos;
1130 m_evt_pos += 3;
1131 }

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 1139 of file event_handler_ints.hpp.

1140 {
1141 // ideally we should search back in the latest event that has
1142 // a scalar, then select a zero-length scalar immediately
1143 // after that scalar. But this also works for now:
1144 return m_src.first(0);
1145 }

Referenced by set_key_scalar_plain_empty(), and set_val_scalar_plain_empty().

◆ actually_val_is_first_key_of_new_map_()

void c4::yml::extra::EventHandlerInts::actually_val_is_first_key_of_new_map_ ( ievt::evt_bits sty,
type_bits stack_bits )
inline

Definition at line 1147 of file event_handler_ints.hpp.

1148 {
1149 _c4dbgpf("{}/{}: prev={} actually_val_is_first_key_of_new_map_flow", m_evt_pos, m_evt_size, m_evt_prev);
1150 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_evt_pos > 2);
1151 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_evt_prev > 0);
1152 // BEFORE
1153 // ... flag start len (free)
1154 // | |
1155 // prev curr
1156 // AFTER
1157 // ... BMAP flag start len (free)
1158 // | |
1159 // prev curr
1160 if(m_evt_pos < m_evt_size)
1161 {
1162 if(m_evt[m_evt_prev] & ievt::WSTR)
1163 {
1164 _c4dbgpf("{}/{}: WSTR", m_evt_pos, m_evt_size);
1165 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, m_evt_prev > 0);
1167 if(m_evt_pos + 1 < m_evt_size)
1168 {
1169 for(evt_size i = pos; i <= m_evt_prev; i = _next(i))
1170 {
1171 m_evt[i] |= ievt::KEY_;
1172 m_evt[i] &= ~ievt::VAL_;
1173 }
1174 evt_size num_move = m_evt_pos + 1 - pos;
1175 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, num_move > 0);
1176 memmove(m_evt + pos + 1, m_evt + pos, (size_t)num_move * sizeof(ievt::evt_bits));
1177 }
1178 m_evt[pos] = ievt::BMAP|sty|ievt::VAL_;
1179 // move PSTR to prev
1180 if(m_evt[pos + 1] & ievt::PSTR)
1181 {
1182 m_evt[pos ] |= ievt::PSTR;
1183 m_evt[pos + 1] &= ~ievt::PSTR;
1184 }
1185 }
1186 else
1187 {
1188 _c4dbgpf("{}/{}: container key", m_evt_pos, m_evt_size);
1189 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[m_evt_prev] & (ievt::EMAP|ievt::ESEQ)));
1190 evt_size pos;
1191 _c4dbgpf("{}/{}: find matching open for {}", m_evt_pos, m_evt_size, m_evt_prev);
1192 if((m_evt[m_evt_prev] & ievt::EMAP) == ievt::EMAP)
1193 {
1194 pos = _find_matching_open(ievt::BMAP, ievt::EMAP, m_evt_prev);
1195 }
1196 else
1197 {
1198 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[m_evt_prev] & ievt::ESEQ));
1199 pos = _find_matching_open(ievt::BSEQ, ievt::ESEQ, m_evt_prev);
1200 }
1201 _c4dbgpf("{}/{}: matching open for {}={}", m_evt_pos, m_evt_size, m_evt_prev, pos);
1202 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, pos >= 0); // internal error
1203 RYML_CHECK_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_prev); // internal error
1204 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & ievt::ESEQ) == (m_evt[m_evt_prev] & ievt::BSEQ));
1205 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & ievt::EMAP) == (m_evt[m_evt_prev] & ievt::BMAP));
1206 // shift the array one position to the right, starting at pos
1207 evt_size posp1 = pos + 1;
1208 if(m_evt_pos + 1 < m_evt_size)
1209 {
1210 evt_size num_move = m_evt_pos + 1 - pos;
1211 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, num_move > 0);
1212 memmove(m_evt + posp1, m_evt + pos, (size_t)num_move * sizeof(ievt::evt_bits));
1213 }
1214 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, posp1 < m_evt_pos);
1215 // start the map
1216 m_evt[pos] = ievt::BMAP|sty|ievt::VAL_;
1217 // set next as key, not val
1218 m_evt[posp1] |= ievt::KEY_;
1219 m_evt[posp1] &= ~ievt::VAL_;
1220 // move PSTR to pos
1221 if(m_evt[posp1] & ievt::PSTR)
1222 {
1223 m_evt[pos] |= ievt::PSTR;
1224 m_evt[posp1] &= ~ievt::PSTR;
1225 }
1226 }
1227 }
1228 m_curr->evt_id = m_evt_pos - 2;
1229 ++m_evt_prev;
1230 ++m_evt_pos;
1231 enable_(stack_bits);
1232 _push();
1233 }
int32_t evt_size
data type for integer events size.
int32_t evt_bits
data type for integer events bits.
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

Referenced by actually_val_is_first_key_of_new_map_block(), and actually_val_is_first_key_of_new_map_flow().

◆ _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 1235 of file event_handler_ints.hpp.

1236 {
1237 _c4dbgpf("find_matching: start at {}", pos);
1238 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1239 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & close) == close);
1240 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, (m_evt[pos] & open) == (close & ~ievt::END_));
1241 pos = _prev(pos); // don't count the starting close token
1242 uint32_t count = 0;
1243 while(pos >= 0)
1244 {
1245 ievt::evt_bits e = m_evt[pos];
1246 _c4dbgpf("find_matching: pos={} count={} e={}", pos, count, m_evt[pos]);
1247 if((e & close) == close)
1248 {
1249 _c4dbgpf(".............: pos={} close! count={} e={}", pos, count, m_evt[pos]);
1250 ++count;
1251 }
1252 else if((e & open) == open)
1253 {
1254 _c4dbgpf(".............: pos={} open! count={} e={}", pos, count, m_evt[pos]);
1255 if(!count)
1256 return pos;
1257 else
1258 --count;
1259 }
1260 pos = _prev(pos);
1261 }
1262 _c4dbgpf("find_matching: not found!", 0); // LCOV_EXCL_LINE
1263 return -1; // LCOV_EXCL_LINE
1264 }
evt_size _prev(evt_size pos) const noexcept

Referenced by actually_val_is_first_key_of_new_map_().

◆ _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 1266 of file event_handler_ints.hpp.

1267 {
1268 RYML_ASSERT_BASIC_CB_(m_stack.m_callbacks, pos < m_evt_size);
1269 evt_size prev = _prev(pos);
1270 while((prev > 0) && (m_evt[prev] & (ievt::TAG_|ievt::ANCH)))
1271 {
1272 _c4dbgpf("{}/{}: {} is anchor/tag. extend to {}", m_evt_pos, m_evt_size, prev, prev);
1273 pos = prev;
1274 prev = _prev(prev);
1275 }
1276 return pos;
1277 }

Referenced by actually_val_is_first_key_of_new_map_().

◆ _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/latest/src_extra/c4/yml/extra/event_handler_ints.hpp