37 char yaml[] =
"do: a deer, a female deer\n"
38 "re: a drop of golden sun\n"
39 "mi: a name I call myself\n"
40 "fa: a long long way to run\n";
42 const int expected_events[] = {
84 constexpr
const int events_size = 100;
85 int events[events_size] = {};
86 static_assert(events_size >=
sizeof(expected_events)/
sizeof(expected_events[0]),
"buffer too small");
94 if (estimated_size > events_size)
96 printf(
"the estimated size (%d) will not fit the events array (%d)\n", estimated_size, events_size);
106 handler.
reset(yaml, arena, events, estimated_size);
107 parser.parse_in_place_ev(
"filename", yaml);
114 printf(
"error: buffers too small: required_evt=%d actual_evt=%d\n required_arena=%zu actual_arena=%zu\n",
124 printf(
"success! YAML requires event size %d, estimated=%d (required_arena=%zu actual_arena=%zu)\n",
135 bool status = (events[pos] == expected_events[pos]);
138 memset(flags, 0,
sizeof(flags));
140 if(len + 1 >=
sizeof(flags)) { printf(
"error: could not format flags");
return 1; }
142 printf(
"pos=%d\tevent[%d]:\t%20s = 0x%08x", pos, evt, flags, events[pos]);
143 if(events[pos] &
WSTR)
145 int offset = events[pos + 1];
146 int length = events[pos + 2];
147 bool in_arena = (events[pos] &
AREN);
149 const char *ptr = in_arena ? arena : yaml;
150 const char *str = ptr + offset;
151 printf(
"\tstr=(%d,%d)\t'%.*s'", offset, length, length, str);
152 status = status && (offset == expected_events[pos + 1]);
153 status = status && (length == expected_events[pos + 2]);
158 printf(
" ... fail!");
164 return success ? 0 : 1;
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
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
A parser event handler that creates a compact representation of the YAML tree in a buffer of integers...
bool fits_buffers() const
Predicate to test if the event buffer 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(csubstr str, substr arena, ievt::DataType *dst, int32_t dst_size)