Support ... in list patterns#8
Merged
Merged
Conversation
`[...]`, `[1, ...]`, `[first, ..., last]` silently matched nothing:
candidate prefiltering treated the `...` node `{:..., nil, []}` as a call
named `:...`, deriving the signature `{:contains_call, :..., 0}` — a filter
no list can satisfy — so find_all discarded the node before matching. The
matcher itself already handled variable-length lists.
Exclude `...` from signature derivation so any list pattern containing it
yields `:unknown` (a match-all candidate), like `[_, _, _]` already did.
Plain fixed-length list patterns are unchanged.
Also fix a pre-existing duplication surfaced by this: Sourceror wraps
literals in a one-child `__block__` carrying token metadata, and the zipper
visits both it and its inner child, so find_all/find_many matched the same
source twice (every list, tuple, atom, string and number). Skip the bare
inner child when its parent is that one-child block, keeping the wrapper
match whose range spans the brackets/quotes.
Document ellipsis sub-patterns in the README and cover the leading/trailing
capture forms plus the dedup with tests.
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.
...now works inside list patterns, so you can match lists by their edges and ignore the middle:[...][1, ...]1[x, y, z, ...][..., y, z][first, ..., last]...absorbs the middleFixed-length list patterns (
[1, 2, 3],[_, _, _]) are unchanged — still an exact-length match.Before
After
Also collapses a duplicate-match quirk where every literal (lists, tuples, atoms, strings, numbers) was reported twice.