langston-barrett / mogglo

Multi-language AST-based code search and rewriting tool that supports embedding Lua code in patterns
https://langston-barrett.github.io/mogglo/
MIT License
28 stars 1 forks source link

Lua + ellipses #12

Open langston-barrett opened 1 year ago

langston-barrett commented 1 year ago

As a general principle, the Lua API should subsume all other features:

However, Lua can't replace $... What would such an API look like? Perhaps ${{lua}}.., where lua would have access to a sequence of nodes' text ts and a sequence of kinds ks? An even more general API would be something like ${{cond||lua}}.. that functions like a take-while, where cond is repeatedly evaluated (in the same context, so it can use state) and siblings are repeatedly consumed until it returns false, and then the lua code gets executed with all the consumed siblings.

langston-barrett commented 1 year ago

Yet another alternative would be to expose a notion of "focus" or "current node" to the Lua code, which it could manipulate (get and set) freely. This, combined with an optionality construct (perhaps ${{lua}}?) would be enough to implement take-while or ellipses. Indeed, it would be more general. This would require #4.