Change ParserContext::m_curPath to dataPath_

This will be used for the upcoming key value completion feature.
Completing key values in a nested list means, that I need the whole
context (all keys of parent list instances). That means m_curPath needs
to be changed to dataPath_.

Change-Id: I29a13576802d01df4f1f420be1c73178a263dad7
diff --git a/src/parser_context.cpp b/src/parser_context.cpp
index c240984..7750301 100644
--- a/src/parser_context.cpp
+++ b/src/parser_context.cpp
@@ -7,11 +7,72 @@
 */
 
 #include "parser_context.hpp"
-ParserContext::ParserContext(const Schema& schema, const schemaPath_& curDir)
+ParserContext::ParserContext(const Schema& schema, const dataPath_& curDir)
     : m_schema(schema)
-    , m_curPath(curDir)
     , m_curPathOrig(curDir)
+    , m_curPath(curDir)
 {
-    if (!m_curPath.m_nodes.empty() && m_curPath.m_nodes.at(0).m_prefix)
+    if (!currentDataPath().m_nodes.empty() && currentDataPath().m_nodes.at(0).m_prefix)
         m_topLevelModulePresent = true;
 }
+
+void ParserContext::clearPath()
+{
+    m_curPath = dataPath_{Scope::Absolute, {}};
+    m_topLevelModulePresent = false;
+}
+
+schemaPath_ ParserContext::currentSchemaPath()
+{
+    if (m_curPath.type() == typeid(dataPath_)) {
+        return dataPathToSchemaPath(boost::get<dataPath_>(m_curPath));
+    } else {
+        return boost::get<schemaPath_>(m_curPath);
+    }
+}
+
+dataPath_ ParserContext::currentDataPath()
+{
+    if (m_curPath.type() != typeid(dataPath_)) {
+        throw std::runtime_error("Tried getting a dataPath_ from ParserContext when only schemaPath_ was available.");
+    }
+    return boost::get<dataPath_>(m_curPath);
+}
+
+void ParserContext::pushPathFragment(const dataNode_& node)
+{
+    auto pushNode = [this] (auto& where, const auto& what) {
+        if (what.m_suffix.type() == typeid(nodeup_)) {
+            where.m_nodes.pop_back();
+            if (where.m_nodes.empty()) {
+                m_topLevelModulePresent = false;
+            }
+        } else {
+            where.m_nodes.push_back(what);
+        }
+    };
+
+    if (m_curPath.type() == typeid(dataPath_)) {
+        pushNode(boost::get<dataPath_>(m_curPath), node);
+    } else {
+        pushNode(boost::get<schemaPath_>(m_curPath), dataNodeToSchemaNode(node));
+    }
+}
+
+void ParserContext::pushPathFragment(const schemaNode_& node)
+{
+    if (m_curPath.type() == typeid(dataPath_)) {
+        m_curPath = dataPathToSchemaPath(boost::get<dataPath_>(m_curPath));
+    }
+
+    boost::get<schemaPath_>(m_curPath).m_nodes.push_back(node);
+    if (currentSchemaPath().m_nodes.empty()) {
+        m_topLevelModulePresent = false;
+    }
+}
+
+void ParserContext::resetPath()
+{
+    m_curPath = m_curPathOrig;
+    m_topLevelModulePresent = !currentDataPath().m_nodes.empty() && currentDataPath().m_nodes.at(0).m_prefix;
+}