Replies: 2 comments 7 replies
-
What's the purpose of modifying AST? You can modify data. |
Beta Was this translation helpful? Give feedback.
-
Janet doesn't have native concrete syntax trees so it will be difficult to do the sort of bidirectional sync that you see in the demo you linked. That said, you can do an approximation of it with the AST by reserializing it whenever you change previews and such. But any time you edit the "preview" values, it would lose some formatting in the text display. Janet does store position information in tuple forms, but not in any other forms. But you're really parsing the AST -> modifying it as a regular data structure, with functional updates since the AST is mostly immutable -> serializing that back into a form. I don't think Janet has built-in functional update helpers but you can implement the ones that you need:
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to write a program that can self-modify its AST.
The idea is to have an evaluator program that takes a janet file and parses it generating the AST.
Then it evaluates the program that reaches out from itself to get the AST and update the value.
In the example above I just get the input binding that stores the AST and update the value.
This example is obviously very simplified, but what I want to eventually do is to have a way to interactively modify the file from inside the executing program.
Does this seem like the right approach?
Is there a better way for self modifying the AST?
Beta Was this translation helpful? Give feedback.
All reactions