feat: allow user-defined string formats (close #1227)#3230
feat: allow user-defined string formats (close #1227)#3230itchyny wants to merge 1 commit intojqlang:masterfrom
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 |
1927a30 to
bfb3ba5
Compare
This commit extends the "def" syntax to define string formats.
By writing
def @foo: ...;,@foostring format is availablein the following query. This idea is influenced by jaq. Close #1227.