blob: 7d38d7333c281f653df81122851e75503da9043c [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át7707cae2020-01-16 12:04:53 +010049struct key_identifier_class {
50 template <typename T, typename Iterator, typename Context>
51 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
52 {
53 auto& parserContext = x3::get<parser_context_tag>(context);
54 const Schema& schema = parserContext.m_schema;
55 schemaPath_ location = parserContext.currentSchemaPath();
56 ModuleNodePair list{parserContext.m_curModule, parserContext.m_tmpListName};
57
58 if (schema.listHasKey(location, list, ast)) {
59 schemaNode_ listNode;
Václav Kubernát43908fb2020-01-02 19:05:51 +010060 listNode.m_prefix = parserContext.m_curModule.flat_map([] (auto mod) { return boost::optional<module_>{{mod}}; });;
Václav Kubernát7707cae2020-01-16 12:04:53 +010061 listNode.m_suffix = list_{parserContext.m_tmpListName};
62 location.m_nodes.push_back(listNode);
63 parserContext.m_tmpListKeyLeafPath.m_location = location;
Václav Kubernát43908fb2020-01-02 19:05:51 +010064 parserContext.m_tmpListKeyLeafPath.m_node = { parserContext.m_curModule, ast };
Václav Kubernát7707cae2020-01-16 12:04:53 +010065 } else {
66 parserContext.m_errorMsg = parserContext.m_tmpListName + " is not indexed by \"" + ast + "\".";
67 _pass(context) = false;
68 }
69 }
70};
Václav Kubernát89728d82018-09-13 16:28:28 +020071
Václav Kubernát744f57f2018-06-29 22:46:26 +020072struct module_identifier_class;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020073
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020074struct listSuffix_class {
75 template <typename T, typename Iterator, typename Context>
76 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
77 {
78 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát48fc3832018-05-28 14:21:22 +020079 const Schema& schema = parserContext.m_schema;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020080
Václav Kubernát72749c62020-01-03 16:47:34 +010081 const auto& keysNeeded = schema.listKeys(parserContext.currentSchemaPath(), {parserContext.m_curModule, parserContext.m_tmpListName});
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020082 std::set<std::string> keysSupplied;
83 for (const auto& it : ast)
84 keysSupplied.insert(it.first);
85
86 if (keysNeeded != keysSupplied) {
87 parserContext.m_errorMsg = "Not enough keys for " + parserContext.m_tmpListName + ". " +
88 "These keys were not supplied:";
89 std::set<std::string> missingKeys;
90 std::set_difference(keysNeeded.begin(), keysNeeded.end(),
91 keysSupplied.begin(), keysSupplied.end(),
92 std::inserter(missingKeys, missingKeys.end()));
93
94 for (const auto& it : missingKeys)
95 parserContext.m_errorMsg += " " + it;
96 parserContext.m_errorMsg += ".";
97
98 _pass(context) = false;
99 }
100 }
Václav Kubernát41378452018-06-06 16:29:40 +0200101
102 template <typename Iterator, typename Exception, typename Context>
103 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
104 {
105 auto& parserContext = x3::get<parser_context_tag>(context);
106 if (parserContext.m_errorMsg.empty())
107 parserContext.m_errorMsg = "Expecting ']' here:";
108 return x3::error_handler_result::rethrow;
Václav Kubernát41378452018-06-06 16:29:40 +0200109 }
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200110};
Václav Kubernát744f57f2018-06-29 22:46:26 +0200111
Václav Kubernát744f57f2018-06-29 22:46:26 +0200112struct module_class {
113 template <typename T, typename Iterator, typename Context>
114 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
115 {
116 auto& parserContext = x3::get<parser_context_tag>(context);
117 const auto& schema = parserContext.m_schema;
118
Václav Kubernát75877de2019-11-20 17:43:02 +0100119 if (schema.isModule(ast.m_name)) {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200120 parserContext.m_curModule = ast.m_name;
Václav Kubernát07204242018-06-04 18:12:09 +0200121 } else {
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átb61336d2018-05-28 17:35:03 +0200164 try {
Václav Kubernát744f57f2018-06-29 22:46:26 +0200165 boost::optional<std::string> module;
Václav Kubernát6797df02019-03-18 20:21:50 +0100166 if (ast.m_nodes.back().m_prefix)
167 module = ast.m_nodes.back().m_prefix.value().m_name;
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200168 container_ cont = std::get<container_>(ast.m_nodes.back().m_suffix);
Václav Kubernát72749c62020-01-03 16:47:34 +0100169 auto location = pathWithoutLastNode(parserContext.currentSchemaPath());
Václav Kubernátb61336d2018-05-28 17:35:03 +0200170
Václav Kubernát744f57f2018-06-29 22:46:26 +0200171 if (!schema.isPresenceContainer(location, {module, cont.m_name})) {
Václav Kubernát41378452018-06-06 16:29:40 +0200172 parserContext.m_errorMsg = "This container is not a presence container.";
Václav Kubernátb61336d2018-05-28 17:35:03 +0200173 _pass(context) = false;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200174 }
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200175 } catch (std::bad_variant_access&) {
Václav Kubernát41378452018-06-06 16:29:40 +0200176 parserContext.m_errorMsg = "This is not a container.";
Václav Kubernátb61336d2018-05-28 17:35:03 +0200177 _pass(context) = false;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200178 }
179 }
Václav Kubernát6797df02019-03-18 20:21:50 +0100180};
Václav Kubernátb61336d2018-05-28 17:35:03 +0200181
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100182struct listInstancePath_class {
183 template <typename T, typename Iterator, typename Context>
184 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
185 {
186 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát2ebab1d2020-05-27 01:28:30 +0200187 if (ast.m_nodes.empty() || !std::holds_alternative<listElement_>(ast.m_nodes.back().m_suffix)) {
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100188 parserContext.m_errorMsg = "This is not a list instance.";
189 _pass(context) = false;
190 }
191 }
192};
193
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200194struct leafListElementPath_class {
195 template <typename T, typename Iterator, typename Context>
196 void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
197 {
198 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200199 if (ast.m_nodes.empty() || !std::holds_alternative<leafListElement_>(ast.m_nodes.back().m_suffix)) {
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200200 parserContext.m_errorMsg = "This is not a leaf list element.";
201 _pass(context) = false;
202 }
203 }
204};
205
Václav Kubernát8028f942019-09-25 16:03:23 +0200206struct space_separator_class {
207 template <typename T, typename Iterator, typename Context>
208 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
209 {
210 auto& parserContext = x3::get<parser_context_tag>(context);
211 parserContext.m_suggestions.clear();
Václav Kubernát1ed4aa32020-01-23 13:13:28 +0100212 parserContext.m_completionIterator = boost::none;
Václav Kubernát8028f942019-09-25 16:03:23 +0200213 }
214};
215
Václav Kubernát6797df02019-03-18 20:21:50 +0100216struct create_class {
Václav Kubernátb61336d2018-05-28 17:35:03 +0200217 template <typename Iterator, typename Exception, typename Context>
Václav Kubernát41378452018-06-06 16:29:40 +0200218 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200219 {
220 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200221 if (parserContext.m_errorMsg.empty())
222 parserContext.m_errorMsg = "Couldn't parse create/delete command.";
223 return x3::error_handler_result::rethrow;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200224 }
225};
226
Václav Kubernát6797df02019-03-18 20:21:50 +0100227struct delete_class {
228 template <typename Iterator, typename Exception, typename Context>
229 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
230 {
231 auto& parserContext = x3::get<parser_context_tag>(context);
232 if (parserContext.m_errorMsg.empty())
233 parserContext.m_errorMsg = "Couldn't parse create/delete command.";
234 return x3::error_handler_result::rethrow;
235 }
Václav Kubernátb61336d2018-05-28 17:35:03 +0200236};
237
Václav Kubernátabf52802020-05-19 01:31:17 +0200238struct writable_leaf_path_class {
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200239 template <typename T, typename Iterator, typename Context>
Václav Kubernát7707cae2020-01-16 12:04:53 +0100240 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200241 {
242 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát0d42c512020-05-20 21:18:39 +0200243 if (parserContext.currentSchemaPath().m_nodes.empty()) {
244 parserContext.m_errorMsg = "This is not a path to leaf.";
245 _pass(context) = false;
246 return;
247 }
248
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200249 try {
Václav Kubernát7707cae2020-01-16 12:04:53 +0100250 auto lastNode = parserContext.currentSchemaPath().m_nodes.back();
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200251 auto leaf = std::get<leaf_>(lastNode.m_suffix);
Václav Kubernát7707cae2020-01-16 12:04:53 +0100252 auto location = pathWithoutLastNode(parserContext.currentSchemaPath());
253 ModuleNodePair node{lastNode.m_prefix.flat_map([](const auto& it) { return boost::optional<std::string>{it.m_name}; }), leaf.m_name};
254
255 parserContext.m_tmpListKeyLeafPath.m_location = location;
256 parserContext.m_tmpListKeyLeafPath.m_node = node;
257
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200258 } catch (std::bad_variant_access&) {
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200259 parserContext.m_errorMsg = "This is not a path to leaf.";
260 _pass(context) = false;
261 }
262 }
263};
264
Václav Kubernát07204242018-06-04 18:12:09 +0200265struct set_class {
Václav Kubernát07204242018-06-04 18:12:09 +0200266 template <typename Iterator, typename Exception, typename Context>
267 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
268 {
269 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát41378452018-06-06 16:29:40 +0200270 if (parserContext.m_errorMsg.empty())
271 parserContext.m_errorMsg = "Expected " + x.which() + " here:";
272 return x3::error_handler_result::rethrow;
Václav Kubernát07204242018-06-04 18:12:09 +0200273 }
274};
275
Václav Kubernát812ee282018-08-30 17:10:03 +0200276struct commit_class;
277
Václav Kubernát9cfcd872020-02-18 12:34:02 +0100278struct describe_class;
279
Václav Kubernát054cc992019-02-21 14:23:52 +0100280struct help_class;
281
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200282struct get_class;
283
Václav Kubernát7160a132020-04-03 02:11:01 +0200284struct copy_class;
285
Václav Kubernátb61336d2018-05-28 17:35:03 +0200286struct command_class {
287 template <typename Iterator, typename Exception, typename Context>
288 x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
289 {
290 auto& parserContext = x3::get<parser_context_tag>(context);
291 auto& error_handler = x3::get<x3::error_handler_tag>(context).get();
Václav Kubernát41378452018-06-06 16:29:40 +0200292 if (parserContext.m_errorMsg.empty()) {
293 parserContext.m_errorMsg = "Unknown command.";
294 }
295 error_handler(x.where(), parserContext.m_errorMsg);
Václav Kubernátb61336d2018-05-28 17:35:03 +0200296 return x3::error_handler_result::fail;
297 }
298};
Václav Kubernát5c75b252018-10-10 18:33:47 +0200299
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100300struct initializePath_class {
Václav Kubernát5c75b252018-10-10 18:33:47 +0200301 template <typename T, typename Iterator, typename Context>
302 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
303 {
304 auto& parserContext = x3::get<parser_context_tag>(context);
Václav Kubernát72749c62020-01-03 16:47:34 +0100305 parserContext.resetPath();
Václav Kubernát5c75b252018-10-10 18:33:47 +0200306 parserContext.m_tmpListKeys.clear();
307 parserContext.m_tmpListName.clear();
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100308 parserContext.m_suggestions.clear();
Václav Kubernát5c75b252018-10-10 18:33:47 +0200309 }
310};
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100311
312struct trailingSlash_class;
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100313
Václav Kubernátcb3af402020-02-12 16:49:17 +0100314std::set<Completion> generateMissingKeyCompletionSet(std::set<std::string> keysNeeded, std::map<std::string, leaf_data_> currentSet);
Václav Kubernát329c6c32019-02-06 16:41:53 +0100315
316struct createKeySuggestions_class {
317 template <typename T, typename Iterator, typename Context>
318 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
319 {
320 auto& parserContext = x3::get<parser_context_tag>(context);
321 const auto& schema = parserContext.m_schema;
322
323 parserContext.m_completionIterator = begin;
324
Václav Kubernát72749c62020-01-03 16:47:34 +0100325 const auto& keysNeeded = schema.listKeys(parserContext.currentSchemaPath(), {parserContext.m_curModule, parserContext.m_tmpListName});
Václav Kubernát329c6c32019-02-06 16:41:53 +0100326 parserContext.m_suggestions = generateMissingKeyCompletionSet(keysNeeded, parserContext.m_tmpListKeys);
327 }
328};
329
Václav Kubernát43908fb2020-01-02 19:05:51 +0100330std::string leafDataToCompletion(const leaf_data_& value);
331
332struct createValueSuggestions_class {
333 template <typename T, typename Iterator, typename Context>
334 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
335 {
336 auto& parserContext = x3::get<parser_context_tag>(context);
337 if (!parserContext.m_completing) {
338 return;
339 }
340 const auto& dataQuery = parserContext.m_dataquery;
341
342 parserContext.m_completionIterator = begin;
343 auto listInstances = dataQuery->listKeys(parserContext.currentDataPath(), {parserContext.m_curModule, parserContext.m_tmpListName});
344
345 decltype(listInstances) filteredInstances;
346 //This filters out instances, which don't correspond to the partial instance we have.
347 const auto partialFitsComplete = [&parserContext] (const auto& complete) {
348 const auto& partial = parserContext.m_tmpListKeys;
349 return std::all_of(partial.begin(), partial.end(), [&complete] (const auto& oneKV) {
350 const auto& [k, v] = oneKV;
351 return complete.at(k) == v;
352 });
353 };
354 std::copy_if(listInstances.begin(), listInstances.end(), std::inserter(filteredInstances, filteredInstances.end()), partialFitsComplete);
355
Václav Kubernátcb3af402020-02-12 16:49:17 +0100356 std::set<Completion> validValues;
Václav Kubernát43908fb2020-01-02 19:05:51 +0100357
Václav Kubernátcb3af402020-02-12 16:49:17 +0100358 std::transform(filteredInstances.begin(), filteredInstances.end(), std::inserter(validValues, validValues.end()), [&parserContext](const auto& instance) {
359 return Completion{leafDataToCompletion(instance.at(parserContext.m_tmpListKeyLeafPath.m_node.second))};
Václav Kubernát43908fb2020-01-02 19:05:51 +0100360 });
361
362 parserContext.m_suggestions = validValues;
363 }
364};
365
Václav Kubernát329c6c32019-02-06 16:41:53 +0100366struct suggestKeysEnd_class {
367 template <typename T, typename Iterator, typename Context>
368 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
369 {
370 auto& parserContext = x3::get<parser_context_tag>(context);
371 const auto& schema = parserContext.m_schema;
372
373 parserContext.m_completionIterator = begin;
Václav Kubernát72749c62020-01-03 16:47:34 +0100374 const auto& keysNeeded = schema.listKeys(parserContext.currentSchemaPath(), {parserContext.m_curModule, parserContext.m_tmpListName});
Václav Kubernát329c6c32019-02-06 16:41:53 +0100375 if (generateMissingKeyCompletionSet(keysNeeded, parserContext.m_tmpListKeys).empty()) {
Václav Kubernátcb3af402020-02-12 16:49:17 +0100376 parserContext.m_suggestions = {Completion{"]/"}};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100377 } else {
Václav Kubernátcb3af402020-02-12 16:49:17 +0100378 parserContext.m_suggestions = {Completion{"]["}};
Václav Kubernát329c6c32019-02-06 16:41:53 +0100379 }
380 }
381};
Václav Kubernát57272422019-02-08 12:48:24 +0100382
Václav Kubernát672889c2020-05-27 04:11:36 +0200383template <typename T>
384std::string commandNamesVisitor (boost::type<T>)
385{
386 return T::name;
387}
Václav Kubernát57272422019-02-08 12:48:24 +0100388
389struct createCommandSuggestions_class {
390 template <typename T, typename Iterator, typename Context>
391 void on_success(Iterator const& begin, Iterator const&, T&, Context const& context)
392 {
393 auto& parserContext = x3::get<parser_context_tag>(context);
394 parserContext.m_completionIterator = begin;
395
396 parserContext.m_suggestions.clear();
397 boost::mpl::for_each<CommandTypes, boost::type<boost::mpl::_>>([&parserContext](auto cmd) {
Václav Kubernát672889c2020-05-27 04:11:36 +0200398 parserContext.m_suggestions.insert({commandNamesVisitor(cmd), " "});
Václav Kubernát57272422019-02-08 12:48:24 +0100399 });
400 }
401};
Václav Kubernátac035d62019-02-18 10:59:08 +0100402
403struct completing_class {
404 template <typename T, typename Iterator, typename Context>
405 void on_success(Iterator const&, Iterator const&, T&, Context const& context)
406 {
407 auto& parserContext = x3::get<parser_context_tag>(context);
408
409 if (!parserContext.m_completing)
410 _pass(context) = false;
411 }
412};