Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Václav Kubernát <kubernat@cesnet.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #pragma once |
| 9 | |
| 10 | #include <boost/spirit/home/x3.hpp> |
| 11 | #include "ast_handlers.hpp" |
| 12 | #include "common_parsers.hpp" |
| 13 | #include "leaf_data.hpp" |
| 14 | |
| 15 | namespace x3 = boost::spirit::x3; |
| 16 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 17 | x3::rule<writable_leaf_path_class, dataPath_> const writableLeafPath = "writableLeafPath"; |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 18 | x3::rule<presenceContainerPath_class, dataPath_> const presenceContainerPath = "presenceContainerPath"; |
| 19 | x3::rule<listInstancePath_class, dataPath_> const listInstancePath = "listInstancePath"; |
| 20 | x3::rule<initializePath_class, x3::unused_type> const initializePath = "initializePath"; |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 21 | x3::rule<trailingSlash_class, TrailingSlash> const trailingSlash = "trailingSlash"; |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 22 | x3::rule<absoluteStart_class, Scope> const absoluteStart = "absoluteStart"; |
| 23 | x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue"; |
| 24 | x3::rule<key_identifier_class, std::string> const key_identifier = "key_identifier"; |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 25 | x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix"; |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 26 | x3::rule<createKeySuggestions_class, x3::unused_type> const createKeySuggestions = "createKeySuggestions"; |
| 27 | x3::rule<createValueSuggestions_class, x3::unused_type> const createValueSuggestions = "createValueSuggestions"; |
| 28 | x3::rule<suggestKeysEnd_class, x3::unused_type> const suggestKeysEnd = "suggestKeysEnd"; |
| 29 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 30 | enum class NodeParserMode { |
| 31 | CompleteDataNode, |
| 32 | IncompleteDataNode, |
| 33 | CompletionsOnly, |
| 34 | SchemaNode |
| 35 | }; |
| 36 | |
| 37 | template <auto> |
| 38 | struct ModeToAttribute; |
| 39 | template <> |
| 40 | struct ModeToAttribute<NodeParserMode::CompleteDataNode> { |
| 41 | using type = dataNode_; |
| 42 | }; |
| 43 | template <> |
| 44 | struct ModeToAttribute<NodeParserMode::IncompleteDataNode> { |
| 45 | using type = dataNode_; |
| 46 | }; |
| 47 | template <> |
| 48 | struct ModeToAttribute<NodeParserMode::SchemaNode> { |
| 49 | using type = schemaNode_; |
| 50 | }; |
| 51 | // The CompletionsOnly attribute is dataNode_ only because of convenience: |
| 52 | // having the same return type means we can get by without a ton of `if constexpr` stanzas. |
| 53 | // So the code will still "parse data into the target attr" for simplicity. |
| 54 | template <> |
| 55 | struct ModeToAttribute<NodeParserMode::CompletionsOnly> { |
| 56 | using type = dataNode_; |
| 57 | }; |
| 58 | |
| 59 | template <NodeParserMode PARSER_MODE> |
| 60 | struct NodeParser : x3::parser<NodeParser<PARSER_MODE>> { |
| 61 | using attribute_type = typename ModeToAttribute<PARSER_MODE>::type; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 62 | |
| 63 | std::function<bool(const Schema&, const std::string& path)> m_filterFunction; |
| 64 | |
| 65 | NodeParser(const std::function<bool(const Schema&, const std::string& path)>& filterFunction) |
| 66 | : m_filterFunction(filterFunction) |
| 67 | { |
| 68 | } |
| 69 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 70 | // GCC complains that `end` isn't used when doing completions only |
| 71 | // FIXME: GCC 10.1 doesn't emit a warning here. Remove [[maybe_unused]] when GCC 10 is available |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 72 | template <typename It, typename Ctx, typename RCtx, typename Attr> |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 73 | bool parse(It& begin, [[maybe_unused]] It end, Ctx const& ctx, RCtx& rctx, Attr& attr) const |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 74 | { |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 75 | std::string tableName; |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 76 | if constexpr (std::is_same<attribute_type, schemaNode_>()) { |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 77 | tableName = "schemaNode"; |
| 78 | } else { |
| 79 | tableName = "dataNode"; |
| 80 | } |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 81 | x3::symbols<attribute_type> table(tableName); |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 82 | |
| 83 | ParserContext& parserContext = x3::get<parser_context_tag>(ctx); |
| 84 | parserContext.m_suggestions.clear(); |
| 85 | for (const auto& child : parserContext.m_schema.availableNodes(parserContext.currentSchemaPath(), Recursion::NonRecursive)) { |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 86 | attribute_type out; |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 87 | std::string parseString; |
| 88 | if (child.first) { |
| 89 | out.m_prefix = module_{*child.first}; |
| 90 | parseString = *child.first + ":"; |
| 91 | } |
| 92 | parseString += child.second; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 93 | |
| 94 | if (!m_filterFunction(parserContext.m_schema, joinPaths(pathToSchemaString(parserContext.currentSchemaPath(), Prefixes::Always), parseString))) { |
| 95 | continue; |
| 96 | } |
| 97 | |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 98 | switch (parserContext.m_schema.nodeType(parserContext.currentSchemaPath(), child)) { |
| 99 | case yang::NodeTypes::Container: |
| 100 | case yang::NodeTypes::PresenceContainer: |
| 101 | out.m_suffix = container_{child.second}; |
| 102 | parserContext.m_suggestions.emplace(Completion{parseString + "/"}); |
| 103 | break; |
| 104 | case yang::NodeTypes::Leaf: |
| 105 | out.m_suffix = leaf_{child.second}; |
| 106 | parserContext.m_suggestions.emplace(Completion{parseString + " "}); |
| 107 | break; |
| 108 | case yang::NodeTypes::List: |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 109 | if constexpr (std::is_same<attribute_type, schemaNode_>()) { |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 110 | out.m_suffix = list_{child.second}; |
| 111 | } else { |
| 112 | out.m_suffix = listElement_{child.second, {}}; |
| 113 | } |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 114 | parserContext.m_suggestions.emplace(Completion{parseString, "[", Completion::WhenToAdd::IfFullMatch}); |
| 115 | break; |
| 116 | case yang::NodeTypes::Action: |
| 117 | case yang::NodeTypes::AnyXml: |
| 118 | case yang::NodeTypes::LeafList: |
| 119 | case yang::NodeTypes::Notification: |
| 120 | case yang::NodeTypes::Rpc: |
| 121 | continue; |
| 122 | } |
| 123 | table.add(parseString, out); |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 124 | table.add("..", attribute_type{nodeup_{}}); |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 125 | if (!child.first) { |
| 126 | auto topLevelModule = parserContext.currentSchemaPath().m_nodes.begin()->m_prefix; |
| 127 | out.m_prefix = topLevelModule; |
| 128 | table.add(topLevelModule->m_name + ":" + parseString, out); |
| 129 | } |
| 130 | } |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 131 | parserContext.m_completionIterator = begin; |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 132 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 133 | if constexpr (PARSER_MODE == NodeParserMode::CompletionsOnly) { |
| 134 | return true; |
| 135 | } else { |
| 136 | It saveIter; |
| 137 | // GCC complains that I assign saveIter because I use it only if NodeType is dataNode_ |
| 138 | // FIXME: GCC 10.1 doesn't emit a warning here. Make this unconditional when GCC 10 is available. |
| 139 | if constexpr (std::is_same<attribute_type, dataNode_>()) { |
| 140 | saveIter = begin; |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 141 | } |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 142 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 143 | auto res = table.parse(begin, end, ctx, rctx, attr); |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 144 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 145 | if (attr.m_prefix) { |
| 146 | parserContext.m_curModule = attr.m_prefix->m_name; |
| 147 | } |
| 148 | |
| 149 | if (attr.m_suffix.type() == typeid(leaf_)) { |
| 150 | parserContext.m_tmpListKeyLeafPath.m_location = parserContext.currentSchemaPath(); |
| 151 | ModuleNodePair node{attr.m_prefix.flat_map([](const auto& it) { |
| 152 | return boost::optional<std::string>{it.m_name}; |
| 153 | }), |
| 154 | boost::get<leaf_>(attr.m_suffix).m_name}; |
| 155 | parserContext.m_tmpListKeyLeafPath.m_node = node; |
| 156 | } |
| 157 | |
| 158 | if constexpr (std::is_same<attribute_type, dataNode_>()) { |
| 159 | if (attr.m_suffix.type() == typeid(listElement_)) { |
| 160 | parserContext.m_tmpListName = boost::get<listElement_>(attr.m_suffix).m_name; |
| 161 | res = listSuffix.parse(begin, end, ctx, rctx, boost::get<listElement_>(attr.m_suffix).m_keys); |
| 162 | |
| 163 | // FIXME: think of a better way to do this, that is, get rid of manual iterator reverting |
| 164 | if (!res) { |
| 165 | // If listSuffix didn't succeed, we check, if we allow incomplete nodes. If we do, then we replace listElement_ with list_. |
| 166 | // If we don't, we fail the whole symbol table. |
| 167 | if constexpr (PARSER_MODE == NodeParserMode::IncompleteDataNode) { |
| 168 | res = true; |
| 169 | attr.m_suffix = list_{boost::get<listElement_>(attr.m_suffix).m_name}; |
| 170 | } else { |
| 171 | begin = saveIter; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (res) { |
| 178 | parserContext.pushPathFragment(attr); |
| 179 | parserContext.m_topLevelModulePresent = true; |
| 180 | } |
| 181 | |
| 182 | if (attr.m_prefix) { |
| 183 | parserContext.m_curModule = boost::none; |
| 184 | } |
| 185 | return res; |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 186 | } |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 187 | } |
Václav Kubernát | dd5945a | 2020-05-05 01:24:23 +0200 | [diff] [blame] | 188 | }; |
| 189 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 190 | using schemaNode = NodeParser<NodeParserMode::SchemaNode>; |
| 191 | using dataNode = NodeParser<NodeParserMode::CompleteDataNode>; |
| 192 | using dataNodeAllowList = NodeParser<NodeParserMode::IncompleteDataNode>; |
| 193 | using pathCompletions = NodeParser<NodeParserMode::CompletionsOnly>; |
Václav Kubernát | 60a0ed5 | 2020-04-28 15:21:33 +0200 | [diff] [blame] | 194 | |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 195 | using AnyPath = boost::variant<schemaPath_, dataPath_>; |
| 196 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 197 | enum class PathParserMode { |
| 198 | AnyPath, |
| 199 | DataPath, |
| 200 | DataPathListEnd |
| 201 | }; |
| 202 | |
| 203 | template <> |
| 204 | struct ModeToAttribute<PathParserMode::AnyPath> { |
| 205 | using type = AnyPath; |
| 206 | }; |
| 207 | |
| 208 | template <> |
| 209 | struct ModeToAttribute<PathParserMode::DataPath> { |
| 210 | using type = dataPath_; |
| 211 | }; |
| 212 | |
| 213 | template <> |
| 214 | struct ModeToAttribute<PathParserMode::DataPathListEnd> { |
| 215 | using type = dataPath_; |
| 216 | }; |
| 217 | |
| 218 | template <PathParserMode PARSER_MODE> |
| 219 | struct PathParser : x3::parser<PathParser<PARSER_MODE>> { |
| 220 | using attribute_type = ModeToAttribute<PARSER_MODE>; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 221 | std::function<bool(const Schema&, const std::string& path)> m_filterFunction; |
| 222 | |
| 223 | PathParser(const std::function<bool(const Schema&, const std::string& path)>& filterFunction = [] (const auto&, const auto&) {return true;}) |
| 224 | : m_filterFunction(filterFunction) |
| 225 | { |
| 226 | } |
| 227 | |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 228 | template <typename It, typename Ctx, typename RCtx, typename Attr> |
| 229 | bool parse(It& begin, It end, Ctx const& ctx, RCtx& rctx, Attr& attr) const |
| 230 | { |
Václav Kubernát | 74d35a4 | 2020-05-15 15:29:16 +0200 | [diff] [blame] | 231 | initializePath.parse(begin, end, ctx, rctx, x3::unused); |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 232 | dataPath_ attrData; |
| 233 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 234 | auto pathEnd = x3::rule<class PathEnd>{"pathEnd"} = &space_separator | x3::eoi; |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 235 | // absoluteStart has to be separate from the dataPath parser, |
| 236 | // otherwise, if the "dataNode % '/'" parser fails, the begin iterator |
| 237 | // gets reverted to before the starting slash. |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 238 | auto res = (-absoluteStart).parse(begin, end, ctx, rctx, attrData.m_scope); |
| 239 | auto dataPath = x3::attr(attrData.m_scope) |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 240 | >> (dataNode{m_filterFunction} % '/' | pathEnd >> x3::attr(std::vector<dataNode_>{})) |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 241 | >> -trailingSlash; |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 242 | res = dataPath.parse(begin, end, ctx, rctx, attrData); |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 243 | |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 244 | // If we allow data paths with a list at the end, we just try to parse that separately. |
| 245 | if constexpr (PARSER_MODE == PathParserMode::DataPathListEnd || PARSER_MODE == PathParserMode::AnyPath) { |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 246 | if (!res || !pathEnd.parse(begin, end, ctx, rctx, x3::unused)) { |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 247 | dataNode_ attrNodeList; |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 248 | res = dataNodeAllowList{m_filterFunction}.parse(begin, end, ctx, rctx, attrNodeList); |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 249 | if (res) { |
| 250 | attrData.m_nodes.push_back(attrNodeList); |
| 251 | // If the trailing slash matches, no more nodes are parsed. |
| 252 | // That means no more completion. So, I generate them |
| 253 | // manually. |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 254 | res = (-(trailingSlash >> x3::omit[pathCompletions{m_filterFunction}])).parse(begin, end, ctx, rctx, attrData.m_trailingSlash); |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | attr = attrData; |
| 260 | if constexpr (PARSER_MODE == PathParserMode::AnyPath) { |
| 261 | // If our data path already has some listElement_ fragments, we can't parse rest of the path as a schema path |
| 262 | auto hasLists = std::any_of(attrData.m_nodes.begin(), attrData.m_nodes.end(), |
| 263 | [] (const auto& node) { return node.m_suffix.type() == typeid(listElement_); }); |
| 264 | // If parsing failed, or if there's more input we try parsing schema nodes. |
| 265 | if (!hasLists) { |
| 266 | if (!res || !pathEnd.parse(begin, end, ctx, rctx, x3::unused)) { |
| 267 | // If dataPath parsed some nodes, they will be saved in `attrData`. We have to keep these. |
| 268 | schemaPath_ attrSchema = dataPathToSchemaPath(attrData); |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 269 | auto schemaPath = schemaNode{m_filterFunction} % '/'; |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 270 | // The schemaPath parser continues where the dataPath parser ended. |
| 271 | res = schemaPath.parse(begin, end, ctx, rctx, attrSchema.m_nodes); |
| 272 | auto trailing = -trailingSlash >> pathEnd; |
| 273 | res = trailing.parse(begin, end, ctx, rctx, attrSchema.m_trailingSlash); |
| 274 | attr = attrSchema; |
| 275 | } |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | return res; |
| 279 | } |
Václav Kubernát | 74d35a4 | 2020-05-15 15:29:16 +0200 | [diff] [blame] | 280 | }; |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 281 | |
| 282 | // Need to use these wrappers so that my PathParser class gets the proper |
| 283 | // attribute. Otherwise, Spirit injects the attribute of the outer parser that |
| 284 | // uses my PathParser. |
| 285 | // Example grammar: anyPath | module. |
| 286 | // The PathParser class would get a boost::variant as the attribute, but I |
| 287 | // don't want to deal with that, so I use these wrappers to ensure the |
Václav Kubernát | 74d35a4 | 2020-05-15 15:29:16 +0200 | [diff] [blame] | 288 | // attribute I want (and let Spirit deal with boost::variant). |
Václav Kubernát | 4a58ce6 | 2020-05-14 17:58:10 +0200 | [diff] [blame] | 289 | auto const anyPath = x3::rule<class anyPath_class, AnyPath>{"anyPath"} = PathParser<PathParserMode::AnyPath>{}; |
| 290 | auto const dataPath = x3::rule<class dataPath_class, dataPath_>{"dataPath"} = PathParser<PathParserMode::DataPath>{}; |
| 291 | auto const dataPathListEnd = x3::rule<class dataPath_class, dataPath_>{"dataPath"} = PathParser<PathParserMode::DataPathListEnd>{}; |
Václav Kubernát | 4618fa4 | 2020-05-07 01:33:19 +0200 | [diff] [blame] | 292 | |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 293 | #if __clang__ |
| 294 | #pragma GCC diagnostic push |
| 295 | #pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses" |
| 296 | #endif |
| 297 | |
| 298 | auto const rest = |
| 299 | x3::omit[x3::no_skip[+(x3::char_ - '/' - space_separator)]]; |
| 300 | |
| 301 | auto const key_identifier_def = |
| 302 | x3::lexeme[ |
| 303 | ((x3::alpha | char_("_")) >> *(x3::alnum | char_("_") | char_("-") | char_("."))) |
| 304 | ]; |
| 305 | |
| 306 | auto const createKeySuggestions_def = |
| 307 | x3::eps; |
| 308 | |
| 309 | auto const createValueSuggestions_def = |
| 310 | x3::eps; |
| 311 | |
| 312 | auto const suggestKeysEnd_def = |
| 313 | x3::eps; |
| 314 | |
| 315 | auto const keyValue_def = |
| 316 | key_identifier > '=' > createValueSuggestions > leaf_data; |
| 317 | |
| 318 | auto const keyValueWrapper = |
| 319 | x3::lexeme['[' > createKeySuggestions > keyValue > suggestKeysEnd > ']']; |
| 320 | |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 321 | // even though we don't allow no keys to be supplied, the star allows me to check which keys are missing |
| 322 | auto const listSuffix_def = |
| 323 | *keyValueWrapper; |
| 324 | |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 325 | auto const list_def = |
| 326 | node_identifier >> !char_('['); |
| 327 | |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 328 | auto const absoluteStart_def = |
| 329 | x3::omit['/'] >> x3::attr(Scope::Absolute); |
| 330 | |
| 331 | auto const trailingSlash_def = |
| 332 | x3::omit['/'] >> x3::attr(TrailingSlash::Present); |
| 333 | |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 334 | auto const filterConfigFalse = [] (const Schema& schema, const std::string& path) { |
| 335 | return schema.isConfig(path); |
| 336 | }; |
| 337 | |
| 338 | auto const writableLeafPath_def = |
| 339 | PathParser<PathParserMode::DataPath>{filterConfigFalse}; |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 340 | |
| 341 | auto const presenceContainerPath_def = |
| 342 | dataPath; |
| 343 | |
| 344 | auto const listInstancePath_def = |
| 345 | dataPath; |
| 346 | |
| 347 | // A "nothing" parser, which is used to indicate we tried to parse a path |
| 348 | auto const initializePath_def = |
| 349 | x3::eps; |
| 350 | |
| 351 | |
| 352 | |
| 353 | #if __clang__ |
| 354 | #pragma GCC diagnostic pop |
| 355 | #endif |
| 356 | |
| 357 | BOOST_SPIRIT_DEFINE(keyValue) |
| 358 | BOOST_SPIRIT_DEFINE(key_identifier) |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 359 | BOOST_SPIRIT_DEFINE(listSuffix) |
Václav Kubernát | abf5280 | 2020-05-19 01:31:17 +0200 | [diff] [blame] | 360 | BOOST_SPIRIT_DEFINE(writableLeafPath) |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 361 | BOOST_SPIRIT_DEFINE(presenceContainerPath) |
| 362 | BOOST_SPIRIT_DEFINE(listInstancePath) |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 363 | BOOST_SPIRIT_DEFINE(initializePath) |
| 364 | BOOST_SPIRIT_DEFINE(createKeySuggestions) |
Václav Kubernát | d0ea9b2 | 2020-04-24 00:44:15 +0200 | [diff] [blame] | 365 | BOOST_SPIRIT_DEFINE(createValueSuggestions) |
| 366 | BOOST_SPIRIT_DEFINE(suggestKeysEnd) |
| 367 | BOOST_SPIRIT_DEFINE(absoluteStart) |
| 368 | BOOST_SPIRIT_DEFINE(trailingSlash) |