rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
Parse in arena with existing parser

parse a read-only (immutable) YAML source buffer. More...

Macros

#define RYML_DONT_PARSE_SUBSTR_IN_ARENA

Functions

void c4::yml::parse_in_arena (Parser *parser, csubstr filename, csubstr yaml, Tree *t, id_type node_id)
 (1) parse YAML into an existing tree node. The filename will be used in any error messages arising during the parse.
void c4::yml::parse_in_arena (Parser *parser, csubstr yaml, Tree *t, id_type node_id)
 (2) like (1) but no filename will be reported
void c4::yml::parse_in_arena (Parser *parser, csubstr filename, csubstr yaml, Tree *t)
 (3) parse YAML into an existing tree, into its root node.
void c4::yml::parse_in_arena (Parser *parser, csubstr yaml, Tree *t)
 (4) like (3) but no filename will be reported
void c4::yml::parse_in_arena (Parser *parser, csubstr filename, csubstr yaml, NodeRef node)
 (5) like (1) but the node is given as a NodeRef
void c4::yml::parse_in_arena (Parser *parser, csubstr yaml, NodeRef node)
 (6) like (5) but no filename will be reported
Tree c4::yml::parse_in_arena (Parser *parser, csubstr filename, csubstr yaml)
 (7) create a new tree, and parse YAML into its root node.
Tree c4::yml::parse_in_arena (Parser *parser, csubstr yaml)
 (8) like (7) but no filename will be reported
void c4::yml::parse_json_in_arena (Parser *parser, csubstr filename, csubstr json, Tree *t, id_type node_id)
 (1) parse JSON into an existing tree node. The filename will be used in any error messages arising during the parse.
void c4::yml::parse_json_in_arena (Parser *parser, csubstr json, Tree *t, id_type node_id)
 (2) like (1) but no filename will be reported
void c4::yml::parse_json_in_arena (Parser *parser, csubstr filename, csubstr json, Tree *t)
 (3) parse JSON into an existing tree, into its root node.
void c4::yml::parse_json_in_arena (Parser *parser, csubstr json, Tree *t)
 (4) like (3) but no filename will be reported
void c4::yml::parse_json_in_arena (Parser *parser, csubstr filename, csubstr json, NodeRef node)
 (5) like (1) but the node is given as a NodeRef
void c4::yml::parse_json_in_arena (Parser *parser, csubstr json, NodeRef node)
 (6) like (5) but no filename will be reported
Tree c4::yml::parse_json_in_arena (Parser *parser, csubstr filename, csubstr json)
 (7) create a new tree, and parse JSON into its root node.
Tree c4::yml::parse_json_in_arena (Parser *parser, csubstr json)
 (8) like (7) but no filename will be reported

Detailed Description

parse a read-only (immutable) YAML source buffer.

This is achieved by first copying the contents of the buffer to the tree's arena, and then calling parse_in_arena() . All the resulting scalars will be filtered in the arena. These overloads accept an existing parser object, and provide the opportunity to use special parser options.

See also
ParserOptions
Note
These freestanding functions use a temporary parser object, and are convenience functions to easily parse YAML without the need to instantiate a separate parser. Note that some properties (notably node locations in the original source code) are only available through the parser class. If you need access to any of these properties, use the appropriate overload from Parse in arena with existing parser
Warning
overloads receiving a substr YAML buffer are intentionally left undefined, such that calling parse_in_arena() with a substr will cause a linker error. This is to prevent an accidental copy of the source buffer to the tree's arena, because substr (which is mutable) is implicitly convertible to csubstr (which is immutable). If you really intend to parse a mutable buffer in the tree's arena, convert it first to immutable by assigning the substr to a csubstr prior to calling parse_in_arena(). This is not needed for parse_in_place() because csubstr is not implicitly convertible to substr. To be clear:
substr mutable_buffer = ...;
parser.parse_in_arena(mutable_buffer); // linker error
csubstr immutable_buffer = mutable_buffer; // convert first to csubstr
parser.parse_in_arena(immutable_buffer); // ok
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2356
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2357

Macro Definition Documentation

◆ RYML_DONT_PARSE_SUBSTR_IN_ARENA

