Change how create/delete path argument is parsed

The handler for create/delete was an inherited class from
presenceContainerPathHandler class, so that the code is shared between
create/delete. However, this means that it is impossible to change the
grammar for create/delete to include other types of paths (because the
handler was hardcoded to presence containers). This change ties the
handler to the "path" rule rather than to the create/delete rule. This
method is also in line with the "set" command where the path is checked
in the "leafPath" rule rather than in the "set" rule.

Change-Id: Ic41aa26bf4bc93f762435f43312489e10472e475
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index b32330e..c937eee 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -288,7 +288,7 @@
     }
 };
 
-struct presenceContainerPathHandler {
+struct presenceContainerPath_class {
     template <typename T, typename Iterator, typename Context>
     void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
     {
@@ -296,9 +296,9 @@
         const auto& schema = parserContext.m_schema;
         try {
             boost::optional<std::string> module;
-            if (ast.m_path.m_nodes.back().m_prefix)
-                module = ast.m_path.m_nodes.back().m_prefix.value().m_name;
-            container_ cont = boost::get<container_>(ast.m_path.m_nodes.back().m_suffix);
+            if (ast.m_nodes.back().m_prefix)
+                module = ast.m_nodes.back().m_prefix.value().m_name;
+            container_ cont = boost::get<container_>(ast.m_nodes.back().m_suffix);
             schemaPath_ location = pathWithoutLastNode(parserContext.m_curPath);
 
             if (!schema.isPresenceContainer(location, {module, cont.m_name})) {
@@ -310,7 +310,9 @@
             _pass(context) = false;
         }
     }
+};
 
+struct create_class {
     template <typename Iterator, typename Exception, typename Context>
     x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
     {
@@ -321,10 +323,15 @@
     }
 };
 
-struct create_class : public presenceContainerPathHandler {
-};
-
-struct delete_class : public presenceContainerPathHandler {
+struct delete_class {
+    template <typename Iterator, typename Exception, typename Context>
+    x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const&, Context const& context)
+    {
+        auto& parserContext = x3::get<parser_context_tag>(context);
+        if (parserContext.m_errorMsg.empty())
+            parserContext.m_errorMsg = "Couldn't parse create/delete command.";
+        return x3::error_handler_result::rethrow;
+    }
 };
 
 struct leaf_path_class {
diff --git a/src/grammars.hpp b/src/grammars.hpp
index 5878053..abdd9ce 100644
--- a/src/grammars.hpp
+++ b/src/grammars.hpp
@@ -34,6 +34,7 @@
 x3::rule<dataPathListEnd_class, dataPath_> const dataPathListEnd = "dataPathListEnd";
 x3::rule<dataPath_class, dataPath_> const dataPath = "dataPath";
 x3::rule<leaf_path_class, dataPath_> const leafPath = "leafPath";
+x3::rule<presenceContainerPath_class, dataPath_> const presenceContainerPath = "presenceContainerPath";
 
 x3::rule<leaf_data_class, leaf_data_> const leaf_data = "leaf_data";
 x3::rule<leaf_data_enum_class, enum_> const leaf_data_enum = "leaf_data_enum";
@@ -178,6 +179,9 @@
 auto const leafPath_def =
     dataPath;
 
+auto const presenceContainerPath_def =
+    dataPath;
+
 auto const createEnumSuggestions_def =
     x3::eps;
 
@@ -240,10 +244,10 @@
     cd_::name >> space_separator > dataPath;
 
 auto const create_def =
-    create_::name >> space_separator > dataPath;
+    create_::name >> space_separator > presenceContainerPath;
 
 auto const delete_rule_def =
-    delete_::name >> space_separator > dataPath;
+    delete_::name >> space_separator > presenceContainerPath;
 
 auto const get_def =
     get_::name >> -(space_separator >> (dataPathListEnd | dataPath));
@@ -293,6 +297,7 @@
 BOOST_SPIRIT_DEFINE(container)
 BOOST_SPIRIT_DEFINE(leaf)
 BOOST_SPIRIT_DEFINE(leafPath)
+BOOST_SPIRIT_DEFINE(presenceContainerPath)
 BOOST_SPIRIT_DEFINE(schemaPath)
 BOOST_SPIRIT_DEFINE(dataPath)
 BOOST_SPIRIT_DEFINE(dataNodeList)