Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 1 | /* |
| 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 |
| 10 | |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 11 | #include <boost/spirit/home/x3.hpp> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 12 | #include "ast_commands.hpp" |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 13 | #include "ast_handlers.hpp" |
Václav Kubernát | 9ae8cc4 | 2020-03-25 19:17:41 +0100 | [diff] [blame] | 14 | #include "common_parsers.hpp" |
| 15 | #include "leaf_data.hpp" |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 16 | #include "path_parser.hpp" |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 17 | |
Václav Kubernát | 7ff2207 | 2022-04-05 10:22:40 +0200 | [diff] [blame] | 18 | /** |
| 19 | * Returns a parser that generates suggestions based on a Completion set. |
| 20 | * Usage: |
| 21 | * const auto suggestSomeStuff = staticSuggestions({"some", "stuff", "yay"}); |
| 22 | * |
| 23 | * You can use this as a standard parser in a Spirit grammar. |
| 24 | */ |
| 25 | auto staticSuggestions(const std::initializer_list<std::string>& strings) |
| 26 | { |
| 27 | std::set<Completion> completions; |
| 28 | std::transform(begin(strings), end(strings), std::inserter(completions, completions.end()), |
| 29 | [](const auto s) { return Completion{s, " "}; }); |
| 30 | return as<x3::unused_type>[x3::eps[([completions](auto& ctx) { |
| 31 | auto& parserContext = x3::get<parser_context_tag>(ctx); |
| 32 | parserContext.m_suggestions = completions; |
| 33 | parserContext.m_completionIterator = _where(ctx).begin(); |
| 34 | })]]; |
| 35 | } |
| 36 | |
Václav Kubernát | 68c8942 | 2021-10-20 15:32:20 +0200 | [diff] [blame] | 37 | #if BOOST_VERSION <= 107700 |
Václav Kubernát | f5f6d24 | 2022-04-07 01:06:19 +0200 | [diff] [blame] | 38 | namespace boost::spirit::x3::traits { |
Václav Kubernát | 68c8942 | 2021-10-20 15:32:20 +0200 | [diff] [blame] | 39 | // Backport https://github.com/boostorg/spirit/pull/702 |
| 40 | // with instructions from https://github.com/boostorg/spirit/issues/701#issuecomment-946743099 |
| 41 | template <typename... Types, typename T> |
| 42 | struct variant_find_substitute<boost::variant<Types...>, T> |
| 43 | { |
| 44 | using variant_type = boost::variant<Types...>; |
| 45 | |
| 46 | typedef typename variant_type::types types; |
| 47 | typedef typename mpl::end<types>::type end; |
| 48 | |
| 49 | typedef typename mpl::find<types, T>::type iter_1; |
| 50 | |
| 51 | typedef typename |
| 52 | mpl::eval_if< |
| 53 | is_same<iter_1, end>, |
| 54 | mpl::find_if<types, traits::is_substitute<T, mpl::_1> >, |
| 55 | mpl::identity<iter_1> |
| 56 | >::type |
| 57 | iter; |
| 58 | |
| 59 | typedef typename |
| 60 | mpl::eval_if< |
| 61 | is_same<iter, end>, |
| 62 | mpl::identity<T>, |
| 63 | mpl::deref<iter> |
| 64 | >::type |
| 65 | type; |
| 66 | }; |
| 67 | } |
| 68 | #endif |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 69 | |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 70 | x3::rule<discard_class, discard_> const discard = "discard"; |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 71 | x3::rule<ls_class, ls_> const ls = "ls"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 72 | x3::rule<cd_class, cd_> const cd = "cd"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 73 | x3::rule<set_class, set_> const set = "set"; |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 74 | x3::rule<get_class, get_> const get = "get"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 75 | x3::rule<create_class, create_> const create = "create"; |
| 76 | x3::rule<delete_class, delete_> const delete_rule = "delete_rule"; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 77 | x3::rule<commit_class, commit_> const commit = "commit"; |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 78 | x3::rule<describe_class, describe_> const describe = "describe"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 79 | x3::rule<help_class, help_> const help = "help"; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 80 | x3::rule<copy_class, copy_> const copy = "copy"; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 81 | x3::rule<move_class, move_> const move = "move"; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 82 | x3::rule<dump_class, dump_> const dump = "dump"; |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 83 | x3::rule<prepare_class, prepare_> const prepare = "prepare"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 84 | x3::rule<exec_class, exec_> const exec = "exec"; |
Václav Kubernát | 1d59390 | 2021-03-08 08:55:16 +0100 | [diff] [blame] | 85 | x3::rule<switch_class, switch_> const switch_rule = "switch"; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 86 | x3::rule<cancel_class, cancel_> const cancel = "cancel"; |
Petr Gotthard | 1c76dea | 2022-04-13 17:56:58 +0200 | [diff] [blame] | 87 | x3::rule<quit_class, quit_> const quit = "quit"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 88 | x3::rule<command_class, command_> const command = "command"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 89 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 90 | x3::rule<createCommandSuggestions_class, x3::unused_type> const createCommandSuggestions = "createCommandSuggestions"; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 91 | |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame] | 92 | #if __clang__ |
| 93 | #pragma GCC diagnostic push |
| 94 | #pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses" |
| 95 | #endif |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 96 | |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 97 | namespace ascii = boost::spirit::x3::ascii; |
| 98 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 99 | struct ls_options_table : x3::symbols<LsOption> { |
| 100 | ls_options_table() |
| 101 | { |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 102 | add |
| 103 | ("--recursive", LsOption::Recursive); |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 104 | } |
| 105 | } const ls_options; |
| 106 | |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 107 | auto const ls_def = |
Václav Kubernát | 76bb8c2 | 2022-01-19 01:32:31 +0100 | [diff] [blame] | 108 | ls_::name >> *(space_separator >> ls_options) >> -(space_separator > (anyPath | (module >> "*"))); |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 109 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 110 | auto const cd_def = |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 111 | cd_::name >> space_separator > cdPath; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 112 | |
Václav Kubernát | 3817502 | 2021-11-04 14:58:57 +0100 | [diff] [blame] | 113 | #if BOOST_VERSION <= 107700 |
| 114 | auto const create_def = |
| 115 | create_::name >> space_separator > |
| 116 | (x3::eps >> presenceContainerPath | |
| 117 | x3::eps >> listInstancePath | |
| 118 | x3::eps >> leafListElementPath); |
| 119 | |
| 120 | auto const delete_rule_def = |
| 121 | delete_::name >> space_separator > |
| 122 | (x3::eps >> presenceContainerPath | |
| 123 | x3::eps >> listInstancePath | |
| 124 | x3::eps >> leafListElementPath | |
| 125 | x3::eps >> writableLeafPath); |
| 126 | #else |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 127 | auto const create_def = |
Václav Kubernát | 5b8a8f3 | 2020-05-20 00:57:22 +0200 | [diff] [blame] | 128 | create_::name >> space_separator > (presenceContainerPath | listInstancePath | leafListElementPath); |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 129 | |
| 130 | auto const delete_rule_def = |
Jan Kundrát | b7206ad | 2020-06-18 21:08:14 +0200 | [diff] [blame] | 131 | delete_::name >> space_separator > (presenceContainerPath | listInstancePath | leafListElementPath | writableLeafPath); |
Václav Kubernát | 3817502 | 2021-11-04 14:58:57 +0100 | [diff] [blame] | 132 | #endif |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 133 | |
Václav Kubernát | e066fe2 | 2022-04-06 00:32:26 +0200 | [diff] [blame] | 134 | const auto dsTargetSuggestions = staticSuggestions({"running", "startup", "operational"}); |
| 135 | |
| 136 | struct ds_target_table : x3::symbols<DatastoreTarget> { |
| 137 | ds_target_table() |
| 138 | { |
| 139 | add |
| 140 | ("operational", DatastoreTarget::Operational) |
| 141 | ("startup", DatastoreTarget::Startup) |
| 142 | ("running", DatastoreTarget::Running); |
| 143 | } |
| 144 | } const ds_target_table; |
| 145 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 146 | auto const get_def = |
Václav Kubernát | e066fe2 | 2022-04-06 00:32:26 +0200 | [diff] [blame] | 147 | get_::name |
| 148 | >> -(space_separator >> "-" > staticSuggestions({"-datastore"}) > "-datastore" > space_separator > dsTargetSuggestions > ds_target_table) |
Václav Kubernát | 76bb8c2 | 2022-01-19 01:32:31 +0100 | [diff] [blame] | 149 | >> -(space_separator > getPath); |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 150 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 151 | auto const set_def = |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 152 | set_::name >> space_separator > writableLeafPath > space_separator > leaf_data; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 153 | |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 154 | auto const commit_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 155 | commit_::name >> x3::attr(commit_()); |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 156 | |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 157 | auto const discard_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 158 | discard_::name >> x3::attr(discard_()); |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 159 | |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 160 | struct command_names_table : x3::symbols<decltype(help_::m_cmd)> { |
| 161 | command_names_table() |
| 162 | { |
| 163 | boost::mpl::for_each<CommandTypes, boost::type<boost::mpl::_>>([this](auto cmd) { |
Václav Kubernát | 672889c | 2020-05-27 04:11:36 +0200 | [diff] [blame] | 164 | add(commandNamesVisitor(cmd), decltype(help_::m_cmd)(cmd)); |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 165 | }); |
| 166 | } |
| 167 | } const command_names; |
| 168 | |
| 169 | auto const help_def = |
| 170 | help_::name > createCommandSuggestions >> -command_names; |
| 171 | |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 172 | struct datastore_symbol_table : x3::symbols<Datastore> { |
| 173 | datastore_symbol_table() |
| 174 | { |
| 175 | add |
| 176 | ("running", Datastore::Running) |
| 177 | ("startup", Datastore::Startup); |
| 178 | } |
| 179 | } const datastore; |
| 180 | |
Václav Kubernát | 21fc5e2 | 2020-11-26 04:28:27 +0100 | [diff] [blame] | 181 | const auto copy_source = x3::rule<class source, Datastore>{"source datastore"} = datastore; |
| 182 | const auto copy_destination = x3::rule<class source, Datastore>{"destination datastore"} = datastore; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 183 | |
Václav Kubernát | 7ff2207 | 2022-04-05 10:22:40 +0200 | [diff] [blame] | 184 | const auto datastoreSuggestions = staticSuggestions({"running", "startup"}); |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 185 | |
| 186 | struct copy_args : x3::parser<copy_args> { |
| 187 | using attribute_type = copy_; |
| 188 | template <typename It, typename Ctx, typename RCtx> |
| 189 | bool parse(It& begin, It end, Ctx const& ctx, RCtx& rctx, copy_& attr) const |
| 190 | { |
| 191 | auto& parserContext = x3::get<parser_context_tag>(ctx); |
| 192 | auto iterBeforeDestination = begin; |
Václav Kubernát | 76bb8c2 | 2022-01-19 01:32:31 +0100 | [diff] [blame] | 193 | auto save_iter = x3::eps[([&iterBeforeDestination](auto& ctx) { iterBeforeDestination = _where(ctx).begin(); })]; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 194 | auto grammar = datastoreSuggestions > copy_source > space_separator > datastoreSuggestions > save_iter > copy_destination; |
| 195 | |
| 196 | try { |
| 197 | grammar.parse(begin, end, ctx, rctx, attr); |
| 198 | } catch (x3::expectation_failure<It>& ex) { |
| 199 | using namespace std::string_literals; |
| 200 | parserContext.m_errorMsg = "Expected "s + ex.which() + " here:"; |
| 201 | throw; |
| 202 | } |
| 203 | |
| 204 | if (attr.m_source == attr.m_destination) { |
| 205 | begin = iterBeforeDestination; // Restoring the iterator here makes the error caret point to the second datastore |
| 206 | parserContext.m_errorMsg = "Source datastore and destination datastore can't be the same."; |
| 207 | return false; |
| 208 | } |
| 209 | |
| 210 | return true; |
| 211 | } |
Václav Kubernát | 21fc5e2 | 2020-11-26 04:28:27 +0100 | [diff] [blame] | 212 | } const copy_args; |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 213 | |
| 214 | auto const copy_def = |
| 215 | copy_::name > space_separator > copy_args; |
| 216 | |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 217 | auto const describe_def = |
Václav Kubernát | 3200b86 | 2020-12-03 02:34:55 +0100 | [diff] [blame] | 218 | describe_::name >> space_separator > anyPath; |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 219 | |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 220 | struct move_mode_table : x3::symbols<MoveMode> { |
| 221 | move_mode_table() |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 222 | { |
| 223 | add |
| 224 | ("after", MoveMode::After) |
| 225 | ("before", MoveMode::Before) |
| 226 | ("begin", MoveMode::Begin) |
| 227 | ("end", MoveMode::End); |
| 228 | } |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 229 | } const move_mode_table; |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 230 | |
| 231 | struct move_absolute_table : x3::symbols<yang::move::Absolute> { |
| 232 | move_absolute_table() |
| 233 | { |
| 234 | add |
| 235 | ("begin", yang::move::Absolute::Begin) |
| 236 | ("end", yang::move::Absolute::End); |
| 237 | } |
| 238 | } const move_absolute_table; |
| 239 | |
| 240 | struct move_relative_table : x3::symbols<yang::move::Relative::Position> { |
| 241 | move_relative_table() |
| 242 | { |
| 243 | add |
| 244 | ("before", yang::move::Relative::Position::Before) |
| 245 | ("after", yang::move::Relative::Position::After); |
| 246 | } |
| 247 | } const move_relative_table; |
| 248 | |
| 249 | struct move_args : x3::parser<move_args> { |
| 250 | using attribute_type = move_; |
| 251 | template <typename It, typename Ctx, typename RCtx> |
| 252 | bool parse(It& begin, It end, Ctx const& ctx, RCtx& rctx, move_& attr) const |
| 253 | { |
| 254 | ParserContext& parserContext = x3::get<parser_context_tag>(ctx); |
| 255 | dataPath_ movePath; |
Václav Kubernát | 3817502 | 2021-11-04 14:58:57 +0100 | [diff] [blame] | 256 | #if BOOST_VERSION <= 107700 |
| 257 | auto movePathGrammar = x3::eps >> listInstancePath | x3::eps >> leafListElementPath; |
| 258 | #else |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 259 | auto movePathGrammar = listInstancePath | leafListElementPath; |
Václav Kubernát | 3817502 | 2021-11-04 14:58:57 +0100 | [diff] [blame] | 260 | #endif |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 261 | auto res = movePathGrammar.parse(begin, end, ctx, rctx, attr.m_source); |
| 262 | if (!res) { |
| 263 | parserContext.m_errorMsg = "Expected source path here:"; |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | // Try absolute move first. |
| 268 | res = (space_separator >> move_absolute_table).parse(begin, end, ctx, rctx, attr.m_destination); |
| 269 | if (res) { |
| 270 | // Absolute move parsing succeeded, we don't need to parse anything else. |
| 271 | return true; |
| 272 | } |
| 273 | |
| 274 | // If absolute move didn't succeed, try relative. |
| 275 | attr.m_destination = yang::move::Relative{}; |
| 276 | res = (space_separator >> move_relative_table).parse(begin, end, ctx, rctx, std::get<yang::move::Relative>(attr.m_destination).m_position); |
| 277 | |
| 278 | if (!res) { |
| 279 | parserContext.m_errorMsg = "Expected a move position (begin, end, before, after) here:"; |
| 280 | return false; |
| 281 | } |
| 282 | |
| 283 | if (std::holds_alternative<leafListElement_>(attr.m_source.m_nodes.back().m_suffix)) { |
| 284 | leaf_data_ value; |
| 285 | res = (space_separator >> leaf_data).parse(begin, end, ctx, rctx, value); |
| 286 | if (res) { |
| 287 | std::get<yang::move::Relative>(attr.m_destination).m_path = {{".", value}}; |
| 288 | } |
| 289 | } else { |
| 290 | ListInstance listInstance; |
| 291 | // The source list instance will be stored inside the parser context path. |
| 292 | // The source list instance will be full data path (with keys included). |
| 293 | // However, m_tmpListPath is supposed to store a path with a list without the keys. |
| 294 | // So, I pop the last listElement_ (which has the keys) and put in a list_ (which doesn't have the keys). |
| 295 | // Example: /mod:cont/protocols[name='ftp'] gets turned into /mod:cont/protocols |
| 296 | parserContext.m_tmpListPath = parserContext.currentDataPath(); |
| 297 | parserContext.m_tmpListPath.m_nodes.pop_back(); |
| 298 | auto list = list_{std::get<listElement_>(attr.m_source.m_nodes.back().m_suffix).m_name}; |
Václav Kubernát | faacd02 | 2020-07-08 16:44:38 +0200 | [diff] [blame] | 299 | parserContext.m_tmpListPath.m_nodes.emplace_back(attr.m_source.m_nodes.back().m_prefix, list); |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 300 | |
| 301 | res = (space_separator >> listSuffix).parse(begin, end, ctx, rctx, listInstance); |
| 302 | if (res) { |
| 303 | std::get<yang::move::Relative>(attr.m_destination).m_path = listInstance; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | if (!res) { |
| 308 | parserContext.m_errorMsg = "Expected a destination here:"; |
| 309 | } |
| 310 | |
| 311 | return res; |
| 312 | } |
| 313 | } const move_args; |
| 314 | |
| 315 | auto const move_def = |
| 316 | move_::name >> space_separator >> move_args; |
| 317 | |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 318 | struct format_table : x3::symbols<DataFormat> { |
| 319 | format_table() |
| 320 | { |
| 321 | add |
| 322 | ("xml", DataFormat::Xml) |
| 323 | ("json", DataFormat::Json); |
| 324 | } |
| 325 | } const format_table; |
| 326 | |
Václav Kubernát | 3b5e652 | 2020-06-26 18:36:09 +0200 | [diff] [blame] | 327 | struct dump_args : x3::parser<dump_args> { |
| 328 | using attribute_type = dump_; |
| 329 | template <typename It, typename Ctx, typename RCtx> |
| 330 | bool parse(It& begin, It end, Ctx const& ctx, RCtx& rctx, dump_& attr) const |
| 331 | { |
| 332 | ParserContext& parserContext = x3::get<parser_context_tag>(ctx); |
| 333 | parserContext.m_suggestions = {{"xml"}, {"json"}}; |
| 334 | parserContext.m_completionIterator = begin; |
| 335 | auto res = format_table.parse(begin, end, ctx, rctx, attr); |
| 336 | if (!res) { |
| 337 | parserContext.m_errorMsg = "Expected a data format (xml, json) here:"; |
| 338 | } |
| 339 | return res; |
| 340 | } |
| 341 | } const dump_args; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 342 | |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 343 | auto const prepare_def = |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 344 | prepare_::name > space_separator > as<dataPath_>[RpcActionPath<AllowInput::Yes>{}]; |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 345 | |
| 346 | auto const exec_def = |
Václav Kubernát | aff1f49 | 2021-02-17 10:56:28 +0100 | [diff] [blame] | 347 | exec_::name > -(space_separator > -as<dataPath_>[RpcActionPath<AllowInput::No>{}]); |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 348 | |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 349 | auto const switch_rule_def = |
Václav Kubernát | 7ff2207 | 2022-04-05 10:22:40 +0200 | [diff] [blame] | 350 | switch_::name > space_separator > dsTargetSuggestions > ds_target_table; |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 351 | |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 352 | auto const cancel_def = |
| 353 | cancel_::name >> x3::attr(cancel_{}); |
| 354 | |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 355 | auto const dump_def = |
Václav Kubernát | 3b5e652 | 2020-06-26 18:36:09 +0200 | [diff] [blame] | 356 | dump_::name > space_separator >> dump_args; |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 357 | |
Petr Gotthard | 1c76dea | 2022-04-13 17:56:58 +0200 | [diff] [blame] | 358 | auto const quit_def = |
| 359 | quit_::name >> x3::attr(quit_{}); |
| 360 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 361 | auto const createCommandSuggestions_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 362 | x3::eps; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 363 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 364 | auto const command_def = |
Václav Kubernát | 5b8e282 | 2022-01-14 03:19:54 +0100 | [diff] [blame] | 365 | #if BOOST_VERSION <= 107800 |
Václav Kubernát | f9533c2 | 2021-11-04 15:13:30 +0100 | [diff] [blame] | 366 | x3::eps >> |
| 367 | #endif |
Václav Kubernát | 76bb8c2 | 2022-01-19 01:32:31 +0100 | [diff] [blame] | 368 | -space_separator >> createCommandSuggestions >> x3::expect[cd | copy | create | delete_rule | set | commit | get | ls | discard | describe | help | move | dump | prepare | exec | cancel | switch_rule | quit] >> -space_separator; |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame] | 369 | |
| 370 | #if __clang__ |
| 371 | #pragma GCC diagnostic pop |
| 372 | #endif |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 373 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 374 | BOOST_SPIRIT_DEFINE(set) |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 375 | BOOST_SPIRIT_DEFINE(commit) |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 376 | BOOST_SPIRIT_DEFINE(get) |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 377 | BOOST_SPIRIT_DEFINE(ls) |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 378 | BOOST_SPIRIT_DEFINE(discard) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 379 | BOOST_SPIRIT_DEFINE(cd) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 380 | BOOST_SPIRIT_DEFINE(create) |
| 381 | BOOST_SPIRIT_DEFINE(delete_rule) |
Václav Kubernát | 9cfcd87 | 2020-02-18 12:34:02 +0100 | [diff] [blame] | 382 | BOOST_SPIRIT_DEFINE(describe) |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 383 | BOOST_SPIRIT_DEFINE(help) |
Václav Kubernát | 7160a13 | 2020-04-03 02:11:01 +0200 | [diff] [blame] | 384 | BOOST_SPIRIT_DEFINE(copy) |
Václav Kubernát | bf65dd7 | 2020-05-28 02:32:31 +0200 | [diff] [blame] | 385 | BOOST_SPIRIT_DEFINE(move) |
Václav Kubernát | 70d7f7a | 2020-06-23 14:40:40 +0200 | [diff] [blame] | 386 | BOOST_SPIRIT_DEFINE(dump) |
Václav Kubernát | aa4250a | 2020-07-22 00:02:23 +0200 | [diff] [blame] | 387 | BOOST_SPIRIT_DEFINE(prepare) |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 388 | BOOST_SPIRIT_DEFINE(exec) |
Václav Kubernát | 162165e | 2021-02-22 09:46:53 +0100 | [diff] [blame] | 389 | BOOST_SPIRIT_DEFINE(switch_rule) |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 390 | BOOST_SPIRIT_DEFINE(cancel) |
Petr Gotthard | 1c76dea | 2022-04-13 17:56:58 +0200 | [diff] [blame] | 391 | BOOST_SPIRIT_DEFINE(quit) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 392 | BOOST_SPIRIT_DEFINE(command) |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 393 | BOOST_SPIRIT_DEFINE(createCommandSuggestions) |