String representation of a function


#1

Hi,

Does the ChaiScript lets getting a string representation of a function’s body defined from ChaiScript’s level? :slight_smile:

In other words: if I had a function in .chai file, I would like to load that function in C++ level and get it’s body as a string. Is that possible? :slight_smile:

Best regards
Dariusz Pyś


#2

Why are you trying to do that? ChaiScript can take some Chai, and output a std::function… You parse the .file. Some regex-fu would get you there.


#3

Because it’s fun. :wink: With a little work you can do a self-modyfying program. Particullarly, I would like to use this feature for the visual editor of behavior trees, where action nodes could be stored as chaiscript’s functions.

Obviously it can.

I would like to avoid doing an extra pre-parsing until I’ll be sure that ChaiScript itself can’t help me. So here it is: this thread.


#4

There was discussion about the AST over at Moving to a ByteCode Representation? … Maybe worth a read.


#5

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.


#6

Thanks you guys for replies. :slight_smile:
I’ll know now where start digging.
However I’m afraid, I don’t have enough free time to get myself into ChaiScript’s code base. :frowning: Miracles happen so maybe I’ll do that.

Best regards
Dariusz Pyś