Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This reverts commit 5d95791a6795bfc44380c2e6e343ee66dd891e8b.

authored by Emanuele Torre · committed by Nico Williams · parent f954e82 · Browse files · 7 files+435 added−274 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

7 files+435 added−274 removed

  • tests:+18 added−0 removed
  • other:+417 added−274 removed

7 files+435 added−274 removed

modified:docs/content/manual/manual.yml+63 added-1 removed
227 unmodified lines
228229 * `-f filename` / `--from-file filename`:230231 Read filter from the file rather than from a command line, like232 awk's -f option. You can also use '#' to make comments.232 awk's -f option.233234 * `-L directory`:235236 Prepend `directory` to the search list for modules. If this
3299 unmodified lines
35363537 (.posts[] | select(.author == "stedolan") | .comments) |=3538 . + ["terrible."]35393540 - title: Comments35413542 body: |35433544 You can write comments in your jq filters using `#`.35453546 A `#` character (not part of a string) starts a comment.3547 All characters from `#` to the end of the line are ignored.35483549 If the end of the line is preceded by an odd number of backslash3550 characters, the following line is also considered part of the3551 comment and is ignored.35523553 For example, the following code outputs `[1,3,4,7]`35543555 [3556 1,3557 # foo \3558 2,3559 # bar \\3560 3,3561 4, # baz \\\3562 5, \3563 6,3564 73565 # comment \3566 comment \3567 comment3568 ]35693570 Backslash continuing the comment on the next line can be useful3571 when writing the "shebang" for a jq script:35723573 #!/bin/sh --3574 # sum - Output the sum of the given arguments (or stdin)3575 # usage: sum [numbers...]3576 # \3577 exec jq --args -MRnf "$0" -- "$@"35783579 $ARGS.positional |3580 reduce (3581 if . == []3582 then inputs3583 else .[]3584 end |3585 . as $dot |3586 try tonumber catch false |3587 if not or isnan then3588 @json "sum: Invalid number \($dot).\n" | halt_error(1)3589 end3590 ) as $n (0; . + $n)35913592 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 the3594 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 then3597 run `exec jq --args -MRnf /path/to/sum -- 1 2` replacing itself3598 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`.36013602 - title: Modules3603 body: |36043605 jq has a library/module system. Modules are files whose names end
158 unmodified lines
modified:src/lexer.c+274 added-253 removed
571 unmodified lines
572 yyleng = (int) (yy_cp - yy_bp); \573 yyg->yy_hold_char = *yy_cp; \574 *yy_cp = '\0'; \575 yyg->yy_c_buf_p = yy_cp;576#define YY_NUM_RULES 51577#define YY_END_OF_BUFFER 52576#define YY_NUM_RULES 53577#define YY_END_OF_BUFFER 54578/* This struct is not used in this scanner,579 but its presence is necessary. */580struct yy_trans_info581 {582 flex_int32_t yy_verify;583 flex_int32_t yy_nxt;584 };585static const flex_int16_t yy_accept[163] =585static const flex_int16_t yy_accept[168] =586 { 0,587 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,588 0, 0, 52, 50, 49, 49, 50, 40, 1, 35,589 35, 36, 37, 35, 35, 35, 35, 35, 35, 39,590 35, 35, 35, 35, 50, 46, 46, 46, 46, 46,591 46, 46, 46, 46, 46, 46, 46, 46, 35, 44,592 44, 42, 45, 49, 2, 1, 48, 48, 29, 27,593 25, 26, 33, 39, 47, 18, 28, 39, 39, 0,594 31, 3, 32, 0, 38, 46, 0, 46, 4, 46,595 46, 46, 46, 46, 46, 9, 46, 46, 46, 46,596 14, 46, 46, 46, 24, 44, 43, 41, 43, 48,588 0, 0, 0, 0, 54, 52, 51, 51, 52, 42,589 1, 37, 37, 38, 39, 37, 37, 37, 37, 37,590 37, 41, 37, 37, 37, 37, 52, 48, 48, 48,591 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,592 37, 46, 46, 44, 47, 2, 3, 2, 51, 4,593 50, 50, 31, 29, 27, 28, 35, 41, 49, 20,594 30, 41, 41, 0, 33, 5, 34, 0, 40, 48,595 0, 48, 6, 48, 48, 48, 48, 48, 48, 11,596 48, 48, 48, 48, 16, 48, 48, 48, 26, 46,597598 0, 48, 47, 30, 39, 0, 39, 34, 0, 13,599 46, 46, 8, 46, 46, 15, 46, 46, 46, 46,600 46, 46, 46, 19, 0, 43, 0, 48, 46, 46,601 46, 12, 11, 46, 46, 46, 46, 46, 46, 10,602 43, 48, 22, 20, 46, 46, 46, 21, 46, 46,603 43, 48, 46, 5, 46, 7, 16, 48, 17, 6,604 23, 0598 45, 43, 45, 2, 50, 0, 50, 49, 32, 41,599 0, 41, 36, 0, 15, 48, 48, 10, 48, 48,600 17, 48, 48, 48, 48, 48, 48, 48, 21, 0,601 45, 0, 50, 48, 48, 48, 14, 13, 48, 48,602 48, 48, 48, 48, 12, 45, 50, 24, 22, 48,603 48, 48, 23, 48, 48, 45, 50, 48, 7, 48,604 9, 18, 50, 19, 8, 25, 0605 } ;606607static const YY_CHAR yy_ec[256] =608 { 0,
28 unmodified lines
637 } ;638639static const YY_CHAR yy_meta[53] =640 { 0,641 1, 1, 2, 1, 3, 1, 1, 1, 1, 1,642 1, 1, 1, 1, 4, 1, 5, 6, 1, 1,643 1, 1, 1, 1, 7, 7, 1, 8, 1, 9,644 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,645 7, 7, 7, 7, 7, 7, 7, 7, 7, 1,641 1, 1, 1, 1, 2, 1, 1, 1, 1, 1,642 1, 1, 1, 1, 3, 1, 4, 5, 1, 1,643 1, 1, 1, 1, 6, 6, 1, 7, 1, 8,644 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,645 6, 6, 6, 6, 6, 6, 6, 6, 6, 1,646 1, 1647 } ;648649static const flex_int16_t yy_base[178] =649static const flex_int16_t yy_base[183] =650 { 0,651 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,652 50, 51, 328, 329, 55, 57, 306, 329, 0, 296,653 304, 329, 329, 303, 302, 329, 301, 46, 46, 49,654 300, 299, 298, 302, 0, 299, 47, 50, 51, 52,655 54, 55, 63, 59, 58, 62, 53, 65, 295, 0,656 0, 329, 65, 83, 329, 0, 297, 73, 329, 329,657 329, 329, 329, 80, 0, 293, 329, 83, 97, 105,658 329, 329, 329, 297, 0, 292, 288, 74, 284, 93,659 98, 102, 103, 106, 107, 281, 109, 111, 115, 108,660 277, 112, 113, 116, 329, 0, 264, 329, 262, 269,652 50, 51, 54, 55, 331, 332, 57, 59, 309, 332,653 332, 299, 307, 332, 332, 306, 305, 332, 304, 48,654 48, 51, 303, 302, 301, 305, 0, 302, 49, 52,655 53, 54, 56, 57, 63, 62, 58, 67, 55, 69,656 298, 0, 0, 332, 79, 332, 332, 89, 100, 332,657 300, 89, 332, 332, 332, 332, 332, 94, 0, 296,658 332, 96, 106, 116, 332, 332, 332, 300, 0, 297,659 296, 76, 295, 90, 91, 98, 97, 106, 100, 294,660 108, 118, 121, 124, 293, 126, 119, 128, 332, 0,661662 255, 117, 0, 329, 133, 251, 247, 329, 0, 241,663 125, 118, 239, 119, 136, 236, 140, 121, 142, 143,664 144, 145, 148, 234, 158, 220, 0, 151, 221, 152,665 158, 208, 207, 154, 155, 156, 159, 161, 163, 206,666 195, 165, 203, 202, 169, 162, 171, 200, 168, 179,667 189, 189, 190, 198, 193, 197, 195, 192, 194, 170,668 166, 329, 228, 237, 240, 246, 251, 256, 265, 274,669 279, 284, 289, 291, 296, 300, 304662 282, 332, 281, 332, 288, 284, 129, 0, 332, 131,663 281, 278, 332, 0, 273, 131, 132, 270, 137, 141,664 268, 143, 138, 145, 149, 146, 150, 153, 265, 161,665 242, 0, 154, 247, 157, 156, 244, 239, 161, 162,666 164, 165, 168, 169, 237, 224, 170, 232, 228, 171,667 172, 181, 209, 182, 183, 196, 192, 188, 205, 193,668 203, 202, 196, 198, 195, 173, 332, 228, 236, 239,669 245, 250, 255, 263, 271, 276, 281, 286, 288, 293,670 297, 301671 } ;672672static const flex_int16_t yy_def[178] =673static const flex_int16_t yy_def[183] =674 { 0,674 162, 1, 1, 1, 1, 1, 1, 1, 1, 1,675 163, 163, 162, 162, 162, 162, 162, 162, 164, 165,676 162, 162, 162, 162, 162, 162, 162, 166, 162, 162,677 162, 162, 162, 162, 167, 168, 168, 168, 168, 168,678 168, 168, 168, 168, 168, 168, 168, 168, 162, 169,679 169, 162, 170, 162, 162, 164, 171, 171, 162, 162,680 162, 162, 162, 162, 172, 162, 162, 162, 162, 162,681 162, 162, 162, 162, 167, 168, 162, 168, 168, 168,682 168, 168, 168, 168, 168, 168, 168, 168, 168, 168,683 168, 168, 168, 168, 162, 169, 162, 162, 173, 171,675 167, 1, 1, 1, 1, 1, 1, 1, 1, 1,676 168, 168, 169, 169, 167, 167, 167, 167, 167, 167,677 167, 170, 167, 167, 167, 167, 167, 167, 167, 171,678 167, 167, 167, 167, 167, 167, 172, 173, 173, 173,679 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,680 167, 174, 174, 167, 175, 167, 167, 167, 167, 167,681 176, 176, 167, 167, 167, 167, 167, 167, 177, 167,682 167, 167, 167, 167, 167, 167, 167, 167, 172, 173,683 167, 173, 173, 173, 173, 173, 173, 173, 173, 173,684 173, 173, 173, 173, 173, 173, 173, 173, 167, 174,685685 162, 171, 172, 162, 162, 162, 162, 162, 174, 168,686 168, 168, 168, 168, 168, 168, 168, 168, 168, 168,687 168, 168, 168, 168, 170, 175, 165, 171, 168, 168,688 168, 168, 168, 168, 168, 168, 168, 168, 168, 168,689 176, 171, 168, 168, 168, 168, 168, 168, 168, 168,690 177, 171, 168, 168, 168, 168, 168, 171, 168, 168,691 171, 0, 162, 162, 162, 162, 162, 162, 162, 162,692 162, 162, 162, 162, 162, 162, 162686 167, 167, 178, 167, 176, 167, 176, 177, 167, 167,687 167, 167, 167, 179, 173, 173, 173, 173, 173, 173,688 173, 173, 173, 173, 173, 173, 173, 173, 173, 175,689 180, 170, 176, 173, 173, 173, 173, 173, 173, 173,690 173, 173, 173, 173, 173, 181, 176, 173, 173, 173,691 173, 173, 173, 173, 173, 182, 176, 173, 173, 173,692 173, 173, 176, 173, 173, 176, 0, 167, 167, 167,693 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,694 167, 167695 } ;696695static const flex_int16_t yy_nxt[382] =697static const flex_int16_t yy_nxt[385] =698 { 0,697 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,698 24, 25, 26, 27, 28, 29, 30, 26, 26, 31,699 32, 33, 34, 35, 36, 36, 22, 14, 23, 36,700 37, 38, 39, 40, 41, 42, 36, 43, 36, 44,701 45, 36, 46, 36, 47, 36, 48, 36, 36, 22,702 49, 23, 51, 51, 52, 52, 54, 54, 54, 54,703 63, 66, 64, 68, 77, 69, 67, 77, 77, 77,704 77, 77, 77, 98, 70, 77, 77, 53, 53, 77,705 77, 81, 77, 70, 54, 54, 82, 92, 78, 89,706 101, 77, 79, 83, 80, 84, 64, 85, 86, 105,699 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,700 26, 27, 28, 29, 30, 31, 32, 28, 28, 33,701 34, 35, 36, 37, 38, 38, 24, 16, 25, 38,702 39, 40, 41, 42, 43, 44, 38, 45, 38, 46,703 47, 38, 48, 38, 49, 38, 50, 38, 38, 24,704 51, 25, 53, 53, 54, 54, 57, 57, 59, 59,705 59, 59, 67, 70, 68, 72, 81, 73, 71, 81,706 81, 81, 81, 81, 81, 81, 74, 55, 55, 81,707 81, 58, 58, 85, 81, 74, 81, 102, 86, 96,708 82, 104, 93, 81, 83, 87, 84, 88, 90, 89,709708 90, 93, 102, 87, 88, 70, 91, 110, 70, 94,709 77, 68, 99, 69, 70, 77, 106, 70, 106, 77,710 77, 107, 70, 77, 77, 77, 77, 111, 77, 77,711 77, 70, 77, 77, 101, 77, 77, 113, 77, 116,712 114, 121, 77, 119, 112, 122, 120, 123, 115, 105,713 131, 117, 118, 77, 132, 130, 128, 77, 70, 77,714 77, 77, 77, 135, 124, 77, 162, 70, 101, 77,715 133, 77, 77, 77, 134, 77, 77, 137, 77, 77,716 77, 136, 101, 101, 145, 77, 77, 77, 77, 140,717 143, 138, 139, 142, 144, 150, 77, 152, 148, 146,710 94, 59, 59, 91, 92, 97, 106, 81, 81, 115,711 68, 95, 110, 98, 81, 81, 104, 81, 107, 74,712 72, 74, 73, 81, 116, 81, 103, 111, 74, 111,713 74, 74, 112, 118, 119, 81, 81, 117, 81, 121,714 74, 81, 120, 81, 122, 81, 106, 110, 81, 81,715 124, 123, 125, 128, 81, 81, 74, 126, 81, 127,716 81, 135, 81, 81, 136, 74, 81, 81, 133, 167,717 81, 106, 137, 81, 81, 138, 129, 139, 81, 81,718 140, 81, 81, 142, 141, 81, 81, 106, 81, 81,719 106, 150, 149, 143, 145, 148, 147, 144, 81, 81,720719 149, 153, 156, 147, 155, 99, 101, 77, 154, 101,720 77, 77, 77, 157, 77, 77, 125, 77, 158, 77,721 77, 161, 125, 77, 77, 77, 159, 160, 50, 50,722 50, 50, 50, 50, 50, 50, 50, 56, 77, 56,723 56, 56, 56, 56, 56, 56, 57, 125, 57, 65,724 65, 77, 65, 77, 65, 75, 77, 75, 77, 75,725 76, 76, 76, 107, 76, 96, 96, 107, 96, 96,726 96, 96, 127, 96, 97, 97, 97, 97, 97, 97,727 97, 97, 97, 100, 100, 100, 101, 100, 103, 125,728 103, 125, 103, 126, 77, 126, 126, 129, 77, 129,721 81, 155, 157, 158, 153, 81, 151, 154, 103, 106,722 81, 152, 81, 106, 160, 81, 161, 162, 159, 81,723 81, 163, 81, 130, 164, 166, 81, 165, 52, 52,724 52, 52, 52, 52, 52, 52, 56, 56, 56, 56,725 56, 56, 56, 56, 61, 81, 61, 69, 69, 81,726 69, 130, 69, 79, 81, 79, 81, 79, 80, 80,727 80, 81, 80, 100, 81, 100, 100, 100, 100, 130,728 100, 101, 101, 101, 101, 101, 101, 101, 101, 105,729 105, 105, 81, 105, 108, 81, 108, 81, 108, 131,730 81, 131, 131, 134, 112, 134, 146, 112, 146, 146,731730 141, 77, 141, 141, 151, 109, 151, 151, 97, 77,731 97, 97, 108, 104, 101, 95, 77, 74, 73, 72,732 71, 62, 61, 60, 59, 58, 55, 162, 13, 162,733 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,734 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,735 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,736 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,737 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,738 162732 156, 132, 156, 156, 101, 106, 101, 101, 130, 130,733 81, 81, 81, 114, 81, 113, 109, 106, 99, 81,734 78, 77, 76, 75, 66, 65, 64, 63, 62, 60,735 167, 15, 167, 167, 167, 167, 167, 167, 167, 167,736 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,737 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,738 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,739 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,740 167, 167, 167, 167741 } ;742741static const flex_int16_t yy_chk[382] =743static const flex_int16_t yy_chk[385] =744 { 0,745 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,746 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,747 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,748 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,749 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,748 1, 1, 11, 12, 11, 12, 15, 15, 16, 16,749 28, 29, 28, 30, 37, 30, 29, 38, 39, 40,750 47, 41, 42, 53, 30, 45, 44, 11, 12, 46,751 43, 39, 48, 30, 54, 54, 40, 47, 37, 44,752 58, 78, 37, 41, 38, 41, 64, 42, 43, 68,750 1, 1, 11, 12, 11, 12, 13, 14, 17, 17,751 18, 18, 30, 31, 30, 32, 39, 32, 31, 40,752 41, 42, 49, 43, 44, 47, 32, 11, 12, 46,753 45, 13, 14, 41, 48, 32, 50, 55, 42, 49,754 39, 58, 46, 82, 39, 43, 40, 43, 45, 44,755754 45, 48, 58, 43, 43, 64, 46, 78, 68, 48,755 80, 69, 53, 69, 64, 81, 70, 68, 70, 82,756 83, 70, 69, 84, 85, 90, 87, 80, 88, 92,757 93, 69, 89, 94, 102, 112, 114, 82, 118, 84,758 83, 90, 111, 88, 81, 92, 89, 93, 83, 105,759 112, 85, 87, 115, 114, 111, 102, 117, 105, 119,760 120, 121, 122, 118, 94, 123, 125, 105, 128, 130,761 115, 134, 135, 136, 117, 131, 137, 120, 138, 146,762 139, 119, 142, 161, 134, 149, 145, 160, 147, 123,763 130, 121, 122, 128, 131, 139, 150, 142, 137, 135,756 47, 59, 59, 45, 45, 50, 62, 84, 85, 82,757 68, 48, 72, 50, 87, 86, 58, 89, 62, 68,758 73, 72, 73, 88, 84, 91, 55, 74, 68, 74,759 72, 73, 74, 86, 87, 92, 97, 85, 93, 88,760 73, 94, 87, 96, 89, 98, 107, 110, 116, 117,761 92, 91, 93, 97, 119, 123, 110, 94, 120, 96,762 122, 116, 124, 126, 117, 110, 125, 127, 107, 130,763 128, 133, 119, 136, 135, 120, 98, 122, 139, 140,764 123, 141, 142, 125, 124, 143, 144, 147, 150, 151,765 166, 139, 136, 126, 128, 135, 133, 127, 152, 154,766765 138, 145, 149, 136, 147, 125, 152, 153, 146, 158,766 155, 159, 157, 150, 156, 154, 151, 148, 152, 144,767 143, 158, 141, 140, 133, 132, 153, 155, 163, 163,768 163, 163, 163, 163, 163, 163, 163, 164, 129, 164,769 164, 164, 164, 164, 164, 164, 165, 126, 165, 166,770 166, 124, 166, 116, 166, 167, 113, 167, 110, 167,771 168, 168, 168, 107, 168, 169, 169, 106, 169, 169,772 169, 169, 101, 169, 170, 170, 170, 170, 170, 170,773 170, 170, 170, 171, 171, 171, 100, 171, 172, 99,774 172, 97, 172, 173, 91, 173, 173, 174, 86, 174,767 155, 144, 147, 150, 142, 158, 140, 143, 130, 157,768 160, 141, 165, 163, 152, 164, 154, 155, 151, 162,769 161, 157, 159, 156, 158, 163, 153, 160, 168, 168,770 168, 168, 168, 168, 168, 168, 169, 169, 169, 169,771 169, 169, 169, 169, 170, 149, 170, 171, 171, 148,772 171, 146, 171, 172, 145, 172, 138, 172, 173, 173,773 173, 137, 173, 174, 134, 174, 174, 174, 174, 131,774 174, 175, 175, 175, 175, 175, 175, 175, 175, 176,775 176, 176, 129, 176, 177, 121, 177, 118, 177, 178,776 115, 178, 178, 179, 112, 179, 180, 111, 180, 180,777776 175, 79, 175, 175, 176, 77, 176, 176, 177, 76,777 177, 177, 74, 66, 57, 49, 36, 34, 33, 32,778 31, 27, 25, 24, 21, 20, 17, 13, 162, 162,779 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,780 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,781 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,782 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,783 162, 162, 162, 162, 162, 162, 162, 162, 162, 162,784 162778 181, 106, 181, 181, 182, 105, 182, 182, 103, 101,779 95, 90, 83, 81, 80, 78, 70, 61, 51, 38,780 36, 35, 34, 33, 29, 27, 26, 23, 22, 19,781 15, 167, 167, 167, 167, 167, 167, 167, 167, 167,782 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,783 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,784 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,785 167, 167, 167, 167, 167, 167, 167, 167, 167, 167,786 167, 167, 167, 167787 } ;788789/* The intent behind this definition is that it'll catch790 * any uses of REJECT which flex missed.
18 unmodified lines
809 yylloc->end = yylloc->start + yyleng; \810 yyset_extra(yylloc->end, yyscanner); \811 } while (0);812811#line 811 "src/lexer.c"813#line 813 "src/lexer.c"814813#line 25 "src/lexer.l"815#line 26 "src/lexer.l"816 static int enter(int opening, int state, yyscan_t yyscanner);817 static int try_exit(int closing, int state, yyscan_t yyscanner);816#line 816 "src/lexer.c"817#define YY_NO_INPUT 1818#line 818 "src/lexer.c"819#define YY_NO_INPUT 1820#line 820 "src/lexer.c"821822#define INITIAL 0823#define IN_PAREN 1824#define IN_BRACKET 2825#define IN_BRACE 3826#define IN_QQINTERP 4827#define IN_QQSTRING 5828#define IN_COMMENT 6829830#ifndef YY_NO_UNISTD_H831/* Special case for "unistd.h", since it is non-ANSI. We include it way832 * down here because we want the user's section 1 to have been scanned first.
275 unmodified lines
1108 yy_load_buffer_state( yyscanner );1109 }11101111 {1109#line 38 "src/lexer.l"1112#line 39 "src/lexer.l"111311141112#line 1112 "src/lexer.c"1115#line 1115 "src/lexer.c"11161117 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */1118 {1119 yy_cp = yyg->yy_c_buf_p;
18 unmodified lines
1138 }1139 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )1140 {1141 yy_current_state = (int) yy_def[yy_current_state];1139 if ( yy_current_state >= 163 )1142 if ( yy_current_state >= 168 )1143 yy_c = yy_meta[yy_c];1144 }1145 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];1146 ++yy_cp;1147 }1145 while ( yy_base[yy_current_state] != 329 );1148 while ( yy_base[yy_current_state] != 332 );11491150yy_find_action:1151 yy_act = yy_accept[yy_current_state];1152 if ( yy_act == 0 )
17 unmodified lines
1170 goto yy_find_action;11711172case 1:1173YY_RULE_SETUP1171#line 40 "src/lexer.l"1172{ /* comments */ }1174#line 41 "src/lexer.l"1175{ yy_push_state(IN_COMMENT, yyscanner); }1176 YY_BREAK11771178case 2:1179/* rule 2 can match eol */1180YY_RULE_SETUP1176#line 42 "src/lexer.l"1177{ return NEQ; }1181#line 43 "src/lexer.l"1182{ }1183 YY_BREAK1184case 3:1185/* rule 3 can match eol */1186YY_RULE_SETUP1181#line 43 "src/lexer.l"1182{ return EQ; }1187#line 44 "src/lexer.l"1188{ yy_pop_state(yyscanner); }1189 YY_BREAK11901191case YY_STATE_EOF(IN_COMMENT):1192#line 46 "src/lexer.l"1193{ yy_pop_state(yyscanner); }1194 YY_BREAK1195case 4:1196YY_RULE_SETUP1186#line 44 "src/lexer.l"1187{ return AS; }1197#line 48 "src/lexer.l"1198{ return NEQ; }1199 YY_BREAK1200case 5:1201YY_RULE_SETUP1191#line 45 "src/lexer.l"1192{ return IMPORT; }1202#line 49 "src/lexer.l"1203{ return EQ; }1204 YY_BREAK1205case 6:1206YY_RULE_SETUP1196#line 46 "src/lexer.l"1197{ return INCLUDE; }1207#line 50 "src/lexer.l"1208{ return AS; }1209 YY_BREAK1210case 7:1211YY_RULE_SETUP1201#line 47 "src/lexer.l"1202{ return MODULE; }1212#line 51 "src/lexer.l"1213{ return IMPORT; }1214 YY_BREAK1215case 8:1216YY_RULE_SETUP1206#line 48 "src/lexer.l"1207{ return DEF; }1217#line 52 "src/lexer.l"1218{ return INCLUDE; }1219 YY_BREAK1220case 9:1221YY_RULE_SETUP1211#line 49 "src/lexer.l"1212{ return IF; }1222#line 53 "src/lexer.l"1223{ return MODULE; }1224 YY_BREAK1225case 10:1226YY_RULE_SETUP1216#line 50 "src/lexer.l"1217{ return THEN; }1227#line 54 "src/lexer.l"1228{ return DEF; }1229 YY_BREAK1230case 11:1231YY_RULE_SETUP1221#line 51 "src/lexer.l"1222{ return ELSE; }1232#line 55 "src/lexer.l"1233{ return IF; }1234 YY_BREAK1235case 12:1236YY_RULE_SETUP1226#line 52 "src/lexer.l"1227{ return ELSE_IF; }1237#line 56 "src/lexer.l"1238{ return THEN; }1239 YY_BREAK1240case 13:1241YY_RULE_SETUP1231#line 53 "src/lexer.l"1232{ return AND; }1242#line 57 "src/lexer.l"1243{ return ELSE; }1244 YY_BREAK1245case 14:1246YY_RULE_SETUP1236#line 54 "src/lexer.l"1237{ return OR; }1247#line 58 "src/lexer.l"1248{ return ELSE_IF; }1249 YY_BREAK1250case 15:1251YY_RULE_SETUP1241#line 55 "src/lexer.l"1242{ return END; }1252#line 59 "src/lexer.l"1253{ return AND; }1254 YY_BREAK1255case 16:1256YY_RULE_SETUP1246#line 56 "src/lexer.l"1247{ return REDUCE; }1257#line 60 "src/lexer.l"1258{ return OR; }1259 YY_BREAK1260case 17:1261YY_RULE_SETUP1251#line 57 "src/lexer.l"1252{ return FOREACH; }1262#line 61 "src/lexer.l"1263{ return END; }1264 YY_BREAK1265case 18:1266YY_RULE_SETUP1256#line 58 "src/lexer.l"1257{ return DEFINEDOR; }1267#line 62 "src/lexer.l"1268{ return REDUCE; }1269 YY_BREAK1270case 19:1271YY_RULE_SETUP1261#line 59 "src/lexer.l"1262{ return TRY; }1272#line 63 "src/lexer.l"1273{ return FOREACH; }1274 YY_BREAK1275case 20:1276YY_RULE_SETUP1266#line 60 "src/lexer.l"1267{ return CATCH; }1277#line 64 "src/lexer.l"1278{ return DEFINEDOR; }1279 YY_BREAK1280case 21:1281YY_RULE_SETUP1271#line 61 "src/lexer.l"1272{ return LABEL; }1282#line 65 "src/lexer.l"1283{ return TRY; }1284 YY_BREAK1285case 22:1286YY_RULE_SETUP1276#line 62 "src/lexer.l"1277{ return BREAK; }1287#line 66 "src/lexer.l"1288{ return CATCH; }1289 YY_BREAK1290case 23:1291YY_RULE_SETUP1281#line 63 "src/lexer.l"1282{ return LOC; }1292#line 67 "src/lexer.l"1293{ return LABEL; }1294 YY_BREAK1295case 24:1296YY_RULE_SETUP1286#line 64 "src/lexer.l"1287{ return SETPIPE; }1297#line 68 "src/lexer.l"1298{ return BREAK; }1299 YY_BREAK1300case 25:1301YY_RULE_SETUP1291#line 65 "src/lexer.l"1292{ return SETPLUS; }1302#line 69 "src/lexer.l"1303{ return LOC; }1304 YY_BREAK1305case 26:1306YY_RULE_SETUP1296#line 66 "src/lexer.l"1297{ return SETMINUS; }1307#line 70 "src/lexer.l"1308{ return SETPIPE; }1309 YY_BREAK1310case 27:1311YY_RULE_SETUP1301#line 67 "src/lexer.l"1302{ return SETMULT; }1312#line 71 "src/lexer.l"1313{ return SETPLUS; }1314 YY_BREAK1315case 28:1316YY_RULE_SETUP1306#line 68 "src/lexer.l"1307{ return SETDIV; }1317#line 72 "src/lexer.l"1318{ return SETMINUS; }1319 YY_BREAK1320case 29:1321YY_RULE_SETUP1311#line 69 "src/lexer.l"1312{ return SETMOD; }1322#line 73 "src/lexer.l"1323{ return SETMULT; }1324 YY_BREAK1325case 30:1326YY_RULE_SETUP1316#line 70 "src/lexer.l"1317{ return SETDEFINEDOR; }1327#line 74 "src/lexer.l"1328{ return SETDIV; }1329 YY_BREAK1330case 31:1331YY_RULE_SETUP1321#line 71 "src/lexer.l"1322{ return LESSEQ; }1332#line 75 "src/lexer.l"1333{ return SETMOD; }1334 YY_BREAK1335case 32:1336YY_RULE_SETUP1326#line 72 "src/lexer.l"1327{ return GREATEREQ; }1337#line 76 "src/lexer.l"1338{ return SETDEFINEDOR; }1339 YY_BREAK1340case 33:1341YY_RULE_SETUP1331#line 73 "src/lexer.l"1332{ return REC; }1342#line 77 "src/lexer.l"1343{ return LESSEQ; }1344 YY_BREAK1345case 34:1346YY_RULE_SETUP1336#line 74 "src/lexer.l"1337{ return ALTERNATION; }1347#line 78 "src/lexer.l"1348{ return GREATEREQ; }1349 YY_BREAK1350case 35:1351YY_RULE_SETUP1341#line 75 "src/lexer.l"1342{ return yytext[0];}1352#line 79 "src/lexer.l"1353{ return REC; }1354 YY_BREAK1355case 36:1356YY_RULE_SETUP1346#line 77 "src/lexer.l"1357#line 80 "src/lexer.l"1358{ return ALTERNATION; }1359 YY_BREAK1360case 37:1361YY_RULE_SETUP1362#line 81 "src/lexer.l"1363{ return yytext[0];}1364 YY_BREAK1365case 38:1366YY_RULE_SETUP1367#line 83 "src/lexer.l"1368{1369 return enter(yytext[0], YY_START, yyscanner);1370}1371 YY_BREAK1351case 37:1372case 39:1373YY_RULE_SETUP1353#line 81 "src/lexer.l"1374#line 87 "src/lexer.l"1375{1376 return try_exit(yytext[0], YY_START, yyscanner);1377}1378 YY_BREAK1358case 38:1379case 40:1380YY_RULE_SETUP1360#line 85 "src/lexer.l"1381#line 91 "src/lexer.l"1382{1383 yylval->literal = jv_string_sized(yytext + 1, yyleng - 1); return FORMAT;1384}1385 YY_BREAK1365case 39:1386case 41:1387YY_RULE_SETUP1367#line 89 "src/lexer.l"1388#line 95 "src/lexer.l"1389{1390 yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;1391}1392 YY_BREAK1372case 40:1393case 42:1394YY_RULE_SETUP1374#line 93 "src/lexer.l"1395#line 99 "src/lexer.l"1396{1397 yy_push_state(IN_QQSTRING, yyscanner);1398 return QQSTRING_START;1399}1400 YY_BREAK14011381case 41:1402case 43:1403YY_RULE_SETUP1383#line 99 "src/lexer.l"1404#line 105 "src/lexer.l"1405{1406 return enter(QQSTRING_INTERP_START, YY_START, yyscanner);1407 }1408 YY_BREAK1388case 42:1409case 44:1410YY_RULE_SETUP1390#line 102 "src/lexer.l"1411#line 108 "src/lexer.l"1412{1413 yy_pop_state(yyscanner);1414 return QQSTRING_END;1415 }1416 YY_BREAK1396case 43:1397/* rule 43 can match eol */1417case 45:1418/* rule 45 can match eol */1419YY_RULE_SETUP1399#line 106 "src/lexer.l"1420#line 112 "src/lexer.l"1421{1422 /* pass escapes to the json parser */1423 jv escapes = jv_string_fmt("\"%.*s\"", (int)yyleng, yytext);1424 yylval->literal = jv_parse_sized(jv_string_value(escapes), jv_string_length_bytes(jv_copy(escapes)));1425 jv_free(escapes);1426 return QQSTRING_TEXT;1427 }1428 YY_BREAK1408case 44:1409/* rule 44 can match eol */1429case 46:1430/* rule 46 can match eol */1431YY_RULE_SETUP1411#line 113 "src/lexer.l"1432#line 119 "src/lexer.l"1433{1434 yylval->literal = jv_string_sized(yytext, yyleng);1435 return QQSTRING_TEXT;1436 }1437 YY_BREAK1417case 45:1438case 47:1439YY_RULE_SETUP1419#line 117 "src/lexer.l"1440#line 123 "src/lexer.l"1441{1442 return INVALID_CHARACTER;1443 }1444 YY_BREAK14451425case 46:1446case 48:1447YY_RULE_SETUP1427#line 123 "src/lexer.l"1448#line 129 "src/lexer.l"1449{ yylval->literal = jv_string(yytext); return IDENT;}1450 YY_BREAK1430case 47:1451case 49:1452YY_RULE_SETUP1432#line 124 "src/lexer.l"1453#line 130 "src/lexer.l"1454{ yylval->literal = jv_string(yytext+1); return FIELD;}1455 YY_BREAK1435case 48:1456case 50:1457YY_RULE_SETUP1437#line 125 "src/lexer.l"1458#line 131 "src/lexer.l"1459{ yylval->literal = jv_string(yytext+1); return BINDING;}1460 YY_BREAK1440case 49:1441/* rule 49 can match eol */1461case 51:1462/* rule 51 can match eol */1463YY_RULE_SETUP1443#line 127 "src/lexer.l"1464#line 133 "src/lexer.l"1465{}1466 YY_BREAK1446case 50:1467case 52:1468YY_RULE_SETUP1448#line 129 "src/lexer.l"1469#line 135 "src/lexer.l"1470{ return INVALID_CHARACTER; }1471 YY_BREAK1451case 51:1472case 53:1473YY_RULE_SETUP1453#line 131 "src/lexer.l"1474#line 137 "src/lexer.l"1475YY_FATAL_ERROR( "flex scanner jammed" );1476 YY_BREAK1456#line 1456 "src/lexer.c"1477#line 1477 "src/lexer.c"1478case YY_STATE_EOF(INITIAL):1479case YY_STATE_EOF(IN_PAREN):1480case YY_STATE_EOF(IN_BRACKET):1481case YY_STATE_EOF(IN_BRACE):
295 unmodified lines
1777 }1778 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )1779 {1780 yy_current_state = (int) yy_def[yy_current_state];1760 if ( yy_current_state >= 163 )1781 if ( yy_current_state >= 168 )1782 yy_c = yy_meta[yy_c];1783 }1784 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];1785 }
20 unmodified lines
1806 }1807 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )1808 {1809 yy_current_state = (int) yy_def[yy_current_state];1789 if ( yy_current_state >= 163 )1810 if ( yy_current_state >= 168 )1811 yy_c = yy_meta[yy_c];1812 }1813 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];1793 yy_is_jam = (yy_current_state == 162);1814 yy_is_jam = (yy_current_state == 167);18151816 (void)yyg;1817 return yy_is_jam ? 0 : yy_current_state;1818}
826 unmodified lines
2645#endif26462647#define YYTABLES_NAME "yytables"26482628#line 131 "src/lexer.l"2649#line 137 "src/lexer.l"26502651/* perhaps these should be calls... */2652/*2653"true" { return TRUE; }
53 unmodified lines
modified:src/lexer.h+3 added-2 removed
460 unmodified lines
461#define IN_BRACKET 2462#define IN_BRACE 3463#define IN_QQINTERP 4464#define IN_QQSTRING 5465#define IN_COMMENT 6466467#endif468469#ifndef YY_NO_UNISTD_H
261 unmodified lines
731#ifndef jq_yyTABLES_NAME_ALREADY_DEFINED732#undef yyTABLES_NAME733#endif734734#line 131 "src/lexer.l"735#line 137 "src/lexer.l"736737737#line 737 "src/lexer.h"738#line 738 "src/lexer.h"739#undef jq_yyIN_HEADER740#endif /* jq_yyHEADER_H */
modified:src/lexer.l+7 added-1 removed
19 unmodified lines
20%s IN_BRACKET21%s IN_BRACE22%s IN_QQINTERP23%x IN_QQSTRING24%x IN_COMMENT25%{26 static int enter(int opening, int state, yyscan_t yyscanner);27 static int try_exit(int closing, int state, yyscan_t yyscanner);28%}
8 unmodified lines
373839%%4040"#"[^\n]* { /* comments */ }41"#" { yy_push_state(IN_COMMENT, yyscanner); }42<IN_COMMENT>{43 \\[\\\n]|. { }44 \n { yy_pop_state(yyscanner); }45}46<IN_COMMENT><<EOF>> { yy_pop_state(yyscanner); }4748"!=" { return NEQ; }49"==" { return EQ; }50"as" { return AS; }
142 unmodified lines
modified:src/main.c+1 added-16 removed
176 unmodified lines
177};178#define jq_exit_with_status(r) exit(abs(r))179#define jq_exit(r) exit( r > 0 ? r : 0 )180181static const char *skip_shebang(const char *p) {182 if (strncmp(p, "#!", sizeof("#!") - 1) != 0)183 return p;184 const char *n = strchr(p, '\n');185 if (n == NULL || n[1] != '#')186 return p;187 n = strchr(n + 1, '\n');188 if (n == NULL || n[1] == '#' || n[1] == '\0' || n[-1] != '\\' || n[-2] == '\\')189 return p;190 n = strchr(n + 1, '\n');191 if (n == NULL)192 return p;193 return n+1;194}195181static int process(jq_state *jq, jv value, int flags, int dumpopts, int options) {182 int ret = JQ_OK_NO_OUTPUT; // No valid results && -e -> exit(4)183 jq_start(jq, value, flags);184 jv result;
484 unmodified lines
669 if (!jv_object_has(jv_copy(program_arguments), jv_string("JQ_BUILD_CONFIGURATION")))670 program_arguments = jv_object_set(program_arguments,671 jv_string("JQ_BUILD_CONFIGURATION"),672 jv_string(JQ_CONFIG)); /* named arguments */688 compiled = jq_compile_args(jq, skip_shebang(jv_string_value(data)), jv_copy(program_arguments));673 compiled = jq_compile_args(jq, jv_string_value(data), jv_copy(program_arguments));674 free(program_origin);675 jv_free(data);676 } else {677 jq_set_attr(jq, jv_string("PROGRAM_ORIGIN"), jq_realpath(jv_string("."))); // XXX is this good?
95 unmodified lines
modified:tests/shtest+18 added
592 unmodified lines
593 echo 'regression: carriage return terminates comment'594 exit 1595fi596597if ! x=$($JQ -cn '[598 1,599 # foo \600 2,601 # bar \\602 3,603 4, # baz \\\604 5, \605 6,606 7607 # comment \608 comment \609 comment610]') || [ "$x" != '[1,3,4,7]' ]; then611 echo 'multiline comment was not handled correctly'612 exit 1613fi614615# CVE-2023-50268: No stack overflow comparing a nan with a large payload616$VALGRIND $Q $JQ '1 != .' <<\EOF >/dev/null617Nan4000618EOF
17 unmodified lines
modified:jq.1.prebuilt+69 added-1 removed
164 unmodified lines
165.TP166\fB\-f filename\fR / \fB\-\-from\-file filename\fR:167.168.IP169Read filter from the file rather than from a command line, like awk\'s \-f option\. You can also use \'#\' to make comments\.169Read filter from the file rather than from a command line, like awk\'s \-f option\.170.171.TP172\fB\-L directory\fR:173.
3780 unmodified lines
3954.fi3955.3956.IP "" 03957.3958.SH "COMMENTS"3959You can write comments in your jq filters using \fB#\fR\.3960.3961.P3962A \fB#\fR character (not part of a string) starts a comment\. All characters from \fB#\fR to the end of the line are ignored\.3963.3964.P3965If 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\.3966.3967.P3968For example, the following code outputs \fB[1,3,4,7]\fR3969.3970.IP "" 43971.3972.nf39733974[3975 1,3976 # foo \e3977 2,3978 # bar \e\e3979 3,3980 4, # baz \e\e\e3981 5, \e3982 6,3983 73984 # comment \e3985 comment \e3986 comment3987]3988.3989.fi3990.3991.IP "" 03992.3993.P3994Backslash continuing the comment on the next line can be useful when writing the "shebang" for a jq script:3995.3996.IP "" 43997.3998.nf39994000#!/bin/sh \-\-4001# sum \- Output the sum of the given arguments (or stdin)4002# usage: sum [numbers\.\.\.]4003# \e4004exec jq \-\-args \-MRnf "$0" \-\- "$@"40054006$ARGS\.positional |4007reduce (4008 if \. == []4009 then inputs4010 else \.[]4011 end |4012 \. as $dot |4013 try tonumber catch false |4014 if not or isnan then4015 @json "sum: Invalid number \e($dot)\.\en" | halt_error(1)4016 end4017) as $n (0; \. + $n)4018.4019.fi4020.4021.IP "" 04022.4023.P4024The \fBexec\fR line is considered a comment by jq, so it is ignored\. But it is not ignored by \fBsh\fR, since in \fBsh\fR a backslash at the end of the line does not continue the comment\. With this trick, when the script is invoked as \fBsum 1 2\fR, \fB/bin/sh \-\- /path/to/sum 1 2\fR will be run, and \fBsh\fR will then run \fBexec jq \-\-args \-MRnf /path/to/sum \-\- 1 2\fR replacing itself with a \fBjq\fR interpreter invoked with the specified options (\fB\-M\fR, \fB\-R\fR, \fB\-n\fR, \fB\-\-args\fR), that evaluates the current file (\fB$0\fR), with the arguments (\fB$@\fR) that were passed to \fBsh\fR\.4025.4026.SH "MODULES"4027jq has a library/module system\. Modules are files whose names end in \fB\.jq\fR\.4028.4029.P
170 unmodified lines