Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +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 | #pragma once |
| 9 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 10 | #include <boost/mpl/vector.hpp> |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 11 | #include "ast_path.hpp" |
Václav Kubernát | 627f615 | 2018-08-29 13:23:56 +0200 | [diff] [blame] | 12 | #include "ast_values.hpp" |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 13 | |
| 14 | namespace x3 = boost::spirit::x3; |
| 15 | namespace ascii = boost::spirit::x3::ascii; |
| 16 | |
| 17 | using ascii::space; |
| 18 | using x3::_attr; |
| 19 | using x3::alnum; |
| 20 | using x3::alpha; |
| 21 | using x3::char_; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 22 | using x3::double_; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 23 | using x3::expect; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 24 | using x3::int_; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 25 | using x3::lexeme; |
| 26 | using x3::lit; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 27 | using x3::uint_; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 28 | |
| 29 | struct parser_context_tag; |
| 30 | |
| 31 | using keyValue_ = std::pair<std::string, std::string>; |
| 32 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 33 | enum class LsOption { |
| 34 | Recursive |
| 35 | }; |
| 36 | |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 37 | struct discard_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 38 | static constexpr auto name = "discard"; |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 39 | bool operator==(const discard_& b) const; |
| 40 | }; |
| 41 | |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 42 | struct ls_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 43 | static constexpr auto name = "ls"; |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 44 | bool operator==(const ls_& b) const; |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 45 | std::vector<LsOption> m_options; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 46 | boost::optional<boost::variant<dataPath_, schemaPath_>> m_path; |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 49 | struct cd_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 50 | static constexpr auto name = "cd"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 51 | bool operator==(const cd_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 52 | dataPath_ m_path; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct create_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 56 | static constexpr auto name = "create"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 57 | bool operator==(const create_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 58 | dataPath_ m_path; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | struct delete_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 62 | static constexpr auto name = "delete"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 63 | bool operator==(const delete_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 64 | dataPath_ m_path; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct set_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 68 | static constexpr auto name = "set"; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 69 | bool operator==(const set_& b) const; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 70 | dataPath_ m_path; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 71 | leaf_data_ m_data; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 74 | struct commit_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 75 | static constexpr auto name = "commit"; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 76 | bool operator==(const set_& b) const; |
| 77 | }; |
| 78 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 79 | struct get_ : x3::position_tagged { |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 80 | static constexpr auto name = "get"; |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 81 | bool operator==(const get_& b) const; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 82 | boost::optional<boost::variant<dataPath_, schemaPath_>> m_path; |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 83 | }; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 84 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 85 | // TODO: The usage of MPL won't be necessary after std::variant support is added to Spirit |
| 86 | // https://github.com/boostorg/spirit/issues/270 |
| 87 | using CommandTypes = boost::mpl::vector<discard_, ls_, cd_, create_, delete_, set_, commit_, get_>; |
| 88 | using command_ = boost::make_variant_over<CommandTypes>::type; |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 89 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 90 | BOOST_FUSION_ADAPT_STRUCT(ls_, m_options, m_path) |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 91 | BOOST_FUSION_ADAPT_STRUCT(cd_, m_path) |
| 92 | BOOST_FUSION_ADAPT_STRUCT(create_, m_path) |
| 93 | BOOST_FUSION_ADAPT_STRUCT(delete_, m_path) |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 94 | BOOST_FUSION_ADAPT_STRUCT(enum_, m_value) |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 95 | BOOST_FUSION_ADAPT_STRUCT(set_, m_path, m_data) |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 96 | BOOST_FUSION_ADAPT_STRUCT(commit_) |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 97 | BOOST_FUSION_ADAPT_STRUCT(discard_) |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 98 | BOOST_FUSION_ADAPT_STRUCT(get_, m_path) |