Closed
Conversation
This commit introduces internal attachment that allows unapply macros to be aware of their sub patterns and tweak their expansion depending on that info. At the moment this is not possible due to the way pattern macros are expanded: case MacroPat(inner1, inner2) => ... During type checking this will expand as MacroPat.unapply(<unapply-dummy>) Meaning that macro can’t see inner1 and inner2 in it’s macroApplication. To circumvent this we attach that info as an attachment to the dummy.
1. Refactor Holes slice of quasiquotes to make unliftable fit into
the same framework; replace 3 entities: Holes, HoleTypes and Location
with just a single Hole concept (equiv to previous Holes + HoleTypes)
and some matchers over types (equiv to previous Locations);
2. Move Liftable trait inside of the cake; this is crucial to decrease
boilerplate that is required to define liftable and to allow
combining of liftables together with unliftables in the same class
without pulling ones hair out;
3. Introduce Unliftable — a type class similar to liftable that lets
users to extract custom data types out of trees with the help of
straightforward type ascription syntax:
val q“foo.bar(${baz: Baz})” = ...
This will use Unliftable[Baz] to extract custom data type Baz out of
a tree nested inside of the another tree. A simpler example would be
extracting of constant values:
val q”${x: Int} + ${y: Int}” = q”1 + 2”
4. Vastly increase number of standard liftables.
Contributor
Author
|
I've found a corner case that needs some more work |
Contributor
|
I'm never on the cutting edge of anything, but I already have a commented on SO where I had nothing new to add. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pr introduces a new
Unliftabletype class used by quasiquotes to extract custom data types out of trees:When an implicit value of Unliftable[T] is provided this means that user can extract value of T inside of the quasiquote pattern:
Where this code is semantically equivalent to:
The major use-case for introduction of
Unliftableis vast simplification of extraction of leaf values from the trees:Previously users had to resort to nesting manual tree subpatterns to extract such values:
review by @retronym and @xeno-by