split ast definitions into more files

Also move pathToString definitions into the new files

Change-Id: I08b92ed108392825ec87af1f2b8a49205265dd47
diff --git a/src/ast.cpp b/src/ast.cpp
deleted file mode 100644
index 35bf1cb..0000000
--- a/src/ast.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
- * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
- *
- * Written by Václav Kubernát <kubervac@fit.cvut.cz>
- *
-*/
-#include "ast.hpp"
-
-
-container_::container_(const std::string& name)
-    : m_name(name)
-{
-}
-
-bool container_::operator==(const container_& b) const
-{
-    return this->m_name == b.m_name;
-}
-
-leaf_::leaf_(const std::string& name)
-    : m_name(name)
-{
-}
-
-bool leaf_::operator==(const leaf_& b) const
-{
-    return this->m_name == b.m_name;
-}
-
-listElement_::listElement_(const std::string& listName, const std::map<std::string, std::string>& keys)
-    : m_name(listName)
-    , m_keys(keys)
-{
-}
-
-bool listElement_::operator==(const listElement_& b) const
-{
-    return (this->m_name == b.m_name && this->m_keys == b.m_keys);
-}
-
-bool path_::operator==(const path_& b) const
-{
-    if (this->m_nodes.size() != b.m_nodes.size())
-        return false;
-    return this->m_nodes == b.m_nodes;
-}
-
-bool set_::operator==(const set_& b) const
-{
-    return this->m_path == b.m_path && this->m_data == b.m_data;
-}
-
-bool cd_::operator==(const cd_& b) const
-{
-    return this->m_path == b.m_path;
-}
-
-bool create_::operator==(const create_& b) const
-{
-    return this->m_path == b.m_path;
-}
-
-bool delete_::operator==(const delete_& b) const
-{
-    return this->m_path == b.m_path;
-}
diff --git a/src/ast.hpp b/src/ast.hpp
deleted file mode 100644
index 9638684..0000000
--- a/src/ast.hpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
- * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
- *
- * Written by Václav Kubernát <kubervac@fit.cvut.cz>
- *
-*/
-#pragma once
-#include <boost/spirit/home/x3.hpp>
-#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
-#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
-
-#include <boost/fusion/adapted/struct/adapt_struct.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include <boost/fusion/include/std_pair.hpp>
-#include <boost/variant.hpp>
-#include <map>
-#include <vector>
-
-#include "utils.hpp"
-namespace x3 = boost::spirit::x3;
-namespace ascii = boost::spirit::x3::ascii;
-
-using ascii::space;
-using x3::_attr;
-using x3::alnum;
-using x3::alpha;
-using x3::char_;
-using x3::expect;
-using x3::lexeme;
-using x3::lit;
-using boost::fusion::operator<<;
-
-
-using keyValue_ = std::pair<std::string, std::string>;
-
-
-struct parser_context_tag;
-
-
-struct nodeup_ {
-    bool operator==(const nodeup_&) const
-    {
-        return true;
-    }
-};
-
-struct container_ {
-    container_() = default;
-    container_(const std::string& name);
-
-    bool operator==(const container_& b) const;
-
-    std::string m_name;
-};
-
-struct leaf_ {
-    leaf_() = default;
-    leaf_(const std::string& name);
-
-    bool operator==(const leaf_& b) const;
-
-    std::string m_name;
-};
-
-
-struct list_ {
-    std::vector<std::string> m_keys;
-};
-
-struct listElement_ {
-    listElement_() {}
-    listElement_(const std::string& listName, const std::map<std::string, std::string>& keys);
-
-    bool operator==(const listElement_& b) const;
-
-    std::string m_name;
-    std::map<std::string, std::string> m_keys;
-};
-
-
-struct path_ {
-    bool operator==(const path_& b) const;
-    std::vector<boost::variant<container_, listElement_, nodeup_, leaf_>> m_nodes;
-};
-
-
-struct cd_ : x3::position_tagged {
-    bool operator==(const cd_& b) const;
-    path_ m_path;
-};
-
-struct create_ : x3::position_tagged {
-    bool operator==(const create_& b) const;
-    path_ m_path;
-};
-
-struct delete_ : x3::position_tagged {
-    bool operator==(const delete_& b) const;
-    path_ m_path;
-};
-
-struct set_ : x3::position_tagged {
-    bool operator==(const set_& b) const;
-    path_ m_path;
-    std::string m_data;
-};
-
-using command_ = boost::variant<cd_, create_, delete_, set_>;
-
-BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
-BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
-BOOST_FUSION_ADAPT_STRUCT(path_, m_nodes)
-BOOST_FUSION_ADAPT_STRUCT(cd_, m_path)
-BOOST_FUSION_ADAPT_STRUCT(create_, m_path)
-BOOST_FUSION_ADAPT_STRUCT(delete_, m_path)
-BOOST_FUSION_ADAPT_STRUCT(set_, m_path, m_data)
diff --git a/src/ast_commands.cpp b/src/ast_commands.cpp
new file mode 100644
index 0000000..a8b481d
--- /dev/null
+++ b/src/ast_commands.cpp
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+#include "ast_commands.hpp"
+
+
+bool set_::operator==(const set_& b) const
+{
+    return this->m_path == b.m_path && this->m_data == b.m_data;
+}
+
+bool cd_::operator==(const cd_& b) const
+{
+    return this->m_path == b.m_path;
+}
+
+bool create_::operator==(const create_& b) const
+{
+    return this->m_path == b.m_path;
+}
+
+bool delete_::operator==(const delete_& b) const
+{
+    return this->m_path == b.m_path;
+}
diff --git a/src/ast_commands.hpp b/src/ast_commands.hpp
new file mode 100644
index 0000000..5caeb2e
--- /dev/null
+++ b/src/ast_commands.hpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+#pragma once
+
+#include "ast_path.hpp"
+
+namespace x3 = boost::spirit::x3;
+namespace ascii = boost::spirit::x3::ascii;
+
+using ascii::space;
+using x3::_attr;
+using x3::alnum;
+using x3::alpha;
+using x3::char_;
+using x3::expect;
+using x3::lexeme;
+using x3::lit;
+
+struct parser_context_tag;
+
+using keyValue_ = std::pair<std::string, std::string>;
+
+struct cd_ : x3::position_tagged {
+    bool operator==(const cd_& b) const;
+    path_ m_path;
+};
+
+struct create_ : x3::position_tagged {
+    bool operator==(const create_& b) const;
+    path_ m_path;
+};
+
+struct delete_ : x3::position_tagged {
+    bool operator==(const delete_& b) const;
+    path_ m_path;
+};
+
+struct set_ : x3::position_tagged {
+    bool operator==(const set_& b) const;
+    path_ m_path;
+    std::string m_data;
+};
+
+using command_ = boost::variant<cd_, create_, delete_, set_>;
+
+BOOST_FUSION_ADAPT_STRUCT(cd_, m_path)
+BOOST_FUSION_ADAPT_STRUCT(create_, m_path)
+BOOST_FUSION_ADAPT_STRUCT(delete_, m_path)
+BOOST_FUSION_ADAPT_STRUCT(set_, m_path, m_data)
diff --git a/src/ast_path.cpp b/src/ast_path.cpp
new file mode 100644
index 0000000..2d2c600
--- /dev/null
+++ b/src/ast_path.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+
+#include <experimental/iterator>
+#include "ast_path.hpp"
+#include "utils.hpp"
+
+container_::container_(const std::string& name)
+    : m_name(name)
+{
+}
+
+bool container_::operator==(const container_& b) const
+{
+    return this->m_name == b.m_name;
+}
+
+leaf_::leaf_(const std::string& name)
+    : m_name(name)
+{
+}
+
+bool leaf_::operator==(const leaf_& b) const
+{
+    return this->m_name == b.m_name;
+}
+
+listElement_::listElement_(const std::string& listName, const std::map<std::string, std::string>& keys)
+    : m_name(listName)
+    , m_keys(keys)
+{
+}
+
+bool listElement_::operator==(const listElement_& b) const
+{
+    return (this->m_name == b.m_name && this->m_keys == b.m_keys);
+}
+
+bool path_::operator==(const path_& b) const
+{
+    if (this->m_nodes.size() != b.m_nodes.size())
+        return false;
+    return this->m_nodes == b.m_nodes;
+}
+
+
+struct nodeToSchemaString : public boost::static_visitor<std::string> {
+    std::string operator()(const nodeup_&) const
+    {
+        return "..";
+    }
+    template <class T>
+    std::string operator()(const T& node) const
+    {
+        return node.m_name;
+    }
+};
+struct nodeToDataString : public boost::static_visitor<std::string> {
+    std::string operator()(const listElement_& node) const
+    {
+        std::ostringstream res;
+        res << node.m_name + "[";
+        std::transform(node.m_keys.begin(), node.m_keys.end(),
+                std::experimental::make_ostream_joiner(res, ' '),
+                [] (const auto& it) { return it.first + "=" + it.second; });
+        res << "]";
+    return res.str();
+    }
+    std::string operator()(const nodeup_&) const
+    {
+        return "..";
+    }
+    template <class T>
+    std::string operator()(const T& node) const
+    {
+        return node.m_name;
+    }
+};
+
+std::string pathToDataString(const path_& path)
+{
+    std::string res;
+    for (const auto it : path.m_nodes)
+        res = joinPaths(res, boost::apply_visitor(nodeToDataString(), it));
+    return res;
+}
+
+std::string pathToSchemaString(const path_& path)
+{
+    std::string res;
+    for (const auto it : path.m_nodes)
+        res = joinPaths(res, boost::apply_visitor(nodeToSchemaString(), it));
+    return res;
+}
diff --git a/src/ast_path.hpp b/src/ast_path.hpp
new file mode 100644
index 0000000..1a4b282
--- /dev/null
+++ b/src/ast_path.hpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2018 CESNET, https://photonics.cesnet.cz/
+ * Copyright (C) 2018 FIT CVUT, https://fit.cvut.cz/
+ *
+ * Written by Václav Kubernát <kubervac@fit.cvut.cz>
+ *
+*/
+#pragma once
+
+#include <boost/spirit/home/x3.hpp>
+#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
+#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
+
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/std_pair.hpp>
+#include <boost/variant.hpp>
+#include <map>
+#include <vector>
+
+struct nodeup_ {
+    bool operator==(const nodeup_&) const
+    {
+        return true;
+    }
+};
+
+struct container_ {
+    container_() = default;
+    container_(const std::string& name);
+
+    bool operator==(const container_& b) const;
+
+    std::string m_name;
+};
+
+struct leaf_ {
+    leaf_() = default;
+    leaf_(const std::string& name);
+
+    bool operator==(const leaf_& b) const;
+
+    std::string m_name;
+};
+
+struct listElement_ {
+    listElement_() {}
+    listElement_(const std::string& listName, const std::map<std::string, std::string>& keys);
+
+    bool operator==(const listElement_& b) const;
+
+    std::string m_name;
+    std::map<std::string, std::string> m_keys;
+};
+
+struct path_ {
+    bool operator==(const path_& b) const;
+    std::vector<boost::variant<container_, listElement_, nodeup_, leaf_>> m_nodes;
+};
+
+
+std::string pathToDataString(const path_& path);
+std::string pathToSchemaString(const path_& path);
+
+BOOST_FUSION_ADAPT_STRUCT(container_, m_name)
+BOOST_FUSION_ADAPT_STRUCT(listElement_, m_name, m_keys)
+BOOST_FUSION_ADAPT_STRUCT(path_, m_nodes)
diff --git a/src/grammars.hpp b/src/grammars.hpp
index 9e4ea35..937fd3c 100644
--- a/src/grammars.hpp
+++ b/src/grammars.hpp
@@ -8,7 +8,7 @@
 
 #pragma once
 
