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" |
| 14 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 15 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 16 | x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue"; |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 17 | x3::rule<key_identifier_class, std::string> const key_identifier = "key_identifier"; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 18 | x3::rule<node_identifier_class, std::string> const node_identifier = "node_identifier"; |
| 19 | x3::rule<module_identifier_class, std::string> const module_identifier = "module_identifier"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 20 | x3::rule<listPrefix_class, std::string> const listPrefix = "listPrefix"; |
| 21 | x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix"; |
| 22 | x3::rule<listElement_class, listElement_> const listElement = "listElement"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 23 | x3::rule<list_class, list_> const list = "list"; |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 24 | x3::rule<nodeup_class, nodeup_> const nodeup = "nodeup"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 25 | x3::rule<container_class, container_> const container = "container"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 26 | x3::rule<leaf_class, leaf_> const leaf = "leaf"; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 27 | x3::rule<module_class, module_> const module = "module"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 28 | x3::rule<dataNode_class, dataNode_> const dataNode = "dataNode"; |
| 29 | x3::rule<schemaNode_class, schemaNode_> const schemaNode = "schemaNode"; |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 30 | x3::rule<absoluteStart_class, Scope> const absoluteStart = "absoluteStart"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 31 | x3::rule<schemaPath_class, schemaPath_> const schemaPath = "schemaPath"; |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 32 | x3::rule<trailingSlash_class, TrailingSlash> const trailingSlash = "trailingSlash"; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 33 | x3::rule<dataNodeList_class, decltype(dataPath_::m_nodes)::value_type> const dataNodeList = "dataNodeList"; |
| 34 | x3::rule<dataNodesListEnd_class, decltype(dataPath_::m_nodes)> const dataNodesListEnd = "dataNodesListEnd"; |
| 35 | x3::rule<dataPathListEnd_class, dataPath_> const dataPathListEnd = "dataPathListEnd"; |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 36 | x3::rule<dataPath_class, dataPath_> const dataPath = "dataPath"; |
| 37 | x3::rule<leaf_path_class, dataPath_> const leafPath = "leafPath"; |
Václav Kubernát | 6797df0 | 2019-03-18 20:21:50 +0100 | [diff] [blame] | 38 | x3::rule<presenceContainerPath_class, dataPath_> const presenceContainerPath = "presenceContainerPath"; |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 39 | x3::rule<listInstancePath_class, dataPath_> const listInstancePath = "listInstancePath"; |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame^] | 40 | x3::rule<space_separator_class, x3::unused_type> const space_separator = "space_separator"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 41 | |
| 42 | x3::rule<leaf_data_class, leaf_data_> const leaf_data = "leaf_data"; |
| 43 | x3::rule<leaf_data_enum_class, enum_> const leaf_data_enum = "leaf_data_enum"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 44 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Decimal>, double> const leaf_data_decimal = "leaf_data_decimal"; |
| 45 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Bool>, bool> const leaf_data_bool = "leaf_data_bool"; |
| 46 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int8>, int8_t> const leaf_data_int8 = "leaf_data_int8"; |
| 47 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint8>, uint8_t> const leaf_data_uint8 = "leaf_data_uint8"; |
| 48 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int16>, int16_t> const leaf_data_int16 = "leaf_data_int16"; |
| 49 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint16>, uint16_t> const leaf_data_uint16 = "leaf_data_uint16"; |
| 50 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int32>, int32_t> const leaf_data_int32 = "leaf_data_int32"; |
| 51 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint32>, uint32_t> const leaf_data_uint32 = "leaf_data_uint32"; |
| 52 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Int64>, int64_t> const leaf_data_int64 = "leaf_data_int64"; |
| 53 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Uint64>, uint64_t> const leaf_data_uint64 = "leaf_data_uint64"; |
| 54 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::String>, std::string> const leaf_data_string = "leaf_data_string"; |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 55 | x3::rule<leaf_data_binary_data_class, std::string> const leaf_data_binary_data = "leaf_data_binary_data"; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 56 | x3::rule<leaf_data_base_class<yang::LeafDataTypes::Binary>, binary_> const leaf_data_binary = "leaf_data_binary"; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 57 | x3::rule<leaf_data_identityRef_data_class, identityRef_> const leaf_data_identityRef_data = "leaf_data_identityRef_data"; |
| 58 | x3::rule<leaf_data_identityRef_class, identityRef_> const leaf_data_identityRef = "leaf_data_identityRef"; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 59 | |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 60 | x3::rule<discard_class, discard_> const discard = "discard"; |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 61 | x3::rule<ls_class, ls_> const ls = "ls"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 62 | x3::rule<cd_class, cd_> const cd = "cd"; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 63 | x3::rule<set_class, set_> const set = "set"; |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 64 | x3::rule<get_class, get_> const get = "get"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 65 | x3::rule<create_class, create_> const create = "create"; |
| 66 | x3::rule<delete_class, delete_> const delete_rule = "delete_rule"; |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 67 | x3::rule<commit_class, commit_> const commit = "commit"; |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 68 | x3::rule<help_class, help_> const help = "help"; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 69 | x3::rule<command_class, command_> const command = "command"; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 70 | |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 71 | x3::rule<initializePath_class, x3::unused_type> const initializePath = "initializePath"; |
| 72 | x3::rule<createPathSuggestions_class, x3::unused_type> const createPathSuggestions = "createPathSuggestions"; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 73 | x3::rule<createKeySuggestions_class, x3::unused_type> const createKeySuggestions = "createKeySuggestions"; |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 74 | x3::rule<suggestKeysStart_class, x3::unused_type> const suggestKeysStart = "suggestKeysStart"; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 75 | x3::rule<suggestKeysEnd_class, x3::unused_type> const suggestKeysEnd = "suggestKeysEnd"; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 76 | x3::rule<createCommandSuggestions_class, x3::unused_type> const createCommandSuggestions = "createCommandSuggestions"; |
Václav Kubernát | ac035d6 | 2019-02-18 10:59:08 +0100 | [diff] [blame] | 77 | x3::rule<completing_class, x3::unused_type> const completing = "completing"; |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 78 | x3::rule<createEnumSuggestions_class, x3::unused_type> const createEnumSuggestions = "createEnumSuggestions"; |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 79 | x3::rule<createIdentitySuggestions_class, x3::unused_type> const createIdentitySuggestions = "createIdentitySuggestions"; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 80 | |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame] | 81 | #if __clang__ |
| 82 | #pragma GCC diagnostic push |
| 83 | #pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses" |
| 84 | #endif |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 85 | |
Václav Kubernát | 509ce65 | 2019-05-29 19:46:44 +0200 | [diff] [blame] | 86 | namespace ascii = boost::spirit::x3::ascii; |
| 87 | |
| 88 | using ascii::space; |
| 89 | using x3::_attr; |
| 90 | using x3::alnum; |
| 91 | using x3::alpha; |
| 92 | using x3::char_; |
| 93 | using x3::double_; |
| 94 | using x3::expect; |
| 95 | using x3::lexeme; |
| 96 | using x3::lit; |
| 97 | using x3::int8; |
| 98 | using x3::int16; |
| 99 | using x3::int32; |
| 100 | using x3::int64; |
| 101 | using x3::uint8; |
| 102 | using x3::uint16; |
| 103 | using x3::uint32; |
| 104 | using x3::uint64; |
| 105 | |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 106 | auto const key_identifier_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 107 | lexeme[ |
| 108 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 109 | ]; |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 110 | |
| 111 | auto const quotedValue = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 112 | ('\'' > +(char_-'\'') > '\'') | |
| 113 | ('\"' > +(char_-'\"') > '\"'); |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 114 | |
| 115 | auto const number = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 116 | +x3::digit; |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 117 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 118 | auto const createKeySuggestions_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 119 | x3::eps; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 120 | |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 121 | auto const suggestKeysStart_def = |
| 122 | x3::eps; |
| 123 | |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 124 | auto const suggestKeysEnd_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 125 | x3::eps; |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 126 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 127 | auto const keyValue_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 128 | key_identifier > '=' > (quotedValue | number); |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 129 | |
| 130 | auto const keyValueWrapper = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 131 | lexeme['[' > createKeySuggestions > keyValue > suggestKeysEnd > ']']; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 132 | |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 133 | auto const module_identifier_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 134 | lexeme[ |
| 135 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 136 | ]; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 137 | |
| 138 | auto const node_identifier_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 139 | lexeme[ |
| 140 | ((alpha | char_("_")) >> *(alnum | char_("_") | char_("-") | char_("."))) |
| 141 | ]; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 142 | |
| 143 | auto const listPrefix_def = |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 144 | node_identifier; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 145 | |
Václav Kubernát | 7e4e82f | 2018-05-14 20:04:58 +0200 | [diff] [blame] | 146 | // even though we don't allow no keys to be supplied, the star allows me to check which keys are missing |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 147 | auto const listSuffix_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 148 | *keyValueWrapper; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 149 | |
| 150 | auto const listElement_def = |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 151 | listPrefix >> -(!char_('[') >> suggestKeysStart) >> &char_('[') > listSuffix; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 152 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 153 | auto const list_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 154 | node_identifier >> !char_('['); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 155 | |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 156 | auto const nodeup_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 157 | lit("..") > x3::attr(nodeup_()); |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 158 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 159 | auto const container_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 160 | node_identifier; |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 161 | |
| 162 | auto const module_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 163 | module_identifier >> x3::no_skip[':'] >> !x3::no_skip[space]; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 164 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 165 | auto const leaf_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 166 | node_identifier; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 167 | |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 168 | auto const createPathSuggestions_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 169 | x3::eps; |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 170 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 171 | // 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át | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 172 | auto const schemaNode_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 173 | createPathSuggestions >> -(module) >> (container | list | nodeup | leaf); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 174 | |
| 175 | auto const dataNode_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 176 | createPathSuggestions >> -(module) >> (container | listElement | nodeup | leaf); |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 177 | |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 178 | auto const absoluteStart_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 179 | x3::omit['/'] >> x3::attr(Scope::Absolute); |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 180 | |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 181 | auto const trailingSlash_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 182 | x3::omit['/'] >> x3::attr(TrailingSlash::Present); |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 183 | |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame^] | 184 | auto const space_separator_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 185 | x3::omit[x3::no_skip[space]]; |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 186 | |
Václav Kubernát | ac035d6 | 2019-02-18 10:59:08 +0100 | [diff] [blame] | 187 | // This is a pseudo-parser, that fails if we're not completing a command |
| 188 | auto const completing_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 189 | x3::eps; |
Václav Kubernát | ac035d6 | 2019-02-18 10:59:08 +0100 | [diff] [blame] | 190 | |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 191 | // I have to insert an empty vector to the first alternative, otherwise they won't have the same attribute |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 192 | auto const dataPath_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 193 | initializePath >> absoluteStart >> createPathSuggestions >> x3::attr(decltype(dataPath_::m_nodes)()) >> x3::attr(TrailingSlash::NonPresent) >> x3::eoi | |
| 194 | initializePath >> -(absoluteStart >> createPathSuggestions) >> dataNode % '/' >> (trailingSlash >> createPathSuggestions >> (completing | x3::eoi) | (&space_separator | x3::eoi)); |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 195 | |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 196 | auto const dataNodeList_def = |
Václav Kubernát | 51853b2 | 2019-04-16 21:53:44 +0200 | [diff] [blame] | 197 | createPathSuggestions >> -(module) >> list; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 198 | |
| 199 | // This intermediate rule is mandatory, because we need the first alternative |
| 200 | // to be collapsed to a vector. If we didn't use the intermediate rule, |
| 201 | // Spirit wouldn't know we want it to collapse. |
| 202 | // https://github.com/boostorg/spirit/issues/408 |
| 203 | auto const dataNodesListEnd_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 204 | initializePath >> dataNode % '/' >> '/' >> dataNodeList >> -(&char_('/') >> createPathSuggestions) | |
| 205 | initializePath >> x3::attr(decltype(dataPath_::m_nodes)()) >> dataNodeList; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 206 | |
| 207 | auto const dataPathListEnd_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 208 | initializePath >> absoluteStart >> createPathSuggestions >> x3::attr(decltype(dataPath_::m_nodes)()) >> x3::attr(TrailingSlash::NonPresent) >> x3::eoi | |
| 209 | initializePath >> -(absoluteStart >> createPathSuggestions) >> dataNodesListEnd >> (trailingSlash >> createPathSuggestions >> (completing | x3::eoi) | (&space_separator | x3::eoi)); |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 210 | |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 211 | auto const schemaPath_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 212 | initializePath >> absoluteStart >> createPathSuggestions >> x3::attr(decltype(schemaPath_::m_nodes)()) >> x3::attr(TrailingSlash::NonPresent) >> x3::eoi | |
| 213 | initializePath >> -(absoluteStart >> createPathSuggestions) >> schemaNode % '/' >> (trailingSlash >> createPathSuggestions >> (completing | x3::eoi) | (&space_separator | x3::eoi)); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 214 | |
Václav Kubernát | 0b0272f | 2018-06-13 14:13:08 +0200 | [diff] [blame] | 215 | auto const leafPath_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 216 | dataPath; |
Václav Kubernát | 0b0272f | 2018-06-13 14:13:08 +0200 | [diff] [blame] | 217 | |
Václav Kubernát | 6797df0 | 2019-03-18 20:21:50 +0100 | [diff] [blame] | 218 | auto const presenceContainerPath_def = |
| 219 | dataPath; |
| 220 | |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 221 | auto const listInstancePath_def = |
| 222 | dataPath; |
| 223 | |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 224 | auto const createEnumSuggestions_def = |
| 225 | x3::eps; |
| 226 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 227 | auto const leaf_data_enum_def = |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 228 | createEnumSuggestions >> +char_; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 229 | auto const leaf_data_decimal_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 230 | double_; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 231 | |
| 232 | struct bool_symbol_table : x3::symbols<bool> { |
| 233 | bool_symbol_table() |
| 234 | { |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 235 | add |
| 236 | ("true", true) |
| 237 | ("false", false); |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 238 | } |
| 239 | } const bool_rule; |
| 240 | |
| 241 | auto const leaf_data_bool_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 242 | bool_rule; |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 243 | auto const leaf_data_int8_def = |
| 244 | int8; |
| 245 | auto const leaf_data_int16_def = |
| 246 | int16; |
| 247 | auto const leaf_data_int32_def = |
| 248 | int32; |
| 249 | auto const leaf_data_int64_def = |
| 250 | int64; |
| 251 | auto const leaf_data_uint8_def = |
| 252 | uint8; |
| 253 | auto const leaf_data_uint16_def = |
| 254 | uint16; |
| 255 | auto const leaf_data_uint32_def = |
| 256 | uint32; |
| 257 | auto const leaf_data_uint64_def = |
| 258 | uint64; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 259 | auto const leaf_data_string_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 260 | *char_; |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 261 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 262 | // This intermediate rule is neccessary for coercing to std::string. |
| 263 | auto const leaf_data_binary_data_def = |
| 264 | +(x3::alnum | char_('+') | char_('/')) >> -char_('=') >> -char_('='); |
| 265 | |
| 266 | auto const leaf_data_binary_def = |
| 267 | leaf_data_binary_data; |
| 268 | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 269 | auto const leaf_data_identityRef_data_def = |
| 270 | -module >> node_identifier; |
| 271 | |
| 272 | auto const createIdentitySuggestions_def = |
| 273 | x3::eps; |
| 274 | |
| 275 | auto const leaf_data_identityRef_def = |
| 276 | createIdentitySuggestions >> leaf_data_identityRef_data; |
| 277 | |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 278 | auto const leaf_data_def = |
Václav Kubernát | 0b0272f | 2018-06-13 14:13:08 +0200 | [diff] [blame] | 279 | x3::expect[ |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 280 | leaf_data_enum | |
| 281 | leaf_data_decimal | |
| 282 | leaf_data_bool | |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 283 | leaf_data_int8 | |
| 284 | leaf_data_int16 | |
| 285 | leaf_data_int32 | |
| 286 | leaf_data_int64 | |
| 287 | leaf_data_uint8 | |
| 288 | leaf_data_uint16 | |
| 289 | leaf_data_uint32 | |
| 290 | leaf_data_uint64 | |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 291 | leaf_data_binary | |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 292 | leaf_data_identityRef | |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 293 | leaf_data_string]; |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 294 | |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 295 | struct ls_options_table : x3::symbols<LsOption> { |
| 296 | ls_options_table() |
| 297 | { |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 298 | add |
| 299 | ("--recursive", LsOption::Recursive); |
Václav Kubernát | e7d4aea | 2018-09-11 18:15:48 +0200 | [diff] [blame] | 300 | } |
| 301 | } const ls_options; |
| 302 | |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 303 | // A "nothing" parser, which is used to indicate we tried to parse a path |
| 304 | auto const initializePath_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 305 | x3::eps; |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 306 | |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 307 | auto const ls_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 308 | ls_::name >> *(space_separator >> ls_options) >> -(space_separator >> (dataPathListEnd | dataPath | schemaPath)); |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 309 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 310 | auto const cd_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 311 | cd_::name >> space_separator > dataPath; |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 312 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 313 | auto const create_def = |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 314 | create_::name >> space_separator > (presenceContainerPath | listInstancePath); |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 315 | |
| 316 | auto const delete_rule_def = |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 317 | delete_::name >> space_separator > (presenceContainerPath | listInstancePath); |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 318 | |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 319 | auto const get_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 320 | get_::name >> -(space_separator >> (dataPathListEnd | dataPath)); |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 321 | |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 322 | auto const set_def = |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 323 | set_::name >> space_separator > leafPath > space_separator > leaf_data; |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 324 | |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 325 | auto const commit_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 326 | commit_::name >> x3::attr(commit_()); |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 327 | |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 328 | auto const discard_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 329 | discard_::name >> x3::attr(discard_()); |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 330 | |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 331 | struct command_names_table : x3::symbols<decltype(help_::m_cmd)> { |
| 332 | command_names_table() |
| 333 | { |
| 334 | boost::mpl::for_each<CommandTypes, boost::type<boost::mpl::_>>([this](auto cmd) { |
| 335 | add(commandNamesVisitor()(cmd), decltype(help_::m_cmd)(cmd)); |
| 336 | }); |
| 337 | } |
| 338 | } const command_names; |
| 339 | |
| 340 | auto const help_def = |
| 341 | help_::name > createCommandSuggestions >> -command_names; |
| 342 | |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 343 | auto const createCommandSuggestions_def = |
Václav Kubernát | bf083ec | 2019-02-19 13:58:09 +0100 | [diff] [blame] | 344 | x3::eps; |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 345 | |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 346 | auto const command_def = |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 347 | createCommandSuggestions >> x3::expect[cd | create | delete_rule | set | commit | get | ls | discard | help]; |
Václav Kubernát | 4137845 | 2018-06-06 16:29:40 +0200 | [diff] [blame] | 348 | |
| 349 | #if __clang__ |
| 350 | #pragma GCC diagnostic pop |
| 351 | #endif |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 352 | |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 353 | BOOST_SPIRIT_DEFINE(keyValue) |
Václav Kubernát | 89728d8 | 2018-09-13 16:28:28 +0200 | [diff] [blame] | 354 | BOOST_SPIRIT_DEFINE(key_identifier) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 355 | BOOST_SPIRIT_DEFINE(node_identifier) |
| 356 | BOOST_SPIRIT_DEFINE(module_identifier) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 357 | BOOST_SPIRIT_DEFINE(listPrefix) |
| 358 | BOOST_SPIRIT_DEFINE(listSuffix) |
| 359 | BOOST_SPIRIT_DEFINE(listElement) |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 360 | BOOST_SPIRIT_DEFINE(list) |
Václav Kubernát | 60d6f29 | 2018-05-25 09:45:32 +0200 | [diff] [blame] | 361 | BOOST_SPIRIT_DEFINE(nodeup) |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 362 | BOOST_SPIRIT_DEFINE(schemaNode) |
| 363 | BOOST_SPIRIT_DEFINE(dataNode) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 364 | BOOST_SPIRIT_DEFINE(container) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 365 | BOOST_SPIRIT_DEFINE(leaf) |
Václav Kubernát | 0b0272f | 2018-06-13 14:13:08 +0200 | [diff] [blame] | 366 | BOOST_SPIRIT_DEFINE(leafPath) |
Václav Kubernát | 6797df0 | 2019-03-18 20:21:50 +0100 | [diff] [blame] | 367 | BOOST_SPIRIT_DEFINE(presenceContainerPath) |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 368 | BOOST_SPIRIT_DEFINE(listInstancePath) |
Václav Kubernát | 8028f94 | 2019-09-25 16:03:23 +0200 | [diff] [blame^] | 369 | BOOST_SPIRIT_DEFINE(space_separator) |
Václav Kubernát | 2eaceb8 | 2018-10-08 19:56:30 +0200 | [diff] [blame] | 370 | BOOST_SPIRIT_DEFINE(schemaPath) |
| 371 | BOOST_SPIRIT_DEFINE(dataPath) |
Václav Kubernát | 5c75b25 | 2018-10-10 18:33:47 +0200 | [diff] [blame] | 372 | BOOST_SPIRIT_DEFINE(dataNodeList) |
| 373 | BOOST_SPIRIT_DEFINE(dataNodesListEnd) |
| 374 | BOOST_SPIRIT_DEFINE(dataPathListEnd) |
Václav Kubernát | 37171a1 | 2018-08-31 17:01:48 +0200 | [diff] [blame] | 375 | BOOST_SPIRIT_DEFINE(absoluteStart) |
Václav Kubernát | d6fd249 | 2018-11-19 15:11:16 +0100 | [diff] [blame] | 376 | BOOST_SPIRIT_DEFINE(trailingSlash) |
Václav Kubernát | 744f57f | 2018-06-29 22:46:26 +0200 | [diff] [blame] | 377 | BOOST_SPIRIT_DEFINE(module) |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 378 | BOOST_SPIRIT_DEFINE(leaf_data) |
| 379 | BOOST_SPIRIT_DEFINE(leaf_data_enum) |
| 380 | BOOST_SPIRIT_DEFINE(leaf_data_decimal) |
| 381 | BOOST_SPIRIT_DEFINE(leaf_data_bool) |
Ivona Oboňová | 88c78ca | 2019-07-02 18:40:07 +0200 | [diff] [blame] | 382 | BOOST_SPIRIT_DEFINE(leaf_data_int8) |
| 383 | BOOST_SPIRIT_DEFINE(leaf_data_int16) |
| 384 | BOOST_SPIRIT_DEFINE(leaf_data_int32) |
| 385 | BOOST_SPIRIT_DEFINE(leaf_data_int64) |
| 386 | BOOST_SPIRIT_DEFINE(leaf_data_uint8) |
| 387 | BOOST_SPIRIT_DEFINE(leaf_data_uint16) |
| 388 | BOOST_SPIRIT_DEFINE(leaf_data_uint32) |
| 389 | BOOST_SPIRIT_DEFINE(leaf_data_uint64) |
Václav Kubernát | ebca255 | 2018-06-08 19:06:02 +0200 | [diff] [blame] | 390 | BOOST_SPIRIT_DEFINE(leaf_data_string) |
Václav Kubernát | ab53899 | 2019-03-06 15:30:50 +0100 | [diff] [blame] | 391 | BOOST_SPIRIT_DEFINE(leaf_data_binary_data) |
| 392 | BOOST_SPIRIT_DEFINE(leaf_data_binary) |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 393 | BOOST_SPIRIT_DEFINE(leaf_data_identityRef_data) |
| 394 | BOOST_SPIRIT_DEFINE(leaf_data_identityRef) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 395 | BOOST_SPIRIT_DEFINE(initializePath) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 396 | BOOST_SPIRIT_DEFINE(set) |
Václav Kubernát | 812ee28 | 2018-08-30 17:10:03 +0200 | [diff] [blame] | 397 | BOOST_SPIRIT_DEFINE(commit) |
Václav Kubernát | b6ff0b6 | 2018-08-30 16:14:53 +0200 | [diff] [blame] | 398 | BOOST_SPIRIT_DEFINE(get) |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 399 | BOOST_SPIRIT_DEFINE(ls) |
Václav Kubernát | 6d79143 | 2018-10-25 16:00:35 +0200 | [diff] [blame] | 400 | BOOST_SPIRIT_DEFINE(discard) |
Václav Kubernát | 0a2a2e8 | 2018-05-11 13:59:12 +0200 | [diff] [blame] | 401 | BOOST_SPIRIT_DEFINE(cd) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 402 | BOOST_SPIRIT_DEFINE(create) |
| 403 | BOOST_SPIRIT_DEFINE(delete_rule) |
Václav Kubernát | 054cc99 | 2019-02-21 14:23:52 +0100 | [diff] [blame] | 404 | BOOST_SPIRIT_DEFINE(help) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 405 | BOOST_SPIRIT_DEFINE(command) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 406 | BOOST_SPIRIT_DEFINE(createPathSuggestions) |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 407 | BOOST_SPIRIT_DEFINE(createKeySuggestions) |
Václav Kubernát | 4c32548 | 2019-04-11 17:51:55 +0200 | [diff] [blame] | 408 | BOOST_SPIRIT_DEFINE(suggestKeysStart) |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 409 | BOOST_SPIRIT_DEFINE(suggestKeysEnd) |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 410 | BOOST_SPIRIT_DEFINE(createCommandSuggestions) |
Václav Kubernát | ac035d6 | 2019-02-18 10:59:08 +0100 | [diff] [blame] | 411 | BOOST_SPIRIT_DEFINE(completing) |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 412 | BOOST_SPIRIT_DEFINE(createEnumSuggestions) |
Václav Kubernát | eeb3884 | 2019-03-20 19:46:05 +0100 | [diff] [blame] | 413 | BOOST_SPIRIT_DEFINE(createIdentitySuggestions) |