7 #if defined(RYML_SINGLE_HEADER)
8 #define RYML_SINGLE_HDR_DEFINE_NOW
9 #include <ryml_ints.hpp>
10 #elif defined(RYML_SINGLE_HEADER_LIB)
11 #include <ryml_ints.hpp>
21 int main(
int,
const char *[])
26 char yaml[] =
"do: a deer, a female deer\n"
27 "re: a drop of golden sun\n"
28 "mi: a name I call myself\n"
29 "fa: a long long way to run\n";
31 const int expected_events[] = {
73 constexpr
const int events_size = 100;
74 int events[events_size] = {};
75 static_assert(events_size >=
sizeof(expected_events)/
sizeof(expected_events[0]),
"buffer too small");
83 if (estimated_size > events_size)
85 printf(
"the estimated size (%d) will not fit the events array (%d)\n", estimated_size, events_size);
95 handler.
reset(yaml, arena, events, estimated_size);
103 printf(
"error: buffers too small: required_evt=%d actual_evt=%d\n required_arena=%zu actual_arena=%zu\n",
113 printf(
"success! YAML requires event size %d, estimated=%d (required_arena=%zu actual_arena=%zu)\n",
124 bool status = (events[pos] == expected_events[pos]);
127 memset(flags, 0,
sizeof(flags));
129 if(len + 1 >=
sizeof(flags)) { printf(
"error: could not format flags");
return 1; }
131 printf(
"pos=%d\tevent[%d]:\t%20s = 0x%08x", pos, evt, flags, events[pos]);
132 if(events[pos] &
WSTR)
134 int offset = events[pos + 1];
135 int length = events[pos + 2];
136 bool in_arena = (events[pos] &
AREN);
138 const char *ptr = in_arena ? arena : yaml;
139 const char *str = ptr + offset;
140 printf(
"\tstr=(%d,%d)\t'%.*s'", offset, length, length, str);
141 status = status && (offset == expected_events[pos + 1]);
142 status = status && (length == expected_events[pos + 2]);
147 printf(
" ... fail!");
153 return success ? 0 : 1;
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
void parse_in_place_ev(csubstr filename, substr src)
parse YAML in place, emitting events to the current handler
An event handler that creates an integer buffer with a very compact representation of the YAML tree i...
int32_t estimate_events_ints_size(csubstr src)
Read YAML source and, without undergoing a full parse, estimate the size of the integer buffer requir...
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
int main(int, const char *[])
A parser event handler that creates a compact representation of the YAML tree in a contiguous buffer ...
bool fits_buffers() const
Predicate to test if the event and arena buffers successfully accomodated all the parse events.
int 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
void reset(substr str, substr arena, ievt::DataType *dst, int32_t dst_size)