rapidyaml 0.15.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
parse_options.hpp
Go to the documentation of this file.
1#ifndef _C4_YML_PARSE_OPTIONS_HPP_
2#define _C4_YML_PARSE_OPTIONS_HPP_
3
4/** @file parse_options.hpp */
5
6#ifndef _C4_YML_COMMON_HPP_
7#include <c4/yml/common.hpp>
8#endif
9#ifndef _C4_YML_NODE_TYPE_HPP_
10#include <c4/yml/node_type.hpp>
11#endif
12#ifndef _C4_YML_ERROR_HPP_
13#include <c4/yml/error.hpp>
14#endif
15
16
17namespace c4 {
18namespace yml {
19
20/** Options to give to the parser to control its behavior. */
22{
23private:
24
25 typedef enum : uint32_t { // NOLINT
26 DETECT_FLOW_ML = (1u << 0u),
27 RESOLVE_TAGS = (1u << 1u),
28 RESOLVE_TAGS_ALL = (1u << 2u),
29 SCALAR_FILTERING = (1u << 3u),
30 LOCATIONS = (1u << 4u),
31 DEFAULTS = SCALAR_FILTERING|DETECT_FLOW_ML,
32 } Flags_e;
33
34 uint32_t m_flags = DEFAULTS;
35 NodeType_e m_flow_ml_style = FLOW_ML1;
36
37 ParserOptions& set_flags_(bool enabled, Flags_e f)
38 {
39 if(enabled)
40 m_flags |= f;
41 else
42 m_flags &= ~f;
43 return *this;
44 }
45
46public:
47
48 ParserOptions() noexcept = default;
49
50public:
51
52 /** @name detection of @ref FLOW_ML container style
53 * @{ */
54
55 /** enable/disable detection of flow multiline container
56 * style. When enabled, the parser will set either @ref FLOW_ML1
57 * or @ref FLOW_MLN flow multiline style as the style of flow
58 * containers which have the terminating bracket on a line
59 * different from that of the opening bracket. Default is to
60 * detect flow multiline. Use @ref ParserOptions::flow_ml_style()
61 * to choose between the @ref FLOW_ML1 or @ref FLOW_MLN styles. */
62 ParserOptions& detect_flow_ml(bool enabled) noexcept
63 {
64 return set_flags_(enabled, DETECT_FLOW_ML);
65 }
66 /** query status of detection of flow multiline container style. */
67 C4_ALWAYS_INLINE bool detect_flow_ml() const noexcept { return (m_flags & DETECT_FLOW_ML); }
68
69 /** choose the default style of multiline flow containers, when a
70 * container is detected as flow multiline. Input should be @ref
71 * FLOW_ML1 or @ref FLOW_MLN . Default is @ref FLOW_ML1 (the old
72 * behavior). */
74 {
75 _RYML_ASSERT_BASIC(style & (FLOW_ML1|FLOW_MLN));
76 m_flow_ml_style = style & (FLOW_ML1|FLOW_MLN);
77 return *this;
78 }
79 C4_ALWAYS_INLINE NodeType flow_ml_style() const noexcept { return m_flow_ml_style; }
80
81 /** @} */
82
83public:
84
85 /** @name resolution of tags */
86 /** @{ */
87
88 /** enable/disable resolution of YAML tags during parsing. When
89 * enabled, tags are resolved according to existing tag
90 * directives. Disabled by default. See also @ref
91 * ParserOptions::resolve_tags_all(). */
92 ParserOptions& resolve_tags(bool enabled) noexcept
93 {
94 return set_flags_(enabled, RESOLVE_TAGS);
95 }
96 /** query status of tag resolution setting. */
97 C4_ALWAYS_INLINE bool resolve_tags() const noexcept { return (m_flags & RESOLVE_TAGS); }
98
99 /** When resolve_tags() is enabled, resolve not just prefixed tags
100 * of the form <pre>!handle!tag</pre>, but also non-prefixed tags
101 * (<pre>!!tag</pre> and <pre>!tag!</pre>). Disabled by default. */
102 ParserOptions& resolve_tags_all(bool enabled) noexcept
103 {
104 return set_flags_(enabled, RESOLVE_TAGS_ALL);
105 }
106 /** query status of non-prefixed tag resolution setting. */
107 C4_ALWAYS_INLINE bool resolve_tags_all() const noexcept { return (m_flags & RESOLVE_TAGS_ALL); }
108
109 /** @} */
110
111public:
112
113 /** @name source location tracking */
114 /** @{ */
115
116 /** enable/disable source location tracking. Disabled by default. */
117 ParserOptions& locations(bool enabled) noexcept
118 {
119 return set_flags_(enabled, LOCATIONS);
120 }
121 /** query source location tracking status */
122 C4_ALWAYS_INLINE bool locations() const noexcept { return (m_flags & LOCATIONS); }
123
124 /** @} */
125
126public:
127
128 /** @name scalar filtering status (experimental; disable at your discretion) */
129 /** @{ */
130
131 /** enable/disable scalar filtering while parsing. Enabled by default. */
132 ParserOptions& scalar_filtering(bool enabled) noexcept
133 {
134 return set_flags_(enabled, SCALAR_FILTERING);
135 }
136 /** query scalar filtering status */
137 C4_ALWAYS_INLINE bool scalar_filtering() const noexcept { return (m_flags & SCALAR_FILTERING); }
138
139 /** @} */
140};
141
142} // namespace yml
143} // namespace c4
144
145#endif /* _C4_YML_PARSE_OPTIONS_HPP_ */
Common utilities and infrastructure used by ryml.
Error utilities used by ryml.
#define RYML_EXPORT
Definition export.hpp:18
NodeType_e
a bit mask for marking node types and styles
Definition node_type.hpp:34
@ FLOW_ML1
mark container with multi-line flow style, 1 element per line
Definition node_type.hpp:79
@ FLOW_MLN
mark container with multi-line flow style, n elements per line, wrapped (as set by EmitOptions::max_c...
Definition node_type.hpp:94
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition common.cpp:14
wraps a NodeType_e element with some syntactic sugar and predicates
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of flow multiline container style.
bool scalar_filtering() const noexcept
query scalar filtering status
ParserOptions & locations(bool enabled) noexcept
enable/disable source location tracking.
bool resolve_tags_all() const noexcept
query status of non-prefixed tag resolution setting.
ParserOptions & scalar_filtering(bool enabled) noexcept
enable/disable scalar filtering while parsing.
bool locations() const noexcept
query source location tracking status
NodeType flow_ml_style() const noexcept
bool detect_flow_ml() const noexcept
query status of detection of flow multiline container style.
ParserOptions() noexcept=default
ParserOptions & resolve_tags(bool enabled) noexcept
enable/disable resolution of YAML tags during parsing.
ParserOptions & resolve_tags_all(bool enabled) noexcept
When resolve_tags() is enabled, resolve not just prefixed tags of the form.
ParserOptions & flow_ml_style(NodeType style) noexcept
choose the default style of multiline flow containers, when a container is detected as flow multiline...
bool resolve_tags() const noexcept
query status of tag resolution setting.