-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat: allow user-defined string formats (close #1227) #3230
base: master
Are you sure you want to change the base?
Conversation
This commit extends the "def" syntax to define string formats. By writing `def @foo: ...;`, `@foo` string format is available in the following query. This idea is influenced by jaq.
2148f37
to
b86e734
Compare
7e6217a
to
562cc8a
Compare
Thank you. This is a language change. Any thoughts from other maintainers? |
@itchyny wrote:
Thanks for the opportunity to ask what backward-compatibility issue this change entails. My main question (posed purely out of ignorance) is whether the ability to use the |
How about instead redefining the $ "world" | @ascii_upcase "hello \(.)"
"hello WORLD" Note how |
Since existing string formatters are named to represent the resulting string (e.g. HTML string, URI string, etc.), I think it is better to have a different namespace from the 0-arity filters. Also, they are limited in the type they output and jq doesn't check typing statically, so the syntactic sugar for invoking the 0-arity filter would allow queries that wouldn't actually work. |
I don't think this argument holds up - it's just as possible to define a And if there were some way to statically analyze a
I agree that adding Is this really the best way to solve the namespace pollution problem? For example, one possible alternative would be to have the |
@myaaaaaaaaa String formatters can be called without strings ( |
I think the most consistent approach would be to redefine |
This commit extends the "def" syntax to define string formats.
By writing
def @foo: ...;
,@foo
string format is availablein the following query. This idea is influenced by jaq. Close #1227.