#define RYML_DONT_PARSE_SUBSTR_IN_ARENA
Value:
"" \
"Do not pass a (mutable) substr to parse_in_arena(); " \
"if you have a substr, it should be parsed in place. " \
"Consider using parse_in_place() instead, or convert " \
"the buffer to csubstr prior to calling. This function " \
" is deliberately left undefined, so that calling it " \
"will cause a linker error."

Definition at line 179 of file parse.hpp.

179#define RYML_DONT_PARSE_SUBSTR_IN_ARENA "" \
180 "Do not pass a (mutable) substr to parse_in_arena(); " \
181 "if you have a substr, it should be parsed in place. " \
182 "Consider using parse_in_place() instead, or convert " \
183 "the buffer to csubstr prior to calling. This function " \
184 " is deliberately left undefined, so that calling it " \
185 "will cause a linker error."

Function Documentation

◆ parse_in_arena() [1/8]

void c4::yml::parse_in_arena ( Parser * parser,
csubstr filename,
csubstr yaml,
Tree * t,
id_type node_id )

(1) parse YAML into an existing tree node. The filename will be used in any error messages arising during the parse.

Definition at line 92 of file parse.cpp.

92{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(yaml); parse_in_place(parser, filename, src, t, node_id); }
substr copy_to_arena(csubstr s)
copy the given string to the tree's arena, growing the arena by the required size.
Definition tree.hpp:932
void parse_in_place(Parser *parser, csubstr filename, substr yaml, Tree *t, id_type node_id)
(1) parse YAML into an existing tree node.
Definition parse.cpp:38

◆ parse_in_arena() [2/8]

void c4::yml::parse_in_arena ( Parser * parser,
csubstr yaml,
Tree * t,
id_type node_id )

(2) like (1) but no filename will be reported

Definition at line 93 of file parse.cpp.

93{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(yaml); parse_in_place(parser, {} , src, t, node_id); }

◆ parse_in_arena() [3/8]

void c4::yml::parse_in_arena ( Parser * parser,
csubstr filename,
csubstr yaml,
Tree * t )

(3) parse YAML into an existing tree, into its root node.

Definition at line 94 of file parse.cpp.

94{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(yaml); if(t->empty()) { t->reserve(); } parse_in_place(parser, filename, src, t, t->root_id()); }
id_type root_id() const
Get the id of the root node. The tree must not be empty.
Definition tree.hpp:337
void reserve(id_type node_capacity=RYML_DEFAULT_TREE_CAPACITY)
Definition tree.cpp:292
bool empty() const
Definition tree.hpp:284

◆ parse_in_arena() [4/8]

void c4::yml::parse_in_arena ( Parser * parser,
csubstr yaml,
Tree * t )

(4) like (3) but no filename will be reported

Definition at line 95 of file parse.cpp.

95{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(yaml); if(t->empty()) { t->reserve(); } parse_in_place(parser, {} , src, t, t->root_id()); }

◆ parse_in_arena() [5/8]

void c4::yml::parse_in_arena ( Parser * parser,
csubstr filename,
csubstr yaml,
NodeRef node )

(5) like (1) but the node is given as a NodeRef

Definition at line 96 of file parse.cpp.

96{ _RYML_CHECK_BASIC(!node.invalid()); substr src = node.tree()->copy_to_arena(yaml); parse_in_place(parser, filename, src, node.tree(), node.id()); }
Tree * tree() noexcept
Definition node.hpp:1089
id_type id() const noexcept
Definition node.hpp:1092
bool invalid() const noexcept
true if the object is not referring to any existing or seed node.
Definition node.hpp:1038

◆ parse_in_arena() [6/8]

void c4::yml::parse_in_arena ( Parser * parser,
csubstr yaml,
NodeRef node )

(6) like (5) but no filename will be reported

Definition at line 97 of file parse.cpp.

97{ _RYML_CHECK_BASIC(!node.invalid()); substr src = node.tree()->copy_to_arena(yaml); parse_in_place(parser, {} , src, node.tree(), node.id()); }

◆ parse_in_arena() [7/8]

Tree c4::yml::parse_in_arena ( Parser * parser,
csubstr filename,
csubstr yaml )

(7) create a new tree, and parse YAML into its root node.

Definition at line 98 of file parse.cpp.

98{ _RYML_CHECK_BASIC(parser); _RYML_CHECK_BASIC(parser->m_evt_handler); Tree tree(parser->callbacks()); substr src = tree.copy_to_arena(yaml); parse_in_place(parser, filename, src, &tree, tree.root_id()); return tree; }
Callbacks const & callbacks() const
Get the current callbacks in the parser.

