add definition of the AST for the cd command

The AST enables us to represent commands via structs. These will hold
all the information about the command for an interpreter.

Change-Id: I4ab45865d5b71c2e1695b1c7c82660fd146da627
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8cd1aa9..ad8c3c2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -51,6 +51,7 @@
     src/main.cpp
     src/CTree.cpp
     src/CParser.cpp
+    src/ast.cpp
     )
 
 add_executable(netconf-cli ${netconf-cli_SRCS})
diff --git a/src/ast.cpp b/src/ast.cpp
new file mode 100644
index 0000000..d9964ea
--- /dev/null
+++ b/src/ast.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+#include "ast.hpp"
+
+
+template <typename T, typename Iterator, typename Context>
+inline void container_class::on_success(Iterator const& first, Iterator const& last
+    , T& ast, Context const& context)
+{
+    ast.m_name = ast.m_first + ast.m_name;
+    //std::cout <<"parsed " << ast.m_name << "(container)\n";
+}
+
+template <typename T, typename Iterator, typename Context>
+inline void path_class::on_success(Iterator const& first, Iterator const& last
+    , T& ast, Context const& context)
+{
+    //std::cout << "parsed path:" << std::endl;
+    //for (auto it : ast.m_nodes)
+    //std::cout << it.m_name << std::endl;
+}
+
+template <typename T, typename Iterator, typename Context>
+inline void cd_class::on_success(Iterator const& first, Iterator const& last
+    , T& ast, Context const& context)
+{
+    //std::cout << "parsed cd! final path:" << std::endl;
+    //for (auto it : ast.m_path.m_nodes)
+    //std::cout << it.m_name << std::endl;
+
+}
diff --git a/src/ast.hpp b/src/ast.hpp
new file mode 100644
index 0000000..6c60dc9
--- /dev/null
+++ b/src/ast.hpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+#pragma once
+#include <boost/spirit/home/x3.hpp>
+#include <vector>
+#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include "CTree.hpp"
+namespace x3 = boost::spirit::x3;
+namespace ascii = boost::spirit::x3::ascii;
+
+using x3::alpha;
+using x3::alnum;
+using x3::lit;
+using x3::char_;
+using x3::_attr;
+using x3::lexeme;
+using ascii::space;
+
+using nodeString = std::string;
+
+struct ParserContext
+{
+    ParserContext(const CTree& tree);
+    const CTree& m_tree;
+    std::string m_currentContext;
+};
+
+struct parser_context_tag;
+
+struct container_
+{
+    char m_first;
+    std::string m_name;
+};
+
+BOOST_FUSION_ADAPT_STRUCT(container_, m_first, m_name)
+
+struct path_
+{
+    std::vector<container_> m_nodes;
+};
+
+BOOST_FUSION_ADAPT_STRUCT(path_, m_nodes)
+
+struct cd_
+{
+    path_ m_path;
+};
+
+BOOST_FUSION_ADAPT_STRUCT(cd_, m_path)
+
+
+struct container_class
+{
+    template <typename T, typename Iterator, typename Context>
+        inline void on_success(Iterator const& first, Iterator const& last
+                , T& ast, Context const& context);
+};
+
+struct path_class
+{
+    template <typename T, typename Iterator, typename Context>
+    inline void on_success(Iterator const& first, Iterator const& last
+    , T& ast, Context const& context);
+};
+
+struct cd_class
+{
+    template <typename T, typename Iterator, typename Context>
+    inline void on_success(Iterator const& first, Iterator const& last
+    , T& ast, Context const& context);
+
+};
+
+
+typedef x3::rule<container_class, container_> container_type;
+typedef x3::rule<path_class, path_> path_type;
+typedef x3::rule<cd_class, cd_> cd_type;
+
+container_type const container = "container";
+path_type const path = "path";
+cd_type const cd = "cd";
+
+
+auto const container_def =
+    lexeme[
+        ((alpha | x3::string("_")) >> *(alnum | x3::string("_") | x3::string("-") | x3::string(".")))
+    ];
+auto const path_def =
+    container % '/';
+
+auto const cd_def =
+    lit("cd") >> path >> x3::eoi;
+
+BOOST_SPIRIT_DEFINE(container)
+BOOST_SPIRIT_DEFINE(path)
+BOOST_SPIRIT_DEFINE(cd)