Expand-compile regexes using OTP 28.1 :re.import #14722
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Another PoC, this time using the expand-time approach.
Working at expand time is a bit awkward because we're manipulating map AST, but unlike the
escape
approach from #14720, it doesn't break the assumption that escaping emits a literal.The first commit does it in a regex-aware way.
The second commit is a proof of concept for what a no-cheating version could look like.
The idea:
escape
code checking for refs in maps will, instead of raising, replace the value by:__expand_compile__
(name TBD), if it's a struct definingStructMod.__expand_compile__(struct, key)
:__expand_compile__
value (relatively cheap to check), we confirm it's a literal (more expensive) struct defining the fun, and we callStructMod.__expand_compile__(struct, key)
to get the new value ASTdo_quote
to let refs through and add a meta to the map to letelixir_expand
know to swap it - but I'm not sure there's value in allowing refs in AST if we don't need them anyway?:__expand_compile__
with a wildcard (_
), since we can't call functions like:re.import
anyway and refs would otherwise never match.