blob: c59682180a31015b2d91fdcc0c3b27a2d5bfd9f6 [file] [log] [blame]
Václav Kubernát0a2a2e82018-05-11 13:59:12 +02001/*
2 * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
3 * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
4 *
5 * Written by Václav Kubernát <kubervac@fit.cvut.cz>
6 *
7*/
8
9#pragma once
Václav Kubernát195eeea2018-05-18 13:52:36 +020010
Václav Kubernát195eeea2018-05-18 13:52:36 +020011#include "parser_context.hpp"
Václav Kubernát48fc3832018-05-28 14:21:22 +020012#include "schema.hpp"
Václav Kubernátebca2552018-06-08 19:06:02 +020013#include "utils.hpp"
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020014
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020015struct keyValue_class {
16 template <typename T, typename Iterator, typename Context>
17 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
18 {
19 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát48fc3832018-05-28 14:21:22 +020020 const Schema& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020021
22 if (parserContext.m_tmpListKeys.find(ast.first) != parserContext.m_tmpListKeys.end()) {
23 _pass(context) = false;
24 parserContext.m_errorMsg = "Key \"" + ast.first + "\" was entered more than once.";
Václav Kubernát744f57f2018-06-29 22:46:26 +020025 } else if (!schema.listHasKey(parserContext.m_curPath, {parserContext.m_curModule, parserContext.m_tmpListName}, ast.first)) {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020026 _pass(context) = false;
27 parserContext.m_errorMsg = parserContext.m_tmpListName + " is not indexed by \"" + ast.first + "\".";
Václav Kubernát41378452018-06-06 16:29:40 +020028 } else {
29 parserContext.m_tmpListKeys.insert(ast.first);
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020030 }
31 }
Václav Kubernát41378452018-06-06 16:29:40 +020032
33 template <typename Iterator, typename Exception, typename Context>
34 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
35 {
36 auto& parserContext = x3::get<parser_context_tag>(context);
37 parserContext.m_errorMsg = "Error parsing key values here:";
38 return x3::error_handler_result::rethrow;
39 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020040};
Václav Kubernát41378452018-06-06 16:29:40 +020041
Václav Kubernát744f57f2018-06-29 22:46:26 +020042struct node_identifier_class {
43 template <typename T, typename Iterator, typename Context>
44 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
45 {
46 auto& parserContext = x3::get<parser_context_tag>(context);
47
48 if (!parserContext.m_topLevelModulePresent) {
49 if (parserContext.m_errorMsg.empty())
50 parserContext.m_errorMsg = "You have to specify a top level module.";
51 _pass(context) = false;
52 }
53 }
54};
55
Václav Kubernát89728d82018-09-13 16:28:28 +020056struct key_identifier_class;
57
Václav Kubernát744f57f2018-06-29 22:46:26 +020058struct module_identifier_class;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020059
60struct listPrefix_class {
61 template <typename T, typename Iterator, typename Context>
62 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
63 {
64 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát48fc3832018-05-28 14:21:22 +020065 const Schema& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020066
Václav Kubernát744f57f2018-06-29 22:46:26 +020067 if (schema.isList(parserContext.m_curPath, {parserContext.m_curModule, ast})) {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020068 parserContext.m_tmpListName = ast;
69 } else {
70 _pass(context) = false;
71 }
72 }
73};
74
75struct listSuffix_class {
76 template <typename T, typename Iterator, typename Context>
77 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
78 {
79 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát48fc3832018-05-28 14:21:22 +020080 const Schema& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020081
Václav Kubernát744f57f2018-06-29 22:46:26 +020082 const auto& keysNeeded = schema.listKeys(parserContext.m_curPath, {parserContext.m_curModule, parserContext.m_tmpListName});
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020083 std::set<std::string> keysSupplied;
84 for (const auto& it : ast)
85 keysSupplied.insert(it.first);
86
87 if (keysNeeded != keysSupplied) {
88 parserContext.m_errorMsg = "Not enough keys for " + parserContext.m_tmpListName + ". " +
89 "These keys were not supplied:";
90 std::set<std::string> missingKeys;
91 std::set_difference(keysNeeded.begin(), keysNeeded.end(),
92 keysSupplied.begin(), keysSupplied.end(),
93 std::inserter(missingKeys, missingKeys.end()));
94
95 for (const auto& it : missingKeys)
96 parserContext.m_errorMsg += " " + it;
97 parserContext.m_errorMsg += ".";
98
99 _pass(context) = false;
100 }
101 }
Václav Kubernát41378452018-06-06 16:29:40 +0200102
103 template <typename Iterator, typename Exception, typename Context>
104 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
105 {
106 auto& parserContext = x3::get<parser_context_tag>(context);
107 if (parserContext.m_errorMsg.empty())
108 parserContext.m_errorMsg = "Expecting ']' here:";
109 return x3::error_handler_result::rethrow;
Václav Kubernát41378452018-06-06 16:29:40 +0200110 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200111};
112struct listElement_class {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200113 template <typename Iterator, typename Exception, typename Context>
Václav Kubernát41378452018-06-06 16:29:40 +0200114 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200115 {
116 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200117 if (parserContext.m_errorMsg.empty()) {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200118 return x3::error_handler_result::fail;
Václav Kubernát41378452018-06-06 16:29:40 +0200119 } else {
120 return x3::error_handler_result::rethrow;
121 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200122 }
123};
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200124struct list_class {
125 template <typename T, typename Iterator, typename Context>
126 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
127 {
128 auto& parserContext = x3::get<parser_context_tag>(context);
129 const Schema& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200130
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200131 if (!schema.isList(parserContext.m_curPath, {parserContext.m_curModule, ast.m_name})) {
132 _pass(context) = false;
133 }
134 }
135};
Václav Kubernát60d6f292018-05-25 09:45:32 +0200136struct nodeup_class {
137 template <typename T, typename Iterator, typename Context>
138 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
139 {
140 auto& parserContext = x3::get<parser_context_tag>(context);
141
Václav Kubernát744f57f2018-06-29 22:46:26 +0200142 if (parserContext.m_curPath.m_nodes.empty())
Václav Kubernát60d6f292018-05-25 09:45:32 +0200143 _pass(context) = false;
Václav Kubernát60d6f292018-05-25 09:45:32 +0200144 }
145};
146
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200147struct container_class {
148 template <typename T, typename Iterator, typename Context>
149 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
150 {
151 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát48fc3832018-05-28 14:21:22 +0200152 const auto& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200153
Václav Kubernát744f57f2018-06-29 22:46:26 +0200154 if (!schema.isContainer(parserContext.m_curPath, {parserContext.m_curModule, ast.m_name}))
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200155 _pass(context) = false;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200156 }
157};
158
Václav Kubernát07204242018-06-04 18:12:09 +0200159struct leaf_class {
160 template <typename T, typename Iterator, typename Context>
161 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
162 {
163 auto& parserContext = x3::get<parser_context_tag>(context);
164 const auto& schema = parserContext.m_schema;
165
Václav Kubernát744f57f2018-06-29 22:46:26 +0200166 if (!schema.isLeaf(parserContext.m_curPath, {parserContext.m_curModule, ast.m_name}))
167 _pass(context) = false;
168 }
169};
170
Václav Kubernát744f57f2018-06-29 22:46:26 +0200171struct module_class {
172 template <typename T, typename Iterator, typename Context>
173 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
174 {
175 auto& parserContext = x3::get<parser_context_tag>(context);
176 const auto& schema = parserContext.m_schema;
177
178 if (schema.isModule(parserContext.m_curPath, ast.m_name)) {
179 parserContext.m_curModule = ast.m_name;
180 parserContext.m_topLevelModulePresent = true;
Václav Kubernát07204242018-06-04 18:12:09 +0200181 } else {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200182 parserContext.m_errorMsg = "Invalid module name.";
Václav Kubernát07204242018-06-04 18:12:09 +0200183 _pass(context) = false;
184 }
185 }
186};
187
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200188struct schemaNode_class {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200189 template <typename T, typename Iterator, typename Context>
Václav Kubernát744f57f2018-06-29 22:46:26 +0200190 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200191 {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200192 auto& parserContext = x3::get<parser_context_tag>(context);
193 if (ast.m_suffix.type() == typeid(nodeup_)) {
194 parserContext.m_curPath.m_nodes.pop_back();
195 if (parserContext.m_curPath.m_nodes.empty())
196 parserContext.m_topLevelModulePresent = false;
197 } else {
198 parserContext.m_curPath.m_nodes.push_back(ast);
199 parserContext.m_curModule = boost::none;
200 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200201 }
Václav Kubernát744f57f2018-06-29 22:46:26 +0200202};
Václav Kubernát07204242018-06-04 18:12:09 +0200203
Václav Kubernát5c75b252018-10-10 18:33:47 +0200204struct dataNodeList_class;
205
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200206struct dataNode_class {
207 template <typename T, typename Iterator, typename Context>
208 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
209 {
210 auto& parserContext = x3::get<parser_context_tag>(context);
211 if (ast.m_suffix.type() == typeid(nodeup_)) {
212 parserContext.m_curPath.m_nodes.pop_back();
213 if (parserContext.m_curPath.m_nodes.empty())
214 parserContext.m_topLevelModulePresent = false;
215 } else {
216 parserContext.m_curPath.m_nodes.push_back(dataNodeToSchemaNode(ast));
217 parserContext.m_curModule = boost::none;
218 }
219 }
220};
221
Václav Kubernát37171a12018-08-31 17:01:48 +0200222struct absoluteStart_class {
223 template <typename T, typename Iterator, typename Context>
224 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
225 {
226 auto& parserContext = x3::get<parser_context_tag>(context);
227 parserContext.m_curPath.m_nodes.clear();
228 }
229};
230
Václav Kubernát5c75b252018-10-10 18:33:47 +0200231struct dataNodesListEnd_class;
232
233struct dataPathListEnd_class;
234
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200235struct dataPath_class {
236 template <typename Iterator, typename Exception, typename Context>
237 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
238 {
239 auto& parserContext = x3::get<parser_context_tag>(context);
240 if (parserContext.m_errorMsg.empty()) {
241 parserContext.m_errorMsg = "Expected path.";
242 return x3::error_handler_result::fail;
243 } else {
244 return x3::error_handler_result::rethrow;
245 }
246 }
247};
248
249struct schemaPath_class {
Václav Kubernát07204242018-06-04 18:12:09 +0200250 template <typename Iterator, typename Exception, typename Context>
Václav Kubernát41378452018-06-06 16:29:40 +0200251 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
Václav Kubernát07204242018-06-04 18:12:09 +0200252 {
253 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200254 if (parserContext.m_errorMsg.empty()) {
255 parserContext.m_errorMsg = "Expected path.";
Václav Kubernát07204242018-06-04 18:12:09 +0200256 return x3::error_handler_result::fail;
Václav Kubernát41378452018-06-06 16:29:40 +0200257 } else {
258 return x3::error_handler_result::rethrow;
259 }
Václav Kubernát07204242018-06-04 18:12:09 +0200260 }
261};
262
Václav Kubernát6d791432018-10-25 16:00:35 +0200263struct discard_class;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200264
Václav Kubernát11afac72018-07-18 14:59:53 +0200265struct ls_class;
266
Václav Kubernát744f57f2018-06-29 22:46:26 +0200267struct cd_class {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200268 template <typename Iterator, typename Exception, typename Context>
269 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
270 {
271 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200272 if (parserContext.m_errorMsg.empty())
273 parserContext.m_errorMsg = "Expected " + x.which() + " here:";
274 return x3::error_handler_result::rethrow;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200275 }
276};
Václav Kubernátb61336d2018-05-28 17:35:03 +0200277
278struct presenceContainerPathHandler {
279 template <typename T, typename Iterator, typename Context>
280 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
281 {
282 auto& parserContext = x3::get<parser_context_tag>(context);
283 const auto& schema = parserContext.m_schema;
284 try {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200285 boost::optional<std::string> module;
286 if (ast.m_path.m_nodes.back().m_prefix)
287 module = ast.m_path.m_nodes.back().m_prefix.value().m_name;
288 container_ cont = boost::get<container_>(ast.m_path.m_nodes.back().m_suffix);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200289 schemaPath_ location = pathWithoutLastNode(parserContext.m_curPath);
Václav Kubernátb61336d2018-05-28 17:35:03 +0200290
Václav Kubernát744f57f2018-06-29 22:46:26 +0200291 if (!schema.isPresenceContainer(location, {module, cont.m_name})) {
Václav Kubernát41378452018-06-06 16:29:40 +0200292 parserContext.m_errorMsg = "This container is not a presence container.";
Václav Kubernátb61336d2018-05-28 17:35:03 +0200293 _pass(context) = false;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200294 }
295 } catch (boost::bad_get&) {
Václav Kubernát41378452018-06-06 16:29:40 +0200296 parserContext.m_errorMsg = "This is not a container.";
Václav Kubernátb61336d2018-05-28 17:35:03 +0200297 _pass(context) = false;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200298 }
299 }
300
301 template <typename Iterator, typename Exception, typename Context>
Václav Kubernát41378452018-06-06 16:29:40 +0200302 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200303 {
304 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200305 if (parserContext.m_errorMsg.empty())
306 parserContext.m_errorMsg = "Couldn't parse create/delete command.";
307 return x3::error_handler_result::rethrow;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200308 }
309};
310
311struct create_class : public presenceContainerPathHandler {
312};
313
314struct delete_class : public presenceContainerPathHandler {
315};
316
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200317struct leaf_path_class {
318 template <typename T, typename Iterator, typename Context>
319 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
320 {
321 auto& parserContext = x3::get<parser_context_tag>(context);
322 try {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200323 auto leaf = boost::get<leaf_>(ast.m_nodes.back().m_suffix);
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200324 } catch (boost::bad_get&) {
325 parserContext.m_errorMsg = "This is not a path to leaf.";
326 _pass(context) = false;
327 }
328 }
329};
330
Václav Kubernátebca2552018-06-08 19:06:02 +0200331struct leaf_data_class {
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200332 template <typename Iterator, typename Exception, typename Context>
333 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
334 {
335 auto& parserContext = x3::get<parser_context_tag>(context);
336 auto& schema = parserContext.m_schema;
337 if (parserContext.m_errorMsg.empty()) {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200338 leaf_ leaf = boost::get<leaf_>(parserContext.m_curPath.m_nodes.back().m_suffix);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200339 schemaPath_ location = pathWithoutLastNode(parserContext.m_curPath);
340 if (location.m_nodes.empty()) {
Václav Kubernát5c75b252018-10-10 18:33:47 +0200341 parserContext.m_curModule = parserContext.m_curPath.m_nodes.back().m_prefix->m_name;
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200342 }
Václav Kubernát744f57f2018-06-29 22:46:26 +0200343 parserContext.m_errorMsg = "Expected " + leafDataTypeToString(schema.leafType(location, {parserContext.m_curModule, leaf.m_name})) + " here:";
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200344 return x3::error_handler_result::fail;
345 }
346 return x3::error_handler_result::rethrow;
347 }
Václav Kubernátebca2552018-06-08 19:06:02 +0200348};
349
350struct leaf_data_base_class {
351 yang::LeafDataTypes m_type;
352
353 leaf_data_base_class(yang::LeafDataTypes type)
354 : m_type(type)
355 {
356 }
357
358 template <typename T, typename Iterator, typename Context>
359 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
360 {
361 auto& parserContext = x3::get<parser_context_tag>(context);
362 auto& schema = parserContext.m_schema;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200363 boost::optional<std::string> module;
364 if (parserContext.m_curPath.m_nodes.back().m_prefix)
365 module = parserContext.m_curPath.m_nodes.back().m_prefix.value().m_name;
Václav Kubernátebca2552018-06-08 19:06:02 +0200366
Václav Kubernát744f57f2018-06-29 22:46:26 +0200367 leaf_ leaf = boost::get<leaf_>(parserContext.m_curPath.m_nodes.back().m_suffix);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200368 schemaPath_ location = pathWithoutLastNode(parserContext.m_curPath);
Václav Kubernátebca2552018-06-08 19:06:02 +0200369
Václav Kubernát744f57f2018-06-29 22:46:26 +0200370 if (schema.leafType(location, {module, leaf.m_name}) != m_type) {
Václav Kubernátebca2552018-06-08 19:06:02 +0200371 _pass(context) = false;
372 }
373 }
374};
375
376struct leaf_data_enum_class : leaf_data_base_class {
377 leaf_data_enum_class()
378 : leaf_data_base_class(yang::LeafDataTypes::Enum)
379 {
380 }
381
382 template <typename T, typename Iterator, typename Context>
383 void on_success(Iterator const& start, Iterator const& end, T& ast, Context const& context)
384 {
385 leaf_data_base_class::on_success(start, end, ast, context);
386 auto& parserContext = x3::get<parser_context_tag>(context);
387 auto& schema = parserContext.m_schema;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200388 boost::optional<std::string> module;
389 if (parserContext.m_curPath.m_nodes.back().m_prefix)
390 module = parserContext.m_curPath.m_nodes.back().m_prefix.value().m_name;
Václav Kubernátebca2552018-06-08 19:06:02 +0200391
Václav Kubernát744f57f2018-06-29 22:46:26 +0200392 leaf_ leaf = boost::get<leaf_>(parserContext.m_curPath.m_nodes.back().m_suffix);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200393 schemaPath_ location = pathWithoutLastNode(parserContext.m_curPath);
Václav Kubernátebca2552018-06-08 19:06:02 +0200394
Václav Kubernát744f57f2018-06-29 22:46:26 +0200395 if (!schema.leafEnumHasValue(location, {module, leaf.m_name}, ast.m_value)) {
Václav Kubernátebca2552018-06-08 19:06:02 +0200396 _pass(context) = false;
397 }
398 }
399};
400
401struct leaf_data_decimal_class : leaf_data_base_class {
402 leaf_data_decimal_class()
403 : leaf_data_base_class(yang::LeafDataTypes::Decimal)
404 {
405 }
406};
407
408struct leaf_data_bool_class : leaf_data_base_class {
409 leaf_data_bool_class()
410 : leaf_data_base_class(yang::LeafDataTypes::Bool)
411 {
412 }
413};
414
415struct leaf_data_int_class : leaf_data_base_class {
416 leaf_data_int_class()
417 : leaf_data_base_class(yang::LeafDataTypes::Int)
418 {
419 }
420};
421
422struct leaf_data_uint_class : leaf_data_base_class {
423 leaf_data_uint_class()
424 : leaf_data_base_class(yang::LeafDataTypes::Uint)
425 {
426 }
427};
428
429struct leaf_data_string_class : leaf_data_base_class {
430 leaf_data_string_class()
431 : leaf_data_base_class(yang::LeafDataTypes::String)
432 {
433 }
434};
435
Václav Kubernát07204242018-06-04 18:12:09 +0200436struct set_class {
Václav Kubernát07204242018-06-04 18:12:09 +0200437 template <typename Iterator, typename Exception, typename Context>
438 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
439 {
440 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200441 if (parserContext.m_errorMsg.empty())
442 parserContext.m_errorMsg = "Expected " + x.which() + " here:";
443 return x3::error_handler_result::rethrow;
Václav Kubernát07204242018-06-04 18:12:09 +0200444 }
445};
446
Václav Kubernát812ee282018-08-30 17:10:03 +0200447struct commit_class;
448
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200449struct get_class;
450
Václav Kubernátb61336d2018-05-28 17:35:03 +0200451struct command_class {
452 template <typename Iterator, typename Exception, typename Context>
453 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
454 {
455 auto& parserContext = x3::get<parser_context_tag>(context);
456 auto& error_handler = x3::get<x3::error_handler_tag>(context).get();
Václav Kubernát41378452018-06-06 16:29:40 +0200457 if (parserContext.m_errorMsg.empty()) {
458 parserContext.m_errorMsg = "Unknown command.";
459 }
460 error_handler(x.where(), parserContext.m_errorMsg);
Václav Kubernátb61336d2018-05-28 17:35:03 +0200461 return x3::error_handler_result::fail;
462 }
463};
Václav Kubernát5c75b252018-10-10 18:33:47 +0200464
465struct initializeContext_class {
466 template <typename T, typename Iterator, typename Context>
467 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
468 {
469 auto& parserContext = x3::get<parser_context_tag>(context);
470 parserContext.m_curPath = parserContext.m_curPathOrig;
471 parserContext.m_tmpListKeys.clear();
472 parserContext.m_tmpListName.clear();
473 if (!parserContext.m_curPath.m_nodes.empty() && parserContext.m_curPath.m_nodes.at(0).m_prefix)
474 parserContext.m_topLevelModulePresent = true;
475 else
476 parserContext.m_topLevelModulePresent = false;
477 }
478};
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100479
480struct trailingSlash_class;