Skip to content

Commit

Permalink
Do not execute inline functions which are only a single character lon…
Browse files Browse the repository at this point in the history
…g, or start with a backslash.
  • Loading branch information
Kasper Peeters committed Nov 8, 2024
1 parent b8c582b commit 01819e4
Show file tree
Hide file tree
Showing 3 changed files with 361 additions and 139 deletions.
12 changes: 11 additions & 1 deletion core/Bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ void run_python_functions(std::shared_ptr<Ex> ex, Kernel *kernel)
while(it!=ex->end_post()) {
auto nxt=it;
++nxt;

// Do not call single-letter functions; assume those are
// always mathematics, not python. Also do not even attempt
// to call functions which start with a backslash (those
// are TeX).
if((*it->name).size()==1 || (*it->name)[0]=='\\') {
it=nxt;
continue;
}

// Only call functions if the cadabra symbols have one or
// more child nodes which all have bracket_t::b_none.
Ex::sibling_iterator sib=ex->begin(it);
Expand All @@ -93,7 +103,7 @@ void run_python_functions(std::shared_ptr<Ex> ex, Kernel *kernel)
}

if(scope_has(locals, *it->name)) {
//std::cerr << "can run function " << *it->name << std::endl;
// std::cerr << "can run function " << *it->name << std::endl;
py::object fun=locals[(*it->name).c_str()];
Ex::sibling_iterator sib=ex->begin(it);
py::object res;
Expand Down
Loading

0 comments on commit 01819e4

Please sign in to comment.