-
Notifications
You must be signed in to change notification settings - Fork 28
Parse map literals to key/value pairs #70
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
base: master
Are you sure you want to change the base?
Conversation
|
IIUC, this is something we considered and decided against for the time being. As GH makes searching longer issues / prs / discussions cumbersome because of its "collapsing" [1], I'll post some links to specific comments that touch on entries in the issue:
[1] I very much would have preferred discussion elsewhere but unfortunately the relevant parties were not inclined in that direction. |
|
Many thanks for taking the time to dig out those comments @sogaiu. +1 for focused discussion threads. 😄 For context, the specific use-case I wanted this for was Helix’s match in/around data structure entry functionality: With this in the grammar, you can quickly type At least, I couldn’t figure out any way of doing that in a t-s query, which kicks what seems like a parsing problem all the way up to application/plugin code in the consumer. Grammatically, a map is only valid when composed of balanced pairs, and I feel like the ideal place to parse that information is in the grammar, where it’s close to free and gives every consumer the same solid foundation. And philosophically, in a just and pure world, I think handling syntactically incorrect forms should be a consumer problem. What should move form forwards/backwards do if you have a syntax error? I don’t know, but don’t you need to handle that in the implementation of move form anyway? But pragmatically, making life harder for any Emacs Clojure programmers for the benefit of Helix Clojure programmers (of whom there are, like, maybe three, including me), would be a ludicrous decision. Maintaining a half-dozen line fork is no great burden, and Helix makes it easy to override the grammar and queries in your local config. Maybe revisit if the prospect of Scheme-based extensibility entices a few more over to Helix. 😄 |
|
Thanks for sharing your thoughts and the background involved. If the topic is revisited, what you shared might be of help at that point. ATM, just wanted to make a brief note...
I think the example in this comment might be a counter-example: {:a 1 #?@(:clj [:b 2])}
;; =>
{:a 1, :b 2}Due to splicing of reader conditionals, one might say that there are an odd number of items in the map literal.
|
Ah, that’s a fair point, I missed the implication of that one.
🤞 |

When parsing map literals, it would be useful to group the subtree into k/v pairs. This would allow querying for the matching k/v pair, all keys, etc.
e.g. given a map literal:
{:foo "bar" :baz "quux" "tom" "jerry"}Instead of parsing to 6
values:Parse to 3
map_entrykey/valuepairs: