-
Notifications
You must be signed in to change notification settings - Fork 33
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 support for @upper_case @lower_case captures #838
base: main
Are you sure you want to change the base?
Conversation
bbbf44b
to
5da7294
Compare
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.
Thanks for your contribution 🙏
My immediate concern with this is that it does not respect leaf nodes (i.e., those annotated with @leaf
, which are meant to remain unchanged by formatting). For example:
; test.scm
(string) @leaf
(command
argument: (_) @prepend_space
)
(command) @upper_case
$ topiary format -lbash -qtest.scm <<'SH'
> echo "hello"
> SH
ECHO "HELLO"
Topiary is meant to be general: adding @{upper,lower}_case
already feels a bit overly specific,1 but regardless, they should follow the other assumptions. As such, if you could modify your code to respect @leaf
nodes, then I think it would meet that bar.
Footnotes
-
It occurs to me that one could implement case changes with a mixture of
@delete
and@append_delimiter
. Granted, it's not as clean as your solution, but it's doable. Something like this might work:(select_keyword _ @delete @append_delimiter (#not-eq? @delete "SELECT") (#delimiter! "SELECT") )
Untested, but we use similar tricks in queries for other languages. ↩
Will add respect for leaf nodes. I based my implementation off of
Also, cannot find docs for As for using |
Touché 😉 Yes,
Excellent point 👍 I'll add an issue.
That's fair; this method is a bit unwieldy. There was talk of a more generic rewriting capture some time ago, but even that wouldn't solve your problem as effectively as your |
I think this is ready for review again. Given the previous query you gave, the output is now: ECHO "hello" |
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.
This is great 🙏 Thanks, @ctdunc
I've approved this, but it's not ready to merge just yet. Nearly, but I have a few small requests!
- There is a
TODO
floating around inatom_collection.rs
that either needs to be resolved or removed. (Either way 👌) - A simple test for
@{upper,lower}_case
would be helpful, although I'm not sure where you'd put it (there aren't explicit tests for other capture names). As such, don't sweat on this if it doesn't make sense. - Please update the
CHANGELOG
and credit yourself 💯
Not for this PR, but per this discussion, I think your idea of adding other case modifiers (kebab, snake, etc.) is interesting and, with this contribution, will make it easy to pursue in the future. So, thank you 🙇
Edit: I'll run the CI as well, just to check everything passes...
I have tests for |
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.
I've made a few more suggestions to simplify the code 👍
I have tests for
@{upper,lower}_case
on my feature/sql branch, where this test will actually make sense. Not sure what other language I'd want to put it in, but I can cook one up for sure.
That's fine then; no need to bother in this PR. I was thinking about having explicit tests in the code, rather than using the IO tester. Best to hold your IO tester tests back until they make sense, rather than trying to shoehorn them into an unexpecting language!
Add support for @upper_case @lower_case captures.
Issue: #836
Description
This adds really basic support for the feature discussed in the linked issue.
I tested it with my SQL capture, and it works, but I don't know if adding SQL as a language is in scope for this PR and there are a lot of other issues with my query (it's still kinda ugly).
Checklist
Checklist before merging: