Skip to content

Commit

Permalink
feat: allow user-defined string formats (close jqlang#1227)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
itchyny committed Jan 20, 2025
1 parent 588ff18 commit 562cc8a
Show file tree
Hide file tree
Showing 11 changed files with 1,256 additions and 1,169 deletions.
11 changes: 11 additions & 0 deletions docs/content/manual/dev/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,13 @@ sections:
Note that the slashes, question mark, etc. in the URL are
not escaped, as they were part of the string literal.
You can also define custom string formats using "def" syntax,
just like defining functions.
def @foo: gsub("a+"; ".");
Unlike functions, string formats cannot take arguments.
examples:
- program: '@html'
input: '"This works if x < y"'
Expand All @@ -2212,6 +2219,10 @@ sections:
input: '"VGhpcyBpcyBhIG1lc3NhZ2U="'
output: ['"This is a message"']

- program: 'def @foo: gsub("a+"; "."); @foo, @foo "a \(.) \(. + .) a"'
input: '"aba"'
output: ['".b."', '"a .b. .b.b. a"']

- title: "Dates"
body: |
Expand Down
22 changes: 21 additions & 1 deletion jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 562cc8a

Please sign in to comment.