Skip to content

Commit 72a3af2

Browse files
committed
Fixed inspect request
1 parent ff8c753 commit 72a3af2

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

src/xinspect.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ namespace xcpp
160160
tagfile = it->at("tagfile");
161161
std::string filename = tagfiles_dir + "/" + tagfile;
162162
pugi::xml_document doc;
163+
pugi::xml_parse_result result __attribute__((unused)) = doc.load_file(filename.c_str());
163164
class_member_predicate predicate{typename_, "function", method[2]};
164165
auto node = doc.find_node(predicate);
165166
if (!node.empty())
@@ -193,6 +194,7 @@ namespace xcpp
193194
tagfile = it->at("tagfile");
194195
std::string filename = tagfiles_dir + "/" + tagfile;
195196
pugi::xml_document doc;
197+
pugi::xml_parse_result result __attribute__((unused)) = doc.load_file(filename.c_str());
196198
for (auto c : check)
197199
{
198200
node_predicate predicate{c, find_string};
@@ -262,5 +264,36 @@ namespace xcpp
262264
kernel_res["status"] = "ok";
263265
}
264266
}
267+
268+
class xintrospection : public xpreamble
269+
{
270+
public:
271+
272+
using xpreamble::pattern;
273+
const std::string spattern = R"(^\?)";
274+
275+
xintrospection(clang::Interpreter& p)
276+
: m_interpreter{p}
277+
{
278+
pattern = spattern;
279+
}
280+
281+
void apply(const std::string& code, nl::json& kernel_res) override
282+
{
283+
std::regex re(spattern + R"((.*))");
284+
std::smatch to_inspect;
285+
std::regex_search(code, to_inspect, re);
286+
inspect(to_inspect[1], kernel_res, m_interpreter);
287+
}
288+
289+
virtual xpreamble* clone() const override
290+
{
291+
return new xintrospection(*this);
292+
}
293+
294+
private:
295+
296+
clang::Interpreter& m_interpreter;
297+
};
265298
}
266299
#endif

src/xinterpreter.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,16 +327,8 @@ namespace xcpp
327327
// Attempt normal evaluation
328328

329329
try
330-
{ std::string exp = R"(\w*(?:\:{2}|\<.*\>|\(.*\)|\[.*\])?)";
331-
std::regex re(R"((\w*(?:\:{2}|\<.*\>|\(.*\)|\[.*\])?)(\.?)*$)");
332-
auto inspect_request = is_inspect_request(code, re);
333-
if (inspect_request.first)
334-
{
335-
inspect(inspect_request.second[0], kernel_res, *m_interpreter);
336-
}
337-
330+
{
338331
compilation_result = process_code(*m_interpreter, code, error_stream);
339-
340332
}
341333
catch (std::exception& e)
342334
{
@@ -589,6 +581,7 @@ namespace xcpp
589581

590582
void interpreter::init_preamble()
591583
{
584+
preamble_manager.register_preamble("introspection", new xintrospection(*m_interpreter));
592585
preamble_manager.register_preamble("magics", new xmagics_manager());
593586
preamble_manager.register_preamble("shell", new xsystem());
594587
}

0 commit comments

Comments
 (0)