◆ parse_in_arena() [8/8]

Tree c4::yml::parse_in_arena ( Parser * parser,
csubstr yaml )

(8) like (7) but no filename will be reported

Definition at line 99 of file parse.cpp.

99{ _RYML_CHECK_BASIC(parser); _RYML_CHECK_BASIC(parser->m_evt_handler); Tree tree(parser->callbacks()); substr src = tree.copy_to_arena(yaml); parse_in_place(parser, {} , src, &tree, tree.root_id()); return tree; }

◆ parse_json_in_arena() [1/8]

void c4::yml::parse_json_in_arena ( Parser * parser,
csubstr filename,
csubstr json,
Tree * t,
id_type node_id )

(1) parse JSON into an existing tree node. The filename will be used in any error messages arising during the parse.

Definition at line 113 of file parse.cpp.

113{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(json); parse_json_in_place(parser, filename, src, t, node_id); }
void parse_json_in_place(Parser *parser, csubstr filename, substr json, Tree *t, id_type node_id)
(1) parse JSON into an existing tree node. The filename will be used in any error messages arising du...
Definition parse.cpp:44

◆ parse_json_in_arena() [2/8]

void c4::yml::parse_json_in_arena ( Parser * parser,
csubstr json,
Tree * t,
id_type node_id )

(2) like (1) but no filename will be reported

Definition at line 114 of file parse.cpp.

114{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(json); parse_json_in_place(parser, {} , src, t, node_id); }

◆ parse_json_in_arena() [3/8]

void c4::yml::parse_json_in_arena ( Parser * parser,
csubstr filename,
csubstr json,
Tree * t )

(3) parse JSON into an existing tree, into its root node.

Definition at line 115 of file parse.cpp.

115{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(json); if(t->empty()) { t->reserve(); } parse_json_in_place(parser, filename, src, t, t->root_id()); }

◆ parse_json_in_arena() [4/8]

void c4::yml::parse_json_in_arena ( Parser * parser,
csubstr json,
Tree * t )

(4) like (3) but no filename will be reported

Definition at line 116 of file parse.cpp.

116{ _RYML_CHECK_BASIC(t); substr src = t->copy_to_arena(json); if(t->empty()) { t->reserve(); } parse_json_in_place(parser, {} , src, t, t->root_id()); }

◆ parse_json_in_arena() [5/8]

void c4::yml::parse_json_in_arena ( Parser * parser,
csubstr filename,
csubstr json,
NodeRef node )

(5) like (1) but the node is given as a NodeRef

Definition at line 117 of file parse.cpp.

117{ _RYML_CHECK_BASIC(!node.invalid()); substr src = node.tree()->copy_to_arena(json); parse_json_in_place(parser, filename, src, node.tree(), node.id()); }

◆ parse_json_in_arena() [6/8]

void c4::yml::parse_json_in_arena ( Parser * parser,
csubstr json,
NodeRef node )

(6) like (5) but no filename will be reported

Definition at line 118 of file parse.cpp.

118{ _RYML_CHECK_BASIC(!node.invalid()); substr src = node.tree()->copy_to_arena(json); parse_json_in_place(parser, {} , src, node.tree(), node.id()); }

◆ parse_json_in_arena() [7/8]

Tree c4::yml::parse_json_in_arena ( Parser * parser,
csubstr filename,
csubstr json )

(7) create a new tree, and parse JSON into its root node.

Definition at line 119 of file parse.cpp.

119{ _RYML_CHECK_BASIC(parser); _RYML_CHECK_BASIC(parser->m_evt_handler); Tree tree(parser->callbacks()); substr src = tree.copy_to_arena(json); parse_json_in_place(parser, filename, src, &tree, tree.root_id()); return tree; }

◆ parse_json_in_arena() [8/8]

Tree c4::yml::parse_json_in_arena ( Parser * parser,
csubstr json )

(8) like (7) but no filename will be reported

Definition at line 120 of file parse.cpp.

120{ _RYML_CHECK_BASIC(parser); _RYML_CHECK_BASIC(parser->m_evt_handler); Tree tree(parser->callbacks()); substr src = tree.copy_to_arena(json); parse_json_in_place(parser, {} , src, &tree, tree.root_id()); return tree; }