Open langston-barrett opened 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.
As a general principle, the Lua API should subsume all other features:
bind
andmeta
subsume normal metavariables${{true}}
subsumes$_
match
andrec
subsume sub-patternsrx
and negation replace explicit/special support for these featuresHowever, Lua can't replace
$..
. What would such an API look like? Perhaps${{lua}}..
, wherelua
would have access to a sequence of nodes' textts
and a sequence of kindsks
? An even more general API would be something like${{cond||lua}}..
that functions like a take-while, wherecond
is repeatedly evaluated (in the same context, so it can use state) and siblings are repeatedly consumed until it returnsfalse
, and then thelua
code gets executed with all the consumed siblings.