-#include "ast.hpp"
+#include "ast_commands.hpp"
 #include "ast_handlers.hpp"
 
 
diff --git a/src/parser.cpp b/src/parser.cpp
index f26b164..e2d0330 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -5,7 +5,6 @@
  * Written by Václav Kubernát <kubervac@fit.cvut.cz>
  *
 */
-#include <experimental/iterator>
 #include <ostream>
 #include "parser.hpp"
 
@@ -19,28 +18,6 @@
 {
 }
 
-struct nodeToDataString : public boost::static_visitor<std::string> {
-    std::string operator()(const listElement_& node) const
-    {
-        std::ostringstream res;
-        res << node.m_name + "[";
-        std::transform(node.m_keys.begin(), node.m_keys.end(),
-                       std::experimental::make_ostream_joiner(res, ' '),
-                       [] (const auto& it) { return it.first + "=" + it.second; });
-        res << "]";
-        return res.str();
-    }
-    std::string operator()(const nodeup_&) const
-    {
-        return "..";
-    }
-    template <class T>
-    std::string operator()(const T& node) const
-    {
-        return node.m_name;
-    }
-};
-
 command_ Parser::parseCommand(const std::string& line, std::ostream& errorStream)
 {
     command_ parsedCommand;
@@ -74,10 +51,5 @@
 
 std::string Parser::currentNode() const
 {
-    std::string res;
-    for (const auto& it : m_curDir.m_nodes) {
-        res = joinPaths(res, boost::apply_visitor(nodeToDataString(), it));
-    }
-
-    return res;
+    return pathToDataString(m_curDir);
 }
diff --git a/src/schema.cpp b/src/schema.cpp
index 9832c45..95cd4ae 100644
--- a/src/schema.cpp
+++ b/src/schema.cpp
@@ -11,26 +11,6 @@
 
 InvalidNodeException::~InvalidNodeException() = default;
 
-struct nodeToSchemaString : public boost::static_visitor<std::string> {
-    std::string operator()(const nodeup_&) const
-    {
-        return "..";
-    }
-    template <class T>
-    std::string operator()(const T& node) const
-    {
-        return node.m_name;
-    }
-};
-
-std::string pathToString(const path_& path)
-{
-    std::string res;
-    for (const auto it : path.m_nodes)
-        res = joinPaths(res, boost::apply_visitor(nodeToSchemaString(), it));
-    return res;
-}
-
 Schema::Schema()
 {
     m_nodes.emplace("", std::unordered_map<std::string, NodeType>());
@@ -52,7 +32,7 @@
 
 bool Schema::isContainer(const path_& location, const std::string& name) const
 {
-    std::string locationString = pathToString(location);
+    std::string locationString = pathToSchemaString(location);
     if (!nodeExists(locationString, name))
         return false;
 
@@ -71,7 +51,7 @@
 
 bool Schema::listHasKey(const path_& location, const std::string& name, const std::string& key) const
 {
-    std::string locationString = pathToString(location);
+    std::string locationString = pathToSchemaString(location);
     assert(isList(location, name));
 
     const auto& child = children(locationString).at(name);
@@ -81,7 +61,7 @@
 
 const std::set<std::string>& Schema::listKeys(const path_& location, const std::string& name) const
 {
-    std::string locationString = pathToString(location);
+    std::string locationString = pathToSchemaString(location);
     assert(isList(location, name));
 
     const auto& child = children(locationString).at(name);
@@ -91,7 +71,7 @@
 
 bool Schema::isList(const path_& location, const std::string& name) const
 {
-    std::string locationString = pathToString(location);
+    std::string locationString = pathToSchemaString(location);
     if (!nodeExists(locationString, name))
         return false;
     const auto& child = children(locationString).at(name);
@@ -112,7 +92,7 @@
 {
     if (!isContainer(location, name))
         return false;
-    std::string locationString = pathToString(location);
+    std::string locationString = pathToSchemaString(location);
     return boost::get<yang::container>(children(locationString).at(name)).m_presence == yang::ContainerTraits::Presence;
 }
 
@@ -123,7 +103,7 @@
 
 bool Schema::isLeaf(const path_& location, const std::string& name) const
 {
-    std::string locationString = pathToString(location);
+    std::string locationString = pathToSchemaString(location);
     if (!nodeExists(locationString, name))
         return false;
 
diff --git a/src/schema.hpp b/src/schema.hpp
index 487f820..73e89df 100644
--- a/src/schema.hpp
+++ b/src/schema.hpp
@@ -12,7 +12,7 @@
 #include <set>
 #include <stdexcept>
 #include <unordered_map>
-#include "ast.hpp"
+#include "ast_path.hpp"
 
 namespace yang {
 enum class ContainerTraits {