-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Zipper.search_pattern/2
#154
Conversation
I am not sure if I understand everything right, maybe I overlook something. But a pattern with |
Not quite; the generalization is that iex(1)> code = """
...(1)> if :foo != :bar do
...(1)> IO.puts("hello")
...(1)> end
...(1)> """ |> Sourceror.parse_string!() |> Sourceror.Zipper.zip()
iex(2)> pattern = "IO.puts(__cursor__())"
"IO.puts(__cursor__())"
iex(3)> Sourceror.Zipper.move_to_cursor(code, pattern)
nil
iex(4)> Sourceror.Zipper.search_to_pattern(code, pattern)
#Sourceror.Zipper<
#...
{:__block__, [trailing_comments: [], leading_comments: [], delimiter: "\"", line: 2, column: 11],
["hello"]}
>
Now that I'm thinking about it, though, maybe |
@zachallaun thanks for your explanation. My assumption about how |
This looks great! |
a0a523d
to
6c7c57a
Compare
Zipper.search_to_pattern/2
Zipper.search_pattern/2
Renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you!
Expanding on #147 which introduced
Zipper.move_to_cursor/2
, this PR adds a more generalZipper.search_pattern/2
, which can match an arbitrarily nested pattern.Also included is a small fix that makes
do_find
private (it was accidentally exposed) and a refactor formove_to_cursor
.cc @zachdaniel, @NickNeck