3#ifndef _C4_YML_NODE_HPP_
6#ifndef _C4_YML_PARSE_ENGINE_HPP_
9#ifndef _C4_YML_PARSE_ENGINE_DEF_HPP_
12#ifndef _C4_YML_EVENT_HANDLER_TREE_HPP_
29void check_(
Tree *tree)
31 if(C4_UNLIKELY(!tree))
32 _RYML_ERR_BASIC(
"null tree");
33 if(C4_UNLIKELY(tree->empty()))
39 if(C4_UNLIKELY(node.id() ==
NONE))
40 _RYML_ERR_VISIT_(node.tree()->m_callbacks, node.tree(), node.id(),
"invalid node");
45 if(C4_UNLIKELY(!parser))
46 _RYML_ERR_BASIC(
"null parser");
47 if(C4_UNLIKELY(!parser->m_evt_handler))
49 _RYML_ERR_BASIC(
"null handler");
53 if(C4_UNLIKELY(!parser && !tree))
55 _RYML_ERR_BASIC(
"null parser and tree");
57 else if(C4_UNLIKELY(!parser))
59 _RYML_ERR_BASIC_(tree->callbacks(),
"null parser");
61 else if(C4_UNLIKELY(!tree))
63 if(C4_UNLIKELY(!parser->m_evt_handler))
64 _RYML_ERR_BASIC(
"null tree and handler");
66 _RYML_ERR_BASIC_(parser->callbacks(),
"null tree");
68 if(C4_UNLIKELY(!parser->m_evt_handler))
70 _RYML_ERR_BASIC(
"null handler");
72 if(C4_UNLIKELY(tree->empty()))
79 check_(parser, node.tree());
84 if(C4_UNLIKELY(src.len && !src.str))
85 _RYML_ERR_BASIC_(tree->callbacks(),
"null source buffer");
90 return tree->copy_to_arena(src);
96 return cpsrc_(tree, src);
101 return cpsrc_(node.tree(), src);
105 check_(parser, tree);
106 return cpsrc_(tree, src);
110 check_(parser, node);
111 return cpsrc_(node.tree(), src);
121 , parser(&handler, opts)
125 : handler(tree->callbacks())
126 , parser(&handler, opts)
130 : handler(node.tree()->callbacks())
131 , parser(&handler, opts)
138 _RYML_ASSERT_BASIC(parser);
139 _RYML_ASSERT_BASIC(parser->m_evt_handler);
140 _RYML_ASSERT_BASIC(tree);
141 if(C4_UNLIKELY(node_id ==
NONE || node_id >= tree->capacity()))
142 _RYML_ERR_VISIT_(tree->m_callbacks, tree, node_id,
"invalid node");
143 parser->m_evt_handler->reset(tree, node_id);
144 _RYML_ASSERT_BASIC(parser->m_evt_handler->m_tree == tree);
149 reset_handler_(parser, tree, node_id);
150 checksrc_(tree, yaml);
151 parser->parse_in_place_ev(filename, yaml);
156 reset_handler_(parser, tree, node_id);
157 checksrc_(tree, json);
158 parser->parse_json_in_place_ev(filename, json);
209void parse_in_arena(
Parser *parser,
csubstr filename,
csubstr yaml,
Tree *tree,
id_type node_id) {
substr src = checkcp_(parser, tree, yaml); parse_yaml_(parser, filename, src, tree, node_id); }
219void parse_in_arena(
csubstr filename,
csubstr yaml,
Tree *tree,
id_type node_id,
ParserOptions const& opts) {
substr src = checkcp_(tree, yaml); TmpParser tmp(tree, opts); parse_yaml_(&tmp.parser, filename, src, tree, node_id); }
231void parse_json_in_arena(
Parser *parser,
csubstr filename,
csubstr json,
Tree *tree,
id_type node_id) {
substr src = checkcp_(parser, tree, json); parse_json_(parser, filename, src, tree, node_id); }
241void parse_json_in_arena(
csubstr filename,
csubstr json,
Tree *tree,
id_type node_id,
ParserOptions const& opts) {
substr src = checkcp_(tree, json); TmpParser tmp(tree, opts); parse_json_(&tmp.parser, filename, src, tree, node_id); }
257 for(
size_t i = 0; i < src.
len; ++i)
259 const char c = src.
str[i];
260 num_nodes += (c ==
'\n') || (c ==
',') || (c ==
'[') || (c ==
'{');
A reference to a node in an existing yaml tree, offering a more convenient API than the index-based A...
id_type id() const noexcept
This is the main driver of parsing logic: it scans the YAML or JSON source for tokens,...
Callbacks const & callbacks() const
Get the current callbacks in the parser.
EventHandlerTree handler_type
id_type root_id() const
Get the id of the root node. The tree must not be empty. The tree can be empty only when constructed ...
Callbacks const & get_callbacks()
get the global callbacks
void parse_in_arena(Parser *parser, csubstr filename, csubstr yaml, Tree *tree, id_type node_id)
(1) parse YAML into an existing tree node. The filename will be used in any error messages arising du...
void parse_json_in_arena(Parser *parser, csubstr filename, csubstr json, Tree *tree, id_type node_id)
(1) parse JSON into an existing tree node. The filename will be used in any error messages arising du...
void parse_json_in_place(Parser *parser, csubstr filename, substr json, Tree *tree, id_type node_id)
(1) parse JSON into an existing tree node. The filename will be used in any error messages arising du...
void parse_in_place(Parser *parser, csubstr filename, substr yaml, Tree *tree, id_type node_id)
(1) parse YAML into an existing tree node.
ParseEngine< EventHandlerTree > Parser
This is the main ryml parser, where the parser events are handled to create a ryml tree (see Event Ha...
id_type estimate_tree_capacity(csubstr src)
Quickly inspect the source to estimate the number of nodes the resulting tree is likely to have.
basic_substring< char > substr
a mutable string view
basic_substring< const char > csubstr
an immutable string view
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
size_t len
the length of the substring
C * str
a restricted pointer to the first character of the substring
Options to give to the ParseEngine to control its behavior.