|
rapidyaml
0.11.0
parse and emit YAML, and do it fast
|
A parser event handler that creates a compact representation of the YAML tree in a buffer of integers (see ievt::EventFlags) containing masks (to represent events) and offset+length (to represent strings in the source buffer). More...
#include <event_handler_ints.hpp>
Public Types | |
| using | pfn_relocate_arena = detail::pfn_relocate_arena |
types | |
| using | value_type = ievt::DataType |
| using | state = EventHandlerIntsState |
Public Member Functions | |
| void | _push () |
| push a new parent, add a child to the new parent, and set the child as the current node More... | |
| void | _pop () |
| end the current scope More... | |
| 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 |
| void | _mark_parent_with_children_ () |
| void | _send_flag_only_ (ievt::DataType flags) |
| void | _send_key_scalar_ (csubstr scalar, ievt::DataType flags) |
| void | _send_val_scalar_ (csubstr scalar, ievt::DataType flags) |
| void | _send_str_ (csubstr scalar, ievt::DataType flags) |
| void | _clear_tag_directives_ () |
| id_type | _num_tag_directives () const |
| csubstr | _transform_directive (csubstr tag) |
| void | check_trailing_doc_token () const |
| Check whether the current parse tokens are trailing on the previous doc, and raise an error if they are. More... | |
construction and resetting | |
| EventHandlerInts (c4::yml::Callbacks const &cb) | |
| EventHandlerInts () | |
| void | reset (csubstr str, substr arena, ievt::DataType *dst, int32_t dst_size) |
| int | required_size_events () const |
| get the size needed for the event buffer from the previous parse More... | |
| size_t | required_size_arena () const |
| get the size needed for the arena from the previous parse More... | |
| bool | fits_buffers () const |
| Predicate to test if the event buffer successfully accomodated all the parse events. More... | |
| void | reserve_arena (int) |
parse events | |
| void | start_parse (const char *filename, csubstr src, c4::yml::detail::pfn_relocate_arena relocate_arena, void *relocate_arena_data) |
| void | finish_parse () |
| void | cancel_parse () |
YAML stream events | |
| void | begin_stream () |
| void | end_stream () |
YAML document events | |
| void | begin_doc () |
| implicit doc start (without —) More... | |
| void | end_doc () |
| implicit doc end (without ...) More... | |
| void | begin_doc_expl () |
| explicit doc start, with — More... | |
| void | end_doc_expl () |
| explicit doc end, with ... More... | |
YAML map functions | |
| void | begin_map_key_flow () |
| void | begin_map_key_block () |
| void | begin_map_val_flow () |
| void | begin_map_val_block () |
| void | end_map_block () |
| void | end_map_flow (bool) |
YAML seq events | |
| void | begin_seq_key_flow () |
| void | begin_seq_key_block () |
| void | begin_seq_val_flow () |
| void | begin_seq_val_block () |
| void | end_seq_block () |
| void | end_seq_flow (bool) |
YAML structure events | |
| void | add_sibling () |
| void | actually_val_is_first_key_of_new_map_flow () |
| set the previous val as the first key of a new map, with flow style. More... | |
| void | actually_val_is_first_key_of_new_map_block () |
| like its flow counterpart, but this function can only be called after the end of a flow-val at root or doc level. More... | |
YAML scalar events | |
| void | set_key_scalar_plain_empty () |
| void | set_val_scalar_plain_empty () |
| csubstr | _get_latest_empty_scalar () const |
| 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) |
| void | _set_tag (csubstr tag, ievt::DataType which) |
YAML directive events | |
| void | add_directive (csubstr directive) |
YAML arena events | |
| substr | arena_rem () |
| substr | alloc_arena (size_t len) |
| this may fail, in which case a an empty string is returned More... | |
| substr | alloc_arena (size_t len, substr *relocated) |
| this may fail, in which case an empty string is returned More... | |
Public Attributes | |
| detail::stack< state > | m_stack |
| state * | m_curr |
| current stack level: top of the stack. cached here for easier access. More... | |
| state * | m_parent |
| parent of the current stack level. More... | |
| pfn_relocate_arena | m_relocate_arena |
| callback when the arena gets relocated More... | |
| void * | m_relocate_arena_data |
| csubstr | m_src |
Protected Member Functions | |
| void | _stack_start_parse (const char *filename, csubstr ymlsrc, pfn_relocate_arena relocate_arena, void *relocate_arena_data) |
| void | _stack_finish_parse () |
| void | _stack_reset_root () |
| void | _stack_reset_non_root () |
| void | _stack_push () |
| void | _stack_pop () |
| bool | _stack_should_push_on_begin_doc () const |
| bool | _stack_should_pop_on_end_doc () const |
| void | _stack_relocate_to_new_arena (csubstr prev, substr curr) |
| substr | _stack_relocate_to_new_arena (csubstr s, csubstr prev, substr curr) |
A parser event handler that creates a compact representation of the YAML tree in a buffer of integers (see ievt::EventFlags) containing masks (to represent events) and offset+length (to represent strings in the source buffer).
This is meant for use by other programming languages, and supports container keys (unlike the ryml tree). It parses faster than the ryml tree parser, because the resulting data structure is much simpler.
The resulting integer buffer is a linear array of integers containing events (as a mask of ievt::EventFlags), which in some cases (see ievt::WSTR) are followed by an encoded string (encoded as an offset and length to the parsed source buffer).
For example, parsing [a, bb, ccc] results in the following event buffer (grouped to highlight the event sequence structure):
Here is a sketch clarifying the meaning of this event sequence:
Note that the buffer contains both events and strings encoded as integer pairs. That is, events that have an associated string are immediately followed by two integers providing the offset and length of that string in the source buffer. (In the example above, this happens in the events for the strings a, bb, and ccc at positions 3, 6 and 9, respectively).
The flag ievt::PSTR and the mask ievt::WSTR are provided to enable easier iteration over the array: you can use them to test for presence of a string when iterating over the array.
The flag ievt::PSTR announces that an event is preceded by a string. That is, the previous event has a string, so that when this flag is found while iterating right-to-left, a jump of -3 should be used to get at the bitmask of the previous event. (In the example above, this flag is present for the events for bb and ccc, but not a because it is not preceded by a string).
Likewise, to signify that the current event is followed by a string, there is the mask ievt::WSTR, which is a mask of all the flags of events that have a string: ievt::SCLR, ievt::ALIA, ievt::ANCH and ievt::TAG_. While iterating left-to-right in the array, presence of any of the bits in the mask ievt::WSTR means that a jump of +3 should be employed to get at the bitmask of the next event.
Here's another example with the result of parsing a: bb
Typical code to iterate left-to-right over the array will look like this:
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:
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:
When bringing this to other programming languages, the semantics will be very similar to this.
Definition at line 435 of file event_handler_ints.hpp.
Definition at line 441 of file event_handler_ints.hpp.
| using c4::yml::extra::EventHandlerInts::state = EventHandlerIntsState |
Definition at line 442 of file event_handler_ints.hpp.
|
inherited |
Definition at line 47 of file event_handler_stack.hpp.
|
inline |
Definition at line 470 of file event_handler_ints.hpp.
|
inline |
Definition at line 475 of file event_handler_ints.hpp.
|
inline |
Definition at line 480 of file event_handler_ints.hpp.
References c4::yml::RTOP, and c4::yml::RUNK.
|
inline |
get the size needed for the event buffer from the previous parse
Definition at line 501 of file event_handler_ints.hpp.
|
inline |
get the size needed for the arena from the previous parse
Definition at line 508 of file event_handler_ints.hpp.
|
inline |
Predicate to test if the event buffer successfully accomodated all the parse events.
Definition at line 516 of file event_handler_ints.hpp.
|
inline |
Definition at line 521 of file event_handler_ints.hpp.
|
inline |
Definition at line 533 of file event_handler_ints.hpp.
|
inline |
Definition at line 540 of file event_handler_ints.hpp.
|
inline |
Definition at line 547 of file event_handler_ints.hpp.
|
inline |
Definition at line 560 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BSTR.
|
inline |
Definition at line 565 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::ESTR.
|
inline |
implicit doc start (without —)
Definition at line 578 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BDOC, and c4::yml::DOC.
|
inline |
implicit doc end (without ...)
Definition at line 591 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::EDOC.
|
inline |
explicit doc start, with —
Definition at line 603 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BDOC, c4::yml::DOC, and c4::yml::extra::ievt::EXPL.
|
inline |
explicit doc end, with ...
Definition at line 613 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::EDOC, and c4::yml::extra::ievt::EXPL.
|
inline |
Definition at line 632 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BMAP, c4::yml::extra::ievt::FLOW, c4::yml::FLOW_SL, c4::yml::KEY, c4::yml::extra::ievt::KEY_, and c4::yml::MAP.
|
inline |
Definition at line 640 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BLCK, c4::yml::BLOCK, c4::yml::extra::ievt::BMAP, c4::yml::KEY, c4::yml::extra::ievt::KEY_, and c4::yml::MAP.
|
inline |
Definition at line 649 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BMAP, c4::yml::extra::ievt::FLOW, c4::yml::FLOW_SL, c4::yml::MAP, and c4::yml::extra::ievt::VAL_.
|
inline |
Definition at line 657 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BLCK, c4::yml::BLOCK, c4::yml::extra::ievt::BMAP, c4::yml::MAP, and c4::yml::extra::ievt::VAL_.
|
inline |
Definition at line 666 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::EMAP.
|
inline |
Definition at line 672 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::EMAP.
|
inline |
Definition at line 685 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BSEQ, c4::yml::extra::ievt::FLOW, c4::yml::FLOW_SL, c4::yml::KEY, c4::yml::extra::ievt::KEY_, and c4::yml::SEQ.
|
inline |
Definition at line 693 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BLCK, c4::yml::BLOCK, c4::yml::extra::ievt::BSEQ, c4::yml::KEY, c4::yml::extra::ievt::KEY_, and c4::yml::SEQ.
|
inline |
Definition at line 702 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BSEQ, c4::yml::extra::ievt::FLOW, c4::yml::FLOW_SL, c4::yml::SEQ, and c4::yml::extra::ievt::VAL_.
|
inline |
Definition at line 710 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BLCK, c4::yml::BLOCK, c4::yml::extra::ievt::BSEQ, c4::yml::SEQ, and c4::yml::extra::ievt::VAL_.
|
inline |
Definition at line 719 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::ESEQ.
|
inline |
Definition at line 725 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::ESEQ.
|
inline |
Definition at line 738 of file event_handler_ints.hpp.
|
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 749 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BMAP, c4::yml::extra::ievt::BSEQ, c4::yml::extra::ievt::EMAP, c4::yml::extra::ievt::ESEQ, c4::yml::extra::ievt::FLOW, c4::yml::FLOW_SL, c4::yml::extra::ievt::KEY_, c4::yml::MAP, c4::yml::extra::ievt::PSTR, c4::yml::extra::ievt::VAL_, and c4::yml::extra::ievt::WSTR.
|
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 843 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::BDOC, c4::yml::extra::ievt::BLCK, c4::yml::extra::ievt::BMAP, c4::yml::extra::ievt::BSEQ, c4::yml::extra::ievt::KEY_, c4::yml::extra::ievt::PSTR, and c4::yml::extra::ievt::VAL_.
|
inline |
Definition at line 952 of file event_handler_ints.hpp.
References c4::yml::KEY, c4::yml::KEY_PLAIN, c4::yml::KEYNIL, and c4::yml::extra::ievt::PLAI.
|
inline |
Definition at line 958 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::PLAI, c4::yml::VAL, c4::yml::VAL_PLAIN, and c4::yml::VALNIL.
|
inline |
Definition at line 964 of file event_handler_ints.hpp.
|
inline |
Definition at line 973 of file event_handler_ints.hpp.
References c4::yml::KEY, c4::yml::KEY_PLAIN, and c4::yml::extra::ievt::PLAI.
|
inline |
Definition at line 979 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::PLAI, c4::yml::VAL, and c4::yml::VAL_PLAIN.
|
inline |
Definition at line 987 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::DQUO, c4::yml::KEY, and c4::yml::KEY_DQUO.
|
inline |
Definition at line 993 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::DQUO, c4::yml::VAL, and c4::yml::VAL_DQUO.
|
inline |
Definition at line 1001 of file event_handler_ints.hpp.
References c4::yml::KEY, c4::yml::KEY_SQUO, and c4::yml::extra::ievt::SQUO.
|
inline |
Definition at line 1007 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::SQUO, c4::yml::VAL, and c4::yml::VAL_SQUO.
|
inline |
Definition at line 1015 of file event_handler_ints.hpp.
References c4::yml::KEY, c4::yml::KEY_LITERAL, and c4::yml::extra::ievt::LITL.
|
inline |
Definition at line 1021 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::LITL, c4::yml::VAL, and c4::yml::VAL_LITERAL.
|
inline |
Definition at line 1029 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::FOLD, c4::yml::KEY, and c4::yml::KEY_FOLDED.
|
inline |
Definition at line 1035 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::FOLD, c4::yml::VAL, and c4::yml::VAL_FOLDED.
|
inline |
Definition at line 1043 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::UNFILT.
|
inline |
|
inline |
Definition at line 1083 of file event_handler_ints.hpp.
References _has_any_, c4::yml::extra::ievt::ANCH, c4::yml::extra::ievt::KEY_, c4::yml::KEYANCH, and c4::yml::KEYREF.
|
inline |
Definition at line 1096 of file event_handler_ints.hpp.
References _has_any_, c4::yml::extra::ievt::ANCH, c4::yml::extra::ievt::VAL_, c4::yml::VALANCH, and c4::yml::VALREF.
|
inline |
Definition at line 1110 of file event_handler_ints.hpp.
References _has_any_, c4::yml::extra::ievt::ALIA, c4::yml::KEY, c4::yml::extra::ievt::KEY_, c4::yml::KEYANCH, and c4::yml::KEYREF.
|
inline |
Definition at line 1118 of file event_handler_ints.hpp.
References _has_any_, c4::yml::extra::ievt::ALIA, c4::yml::VAL, c4::yml::extra::ievt::VAL_, c4::yml::VALANCH, and c4::yml::VALREF.
|
inline |
Definition at line 1134 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::KEY_, and c4::yml::KEYTAG.
|
inline |
Definition at line 1140 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::VAL_, and c4::yml::VALTAG.
|
inline |
Definition at line 1146 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::TAG_.
|
inline |
Definition at line 1166 of file event_handler_ints.hpp.
References c4::yml::TagDirective::create_from_str(), c4::yml::TagDirective::handle, c4::yml::TagDirective::next_node_id, c4::yml::TagDirective::prefix, RYML_MAX_TAG_DIRECTIVES, c4::yml::extra::ievt::TAGD, c4::yml::extra::ievt::TAGV, and c4::yml::extra::ievt::YAML.
|
inline |
Definition at line 1204 of file event_handler_ints.hpp.
|
inline |
this may fail, in which case a an empty string is returned
Definition at line 1210 of file event_handler_ints.hpp.
|
inline |
this may fail, in which case an empty string is returned
Definition at line 1222 of file event_handler_ints.hpp.
|
inline |
push a new parent, add a child to the new parent, and set the child as the current node
Definition at line 1234 of file event_handler_ints.hpp.
|
inline |
end the current scope
Definition at line 1241 of file event_handler_ints.hpp.
|
inlinenoexcept |
Definition at line 1246 of file event_handler_ints.hpp.
|
inlinenoexcept |
Definition at line 1250 of file event_handler_ints.hpp.
|
inlinenoexcept |
Definition at line 1254 of file event_handler_ints.hpp.
|
inline |
Definition at line 1259 of file event_handler_ints.hpp.
|
inline |
Definition at line 1265 of file event_handler_ints.hpp.
|
inline |
Definition at line 1277 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::KEY_, and c4::yml::extra::ievt::SCLR.
|
inline |
Definition at line 1290 of file event_handler_ints.hpp.
References c4::yml::extra::ievt::SCLR, and c4::yml::extra::ievt::VAL_.
|
inline |
Definition at line 1303 of file event_handler_ints.hpp.
|
inline |
Definition at line 1316 of file event_handler_ints.hpp.
|
inline |
|
inline |
Definition at line 1330 of file event_handler_ints.hpp.
References c4::yml::TagDirective::handle, c4::yml::is_custom_tag(), c4::yml::NONE, c4::yml::TagDirective::prefix, RYML_MAX_TAG_DIRECTIVES, and c4::yml::TagDirective::transform().
|
inlineprotectedinherited |
Definition at line 65 of file event_handler_stack.hpp.
|
inlineprotectedinherited |
Definition at line 76 of file event_handler_stack.hpp.
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
|
inlineprotectedinherited |
Definition at line 108 of file event_handler_stack.hpp.
|
inlineprotectedinherited |
|
inlineprotectedinherited |
Definition at line 135 of file event_handler_stack.hpp.
|
inlineprotectedinherited |
Definition at line 143 of file event_handler_stack.hpp.
|
inlineprotectedinherited |
Definition at line 157 of file event_handler_stack.hpp.
|
inlineinherited |
Check whether the current parse tokens are trailing on the previous doc, and raise an error if they are.
This function is called by the parse engine (not the event handler) before a doc is started.
Definition at line 172 of file event_handler_stack.hpp.
|
inherited |
Definition at line 51 of file event_handler_stack.hpp.
|
inherited |
current stack level: top of the stack. cached here for easier access.
Definition at line 52 of file event_handler_stack.hpp.
|
inherited |
parent of the current stack level.
Definition at line 53 of file event_handler_stack.hpp.
|
inherited |
callback when the arena gets relocated
Definition at line 54 of file event_handler_stack.hpp.
|
inherited |
Definition at line 55 of file event_handler_stack.hpp.
|
inherited |
Definition at line 56 of file event_handler_stack.hpp.