blob: 3159fe0e72096f99c402c1b1929c571890d944a3 [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
10
Václav Kubernát509ce652019-05-29 19:46:44 +020011#include <boost/spirit/home/x3.hpp>
Václav Kubernát24df80e2018-06-06 15:18:03 +020012#include "ast_commands.hpp"
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020013#include "ast_handlers.hpp"
14
Václav Kubernát60d6f292018-05-25 09:45:32 +020015
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020016x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue";
Václav Kubernát89728d82018-09-13 16:28:28 +020017x3::rule<key_identifier_class, std::string> const key_identifier = "key_identifier";
Václav Kubernát744f57f2018-06-29 22:46:26 +020018x3::rule<node_identifier_class, std::string> const node_identifier = "node_identifier";
19x3::rule<module_identifier_class, std::string> const module_identifier = "module_identifier";
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020020x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix";
21x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix";
22x3::rule<listElement_class, listElement_> const listElement = "listElement";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020023x3::rule<list_class, list_> const list = "list";
Václav Kubernát60d6f292018-05-25 09:45:32 +020024x3::rule<nodeup_class, nodeup_> const nodeup = "nodeup";
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020025x3::rule<container_class, container_> const container = "container";
Václav Kubernát07204242018-06-04 18:12:09 +020026x3::rule<leaf_class, leaf_> const leaf = "leaf";
Václav Kubernát744f57f2018-06-29 22:46:26 +020027x3::rule<module_class, module_> const module = "module";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020028x3::rule<dataNode_class, dataNode_> const dataNode = "dataNode";
29x3::rule<schemaNode_class, schemaNode_> const schemaNode = "schemaNode";
Václav Kubernát37171a12018-08-31 17:01:48 +020030x3::rule<absoluteStart_class, Scope> const absoluteStart = "absoluteStart";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020031x3::rule<schemaPath_class, schemaPath_> const schemaPath = "schemaPath";
Václav Kubernátd6fd2492018-11-19 15:11:16 +010032x3::rule<trailingSlash_class, TrailingSlash> const trailingSlash = "trailingSlash";
Václav Kubernát5c75b252018-10-10 18:33:47 +020033x3::rule<dataNodeList_class, decltype(dataPath_::m_nodes)::value_type> const dataNodeList = "dataNodeList";
34x3::rule<dataNodesListEnd_class, decltype(dataPath_::m_nodes)> const dataNodesListEnd = "dataNodesListEnd";
35x3::rule<dataPathListEnd_class, dataPath_> const dataPathListEnd = "dataPathListEnd";
Václav Kubernát2eaceb82018-10-08 19:56:30 +020036x3::rule<dataPath_class, dataPath_> const dataPath = "dataPath";
37x3::rule<leaf_path_class, dataPath_> const leafPath = "leafPath";
Václav Kubernát6797df02019-03-18 20:21:50 +010038x3::rule<presenceContainerPath_class, dataPath_> const presenceContainerPath = "presenceContainerPath";
Václav Kubernátf5f64f02019-03-19 17:15:47 +010039x3::rule<listInstancePath_class, dataPath_> const listInstancePath = "listInstancePath";
Václav Kubernát8028f942019-09-25 16:03:23 +020040x3::rule<space_separator_class, x3::unused_type> const space_separator = "space_separator";
Václav Kubernátebca2552018-06-08 19:06:02 +020041
42x3::rule<leaf_data_class, leaf_data_> const leaf_data = "leaf_data";
43x3::rule<leaf_data_enum_class, enum_> const leaf_data_enum = "leaf_data_enum";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +020044x3::rule<leaf_data_base_class<yang::LeafDataTypes::Decimal>, double> const leaf_data_decimal = "leaf_data_decimal";
45x3::rule<leaf_data_base_class<yang::LeafDataTypes::Bool>, bool> const leaf_data_bool = "leaf_data_bool";
46x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int8>, int8_t> const leaf_data_int8 = "leaf_data_int8";
47x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint8>, uint8_t> const leaf_data_uint8 = "leaf_data_uint8";
48x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int16>, int16_t> const leaf_data_int16 = "leaf_data_int16";
49x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint16>, uint16_t> const leaf_data_uint16 = "leaf_data_uint16";
50x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int32>, int32_t> const leaf_data_int32 = "leaf_data_int32";
51x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint32>, uint32_t> const leaf_data_uint32 = "leaf_data_uint32";
52x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int64>, int64_t> const leaf_data_int64 = "leaf_data_int64";
53x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint64>, uint64_t> const leaf_data_uint64 = "leaf_data_uint64";
54x3::rule<leaf_data_base_class<yang::LeafDataTypes::String>, std::string> const leaf_data_string = "leaf_data_string";
Václav Kubernátab538992019-03-06 15:30:50 +010055x3::rule<leaf_data_binary_data_class, std::string> const leaf_data_binary_data = "leaf_data_binary_data";
Ivona Oboňová88c78ca2019-07-02 18:40:07 +020056x3::rule<leaf_data_base_class<yang::LeafDataTypes::Binary>, binary_> const leaf_data_binary = "leaf_data_binary";
Václav Kubernáteeb38842019-03-20 19:46:05 +010057x3::rule<leaf_data_identityRef_data_class, identityRef_> const leaf_data_identityRef_data = "leaf_data_identityRef_data";
58x3::rule<leaf_data_identityRef_class, identityRef_> const leaf_data_identityRef = "leaf_data_identityRef";
Václav Kubernátebca2552018-06-08 19:06:02 +020059
Václav Kubernát6d791432018-10-25 16:00:35 +020060x3::rule<discard_class, discard_> const discard = "discard";
Václav Kubernát11afac72018-07-18 14:59:53 +020061x3::rule<ls_class, ls_> const ls = "ls";
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020062x3::rule<cd_class, cd_> const cd = "cd";
Václav Kubernát07204242018-06-04 18:12:09 +020063x3::rule<set_class, set_> const set = "set";
Václav Kubernátb6ff0b62018-08-30 16:14:53 +020064x3::rule<get_class, get_> const get = "get";
Václav Kubernátb61336d2018-05-28 17:35:03 +020065x3::rule<create_class, create_> const create = "create";
66x3::rule<delete_class, delete_> const delete_rule = "delete_rule";
Václav Kubernát812ee282018-08-30 17:10:03 +020067x3::rule<commit_class, commit_> const commit = "commit";
Václav Kubernát9cfcd872020-02-18 12:34:02 +010068x3::rule<describe_class, describe_> const describe = "describe";
Václav Kubernát054cc992019-02-21 14:23:52 +010069x3::rule<help_class, help_> const help = "help";
Václav Kubernátb61336d2018-05-28 17:35:03 +020070x3::rule<command_class, command_> const command = "command";
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020071
Václav Kubernát4108e0d2018-10-29 13:32:22 +010072x3::rule<initializePath_class, x3::unused_type> const initializePath = "initializePath";
73x3::rule<createPathSuggestions_class, x3::unused_type> const createPathSuggestions = "createPathSuggestions";
Václav Kubernát329c6c32019-02-06 16:41:53 +010074x3::rule<createKeySuggestions_class, x3::unused_type> const createKeySuggestions = "createKeySuggestions";
Václav Kubernát43908fb2020-01-02 19:05:51 +010075x3::rule<createValueSuggestions_class, x3::unused_type> const createValueSuggestions = "createValueSuggestions";
Václav Kubernát329c6c32019-02-06 16:41:53 +010076x3::rule<suggestKeysEnd_class, x3::unused_type> const suggestKeysEnd = "suggestKeysEnd";
Václav Kubernát57272422019-02-08 12:48:24 +010077x3::rule<createCommandSuggestions_class, x3::unused_type> const createCommandSuggestions = "createCommandSuggestions";
Václav Kubernátac035d62019-02-18 10:59:08 +010078x3::rule<completing_class, x3::unused_type> const completing = "completing";
Václav Kubernát4294a852020-02-14 15:07:14 +010079x3::rule<createSetSuggestions_class<yang::LeafDataTypes::Enum>, x3::unused_type> const createEnumSuggestions = "createEnumSuggestions";
80x3::rule<createSetSuggestions_class<yang::LeafDataTypes::IdentityRef>, x3::unused_type> const createIdentitySuggestions = "createIdentitySuggestions";
Václav Kubernát5c75b252018-10-10 18:33:47 +020081
Václav Kubernát41378452018-06-06 16:29:40 +020082#if __clang__
83#pragma GCC diagnostic push
84#pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses"
85#endif
Václav Kubernát0a2a2e82018-05-11 13:59:12 +020086
Václav Kubernát509ce652019-05-29 19:46:44 +020087namespace ascii = boost::spirit::x3::ascii;
88
89using ascii::space;
90using x3::_attr;
91using x3::alnum;
92using x3::alpha;
93using x3::char_;
94using x3::double_;
95using x3::expect;
96using x3::lexeme;
97using x3::lit;
98using x3::int8;
99using x3::int16;
100using x3::int32;
101using x3::int64;
102using x3::uint8;
103using x3::uint16;
104using x3::uint32;
105using x3::uint64;
106
Václav Kubernát89728d82018-09-13 16:28:28 +0200107auto const key_identifier_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100108 lexeme[
109 ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
110 ];
Václav Kubernát89728d82018-09-13 16:28:28 +0200111
Václav Kubernát329c6c32019-02-06 16:41:53 +0100112auto const createKeySuggestions_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100113 x3::eps;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100114
Václav Kubernát43908fb2020-01-02 19:05:51 +0100115auto const createValueSuggestions_def =
116 x3::eps;
117
Václav Kubernát329c6c32019-02-06 16:41:53 +0100118auto const suggestKeysEnd_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100119 x3::eps;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100120
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200121auto const keyValue_def =
Václav Kubernát43908fb2020-01-02 19:05:51 +0100122 key_identifier > '=' > createValueSuggestions > leaf_data;
Václav Kubernát329c6c32019-02-06 16:41:53 +0100123
124auto const keyValueWrapper =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100125 lexeme['[' > createKeySuggestions > keyValue > suggestKeysEnd > ']'];
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200126
Václav Kubernát744f57f2018-06-29 22:46:26 +0200127auto const module_identifier_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100128 lexeme[
129 ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
130 ];
Václav Kubernát744f57f2018-06-29 22:46:26 +0200131
132auto const node_identifier_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100133 lexeme[
134 ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_(".")))
135 ];
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200136
137auto const listPrefix_def =
Václav Kubernát4c325482019-04-11 17:51:55 +0200138 node_identifier;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200139
Václav Kubernát7e4e82f2018-05-14 20:04:58 +0200140// even though we don't allow no keys to be supplied, the star allows me to check which keys are missing
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200141auto const listSuffix_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100142 *keyValueWrapper;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200143
144auto const listElement_def =
Václav Kubernáte69133a2019-11-01 19:01:34 +0100145 listPrefix >> &char_('[') > listSuffix;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200146
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200147auto const list_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100148 node_identifier >> !char_('[');
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200149
Václav Kubernát60d6f292018-05-25 09:45:32 +0200150auto const nodeup_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100151 lit("..") > x3::attr(nodeup_());
Václav Kubernát60d6f292018-05-25 09:45:32 +0200152
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200153auto const container_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100154 node_identifier;
Václav Kubernát744f57f2018-06-29 22:46:26 +0200155
156auto const module_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100157 module_identifier >> x3::no_skip[':'] >> !x3::no_skip[space];
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200158
Václav Kubernát07204242018-06-04 18:12:09 +0200159auto const leaf_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100160 node_identifier;
Václav Kubernát07204242018-06-04 18:12:09 +0200161
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100162auto const createPathSuggestions_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100163 x3::eps;
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100164
Václav Kubernát07204242018-06-04 18:12:09 +0200165// leaf cannot be in the middle of a path, however, I need the grammar's attribute to be a vector of variants
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200166auto const schemaNode_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100167 createPathSuggestions >> -(module) >> (container | list | nodeup | leaf);
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200168
169auto const dataNode_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100170 createPathSuggestions >> -(module) >> (container | listElement | nodeup | leaf);
Václav Kubernát744f57f2018-06-29 22:46:26 +0200171
Václav Kubernát37171a12018-08-31 17:01:48 +0200172auto const absoluteStart_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100173 x3::omit['/'] >> x3::attr(Scope::Absolute);
Václav Kubernát37171a12018-08-31 17:01:48 +0200174
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100175auto const trailingSlash_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100176 x3::omit['/'] >> x3::attr(TrailingSlash::Present);
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100177
Václav Kubernát8028f942019-09-25 16:03:23 +0200178auto const space_separator_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100179 x3::omit[x3::no_skip[space]];
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100180
Václav Kubernátac035d62019-02-18 10:59:08 +0100181// This is a pseudo-parser, that fails if we're not completing a command
182auto const completing_def =
Václav Kubernát26be33a2020-02-13 13:30:14 +0100183 x3::no_skip[x3::eps];
184
185auto const rest =
186 x3::omit[x3::no_skip[+(char_ - '/' - space_separator)]];
Václav Kubernátac035d62019-02-18 10:59:08 +0100187
Václav Kubernát37171a12018-08-31 17:01:48 +0200188// I have to insert an empty vector to the first alternative, otherwise they won't have the same attribute
Václav Kubernát26be33a2020-02-13 13:30:14 +0100189auto const dataPath_def = initializePath >> absoluteStart >> createPathSuggestions >> x3::attr(decltype(dataPath_::m_nodes)()) >> x3::attr(TrailingSlash::NonPresent) >> x3::eoi | initializePath >> -(absoluteStart >> createPathSuggestions) >> dataNode % '/' >> (-(trailingSlash >> createPathSuggestions) >> -(completing >> rest) >> (&space_separator | x3::eoi));
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200190
Václav Kubernát5c75b252018-10-10 18:33:47 +0200191auto const dataNodeList_def =
Václav Kubernát51853b22019-04-16 21:53:44 +0200192 createPathSuggestions >> -(module) >> list;
Václav Kubernát5c75b252018-10-10 18:33:47 +0200193
194// This intermediate rule is mandatory, because we need the first alternative
195// to be collapsed to a vector. If we didn't use the intermediate rule,
196// Spirit wouldn't know we want it to collapse.
197// https://github.com/boostorg/spirit/issues/408
198auto const dataNodesListEnd_def =
Václav Kubernát211383d2020-01-06 18:07:50 +0100199 dataNode % '/' >> '/' >> dataNodeList >> -(&char_('/') >> createPathSuggestions) |
200 x3::attr(decltype(dataPath_::m_nodes)()) >> dataNodeList;
Václav Kubernát5c75b252018-10-10 18:33:47 +0200201
Václav Kubernát26be33a2020-02-13 13:30:14 +0100202auto const dataPathListEnd_def = initializePath >> absoluteStart >> createPathSuggestions >> x3::attr(decltype(dataPath_::m_nodes)()) >> x3::attr(TrailingSlash::NonPresent) >> x3::eoi | initializePath >> -(absoluteStart >> createPathSuggestions) >> dataNodesListEnd >> (-(trailingSlash >> createPathSuggestions) >> -(completing >> rest) >> (&space_separator | x3::eoi));
Václav Kubernát5c75b252018-10-10 18:33:47 +0200203
Václav Kubernát26be33a2020-02-13 13:30:14 +0100204auto const schemaPath_def = initializePath >> absoluteStart >> createPathSuggestions >> x3::attr(decltype(schemaPath_::m_nodes)()) >> x3::attr(TrailingSlash::NonPresent) >> x3::eoi | initializePath >> -(absoluteStart >> createPathSuggestions) >> schemaNode % '/' >> (-(trailingSlash >> createPathSuggestions) >> -(completing >> rest) >> (&space_separator | x3::eoi));
Václav Kubernát07204242018-06-04 18:12:09 +0200205
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200206auto const leafPath_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100207 dataPath;
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200208
Václav Kubernát6797df02019-03-18 20:21:50 +0100209auto const presenceContainerPath_def =
210 dataPath;
211
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100212auto const listInstancePath_def =
213 dataPath;
214
Václav Kubernát989b5de2019-02-20 16:28:35 +0100215auto const createEnumSuggestions_def =
216 x3::eps;
217
Václav Kubernátebca2552018-06-08 19:06:02 +0200218auto const leaf_data_enum_def =
Václav Kubernát989b5de2019-02-20 16:28:35 +0100219 createEnumSuggestions >> +char_;
Václav Kubernát90de9502019-11-20 17:19:44 +0100220
Václav Kubernátebca2552018-06-08 19:06:02 +0200221auto const leaf_data_decimal_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100222 double_;
Václav Kubernátebca2552018-06-08 19:06:02 +0200223
224struct bool_symbol_table : x3::symbols<bool> {
225 bool_symbol_table()
226 {
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100227 add
228 ("true", true)
229 ("false", false);
Václav Kubernátebca2552018-06-08 19:06:02 +0200230 }
231} const bool_rule;
232
233auto const leaf_data_bool_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100234 bool_rule;
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200235auto const leaf_data_int8_def =
236 int8;
237auto const leaf_data_int16_def =
238 int16;
239auto const leaf_data_int32_def =
240 int32;
241auto const leaf_data_int64_def =
242 int64;
243auto const leaf_data_uint8_def =
244 uint8;
245auto const leaf_data_uint16_def =
246 uint16;
247auto const leaf_data_uint32_def =
248 uint32;
249auto const leaf_data_uint64_def =
250 uint64;
Václav Kubernátebca2552018-06-08 19:06:02 +0200251auto const leaf_data_string_def =
Václav Kubernát1bbac7c2020-01-15 17:45:41 +0100252 '\'' >> *(char_-'\'') >> '\'' |
253 '\"' >> *(char_-'\"') >> '\"';
Václav Kubernátebca2552018-06-08 19:06:02 +0200254
Václav Kubernátab538992019-03-06 15:30:50 +0100255// This intermediate rule is neccessary for coercing to std::string.
256auto const leaf_data_binary_data_def =
257 +(x3::alnum | char_('+') | char_('/')) >> -char_('=') >> -char_('=');
258
259auto const leaf_data_binary_def =
260 leaf_data_binary_data;
261
Václav Kubernáteeb38842019-03-20 19:46:05 +0100262auto const leaf_data_identityRef_data_def =
263 -module >> node_identifier;
264
265auto const createIdentitySuggestions_def =
266 x3::eps;
267
268auto const leaf_data_identityRef_def =
269 createIdentitySuggestions >> leaf_data_identityRef_data;
270
Václav Kubernátebca2552018-06-08 19:06:02 +0200271auto const leaf_data_def =
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100272x3::no_skip[x3::expect[
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100273 leaf_data_enum |
274 leaf_data_decimal |
275 leaf_data_bool |
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200276 leaf_data_int8 |
277 leaf_data_int16 |
278 leaf_data_int32 |
279 leaf_data_int64 |
280 leaf_data_uint8 |
281 leaf_data_uint16 |
282 leaf_data_uint32 |
283 leaf_data_uint64 |
Václav Kubernátab538992019-03-06 15:30:50 +0100284 leaf_data_binary |
Václav Kubernáteeb38842019-03-20 19:46:05 +0100285 leaf_data_identityRef |
Václav Kubernátc18ffac2020-01-10 16:06:06 +0100286 leaf_data_string]];
Václav Kubernát07204242018-06-04 18:12:09 +0200287
Václav Kubernáte7d4aea2018-09-11 18:15:48 +0200288struct ls_options_table : x3::symbols<LsOption> {
289 ls_options_table()
290 {
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100291 add
292 ("--recursive", LsOption::Recursive);
Václav Kubernáte7d4aea2018-09-11 18:15:48 +0200293 }
294} const ls_options;
295
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100296// A "nothing" parser, which is used to indicate we tried to parse a path
297auto const initializePath_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100298 x3::eps;
Václav Kubernát5c75b252018-10-10 18:33:47 +0200299
Václav Kubernát11afac72018-07-18 14:59:53 +0200300auto const ls_def =
Václav Kubernát9456b5c2019-10-02 21:14:52 +0200301 ls_::name >> *(space_separator >> ls_options) >> -(space_separator >> ((dataPathListEnd | dataPath | schemaPath) | (module >> "*")));
Václav Kubernát11afac72018-07-18 14:59:53 +0200302
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200303auto const cd_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100304 cd_::name >> space_separator > dataPath;
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200305
Václav Kubernátb61336d2018-05-28 17:35:03 +0200306auto const create_def =
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100307 create_::name >> space_separator > (presenceContainerPath | listInstancePath);
Václav Kubernátb61336d2018-05-28 17:35:03 +0200308
309auto const delete_rule_def =
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100310 delete_::name >> space_separator > (presenceContainerPath | listInstancePath);
Václav Kubernát07204242018-06-04 18:12:09 +0200311
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200312auto const get_def =
Václav Kubernát9456b5c2019-10-02 21:14:52 +0200313 get_::name >> -(space_separator >> ((dataPathListEnd | dataPath) | (module >> "*")));
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200314
Václav Kubernát07204242018-06-04 18:12:09 +0200315auto const set_def =
Václav Kubernát989b5de2019-02-20 16:28:35 +0100316 set_::name >> space_separator > leafPath > space_separator > leaf_data;
Václav Kubernátb61336d2018-05-28 17:35:03 +0200317
Václav Kubernát812ee282018-08-30 17:10:03 +0200318auto const commit_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100319 commit_::name >> x3::attr(commit_());
Václav Kubernát812ee282018-08-30 17:10:03 +0200320
Václav Kubernát6d791432018-10-25 16:00:35 +0200321auto const discard_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100322 discard_::name >> x3::attr(discard_());
Václav Kubernát6d791432018-10-25 16:00:35 +0200323
Václav Kubernát054cc992019-02-21 14:23:52 +0100324struct command_names_table : x3::symbols<decltype(help_::m_cmd)> {
325 command_names_table()
326 {
327 boost::mpl::for_each<CommandTypes, boost::type<boost::mpl::_>>([this](auto cmd) {
328 add(commandNamesVisitor()(cmd), decltype(help_::m_cmd)(cmd));
329 });
330 }
331} const command_names;
332
333auto const help_def =
334 help_::name > createCommandSuggestions >> -command_names;
335
Václav Kubernát9cfcd872020-02-18 12:34:02 +0100336auto const describe_def =
337 describe_::name >> space_separator > (dataPathListEnd | dataPath | schemaPath);
338
Václav Kubernát57272422019-02-08 12:48:24 +0100339auto const createCommandSuggestions_def =
Václav Kubernátbf083ec2019-02-19 13:58:09 +0100340 x3::eps;
Václav Kubernát57272422019-02-08 12:48:24 +0100341
Václav Kubernátb61336d2018-05-28 17:35:03 +0200342auto const command_def =
Václav Kubernát9cfcd872020-02-18 12:34:02 +0100343 createCommandSuggestions >> x3::expect[cd | create | delete_rule | set | commit | get | ls | discard | describe | help];
Václav Kubernát41378452018-06-06 16:29:40 +0200344
345#if __clang__
346#pragma GCC diagnostic pop
347#endif
Václav Kubernátb61336d2018-05-28 17:35:03 +0200348
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200349BOOST_SPIRIT_DEFINE(keyValue)
Václav Kubernát89728d82018-09-13 16:28:28 +0200350BOOST_SPIRIT_DEFINE(key_identifier)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200351BOOST_SPIRIT_DEFINE(node_identifier)
352BOOST_SPIRIT_DEFINE(module_identifier)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200353BOOST_SPIRIT_DEFINE(listPrefix)
354BOOST_SPIRIT_DEFINE(listSuffix)
355BOOST_SPIRIT_DEFINE(listElement)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200356BOOST_SPIRIT_DEFINE(list)
Václav Kubernát60d6f292018-05-25 09:45:32 +0200357BOOST_SPIRIT_DEFINE(nodeup)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200358BOOST_SPIRIT_DEFINE(schemaNode)
359BOOST_SPIRIT_DEFINE(dataNode)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200360BOOST_SPIRIT_DEFINE(container)
Václav Kubernát07204242018-06-04 18:12:09 +0200361BOOST_SPIRIT_DEFINE(leaf)
Václav Kubernát0b0272f2018-06-13 14:13:08 +0200362BOOST_SPIRIT_DEFINE(leafPath)
Václav Kubernát6797df02019-03-18 20:21:50 +0100363BOOST_SPIRIT_DEFINE(presenceContainerPath)
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100364BOOST_SPIRIT_DEFINE(listInstancePath)
Václav Kubernát8028f942019-09-25 16:03:23 +0200365BOOST_SPIRIT_DEFINE(space_separator)
Václav Kubernát2eaceb82018-10-08 19:56:30 +0200366BOOST_SPIRIT_DEFINE(schemaPath)
367BOOST_SPIRIT_DEFINE(dataPath)
Václav Kubernát5c75b252018-10-10 18:33:47 +0200368BOOST_SPIRIT_DEFINE(dataNodeList)
369BOOST_SPIRIT_DEFINE(dataNodesListEnd)
370BOOST_SPIRIT_DEFINE(dataPathListEnd)
Václav Kubernát37171a12018-08-31 17:01:48 +0200371BOOST_SPIRIT_DEFINE(absoluteStart)
Václav Kubernátd6fd2492018-11-19 15:11:16 +0100372BOOST_SPIRIT_DEFINE(trailingSlash)
Václav Kubernát744f57f2018-06-29 22:46:26 +0200373BOOST_SPIRIT_DEFINE(module)
Václav Kubernátebca2552018-06-08 19:06:02 +0200374BOOST_SPIRIT_DEFINE(leaf_data)
375BOOST_SPIRIT_DEFINE(leaf_data_enum)
376BOOST_SPIRIT_DEFINE(leaf_data_decimal)
377BOOST_SPIRIT_DEFINE(leaf_data_bool)
Ivona Oboňová88c78ca2019-07-02 18:40:07 +0200378BOOST_SPIRIT_DEFINE(leaf_data_int8)
379BOOST_SPIRIT_DEFINE(leaf_data_int16)
380BOOST_SPIRIT_DEFINE(leaf_data_int32)
381BOOST_SPIRIT_DEFINE(leaf_data_int64)
382BOOST_SPIRIT_DEFINE(leaf_data_uint8)
383BOOST_SPIRIT_DEFINE(leaf_data_uint16)
384BOOST_SPIRIT_DEFINE(leaf_data_uint32)
385BOOST_SPIRIT_DEFINE(leaf_data_uint64)
Václav Kubernátebca2552018-06-08 19:06:02 +0200386BOOST_SPIRIT_DEFINE(leaf_data_string)
Václav Kubernátab538992019-03-06 15:30:50 +0100387BOOST_SPIRIT_DEFINE(leaf_data_binary_data)
388BOOST_SPIRIT_DEFINE(leaf_data_binary)
Václav Kubernáteeb38842019-03-20 19:46:05 +0100389BOOST_SPIRIT_DEFINE(leaf_data_identityRef_data)
390BOOST_SPIRIT_DEFINE(leaf_data_identityRef)
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100391BOOST_SPIRIT_DEFINE(initializePath)
Václav Kubernát07204242018-06-04 18:12:09 +0200392BOOST_SPIRIT_DEFINE(set)
Václav Kubernát812ee282018-08-30 17:10:03 +0200393BOOST_SPIRIT_DEFINE(commit)
Václav Kubernátb6ff0b62018-08-30 16:14:53 +0200394BOOST_SPIRIT_DEFINE(get)
Václav Kubernát11afac72018-07-18 14:59:53 +0200395BOOST_SPIRIT_DEFINE(ls)
Václav Kubernát6d791432018-10-25 16:00:35 +0200396BOOST_SPIRIT_DEFINE(discard)
Václav Kubernát0a2a2e82018-05-11 13:59:12 +0200397BOOST_SPIRIT_DEFINE(cd)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200398BOOST_SPIRIT_DEFINE(create)
399BOOST_SPIRIT_DEFINE(delete_rule)
Václav Kubernát9cfcd872020-02-18 12:34:02 +0100400BOOST_SPIRIT_DEFINE(describe)
Václav Kubernát054cc992019-02-21 14:23:52 +0100401BOOST_SPIRIT_DEFINE(help)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200402BOOST_SPIRIT_DEFINE(command)
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100403BOOST_SPIRIT_DEFINE(createPathSuggestions)
Václav Kubernát329c6c32019-02-06 16:41:53 +0100404BOOST_SPIRIT_DEFINE(createKeySuggestions)
Václav Kubernát43908fb2020-01-02 19:05:51 +0100405BOOST_SPIRIT_DEFINE(createValueSuggestions)
Václav Kubernát329c6c32019-02-06 16:41:53 +0100406BOOST_SPIRIT_DEFINE(suggestKeysEnd)
Václav Kubernát57272422019-02-08 12:48:24 +0100407BOOST_SPIRIT_DEFINE(createCommandSuggestions)
Václav Kubernátac035d62019-02-18 10:59:08 +0100408BOOST_SPIRIT_DEFINE(completing)
Václav Kubernát989b5de2019-02-20 16:28:35 +0100409BOOST_SPIRIT_DEFINE(createEnumSuggestions)
Václav Kubernáteeb38842019-03-20 19:46:05 +0100410BOOST_SPIRIT_DEFINE(createIdentitySuggestions)