rapidyaml  0.16.0
parseandemitYAML,anddoitfast
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 
17 namespace c4 {
18 namespace yml {
19 
20 /** Options to give to the @ref ParseEngine to control its behavior. */
22 {
23 private:
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  type_bits 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 
46 public:
47 
48  ParserOptions() noexcept = default;
49 
50 public:
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 
83 public:
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 
111 public:
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 
126 public:
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_ */
ParserOptions & resolve_tags_all(bool enabled) noexcept
When resolve_tags() is enabled, resolve not just prefixed tags of the form.
ParserOptions & detect_flow_ml(bool enabled) noexcept
enable/disable detection of flow multiline container style.
bool detect_flow_ml() const noexcept
query status of detection of flow multiline container style.
mark container with multi-line flow style, n elements per line, < wrapped (as set by EmitOptions::max...
Definition: node_type.hpp:90
bool scalar_filtering() const noexcept
query scalar filtering status
ParserOptions & scalar_filtering(bool enabled) noexcept
enable/disable scalar filtering while parsing.
Common utilities and infrastructure used by ryml.
Options to give to the ParseEngine to control its behavior.
ParserOptions & resolve_tags(bool enabled) noexcept
enable/disable resolution of YAML tags during parsing.
ParserOptions & locations(bool enabled) noexcept
enable/disable source location tracking.
Error utilities used by ryml.
bool resolve_tags_all() const noexcept
query status of non-prefixed tag resolution setting.
bool locations() const noexcept
query source location tracking status
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
Definition: node_type.hpp:26
bool resolve_tags() const noexcept
query status of tag resolution setting.
ParserOptions & flow_ml_style(NodeType style) noexcept
choose the default style of multiline flow containers, when a container is detected as flow multiline...
#define RYML_EXPORT
Definition: export.hpp:18
Wraps a type_bits mask of NodeTypeBits flags with some syntactic sugar and predicates.
Definition: node_type.hpp:213
mark container with multi-line flow style, 1 element per line < - seqs as <
Definition: node_type.hpp:75
NodeType flow_ml_style() const noexcept