blob: 54f3f95283946f47bb9dc4e7a25949aade7fb65a [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át57272422019-02-08 12:48:24 +010011#include <boost/mpl/for_each.hpp>
Václav Kubernát509ce652019-05-29 19:46:44 +020012#include <boost/spirit/home/x3.hpp>
13#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
14
15
Václav Kubernát57272422019-02-08 12:48:24 +010016#include "ast_commands.hpp"
Václav Kubernát4294a852020-02-14 15:07:14 +010017#include "parser_context.hpp"
Václav Kubernát48fc3832018-05-28 14:21:22 +020018#include "schema.hpp"
Václav Kubernátebca2552018-06-08 19:06:02 +020019#include "utils.hpp"
Václav Kubernát329c6c32019-02-06 16:41:53 +010020namespace x3 = boost::spirit::x3;
21
22struct parser_context_tag;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020023
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020024struct keyValue_class {
25 template <typename T, typename Iterator, typename Context>
26 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
27 {
28 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020029
30 if (parserContext.m_tmpListKeys.find(ast.first) != parserContext.m_tmpListKeys.end()) {
31 _pass(context) = false;
32 parserContext.m_errorMsg = "Key \"" + ast.first + "\" was entered more than once.";
Václav Kubernát41378452018-06-06 16:29:40 +020033 } else {
Václav Kubernát43908fb2020-01-02 19:05:51 +010034 parserContext.m_tmpListKeys.insert({ast.first, ast.second});
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020035 }
36 }
Václav Kubernát41378452018-06-06 16:29:40 +020037
38 template <typename Iterator, typename Exception, typename Context>
39 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
40 {
41 auto& parserContext = x3::get<parser_context_tag>(context);
42 parserContext.m_errorMsg = "Error parsing key values here:";
43 return x3::error_handler_result::rethrow;
44 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020045};
Václav Kubernát41378452018-06-06 16:29:40 +020046
Václav Kubernátf3e377b2020-05-28 23:26:38 +020047struct node_identifier_class;
Václav Kubernát744f57f2018-06-29 22:46:26 +020048
Václav Kubernát2db124c2020-05-28 21:58:36 +020049boost::optional<std::string> optModuleToOptString(const boost::optional<module_> module);
50
Václav Kubernát7707cae2020-01-16 12:04:53 +010051struct key_identifier_class {
52 template <typename T, typename Iterator, typename Context>
53 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
54 {
Václav Kubernát2db124c2020-05-28 21:58:36 +020055 ParserContext& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát7707cae2020-01-16 12:04:53 +010056 const Schema& schema = parserContext.m_schema;
Václav Kubernát7707cae2020-01-16 12:04:53 +010057
Václav Kubernát2db124c2020-05-28 21:58:36 +020058 if (schema.listHasKey(dataPathToSchemaPath(parserContext.m_tmpListPath), ast)) {
59 parserContext.m_tmpListKeyLeafPath.m_location = dataPathToSchemaPath(parserContext.m_tmpListPath);
60 parserContext.m_tmpListKeyLeafPath.m_node = { optModuleToOptString(parserContext.m_tmpListPath.m_nodes.back().m_prefix), ast };
Václav Kubernát7707cae2020-01-16 12:04:53 +010061 } else {
Václav Kubernát2db124c2020-05-28 21:58:36 +020062 auto listName = std::get<list_>(parserContext.m_tmpListPath.m_nodes.back().m_suffix).m_name;
63 parserContext.m_errorMsg = listName + " is not indexed by \"" + ast + "\".";
Václav Kubernát7707cae2020-01-16 12:04:53 +010064 _pass(context) = false;
65 }
66 }
67};
Václav Kubernát89728d82018-09-13 16:28:28 +020068
Václav Kubernát744f57f2018-06-29 22:46:26 +020069struct module_identifier_class;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020070
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020071struct listSuffix_class {
72 template <typename T, typename Iterator, typename Context>
73 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
74 {
75 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát48fc3832018-05-28 14:21:22 +020076 const Schema& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020077
Václav Kubernát2db124c2020-05-28 21:58:36 +020078 const auto& keysNeeded = schema.listKeys(dataPathToSchemaPath(parserContext.m_tmpListPath));
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020079 std::set<std::string> keysSupplied;
80 for (const auto& it : ast)
81 keysSupplied.insert(it.first);
82
83 if (keysNeeded != keysSupplied) {
Václav Kubernát2db124c2020-05-28 21:58:36 +020084 auto listName = std::get<list_>(parserContext.m_tmpListPath.m_nodes.back().m_suffix).m_name;
85 parserContext.m_errorMsg = "Not enough keys for " + listName + ". " +
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020086 "These keys were not supplied:";
87 std::set<std::string> missingKeys;
88 std::set_difference(keysNeeded.begin(), keysNeeded.end(),
89 keysSupplied.begin(), keysSupplied.end(),
90 std::inserter(missingKeys, missingKeys.end()));
91
92 for (const auto& it : missingKeys)
93 parserContext.m_errorMsg += " " + it;
94 parserContext.m_errorMsg += ".";
95
96 _pass(context) = false;
Václav Kubernátbf65dd72020-05-28 02:32:31 +020097 return;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020098 }
Václav Kubernátbf65dd72020-05-28 02:32:31 +020099
100 // Clean up after listSuffix, in case someone wants to parse more listSuffixes
101 parserContext.m_tmpListKeys.clear();
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200102 }
Václav Kubernát41378452018-06-06 16:29:40 +0200103
104 template <typename Iterator, typename Exception, typename Context>
105 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
106 {
107 auto& parserContext = x3::get<parser_context_tag>(context);
108 if (parserContext.m_errorMsg.empty())
109 parserContext.m_errorMsg = "Expecting ']' here:";
110 return x3::error_handler_result::rethrow;
Václav Kubernát41378452018-06-06 16:29:40 +0200111 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200112};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200113
Václav Kubernát744f57f2018-06-29 22:46:26 +0200114struct module_class {
115 template <typename T, typename Iterator, typename Context>
116 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
117 {
118 auto& parserContext = x3::get<parser_context_tag>(context);
119 const auto& schema = parserContext.m_schema;
120
Václav Kubernát1bcee3b2020-05-28 22:19:59 +0200121 if (!schema.isModule(ast.m_name)) {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200122 parserContext.m_errorMsg = "Invalid module name.";
Václav Kubernát07204242018-06-04 18:12:09 +0200123 _pass(context) = false;
124 }
125 }
126};
127
Václav Kubernát37171a12018-08-31 17:01:48 +0200128struct absoluteStart_class {
129 template <typename T, typename Iterator, typename Context>
130 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
131 {
132 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát72749c62020-01-03 16:47:34 +0100133 parserContext.clearPath();
Václav Kubernát37171a12018-08-31 17:01:48 +0200134 }
135};
136
Václav Kubernát6d791432018-10-25 16:00:35 +0200137struct discard_class;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200138
Václav Kubernát11afac72018-07-18 14:59:53 +0200139struct ls_class;
140
Václav Kubernát744f57f2018-06-29 22:46:26 +0200141struct cd_class {
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200142 template <typename Iterator, typename Exception, typename Context>
143 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
144 {
145 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200146 if (parserContext.m_errorMsg.empty())
147 parserContext.m_errorMsg = "Expected " + x.which() + " here:";
148 return x3::error_handler_result::rethrow;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200149 }
150};
Václav Kubernátb61336d2018-05-28 17:35:03 +0200151
Václav Kubernát6797df02019-03-18 20:21:50 +0100152struct presenceContainerPath_class {
Václav Kubernátb61336d2018-05-28 17:35:03 +0200153 template <typename T, typename Iterator, typename Context>
154 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
155 {
156 auto& parserContext = x3::get<parser_context_tag>(context);
157 const auto& schema = parserContext.m_schema;
Václav Kubernát0d42c512020-05-20 21:18:39 +0200158 if (ast.m_nodes.empty()) {
159 parserContext.m_errorMsg = "This container is not a presence container.";
160 _pass(context) = false;
161 return;
162 }
163
Václav Kubernáte811bfa2020-05-29 02:25:20 +0200164 if (schema.nodeType(pathToSchemaString(parserContext.currentSchemaPath(), Prefixes::Always)) != yang::NodeTypes::PresenceContainer) {
165 parserContext.m_errorMsg = "This container is not a presence container.";
Václav Kubernátb61336d2018-05-28 17:35:03 +0200166 _pass(context) = false;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200167 }
168 }
Václav Kubernát6797df02019-03-18 20:21:50 +0100169};
Václav Kubernátb61336d2018-05-28 17:35:03 +0200170
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100171struct listInstancePath_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);
Václav Kubernát2ebab1d2020-05-27 01:28:30 +0200176 if (ast.m_nodes.empty() || !std::holds_alternative<listElement_>(ast.m_nodes.back().m_suffix)) {
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100177 parserContext.m_errorMsg = "This is not a list instance.";
178 _pass(context) = false;
179 }
180 }
181};
182
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200183struct leafListElementPath_class {
184 template <typename T, typename Iterator, typename Context>
185 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
186 {
187 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200188 if (ast.m_nodes.empty() || !std::holds_alternative<leafListElement_>(ast.m_nodes.back().m_suffix)) {
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200189 parserContext.m_errorMsg = "This is not a leaf list element.";
190 _pass(context) = false;
191 }
192 }
193};
194
Václav Kubernát8028f942019-09-25 16:03:23 +0200195struct space_separator_class {
196 template <typename T, typename Iterator, typename Context>
197 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
198 {
199 auto& parserContext = x3::get<parser_context_tag>(context);
200 parserContext.m_suggestions.clear();
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100201 parserContext.m_completionIterator = boost::none;
Václav Kubernát8028f942019-09-25 16:03:23 +0200202 }
203};
204
Václav Kubernát6797df02019-03-18 20:21:50 +0100205struct create_class {
Václav Kubernátb61336d2018-05-28 17:35:03 +0200206 template <typename Iterator, typename Exception, typename Context>
Václav Kubernát41378452018-06-06 16:29:40 +0200207 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200208 {
209 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200210 if (parserContext.m_errorMsg.empty())
211 parserContext.m_errorMsg = "Couldn't parse create/delete command.";
212 return x3::error_handler_result::rethrow;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200213 }
214};
215
Václav Kubernát6797df02019-03-18 20:21:50 +0100216struct delete_class {
217 template <typename Iterator, typename Exception, typename Context>
218 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
219 {
220 auto& parserContext = x3::get<parser_context_tag>(context);
221 if (parserContext.m_errorMsg.empty())
222 parserContext.m_errorMsg = "Couldn't parse create/delete command.";
223 return x3::error_handler_result::rethrow;
224 }
Václav Kubernátb61336d2018-05-28 17:35:03 +0200225};
226
Václav Kubernátabf52802020-05-19 01:31:17 +0200227struct writable_leaf_path_class {
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200228 template <typename T, typename Iterator, typename Context>
Václav Kubernát7707cae2020-01-16 12:04:53 +0100229 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200230 {
231 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát0d42c512020-05-20 21:18:39 +0200232 if (parserContext.currentSchemaPath().m_nodes.empty()) {
233 parserContext.m_errorMsg = "This is not a path to leaf.";
234 _pass(context) = false;
235 return;
236 }
237
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200238 try {
Václav Kubernát7707cae2020-01-16 12:04:53 +0100239 auto lastNode = parserContext.currentSchemaPath().m_nodes.back();
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200240 auto leaf = std::get<leaf_>(lastNode.m_suffix);
Václav Kubernát7707cae2020-01-16 12:04:53 +0100241 auto location = pathWithoutLastNode(parserContext.currentSchemaPath());
242 ModuleNodePair node{lastNode.m_prefix.flat_map([](const auto& it) { return boost::optional<std::string>{it.m_name}; }), leaf.m_name};
243
244 parserContext.m_tmpListKeyLeafPath.m_location = location;
245 parserContext.m_tmpListKeyLeafPath.m_node = node;
246
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200247 } catch (std::bad_variant_access&) {
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200248 parserContext.m_errorMsg = "This is not a path to leaf.";
249 _pass(context) = false;
250 }
251 }
252};
253
Václav Kubernát07204242018-06-04 18:12:09 +0200254struct set_class {
Václav Kubernát07204242018-06-04 18:12:09 +0200255 template <typename Iterator, typename Exception, typename Context>
256 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
257 {
258 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200259 if (parserContext.m_errorMsg.empty())
260 parserContext.m_errorMsg = "Expected " + x.which() + " here:";
261 return x3::error_handler_result::rethrow;
Václav Kubernát07204242018-06-04 18:12:09 +0200262 }
263};
264
Václav Kubernát812ee282018-08-30 17:10:03 +0200265struct commit_class;
266
Václav Kubernát9cfcd872020-02-18 12:34:02 +0100267struct describe_class;
268
Václav Kubernát054cc992019-02-21 14:23:52 +0100269struct help_class;
270
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200271struct get_class;
272
Václav Kubernát7160a132020-04-03 02:11:01 +0200273struct copy_class;
274
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200275struct move_class;
276
Václav Kubernát70d7f7a2020-06-23 14:40:40 +0200277struct dump_class;
278
Václav Kubernátb61336d2018-05-28 17:35:03 +0200279struct command_class {
280 template <typename Iterator, typename Exception, typename Context>
281 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
282 {
283 auto& parserContext = x3::get<parser_context_tag>(context);
284 auto& error_handler = x3::get<x3::error_handler_tag>(context).get();
Václav Kubernát41378452018-06-06 16:29:40 +0200285 if (parserContext.m_errorMsg.empty()) {
286 parserContext.m_errorMsg = "Unknown command.";
287 }
288 error_handler(x.where(), parserContext.m_errorMsg);
Václav Kubernátb61336d2018-05-28 17:35:03 +0200289 return x3::error_handler_result::fail;
290 }
291};
Václav Kubernát5c75b252018-10-10 18:33:47 +0200292
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100293struct initializePath_class {
Václav Kubernát5c75b252018-10-10 18:33:47 +0200294 template <typename T, typename Iterator, typename Context>
295 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
296 {
297 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát72749c62020-01-03 16:47:34 +0100298 parserContext.resetPath();
Václav Kubernátbf65dd72020-05-28 02:32:31 +0200299 parserContext.m_tmpListPath = dataPath_{};
Václav Kubernát5c75b252018-10-10 18:33:47 +0200300 parserContext.m_tmpListKeys.clear();
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100301 parserContext.m_suggestions.clear();
Václav Kubernát5c75b252018-10-10 18:33:47 +0200302 }
303};
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100304
305struct trailingSlash_class;
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100306
Václav Kubernátc15fe822020-06-04 11:28:39 +0200307std::set<Completion> generateMissingKeyCompletionSet(std::set<std::string> keysNeeded, ListInstance currentSet);
Václav Kubernát329c6c32019-02-06 16:41:53 +0100308
309struct createKeySuggestions_class {
310 template <typename T, typename Iterator, typename Context>
311 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
312 {
313 auto& parserContext = x3::get<parser_context_tag>(context);
314 const auto& schema = parserContext.m_schema;
315
316 parserContext.m_completionIterator = begin;
317
Václav Kubernát2db124c2020-05-28 21:58:36 +0200318 const auto& keysNeeded = schema.listKeys(dataPathToSchemaPath(parserContext.m_tmpListPath));
Václav Kubernát329c6c32019-02-06 16:41:53 +0100319 parserContext.m_suggestions = generateMissingKeyCompletionSet(keysNeeded, parserContext.m_tmpListKeys);
320 }
321};
322
Václav Kubernát43908fb2020-01-02 19:05:51 +0100323std::string leafDataToCompletion(const leaf_data_& value);
324
325struct createValueSuggestions_class {
326 template <typename T, typename Iterator, typename Context>
327 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
328 {
329 auto& parserContext = x3::get<parser_context_tag>(context);
330 if (!parserContext.m_completing) {
331 return;
332 }
333 const auto& dataQuery = parserContext.m_dataquery;
334
335 parserContext.m_completionIterator = begin;
Václav Kubernát2db124c2020-05-28 21:58:36 +0200336 auto listInstances = dataQuery->listKeys(parserContext.m_tmpListPath);
Václav Kubernát43908fb2020-01-02 19:05:51 +0100337
338 decltype(listInstances) filteredInstances;
339 //This filters out instances, which don't correspond to the partial instance we have.
340 const auto partialFitsComplete = [&parserContext] (const auto& complete) {
341 const auto& partial = parserContext.m_tmpListKeys;
342 return std::all_of(partial.begin(), partial.end(), [&complete] (const auto& oneKV) {
343 const auto& [k, v] = oneKV;
344 return complete.at(k) == v;
345 });
346 };
347 std::copy_if(listInstances.begin(), listInstances.end(), std::inserter(filteredInstances, filteredInstances.end()), partialFitsComplete);
348
Václav Kubernátcb3af402020-02-12 16:49:17 +0100349 std::set<Completion> validValues;
Václav Kubernát43908fb2020-01-02 19:05:51 +0100350
Václav Kubernátcb3af402020-02-12 16:49:17 +0100351 std::transform(filteredInstances.begin(), filteredInstances.end(), std::inserter(validValues, validValues.end()), [&parserContext](const auto& instance) {
352 return Completion{leafDataToCompletion(instance.at(parserContext.m_tmpListKeyLeafPath.m_node.second))};
Václav Kubernát43908fb2020-01-02 19:05:51 +0100353 });
354
355 parserContext.m_suggestions = validValues;
356 }
357};
358
Václav Kubernát329c6c32019-02-06 16:41:53 +0100359struct suggestKeysEnd_class {
360 template <typename T, typename Iterator, typename Context>
361 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
362 {
363 auto& parserContext = x3::get<parser_context_tag>(context);
364 const auto& schema = parserContext.m_schema;
365
366 parserContext.m_completionIterator = begin;
Václav Kubernát2db124c2020-05-28 21:58:36 +0200367 const auto& keysNeeded = schema.listKeys(dataPathToSchemaPath(parserContext.m_tmpListPath));
Václav Kubernát329c6c32019-02-06 16:41:53 +0100368 if (generateMissingKeyCompletionSet(keysNeeded, parserContext.m_tmpListKeys).empty()) {
Václav Kubernátcb3af402020-02-12 16:49:17 +0100369 parserContext.m_suggestions = {Completion{"]/"}};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100370 } else {
Václav Kubernátcb3af402020-02-12 16:49:17 +0100371 parserContext.m_suggestions = {Completion{"]["}};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100372 }
373 }
374};
Václav Kubernát57272422019-02-08 12:48:24 +0100375
Václav Kubernát672889c2020-05-27 04:11:36 +0200376template <typename T>
377std::string commandNamesVisitor (boost::type<T>)
378{
379 return T::name;
380}
Václav Kubernát57272422019-02-08 12:48:24 +0100381
382struct createCommandSuggestions_class {
383 template <typename T, typename Iterator, typename Context>
384 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
385 {
386 auto& parserContext = x3::get<parser_context_tag>(context);
387 parserContext.m_completionIterator = begin;
388
389 parserContext.m_suggestions.clear();
390 boost::mpl::for_each<CommandTypes, boost::type<boost::mpl::_>>([&parserContext](auto cmd) {
Václav Kubernát672889c2020-05-27 04:11:36 +0200391 parserContext.m_suggestions.insert({commandNamesVisitor(cmd), " "});
Václav Kubernát57272422019-02-08 12:48:24 +0100392 });
393 }
394};
Václav Kubernátac035d62019-02-18 10:59:08 +0100395
396struct completing_class {
397 template <typename T, typename Iterator, typename Context>
398 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
399 {
400 auto& parserContext = x3::get<parser_context_tag>(context);
401
402 if (!parserContext.m_completing)
403 _pass(context) = false;
404 }
405};