Skip to content

Commit

Permalink
Fixed inspect request
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Nov 27, 2023
1 parent 7c7d42d commit 5111e0c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
33 changes: 33 additions & 0 deletions src/xinspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ namespace xcpp
tagfile = it->at("tagfile");
std::string filename = tagfiles_dir + "/" + tagfile;
pugi::xml_document doc;
pugi::xml_parse_result result __attribute__((unused)) = doc.load_file(filename.c_str());
class_member_predicate predicate{typename_, "function", method[2]};
auto node = doc.find_node(predicate);
if (!node.empty())
Expand Down Expand Up @@ -193,6 +194,7 @@ namespace xcpp
tagfile = it->at("tagfile");
std::string filename = tagfiles_dir + "/" + tagfile;
pugi::xml_document doc;
pugi::xml_parse_result result __attribute__((unused)) = doc.load_file(filename.c_str());
for (auto c : check)
{
node_predicate predicate{c, find_string};
Expand Down Expand Up @@ -262,5 +264,36 @@ namespace xcpp
kernel_res["status"] = "ok";
}
}

class xintrospection : public xpreamble
{
public:

using xpreamble::pattern;
const std::string spattern = R"(^\?)";

xintrospection(clang::Interpreter& p)
: m_interpreter{p}
{
pattern = spattern;
}

void apply(const std::string& code, nl::json& kernel_res) override
{
std::regex re(spattern + R"((.*))");
std::smatch to_inspect;
std::regex_search(code, to_inspect, re);
inspect(to_inspect[1], kernel_res, m_interpreter);
}

virtual xpreamble* clone() const override
{
return new xintrospection(*this);
}

private:

clang::Interpreter& m_interpreter;
};
}
#endif
11 changes: 2 additions & 9 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,8 @@ namespace xcpp
// Attempt normal evaluation

try
{ std::string exp = R"(\w*(?:\:{2}|\<.*\>|\(.*\)|\[.*\])?)";
std::regex re(R"((\w*(?:\:{2}|\<.*\>|\(.*\)|\[.*\])?)(\.?)*$)");
auto inspect_request = is_inspect_request(code, re);
if (inspect_request.first)
{
inspect(inspect_request.second[0], kernel_res, *m_interpreter);
}

{
compilation_result = process_code(*m_interpreter, code, error_stream);

}
catch (std::exception& e)
{
Expand Down Expand Up @@ -589,6 +581,7 @@ namespace xcpp

void interpreter::init_preamble()
{
preamble_manager.register_preamble("introspection", new xintrospection(*m_interpreter));
preamble_manager.register_preamble("magics", new xmagics_manager());
preamble_manager.register_preamble("shell", new xsystem());
}
Expand Down

0 comments on commit 5111e0c

Please sign in to comment.