dep: Add rapidyaml
This commit is contained in:
121
dep/rapidyaml/src/c4/yml/common.cpp
Normal file
121
dep/rapidyaml/src/c4/yml/common.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "c4/yml/common.hpp"
|
||||
|
||||
#ifndef RYML_NO_DEFAULT_CALLBACKS
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
#endif // RYML_NO_DEFAULT_CALLBACKS
|
||||
|
||||
namespace c4 {
|
||||
namespace yml {
|
||||
|
||||
C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
|
||||
|
||||
namespace {
|
||||
Callbacks s_default_callbacks;
|
||||
} // anon namespace
|
||||
|
||||
#ifndef RYML_NO_DEFAULT_CALLBACKS
|
||||
void report_error_impl(const char* msg, size_t length, Location loc, FILE *f)
|
||||
{
|
||||
if(!f)
|
||||
f = stderr;
|
||||
if(loc)
|
||||
{
|
||||
if(!loc.name.empty())
|
||||
{
|
||||
fwrite(loc.name.str, 1, loc.name.len, f);
|
||||
fputc(':', f);
|
||||
}
|
||||
fprintf(f, "%zu:", loc.line);
|
||||
if(loc.col)
|
||||
fprintf(f, "%zu:", loc.col);
|
||||
if(loc.offset)
|
||||
fprintf(f, " (%zuB):", loc.offset);
|
||||
}
|
||||
fprintf(f, "%.*s\n", (int)length, msg);
|
||||
fflush(f);
|
||||
}
|
||||
|
||||
void error_impl(const char* msg, size_t length, Location loc, void * /*user_data*/)
|
||||
{
|
||||
report_error_impl(msg, length, loc, nullptr);
|
||||
::abort();
|
||||
}
|
||||
|
||||
void* allocate_impl(size_t length, void * /*hint*/, void * /*user_data*/)
|
||||
{
|
||||
void *mem = ::malloc(length);
|
||||
if(mem == nullptr)
|
||||
{
|
||||
const char msg[] = "could not allocate memory";
|
||||
error_impl(msg, sizeof(msg)-1, {}, nullptr);
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
void free_impl(void *mem, size_t /*length*/, void * /*user_data*/)
|
||||
{
|
||||
::free(mem);
|
||||
}
|
||||
#endif // RYML_NO_DEFAULT_CALLBACKS
|
||||
|
||||
|
||||
|
||||
Callbacks::Callbacks()
|
||||
:
|
||||
m_user_data(nullptr),
|
||||
#ifndef RYML_NO_DEFAULT_CALLBACKS
|
||||
m_allocate(allocate_impl),
|
||||
m_free(free_impl),
|
||||
m_error(error_impl)
|
||||
#else
|
||||
m_allocate(nullptr),
|
||||
m_free(nullptr),
|
||||
m_error(nullptr)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
Callbacks::Callbacks(void *user_data, pfn_allocate alloc_, pfn_free free_, pfn_error error_)
|
||||
:
|
||||
m_user_data(user_data),
|
||||
#ifndef RYML_NO_DEFAULT_CALLBACKS
|
||||
m_allocate(alloc_ ? alloc_ : allocate_impl),
|
||||
m_free(free_ ? free_ : free_impl),
|
||||
m_error(error_ ? error_ : error_impl)
|
||||
#else
|
||||
m_allocate(alloc_),
|
||||
m_free(free_),
|
||||
m_error(error_)
|
||||
#endif
|
||||
{
|
||||
C4_CHECK(m_allocate);
|
||||
C4_CHECK(m_free);
|
||||
C4_CHECK(m_error);
|
||||
}
|
||||
|
||||
|
||||
void set_callbacks(Callbacks const& c)
|
||||
{
|
||||
s_default_callbacks = c;
|
||||
}
|
||||
|
||||
Callbacks const& get_callbacks()
|
||||
{
|
||||
return s_default_callbacks;
|
||||
}
|
||||
|
||||
void reset_callbacks()
|
||||
{
|
||||
set_callbacks(Callbacks());
|
||||
}
|
||||
|
||||
void error(const char *msg, size_t msg_len, Location loc)
|
||||
{
|
||||
s_default_callbacks.m_error(msg, msg_len, loc, s_default_callbacks.m_user_data);
|
||||
}
|
||||
|
||||
C4_SUPPRESS_WARNING_GCC_CLANG_POP
|
||||
|
||||
} // namespace yml
|
||||
} // namespace c4
|
||||
30
dep/rapidyaml/src/c4/yml/node.cpp
Normal file
30
dep/rapidyaml/src/c4/yml/node.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "c4/yml/node.hpp"
|
||||
|
||||
namespace c4 {
|
||||
namespace yml {
|
||||
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
size_t NodeRef::set_key_serialized(c4::fmt::const_base64_wrapper w)
|
||||
{
|
||||
_apply_seed();
|
||||
csubstr encoded = this->to_arena(w);
|
||||
this->set_key(encoded);
|
||||
return encoded.len;
|
||||
}
|
||||
|
||||
size_t NodeRef::set_val_serialized(c4::fmt::const_base64_wrapper w)
|
||||
{
|
||||
_apply_seed();
|
||||
csubstr encoded = this->to_arena(w);
|
||||
this->set_val(encoded);
|
||||
return encoded.len;
|
||||
}
|
||||
|
||||
} // namespace yml
|
||||
} // namespace c4
|
||||
5750
dep/rapidyaml/src/c4/yml/parse.cpp
Normal file
5750
dep/rapidyaml/src/c4/yml/parse.cpp
Normal file
File diff suppressed because it is too large
Load Diff
112
dep/rapidyaml/src/c4/yml/preprocess.cpp
Normal file
112
dep/rapidyaml/src/c4/yml/preprocess.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "c4/yml/preprocess.hpp"
|
||||
#include "c4/yml/detail/parser_dbg.hpp"
|
||||
|
||||
/** @file preprocess.hpp Functions for preprocessing YAML prior to parsing. */
|
||||
|
||||
namespace c4 {
|
||||
namespace yml {
|
||||
|
||||
C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wold-style-cast")
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
C4_ALWAYS_INLINE bool _is_idchar(char c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9')
|
||||
|| (c == '_' || c == '-' || c == '~' || c == '$');
|
||||
}
|
||||
|
||||
typedef enum { kReadPending = 0, kKeyPending = 1, kValPending = 2 } _ppstate;
|
||||
C4_ALWAYS_INLINE _ppstate _next(_ppstate s)
|
||||
{
|
||||
int n = (int)s + 1;
|
||||
return (_ppstate)(n <= (int)kValPending ? n : 0);
|
||||
}
|
||||
} // empty namespace
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
size_t preprocess_rxmap(csubstr s, substr buf)
|
||||
{
|
||||
detail::_SubstrWriter writer(buf);
|
||||
_ppstate state = kReadPending;
|
||||
size_t last = 0;
|
||||
|
||||
if(s.begins_with('{'))
|
||||
{
|
||||
RYML_CHECK(s.ends_with('}'));
|
||||
s = s.offs(1, 1);
|
||||
}
|
||||
|
||||
writer.append('{');
|
||||
|
||||
for(size_t i = 0; i < s.len; ++i)
|
||||
{
|
||||
const char curr = s[i];
|
||||
const char next = i+1 < s.len ? s[i+1] : '\0';
|
||||
|
||||
if(curr == '\'' || curr == '"')
|
||||
{
|
||||
csubstr ss = s.sub(i).pair_range_esc(curr, '\\');
|
||||
i += static_cast<size_t>(ss.end() - (s.str + i));
|
||||
state = _next(state);
|
||||
}
|
||||
else if(state == kReadPending && _is_idchar(curr))
|
||||
{
|
||||
state = _next(state);
|
||||
}
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case kKeyPending:
|
||||
{
|
||||
if(curr == ':' && next == ' ')
|
||||
{
|
||||
state = _next(state);
|
||||
}
|
||||
else if(curr == ',' && next == ' ')
|
||||
{
|
||||
writer.append(s.range(last, i));
|
||||
writer.append(": 1, ");
|
||||
last = i + 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case kValPending:
|
||||
{
|
||||
if(curr == '[' || curr == '{' || curr == '(')
|
||||
{
|
||||
csubstr ss = s.sub(i).pair_range_nested(curr, '\\');
|
||||
i += static_cast<size_t>(ss.end() - (s.str + i));
|
||||
state = _next(state);
|
||||
}
|
||||
else if(curr == ',' && next == ' ')
|
||||
{
|
||||
state = _next(state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// nothing to do
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
writer.append(s.sub(last));
|
||||
if(state == kKeyPending)
|
||||
writer.append(": 1");
|
||||
writer.append('}');
|
||||
|
||||
return writer.pos;
|
||||
}
|
||||
|
||||
C4_SUPPRESS_WARNING_GCC_CLANG_POP
|
||||
|
||||
} // namespace yml
|
||||
} // namespace c4
|
||||
2184
dep/rapidyaml/src/c4/yml/tree.cpp
Normal file
2184
dep/rapidyaml/src/c4/yml/tree.cpp
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user