Yes, this would be the way to go. Ultimately I have no had very much time to spend on ChaiScript lately (the regulars might have noticed this and if anyone wants to help admin the project, please let me know). But the goal is that each node of the AST should contain a
std::string_view of the actual portion of the parsed script that represents that node. This is how GCC and clang are able to so accurately represent errors today.
The pieces are in place for this and it ultimately would not take a ton of work probably. This would be the best way by far of getting back a string representation of the function.
Also related: I at one point strongly considered a tool that could walk the AST and output C++ from ChaiScript (turning untyped parameters into
template<> functions, for example). This is also quite doable.