blob: c89b9dfee24e3f7bac0419a52160020dfdc8035d [file] [log] [blame]
Václav Kubernátd0ea9b22020-04-24 00:44:15 +02001/*
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
15namespace x3 = boost::spirit::x3;
16
Václav Kubernátabf52802020-05-19 01:31:17 +020017x3::rule<writable_leaf_path_class, dataPath_> const writableLeafPath = "writableLeafPath";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020018x3::rule<presenceContainerPath_class, dataPath_> const presenceContainerPath = "presenceContainerPath";
19x3::rule<listInstancePath_class, dataPath_> const listInstancePath = "listInstancePath";
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020020x3::rule<leafListElementPath_class, dataPath_> const leafListElementPath = "leafListElementPath";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020021x3::rule<initializePath_class, x3::unused_type> const initializePath = "initializePath";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020022x3::rule<trailingSlash_class, TrailingSlash> const trailingSlash = "trailingSlash";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020023x3::rule<absoluteStart_class, Scope> const absoluteStart = "absoluteStart";
24x3::rule<keyValue_class, keyValue_> const keyValue = "keyValue";
25x3::rule<key_identifier_class, std::string> const key_identifier = "key_identifier";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020026x3::rule<listSuffix_class, std::vector<keyValue_>> const listSuffix = "listSuffix";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020027x3::rule<createKeySuggestions_class, x3::unused_type> const createKeySuggestions = "createKeySuggestions";
28x3::rule<createValueSuggestions_class, x3::unused_type> const createValueSuggestions = "createValueSuggestions";
29x3::rule<suggestKeysEnd_class, x3::unused_type> const suggestKeysEnd = "suggestKeysEnd";
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020030x3::rule<class leafListValue_class, leaf_data_> const leafListValue = "leafListValue";
Václav Kubernátd0ea9b22020-04-24 00:44:15 +020031
Václav Kubernát4a58ce62020-05-14 17:58:10 +020032enum class NodeParserMode {
33 CompleteDataNode,
34 IncompleteDataNode,
35 CompletionsOnly,
36 SchemaNode
37};
38
39template <auto>
40struct ModeToAttribute;
41template <>
42struct ModeToAttribute<NodeParserMode::CompleteDataNode> {
43 using type = dataNode_;
44};
45template <>
46struct ModeToAttribute<NodeParserMode::IncompleteDataNode> {
47 using type = dataNode_;
48};
49template <>
50struct ModeToAttribute<NodeParserMode::SchemaNode> {
51 using type = schemaNode_;
52};
53// The CompletionsOnly attribute is dataNode_ only because of convenience:
54// having the same return type means we can get by without a ton of `if constexpr` stanzas.
55// So the code will still "parse data into the target attr" for simplicity.
56template <>
57struct ModeToAttribute<NodeParserMode::CompletionsOnly> {
58 using type = dataNode_;
59};
60
Václav Kubernát743d9eb2020-05-18 13:42:36 +020061enum class CompletionMode {
62 Schema,
63 Data
64};
Václav Kubernát5b8a8f32020-05-20 00:57:22 +020065
Václav Kubernát743d9eb2020-05-18 13:42:36 +020066template <NodeParserMode PARSER_MODE, CompletionMode COMPLETION_MODE>
67struct NodeParser : x3::parser<NodeParser<PARSER_MODE, COMPLETION_MODE>> {
Václav Kubernát4a58ce62020-05-14 17:58:10 +020068 using attribute_type = typename ModeToAttribute<PARSER_MODE>::type;
Václav Kubernátabf52802020-05-19 01:31:17 +020069
70 std::function<bool(const Schema&, const std::string& path)> m_filterFunction;
71
72 NodeParser(const std::function<bool(const Schema&, const std::string& path)>& filterFunction)
73 : m_filterFunction(filterFunction)
74 {
75 }
76
Václav Kubernát4a58ce62020-05-14 17:58:10 +020077 // GCC complains that `end` isn't used when doing completions only
78 // FIXME: GCC 10.1 doesn't emit a warning here. Remove [[maybe_unused]] when GCC 10 is available
Václav Kubernát60a0ed52020-04-28 15:21:33 +020079 template <typename It, typename Ctx, typename RCtx, typename Attr>
Václav Kubernát4a58ce62020-05-14 17:58:10 +020080 bool parse(It& begin, [[maybe_unused]] It end, Ctx const& ctx, RCtx& rctx, Attr& attr) const
Václav Kubernát60a0ed52020-04-28 15:21:33 +020081 {
Václav Kubernátdd5945a2020-05-05 01:24:23 +020082 std::string tableName;
Václav Kubernát4a58ce62020-05-14 17:58:10 +020083 if constexpr (std::is_same<attribute_type, schemaNode_>()) {
Václav Kubernátdd5945a2020-05-05 01:24:23 +020084 tableName = "schemaNode";
85 } else {
86 tableName = "dataNode";
87 }
Václav Kubernát4a58ce62020-05-14 17:58:10 +020088 x3::symbols<attribute_type> table(tableName);
Václav Kubernát60a0ed52020-04-28 15:21:33 +020089
90 ParserContext& parserContext = x3::get<parser_context_tag>(ctx);
91 parserContext.m_suggestions.clear();
92 for (const auto& child : parserContext.m_schema.availableNodes(parserContext.currentSchemaPath(), Recursion::NonRecursive)) {
Václav Kubernát4a58ce62020-05-14 17:58:10 +020093 attribute_type out;
Václav Kubernát60a0ed52020-04-28 15:21:33 +020094 std::string parseString;
95 if (child.first) {
96 out.m_prefix = module_{*child.first};
97 parseString = *child.first + ":";
98 }
99 parseString += child.second;
Václav Kubernátabf52802020-05-19 01:31:17 +0200100
101 if (!m_filterFunction(parserContext.m_schema, joinPaths(pathToSchemaString(parserContext.currentSchemaPath(), Prefixes::Always), parseString))) {
102 continue;
103 }
104
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200105 switch (parserContext.m_schema.nodeType(parserContext.currentSchemaPath(), child)) {
106 case yang::NodeTypes::Container:
107 case yang::NodeTypes::PresenceContainer:
108 out.m_suffix = container_{child.second};
109 parserContext.m_suggestions.emplace(Completion{parseString + "/"});
110 break;
111 case yang::NodeTypes::Leaf:
112 out.m_suffix = leaf_{child.second};
113 parserContext.m_suggestions.emplace(Completion{parseString + " "});
114 break;
115 case yang::NodeTypes::List:
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200116 if constexpr (std::is_same<attribute_type, schemaNode_>()) {
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200117 out.m_suffix = list_{child.second};
118 } else {
119 out.m_suffix = listElement_{child.second, {}};
120 }
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200121
122 if constexpr (COMPLETION_MODE == CompletionMode::Schema) {
123 parserContext.m_suggestions.emplace(Completion{parseString + "/"});
124 } else {
125 parserContext.m_suggestions.emplace(Completion{parseString, "[", Completion::WhenToAdd::IfFullMatch});
126 }
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200127 break;
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200128 case yang::NodeTypes::LeafList:
129 if constexpr (std::is_same<attribute_type, schemaNode_>()) {
130 out.m_suffix = leafList_{child.second};
131 } else {
132 out.m_suffix = leafListElement_{child.second, {}};
133 }
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200134
135 if constexpr (COMPLETION_MODE == CompletionMode::Schema) {
136 parserContext.m_suggestions.emplace(Completion{parseString + "/"});
137 } else {
138 parserContext.m_suggestions.emplace(Completion{parseString, "[", Completion::WhenToAdd::IfFullMatch});
139 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200140 break;
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200141 case yang::NodeTypes::Action:
142 case yang::NodeTypes::AnyXml:
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200143 case yang::NodeTypes::Notification:
144 case yang::NodeTypes::Rpc:
145 continue;
146 }
147 table.add(parseString, out);
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200148 if (!child.first) {
149 auto topLevelModule = parserContext.currentSchemaPath().m_nodes.begin()->m_prefix;
150 out.m_prefix = topLevelModule;
151 table.add(topLevelModule->m_name + ":" + parseString, out);
152 }
153 }
Václav Kubernátaed4bc72020-06-08 01:09:25 +0200154 table.add("..", attribute_type{nodeup_{}});
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200155 parserContext.m_completionIterator = begin;
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200156
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200157 if constexpr (PARSER_MODE == NodeParserMode::CompletionsOnly) {
158 return true;
159 } else {
160 It saveIter;
161 // GCC complains that I assign saveIter because I use it only if NodeType is dataNode_
162 // FIXME: GCC 10.1 doesn't emit a warning here. Make this unconditional when GCC 10 is available.
163 if constexpr (std::is_same<attribute_type, dataNode_>()) {
164 saveIter = begin;
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200165 }
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200166
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200167 auto res = table.parse(begin, end, ctx, rctx, attr);
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200168
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200169 if (std::holds_alternative<leaf_>(attr.m_suffix)) {
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200170 parserContext.m_tmpListKeyLeafPath.m_location = parserContext.currentSchemaPath();
171 ModuleNodePair node{attr.m_prefix.flat_map([](const auto& it) {
172 return boost::optional<std::string>{it.m_name};
173 }),
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200174 std::get<leaf_>(attr.m_suffix).m_name};
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200175 parserContext.m_tmpListKeyLeafPath.m_node = node;
176 }
177
178 if constexpr (std::is_same<attribute_type, dataNode_>()) {
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200179 if (std::holds_alternative<listElement_>(attr.m_suffix)) {
Václav Kubernát2db124c2020-05-28 21:58:36 +0200180 parserContext.m_tmpListPath = parserContext.currentDataPath();
181 auto tmpList = list_{std::get<listElement_>(attr.m_suffix).m_name};
182 parserContext.m_tmpListPath.m_nodes.push_back(dataNode_{attr.m_prefix, tmpList});
183
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200184 res = listSuffix.parse(begin, end, ctx, rctx, std::get<listElement_>(attr.m_suffix).m_keys);
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200185
186 // FIXME: think of a better way to do this, that is, get rid of manual iterator reverting
187 if (!res) {
188 // If listSuffix didn't succeed, we check, if we allow incomplete nodes. If we do, then we replace listElement_ with list_.
189 // If we don't, we fail the whole symbol table.
190 if constexpr (PARSER_MODE == NodeParserMode::IncompleteDataNode) {
191 res = true;
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200192 attr.m_suffix = list_{std::get<listElement_>(attr.m_suffix).m_name};
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200193 } else {
194 begin = saveIter;
195 }
196 }
197 }
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200198
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200199 if (std::holds_alternative<leafListElement_>(attr.m_suffix)) {
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200200 parserContext.m_tmpListKeyLeafPath.m_location = parserContext.currentSchemaPath();
201 ModuleNodePair node{attr.m_prefix.flat_map([](const auto& it) {
202 return boost::optional<std::string>{it.m_name};
203 }),
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200204 std::get<leafListElement_>(attr.m_suffix).m_name};
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200205 parserContext.m_tmpListKeyLeafPath.m_node = node;
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200206 res = leafListValue.parse(begin, end, ctx, rctx, std::get<leafListElement_>(attr.m_suffix).m_value);
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200207
208 if (!res) {
209 if constexpr (PARSER_MODE == NodeParserMode::IncompleteDataNode) {
210 res = true;
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200211 attr.m_suffix = leafList_{std::get<leafListElement_>(attr.m_suffix).m_name};
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200212 } else {
213 begin = saveIter;
214 }
215 }
216 }
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200217 }
218
219 if (res) {
220 parserContext.pushPathFragment(attr);
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200221 }
222
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200223 return res;
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200224 }
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200225 }
Václav Kubernátdd5945a2020-05-05 01:24:23 +0200226};
227
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200228template <CompletionMode COMPLETION_MODE> using schemaNode = NodeParser<NodeParserMode::SchemaNode, COMPLETION_MODE>;
229template <CompletionMode COMPLETION_MODE> using dataNode = NodeParser<NodeParserMode::CompleteDataNode, COMPLETION_MODE>;
230template <CompletionMode COMPLETION_MODE> using incompleteDataNode = NodeParser<NodeParserMode::IncompleteDataNode, COMPLETION_MODE>;
231template <CompletionMode COMPLETION_MODE> using pathCompletions = NodeParser<NodeParserMode::CompletionsOnly, COMPLETION_MODE>;
Václav Kubernát60a0ed52020-04-28 15:21:33 +0200232
Václav Kubernát4618fa42020-05-07 01:33:19 +0200233using AnyPath = boost::variant<schemaPath_, dataPath_>;
234
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200235enum class PathParserMode {
236 AnyPath,
237 DataPath,
238 DataPathListEnd
239};
240
241template <>
242struct ModeToAttribute<PathParserMode::AnyPath> {
243 using type = AnyPath;
244};
245
246template <>
247struct ModeToAttribute<PathParserMode::DataPath> {
248 using type = dataPath_;
249};
250
251template <>
252struct ModeToAttribute<PathParserMode::DataPathListEnd> {
253 using type = dataPath_;
254};
255
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200256template <PathParserMode PARSER_MODE, CompletionMode COMPLETION_MODE>
257struct PathParser : x3::parser<PathParser<PARSER_MODE, COMPLETION_MODE>> {
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200258 using attribute_type = ModeToAttribute<PARSER_MODE>;
Václav Kubernátabf52802020-05-19 01:31:17 +0200259 std::function<bool(const Schema&, const std::string& path)> m_filterFunction;
260
261 PathParser(const std::function<bool(const Schema&, const std::string& path)>& filterFunction = [] (const auto&, const auto&) {return true;})
262 : m_filterFunction(filterFunction)
263 {
264 }
265
Václav Kubernát4618fa42020-05-07 01:33:19 +0200266 template <typename It, typename Ctx, typename RCtx, typename Attr>
267 bool parse(It& begin, It end, Ctx const& ctx, RCtx& rctx, Attr& attr) const
268 {
Václav Kubernát74d35a42020-05-15 15:29:16 +0200269 initializePath.parse(begin, end, ctx, rctx, x3::unused);
Václav Kubernát4618fa42020-05-07 01:33:19 +0200270 dataPath_ attrData;
271
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200272 auto pathEnd = x3::rule<class PathEnd>{"pathEnd"} = &space_separator | x3::eoi;
Václav Kubernát4618fa42020-05-07 01:33:19 +0200273 // absoluteStart has to be separate from the dataPath parser,
274 // otherwise, if the "dataNode % '/'" parser fails, the begin iterator
275 // gets reverted to before the starting slash.
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200276 auto res = (-absoluteStart).parse(begin, end, ctx, rctx, attrData.m_scope);
277 auto dataPath = x3::attr(attrData.m_scope)
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200278 >> (dataNode<COMPLETION_MODE>{m_filterFunction} % '/' | pathEnd >> x3::attr(std::vector<dataNode_>{}))
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200279 >> -trailingSlash;
Václav Kubernát4618fa42020-05-07 01:33:19 +0200280 res = dataPath.parse(begin, end, ctx, rctx, attrData);
Václav Kubernát4618fa42020-05-07 01:33:19 +0200281
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200282 // If we allow data paths with a list at the end, we just try to parse that separately.
283 if constexpr (PARSER_MODE == PathParserMode::DataPathListEnd || PARSER_MODE == PathParserMode::AnyPath) {
Václav Kubernát4618fa42020-05-07 01:33:19 +0200284 if (!res || !pathEnd.parse(begin, end, ctx, rctx, x3::unused)) {
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200285 dataNode_ attrNodeList;
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200286 res = incompleteDataNode<COMPLETION_MODE>{m_filterFunction}.parse(begin, end, ctx, rctx, attrNodeList);
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200287 if (res) {
288 attrData.m_nodes.push_back(attrNodeList);
289 // If the trailing slash matches, no more nodes are parsed.
290 // That means no more completion. So, I generate them
291 // manually.
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200292 res = (-(trailingSlash >> x3::omit[pathCompletions<COMPLETION_MODE>{m_filterFunction}])).parse(begin, end, ctx, rctx, attrData.m_trailingSlash);
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200293 }
294 }
295 }
296
297 attr = attrData;
298 if constexpr (PARSER_MODE == PathParserMode::AnyPath) {
299 // If our data path already has some listElement_ fragments, we can't parse rest of the path as a schema path
300 auto hasLists = std::any_of(attrData.m_nodes.begin(), attrData.m_nodes.end(),
Václav Kubernátb5ca1542020-05-27 01:03:54 +0200301 [] (const auto& node) { return std::holds_alternative<listElement_>(node.m_suffix); });
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200302 // If parsing failed, or if there's more input we try parsing schema nodes.
303 if (!hasLists) {
304 if (!res || !pathEnd.parse(begin, end, ctx, rctx, x3::unused)) {
305 // If dataPath parsed some nodes, they will be saved in `attrData`. We have to keep these.
306 schemaPath_ attrSchema = dataPathToSchemaPath(attrData);
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200307 auto schemaPath = schemaNode<COMPLETION_MODE>{m_filterFunction} % '/';
Václav Kubernát4a58ce62020-05-14 17:58:10 +0200308 // The schemaPath parser continues where the dataPath parser ended.
309 res = schemaPath.parse(begin, end, ctx, rctx, attrSchema.m_nodes);
310 auto trailing = -trailingSlash >> pathEnd;
311 res = trailing.parse(begin, end, ctx, rctx, attrSchema.m_trailingSlash);
312 attr = attrSchema;
313 }
Václav Kubernát4618fa42020-05-07 01:33:19 +0200314 }
315 }
316 return res;
317 }
Václav Kubernát74d35a42020-05-15 15:29:16 +0200318};
Václav Kubernát4618fa42020-05-07 01:33:19 +0200319
320// Need to use these wrappers so that my PathParser class gets the proper
321// attribute. Otherwise, Spirit injects the attribute of the outer parser that
322// uses my PathParser.
323// Example grammar: anyPath | module.
324// The PathParser class would get a boost::variant as the attribute, but I
325// don't want to deal with that, so I use these wrappers to ensure the
Václav Kubernát74d35a42020-05-15 15:29:16 +0200326// attribute I want (and let Spirit deal with boost::variant).
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200327auto const anyPath = x3::rule<class anyPath_class, AnyPath>{"anyPath"} = PathParser<PathParserMode::AnyPath, CompletionMode::Schema>{};
328auto const dataPath = x3::rule<class dataPath_class, dataPath_>{"dataPath"} = PathParser<PathParserMode::DataPath, CompletionMode::Data>{};
329auto const dataPathListEnd = x3::rule<class dataPath_class, dataPath_>{"dataPath"} = PathParser<PathParserMode::DataPathListEnd, CompletionMode::Data>{};
Václav Kubernát4618fa42020-05-07 01:33:19 +0200330
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200331#if __clang__
332#pragma GCC diagnostic push
333#pragma GCC diagnostic ignored "-Woverloaded-shift-op-parentheses"
334#endif
335
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200336struct SuggestLeafListEnd : x3::parser<SuggestLeafListEnd> {
337 using attribute_type = x3::unused_type;
338 template <typename It, typename Ctx, typename RCtx, typename Attr>
339 bool parse(It& begin, It, Ctx const& ctx, RCtx&, Attr&) const
340 {
341 auto& parserContext = x3::get<parser_context_tag>(ctx);
342 parserContext.m_completionIterator = begin;
343 parserContext.m_suggestions = {Completion{"]"}};
344
345 return true;
346 }
347} const suggestLeafListEnd;
348
349auto const leafListValue_def =
350 '[' >> leaf_data >> suggestLeafListEnd >> ']';
351
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200352auto const rest =
353 x3::omit[x3::no_skip[+(x3::char_ - '/' - space_separator)]];
354
355auto const key_identifier_def =
356 x3::lexeme[
357 ((x3::alpha | char_("_")) >> *(x3::alnum | char_("_") | char_("-") | char_(".")))
358 ];
359
360auto const createKeySuggestions_def =
361 x3::eps;
362
363auto const createValueSuggestions_def =
364 x3::eps;
365
366auto const suggestKeysEnd_def =
367 x3::eps;
368
369auto const keyValue_def =
370 key_identifier > '=' > createValueSuggestions > leaf_data;
371
372auto const keyValueWrapper =
Václav Kubernát9fa5dca2020-06-01 03:56:41 +0200373 x3::no_skip['[' > createKeySuggestions > keyValue > suggestKeysEnd > ']'];
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200374
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200375// even though we don't allow no keys to be supplied, the star allows me to check which keys are missing
376auto const listSuffix_def =
377 *keyValueWrapper;
378
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200379auto const list_def =
380 node_identifier >> !char_('[');
381
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200382auto const absoluteStart_def =
383 x3::omit['/'] >> x3::attr(Scope::Absolute);
384
385auto const trailingSlash_def =
386 x3::omit['/'] >> x3::attr(TrailingSlash::Present);
387
Václav Kubernátabf52802020-05-19 01:31:17 +0200388auto const filterConfigFalse = [] (const Schema& schema, const std::string& path) {
389 return schema.isConfig(path);
390};
391
392auto const writableLeafPath_def =
Václav Kubernát743d9eb2020-05-18 13:42:36 +0200393 PathParser<PathParserMode::DataPath, CompletionMode::Data>{filterConfigFalse};
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200394
395auto const presenceContainerPath_def =
396 dataPath;
397
398auto const listInstancePath_def =
399 dataPath;
400
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200401auto const leafListElementPath_def =
402 dataPath;
403
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200404// A "nothing" parser, which is used to indicate we tried to parse a path
405auto const initializePath_def =
406 x3::eps;
407
408
409
410#if __clang__
411#pragma GCC diagnostic pop
412#endif
413
414BOOST_SPIRIT_DEFINE(keyValue)
415BOOST_SPIRIT_DEFINE(key_identifier)
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200416BOOST_SPIRIT_DEFINE(listSuffix)
Václav Kubernátabf52802020-05-19 01:31:17 +0200417BOOST_SPIRIT_DEFINE(writableLeafPath)
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200418BOOST_SPIRIT_DEFINE(presenceContainerPath)
419BOOST_SPIRIT_DEFINE(listInstancePath)
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200420BOOST_SPIRIT_DEFINE(leafListElementPath)
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200421BOOST_SPIRIT_DEFINE(initializePath)
422BOOST_SPIRIT_DEFINE(createKeySuggestions)
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200423BOOST_SPIRIT_DEFINE(createValueSuggestions)
424BOOST_SPIRIT_DEFINE(suggestKeysEnd)
Václav Kubernát5b8a8f32020-05-20 00:57:22 +0200425BOOST_SPIRIT_DEFINE(leafListValue)
Václav Kubernátd0ea9b22020-04-24 00:44:15 +0200426BOOST_SPIRIT_DEFINE(absoluteStart)
427BOOST_SPIRIT_DEFINE(trailingSlash)