Skip to content
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

lexer: temporarily revert #\ patch; keep CR in comment bug fix #2984

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 1 addition & 63 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ sections:
* `-f filename` / `--from-file filename`:

Read filter from the file rather than from a command line, like
awk's -f option.
awk's -f option. You can also use '#' to make comments.

* `-L directory`:

Expand Down Expand Up @@ -3537,68 +3537,6 @@ sections:
(.posts[] | select(.author == "stedolan") | .comments) |=
. + ["terrible."]

- title: Comments

body: |

You can write comments in your jq filters using `#`.

A `#` character (not part of a string) starts a comment.
All characters from `#` to the end of the line are ignored.

If the end of the line is preceded by an odd number of backslash
characters, the following line is also considered part of the
comment and is ignored.

For example, the following code outputs `[1,3,4,7]`

[
1,
# foo \
2,
# bar \\
3,
4, # baz \\\
5, \
6,
7
# comment \
comment \
comment
]

Backslash continuing the comment on the next line can be useful
when writing the "shebang" for a jq script:

#!/bin/sh --
# sum - Output the sum of the given arguments (or stdin)
# usage: sum [numbers...]
# \
exec jq --args -MRnf "$0" -- "$@"

$ARGS.positional |
reduce (
if . == []
then inputs
else .[]
end |
. as $dot |
try tonumber catch false |
if not or isnan then
@json "sum: Invalid number \($dot).\n" | halt_error(1)
end
) as $n (0; . + $n)

The `exec` line is considered a comment by jq, so it is ignored.
But it is not ignored by `sh`, since in `sh` a backslash at the
end of the line does not continue the comment.
With this trick, when the script is invoked as `sum 1 2`,
`/bin/sh -- /path/to/sum 1 2` will be run, and `sh` will then
run `exec jq --args -MRnf /path/to/sum -- 1 2` replacing itself
with a `jq` interpreter invoked with the specified options (`-M`,
`-R`, `-n`, `--args`), that evaluates the current file (`$0`),
with the arguments (`$@`) that were passed to `sh`.

- title: Modules
body: |

Expand Down
70 changes: 1 addition & 69 deletions jq.1.prebuilt

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

Loading