add leaves

Change-Id: I962bb4e74f39ec0a838f984b8c13a420ba36d7ce
diff --git a/src/ast_handlers.hpp b/src/ast_handlers.hpp
index 1feeeab..4b703aa 100644
--- a/src/ast_handlers.hpp
+++ b/src/ast_handlers.hpp
@@ -98,7 +98,6 @@
     }
 };
 
-
 struct nodeup_class {
     template <typename T, typename Iterator, typename Context>
     void on_success(Iterator const&, Iterator const&, T&, Context const& context)
@@ -128,11 +127,43 @@
     }
 };
 
+struct leaf_class {
+    template <typename T, typename Iterator, typename Context>
+    void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
+    {
+        auto& parserContext = x3::get<parser_context_tag>(context);
+        const auto& schema = parserContext.m_schema;
+
+        if (schema.isLeaf(parserContext.m_curPath, ast.m_name)) {
+            parserContext.m_curPath.m_nodes.push_back(ast);
+        } else {
+            _pass(context) = false;
+        }
+    }
+};
+
 struct path_class {
     template <typename T, typename Iterator, typename Context>
     void on_success(Iterator const&, Iterator const&, T&, Context const&)
     {
     }
+
+    template <typename Iterator, typename Exception, typename Context>
+    x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
+    {
+        auto& parserContext = x3::get<parser_context_tag>(context);
+        auto& error_handler = x3::get<x3::error_handler_tag>(context).get();
+        std::string message = "invalid path.";
+        if (parserContext.m_errorHandled) // someone already handled our error
+            return x3::error_handler_result::fail;
+
+        parserContext.m_errorHandled = true;
+        error_handler(x.where(), message);
+        return x3::error_handler_result::fail;
+    }
+};
+
+struct data_string_class {
 };
 
 struct cd_class {
@@ -198,6 +229,33 @@
 struct delete_class : public presenceContainerPathHandler {
 };
 
+struct set_class {
+    template <typename T, typename Iterator, typename Context>
+    void on_success(Iterator const&, Iterator const&, T& ast, Context const& context)
+    {
+        try {
+            auto leaf = boost::get<leaf_>(ast.m_path.m_nodes.back());
+        } catch (boost::bad_get&) {
+            _pass(context) = false;
+            return;
+        }
+    }
+
+    template <typename Iterator, typename Exception, typename Context>
+    x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)
+    {
+        auto& parserContext = x3::get<parser_context_tag>(context);
+        auto& error_handler = x3::get<x3::error_handler_tag>(context).get();
+        std::string message = "This isn't a path to leaf.";
+        if (parserContext.m_errorHandled) // someone already handled our error
+            return x3::error_handler_result::fail;
+
+        parserContext.m_errorHandled = true;
+        error_handler(x.where(), message);
+        return x3::error_handler_result::fail;
+    }
+};
+
 struct command_class {
     template <typename Iterator, typename Exception, typename Context>
     x3::error_handler_result on_error(Iterator&, Iterator const&, Exception const& x, Context const& context)