blob: 3a59e26c3fb70c86df78e0e42cd44e6be1bdd3df [file] [log] [blame]
Václav Kubernát24df80e2018-06-06 15:18:03 +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#pragma once
9
Václav Kubernát57272422019-02-08 12:48:24 +010010#include <boost/mpl/vector.hpp>
Václav Kubernát24df80e2018-06-06 15:18:03 +020011#include "ast_path.hpp"
Václav Kubernát627f6152018-08-29 13:23:56 +020012#include "ast_values.hpp"
Václav Kubernát24df80e2018-06-06 15:18:03 +020013
14namespace x3 = boost::spirit::x3;
15namespace ascii = boost::spirit::x3::ascii;
16
17using ascii::space;
18using x3::_attr;
19using x3::alnum;
20using x3::alpha;
21using x3::char_;
Václav Kubernátebca2552018-06-08 19:06:02 +020022using x3::double_;
Václav Kubernát24df80e2018-06-06 15:18:03 +020023using x3::expect;
Václav Kubernátebca2552018-06-08 19:06:02 +020024using x3::int_;
Václav Kubernát24df80e2018-06-06 15:18:03 +020025using x3::lexeme;
26using x3::lit;
Václav Kubernátebca2552018-06-08 19:06:02 +020027using x3::uint_;
Václav Kubernát24df80e2018-06-06 15:18:03 +020028
29struct parser_context_tag;
30
31using keyValue_ = std::pair<std::string, std::string>;
32
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020033enum class LsOption {
34 Recursive
35};
36
Václav Kubernát6d791432018-10-25 16:00:35 +020037struct discard_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010038 static constexpr auto name = "discard";
Václav Kubernát6d791432018-10-25 16:00:35 +020039 bool operator==(const discard_& b) const;
40};
41
Václav Kubernát11afac72018-07-18 14:59:53 +020042struct ls_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010043 static constexpr auto name = "ls";
Václav Kubernát11afac72018-07-18 14:59:53 +020044 bool operator==(const ls_& b) const;
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020045 std::vector<LsOption> m_options;
Václav Kubernát5c75b252018-10-10 18:33:47 +020046 boost::optional<boost::variant<dataPath_, schemaPath_>> m_path;
Václav Kubernát11afac72018-07-18 14:59:53 +020047};
48
Václav Kubernát24df80e2018-06-06 15:18:03 +020049struct cd_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010050 static constexpr auto name = "cd";
Václav Kubernát24df80e2018-06-06 15:18:03 +020051 bool operator==(const cd_& b) const;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020052 dataPath_ m_path;
Václav Kubernát24df80e2018-06-06 15:18:03 +020053};
54
55struct create_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010056 static constexpr auto name = "create";
Václav Kubernát24df80e2018-06-06 15:18:03 +020057 bool operator==(const create_& b) const;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020058 dataPath_ m_path;
Václav Kubernát24df80e2018-06-06 15:18:03 +020059};
60
61struct delete_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010062 static constexpr auto name = "delete";
Václav Kubernát24df80e2018-06-06 15:18:03 +020063 bool operator==(const delete_& b) const;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020064 dataPath_ m_path;
Václav Kubernát24df80e2018-06-06 15:18:03 +020065};
66
67struct set_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010068 static constexpr auto name = "set";
Václav Kubernát24df80e2018-06-06 15:18:03 +020069 bool operator==(const set_& b) const;
Václav Kubernát2eaceb82018-10-08 19:56:30 +020070 dataPath_ m_path;
Václav Kubernátebca2552018-06-08 19:06:02 +020071 leaf_data_ m_data;
Václav Kubernát24df80e2018-06-06 15:18:03 +020072};
73
Václav Kubernát812ee282018-08-30 17:10:03 +020074struct commit_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010075 static constexpr auto name = "commit";
Václav Kubernát812ee282018-08-30 17:10:03 +020076 bool operator==(const set_& b) const;
77};
78
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020079struct get_ : x3::position_tagged {
Václav Kubernát57272422019-02-08 12:48:24 +010080 static constexpr auto name = "get";
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020081 bool operator==(const get_& b) const;
Václav Kubernát5c75b252018-10-10 18:33:47 +020082 boost::optional<boost::variant<dataPath_, schemaPath_>> m_path;
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020083};
Václav Kubernát812ee282018-08-30 17:10:03 +020084
Václav Kubernát57272422019-02-08 12:48:24 +010085// 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
87using CommandTypes = boost::mpl::vector<discard_, ls_, cd_, create_, delete_, set_, commit_, get_>;
88using command_ = boost::make_variant_over<CommandTypes>::type;
Václav Kubernát24df80e2018-06-06 15:18:03 +020089
Václav Kubernáte7d4aea2018-09-11 18:15:48 +020090BOOST_FUSION_ADAPT_STRUCT(ls_, m_options, m_path)
Václav Kubernát24df80e2018-06-06 15:18:03 +020091BOOST_FUSION_ADAPT_STRUCT(cd_, m_path)
92BOOST_FUSION_ADAPT_STRUCT(create_, m_path)
93BOOST_FUSION_ADAPT_STRUCT(delete_, m_path)
Václav Kubernátebca2552018-06-08 19:06:02 +020094BOOST_FUSION_ADAPT_STRUCT(enum_, m_value)
Václav Kubernát24df80e2018-06-06 15:18:03 +020095BOOST_FUSION_ADAPT_STRUCT(set_, m_path, m_data)
Václav Kubernát812ee282018-08-30 17:10:03 +020096BOOST_FUSION_ADAPT_STRUCT(commit_)
Václav Kubernát6d791432018-10-25 16:00:35 +020097BOOST_FUSION_ADAPT_STRUCT(discard_)
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020098BOOST_FUSION_ADAPT_STRUCT(get_, m_path)