rapidyaml  0.12.1
parse and emit YAML, and do it fast
Parse utilities

Modules

 Scalar filter processors
 These are internal utilities used by ParseEngine to parse the scalars; normally there is no reason for a user to be manually using these classes.
 
 Parse in place with existing parser
 parse a mutable YAML source buffer (re)using an existing parser.
 
 Parse in place with temporary parser
 parse a mutable YAML source buffer.
 
 Parse in arena with existing parser
 parse a read-only (immutable) YAML source buffer.
 
 Parse in arena with temporary parser
 parse a read-only (immutable) YAML source buffer.
 
 Event Handlers
 rapidyaml implements its parsing logic with a two-level model, where a ParseEngine object reads through the YAML source, and dispatches events to an EventHandler bound to the ParseEngine.
 

Classes

class  c4::yml::ParseEngine< EventHandler >
 This is the main driver of parsing logic: it scans the YAML or JSON source for tokens, and emits the appropriate sequence of parsing events to its event handler. More...
 

Typedefs

using c4::yml::Parser = ParseEngine< EventHandlerTree >
 This is the main ryml parser, where the parser events are handled to create a ryml tree. More...
 

Functions

id_type c4::yml::estimate_tree_capacity (csubstr src)
 Quickly inspect the source to estimate the number of nodes the resulting tree is likely to have. More...
 

Detailed Description

See also
sample::sample_parse_in_place
sample::sample_parse_in_arena
sample::sample_parse_file
sample::sample_parse_reuse_tree
sample::sample_parse_reuse_parser
sample::sample_parse_reuse_tree_and_parser
sample::sample_location_tracking

Typedef Documentation

◆ Parser

This is the main ryml parser, where the parser events are handled to create a ryml tree.

Warning
This class cannot parse YAML where there are container keys. This is not a limitation of the ParseEngine, but of the EventHandlerTree, which is present because the Tree does not accept containers as keys. However, the ParseEngine can parse container keys; consult its documentation for more details.
See also
ParserOptions
ParseEngine
EventHandlerTree

Definition at line 19 of file fwd.hpp.

Function Documentation

◆ estimate_tree_capacity()

id_type c4::yml::estimate_tree_capacity ( csubstr  src)

Quickly inspect the source to estimate the number of nodes the resulting tree is likely to have.

If a tree is empty before parsing, considerable time will be spent growing it, so calling this to reserve the tree size prior to parsing is likely to result in a time gain. We encourage using this method before parsing, but as always measure its impact in performance to obtain a good trade-off.

Note
since this method is meant for optimizing performance, it is approximate. The result may be actually smaller than the resulting number of nodes, notably if the YAML uses implicit maps as flow seq members as in [these: are, individual: maps].

Definition at line 134 of file parse.cpp.

135 {
136  id_type num_nodes = 1; // root
137  for(size_t i = 0; i < src.len; ++i)
138  {
139  const char c = src.str[i];
140  num_nodes += (c == '\n') || (c == ',') || (c == '[') || (c == '{');
141  }
142  return num_nodes;
143 }
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...
Definition: common.hpp:244