Get rid of useless variant in get
Change-Id: I2a6c9f46a541c703ceaa02515a8fb6785cb169d2
diff --git a/src/ast_commands.hpp b/src/ast_commands.hpp
index 5ce1cbd..5759eda 100644
--- a/src/ast_commands.hpp
+++ b/src/ast_commands.hpp
@@ -141,7 +141,7 @@
/> get
/> get /module:path)";
bool operator==(const get_& b) const;
- boost::optional<boost::variant<boost::variant<dataPath_, schemaPath_>, module_>> m_path;
+ boost::optional<boost::variant<dataPath_, schemaPath_, module_>> m_path;
};
struct describe_ : x3::position_tagged {
diff --git a/src/interpreter.cpp b/src/interpreter.cpp
index 909d863..ffe303b 100644
--- a/src/interpreter.cpp
+++ b/src/interpreter.cpp
@@ -231,6 +231,11 @@
}
struct pathToStringVisitor : boost::static_visitor<std::string> {
+ std::string operator()(const module_& path) const
+ {
+ using namespace std::string_literals;
+ return "/"s + boost::get<module_>(path).m_name + ":*";
+ }
std::string operator()(const schemaPath_& path) const
{
return pathToSchemaString(path, Prefixes::WhenNeeded);
@@ -242,6 +247,11 @@
};
struct getPathScopeVisitor : boost::static_visitor<Scope> {
+ Scope operator()(const module_&) const
+ {
+ throw std::logic_error("Interpreter: a top-level module has no scope.");
+ }
+
template <typename T>
Scope operator()(const T& path) const
{
@@ -258,11 +268,10 @@
const auto path = *get.m_path;
if (path.type() == typeid(module_)) {
- return "/"s + boost::get<module_>(path).m_name + ":*";
+ return boost::apply_visitor(pathToStringVisitor(), path);
} else {
- auto actualPath = boost::get<boost::variant<dataPath_, schemaPath_>>(path);
- std::string pathString = boost::apply_visitor(pathToStringVisitor(), actualPath);
- auto pathScope{boost::apply_visitor(getPathScopeVisitor(), actualPath)};
+ std::string pathString = boost::apply_visitor(pathToStringVisitor(), path);
+ auto pathScope{boost::apply_visitor(getPathScopeVisitor(), path)};
if (pathScope == Scope::Absolute) {
return pathString;