Skip to content

Commit 5d95791

Browse files
authored
lexer: temporarily revert #\ patch; keep CR in comment bug fix
This commit temporarily reverts the commit that allows #\ "tcl-style" comments everywhere and documents them, for the 1.7.1 patch release cca1f7d. \r is removed from the list of characters not allowed in a comment to preserve that bugfix.
1 parent 511d50b commit 5d95791

File tree

7 files changed

+283
-444
lines changed

7 files changed

+283
-444
lines changed

docs/content/manual/manual.yml

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ sections:
229229
* `-f filename` / `--from-file filename`:
230230
231231
Read filter from the file rather than from a command line, like
232-
awk's -f option.
232+
awk's -f option. You can also use '#' to make comments.
233233
234234
* `-L directory`:
235235
@@ -3537,68 +3537,6 @@ sections:
35373537
(.posts[] | select(.author == "stedolan") | .comments) |=
35383538
. + ["terrible."]
35393539
3540-
- title: Comments
3541-
3542-
body: |
3543-
3544-
You can write comments in your jq filters using `#`.
3545-
3546-
A `#` character (not part of a string) starts a comment.
3547-
All characters from `#` to the end of the line are ignored.
3548-
3549-
If the end of the line is preceded by an odd number of backslash
3550-
characters, the following line is also considered part of the
3551-
comment and is ignored.
3552-
3553-
For example, the following code outputs `[1,3,4,7]`
3554-
3555-
[
3556-
1,
3557-
# foo \
3558-
2,
3559-
# bar \\
3560-
3,
3561-
4, # baz \\\
3562-
5, \
3563-
6,
3564-
7
3565-
# comment \
3566-
comment \
3567-
comment
3568-
]
3569-
3570-
Backslash continuing the comment on the next line can be useful
3571-
when writing the "shebang" for a jq script:
3572-
3573-
#!/bin/sh --
3574-
# sum - Output the sum of the given arguments (or stdin)
3575-
# usage: sum [numbers...]
3576-
# \
3577-
exec jq --args -MRnf "$0" -- "$@"
3578-
3579-
$ARGS.positional |
3580-
reduce (
3581-
if . == []
3582-
then inputs
3583-
else .[]
3584-
end |
3585-
. as $dot |
3586-
try tonumber catch false |
3587-
if not or isnan then
3588-
@json "sum: Invalid number \($dot).\n" | halt_error(1)
3589-
end
3590-
) as $n (0; . + $n)
3591-
3592-
The `exec` line is considered a comment by jq, so it is ignored.
3593-
But it is not ignored by `sh`, since in `sh` a backslash at the
3594-
end of the line does not continue the comment.
3595-
With this trick, when the script is invoked as `sum 1 2`,
3596-
`/bin/sh -- /path/to/sum 1 2` will be run, and `sh` will then
3597-
run `exec jq --args -MRnf /path/to/sum -- 1 2` replacing itself
3598-
with a `jq` interpreter invoked with the specified options (`-M`,
3599-
`-R`, `-n`, `--args`), that evaluates the current file (`$0`),
3600-
with the arguments (`$@`) that were passed to `sh`.
3601-
36023540
- title: Modules
36033541
body: |
36043542

jq.1.prebuilt

Lines changed: 1 addition & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)