Skip to content
Myr

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 commit temporarily reverts the commit that allows #\ "tcl-style" comments everywhere and documents them, for the 1.7.1 patch release cca1f7d18f2fa6721952645821ae429a0166d7e4. \r is removed from the list of characters not allowed in a comment to preserve that bugfix.

authored by Emanuele Torre · committed by GitHub · parent 511d50b · Browse files · 7 files+274 added−435 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+274 added−435 removed

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

7 files+274 added−435 removed

modified:docs/content/manual/manual.yml+1 added-63 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.232 awk's -f option. You can also use '#' to make comments.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`.36013540 - title: Modules3541 body: |35423543 jq has a library/module system. Modules are files whose names end
158 unmodified lines
modified:src/lexer.c+253 added-274 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 53577#define YY_END_OF_BUFFER 54576#define YY_NUM_RULES 51577#define YY_END_OF_BUFFER 52578/* 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[168] =585static const flex_int16_t yy_accept[163] =586 { 0,587 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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,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,597598 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, 0598 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, 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, 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,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,646 1, 1647 } ;648649static const flex_int16_t yy_base[183] =649static const flex_int16_t yy_base[178] =650 { 0,651 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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,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,661662 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, 301662 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, 304670 } ;671673static const flex_int16_t yy_def[183] =672static const flex_int16_t yy_def[178] =673 { 0,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,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,684686 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, 167685 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, 162693 } ;694697static const flex_int16_t yy_nxt[385] =695static const flex_int16_t yy_nxt[382] =696 { 0,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,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,707710 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,708 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,718721 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,719 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,729732 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, 167730 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 162739 } ;740743static const flex_int16_t yy_chk[385] =741static const flex_int16_t yy_chk[382] =742 { 0,743 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,744 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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,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,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,753756 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,754 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,764767 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,765 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,775778 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, 167776 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 162785 } ;786787/* The intent behind this definition is that it'll catch788 * any uses of REJECT which flex missed.
18 unmodified lines
807 yylloc->end = yylloc->start + yyleng; \808 yyset_extra(yylloc->end, yyscanner); \809 } while (0);810813#line 813 "src/lexer.c"811#line 811 "src/lexer.c"812815#line 26 "src/lexer.l"813#line 25 "src/lexer.l"814 static int enter(int opening, int state, yyscan_t yyscanner);815 static int try_exit(int closing, int state, yyscan_t yyscanner);818#line 818 "src/lexer.c"816#line 816 "src/lexer.c"817#define YY_NO_INPUT 1820#line 820 "src/lexer.c"818#line 818 "src/lexer.c"819820#define INITIAL 0821#define IN_PAREN 1822#define IN_BRACKET 2823#define IN_BRACE 3824#define IN_QQINTERP 4825#define IN_QQSTRING 5828#define IN_COMMENT 6826827#ifndef YY_NO_UNISTD_H828/* Special case for "unistd.h", since it is non-ANSI. We include it way829 * down here because we want the user's section 1 to have been scanned first.
275 unmodified lines
1105 yy_load_buffer_state( yyscanner );1106 }11071108 {1112#line 39 "src/lexer.l"1109#line 38 "src/lexer.l"111011111115#line 1115 "src/lexer.c"1112#line 1112 "src/lexer.c"11131114 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */1115 {1116 yy_cp = yyg->yy_c_buf_p;
18 unmodified lines
1135 }1136 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )1137 {1138 yy_current_state = (int) yy_def[yy_current_state];1142 if ( yy_current_state >= 168 )1139 if ( yy_current_state >= 163 )1140 yy_c = yy_meta[yy_c];1141 }1142 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];1143 ++yy_cp;1144 }1148 while ( yy_base[yy_current_state] != 332 );1145 while ( yy_base[yy_current_state] != 329 );11461147yy_find_action:1148 yy_act = yy_accept[yy_current_state];1149 if ( yy_act == 0 )
17 unmodified lines
1167 goto yy_find_action;11681169case 1:1170YY_RULE_SETUP1174#line 41 "src/lexer.l"1175{ yy_push_state(IN_COMMENT, yyscanner); }1171#line 40 "src/lexer.l"1172{ /* comments */ }1173 YY_BREAK11771174case 2:1179/* rule 2 can match eol */1175YY_RULE_SETUP1181#line 43 "src/lexer.l"1182{ }1176#line 42 "src/lexer.l"1177{ return NEQ; }1178 YY_BREAK1179case 3:1185/* rule 3 can match eol */1180YY_RULE_SETUP1187#line 44 "src/lexer.l"1188{ yy_pop_state(yyscanner); }1181#line 43 "src/lexer.l"1182{ return EQ; }1183 YY_BREAK11901191case YY_STATE_EOF(IN_COMMENT):1192#line 46 "src/lexer.l"1193{ yy_pop_state(yyscanner); }1194 YY_BREAK1184case 4:1185YY_RULE_SETUP1197#line 48 "src/lexer.l"1198{ return NEQ; }1186#line 44 "src/lexer.l"1187{ return AS; }1188 YY_BREAK1189case 5:1190YY_RULE_SETUP1202#line 49 "src/lexer.l"1203{ return EQ; }1191#line 45 "src/lexer.l"1192{ return IMPORT; }1193 YY_BREAK1194case 6:1195YY_RULE_SETUP1207#line 50 "src/lexer.l"1208{ return AS; }1196#line 46 "src/lexer.l"1197{ return INCLUDE; }1198 YY_BREAK1199case 7:1200YY_RULE_SETUP1212#line 51 "src/lexer.l"1213{ return IMPORT; }1201#line 47 "src/lexer.l"1202{ return MODULE; }1203 YY_BREAK1204case 8:1205YY_RULE_SETUP1217#line 52 "src/lexer.l"1218{ return INCLUDE; }1206#line 48 "src/lexer.l"1207{ return DEF; }1208 YY_BREAK1209case 9:1210YY_RULE_SETUP1222#line 53 "src/lexer.l"1223{ return MODULE; }1211#line 49 "src/lexer.l"1212{ return IF; }1213 YY_BREAK1214case 10:1215YY_RULE_SETUP1227#line 54 "src/lexer.l"1228{ return DEF; }1216#line 50 "src/lexer.l"1217{ return THEN; }1218 YY_BREAK1219case 11:1220YY_RULE_SETUP1232#line 55 "src/lexer.l"1233{ return IF; }1221#line 51 "src/lexer.l"1222{ return ELSE; }1223 YY_BREAK1224case 12:1225YY_RULE_SETUP1237#line 56 "src/lexer.l"1238{ return THEN; }1226#line 52 "src/lexer.l"1227{ return ELSE_IF; }1228 YY_BREAK1229case 13:1230YY_RULE_SETUP1242#line 57 "src/lexer.l"1243{ return ELSE; }1231#line 53 "src/lexer.l"1232{ return AND; }1233 YY_BREAK1234case 14:1235YY_RULE_SETUP1247#line 58 "src/lexer.l"1248{ return ELSE_IF; }1236#line 54 "src/lexer.l"1237{ return OR; }1238 YY_BREAK1239case 15:1240YY_RULE_SETUP1252#line 59 "src/lexer.l"1253{ return AND; }1241#line 55 "src/lexer.l"1242{ return END; }1243 YY_BREAK1244case 16:1245YY_RULE_SETUP1257#line 60 "src/lexer.l"1258{ return OR; }1246#line 56 "src/lexer.l"1247{ return REDUCE; }1248 YY_BREAK1249case 17:1250YY_RULE_SETUP1262#line 61 "src/lexer.l"1263{ return END; }1251#line 57 "src/lexer.l"1252{ return FOREACH; }1253 YY_BREAK1254case 18:1255YY_RULE_SETUP1267#line 62 "src/lexer.l"1268{ return REDUCE; }1256#line 58 "src/lexer.l"1257{ return DEFINEDOR; }1258 YY_BREAK1259case 19:1260YY_RULE_SETUP1272#line 63 "src/lexer.l"1273{ return FOREACH; }1261#line 59 "src/lexer.l"1262{ return TRY; }1263 YY_BREAK1264case 20:1265YY_RULE_SETUP1277#line 64 "src/lexer.l"1278{ return DEFINEDOR; }1266#line 60 "src/lexer.l"1267{ return CATCH; }1268 YY_BREAK1269case 21:1270YY_RULE_SETUP1282#line 65 "src/lexer.l"1283{ return TRY; }1271#line 61 "src/lexer.l"1272{ return LABEL; }1273 YY_BREAK1274case 22:1275YY_RULE_SETUP1287#line 66 "src/lexer.l"1288{ return CATCH; }1276#line 62 "src/lexer.l"1277{ return BREAK; }1278 YY_BREAK1279case 23:1280YY_RULE_SETUP1292#line 67 "src/lexer.l"1293{ return LABEL; }1281#line 63 "src/lexer.l"1282{ return LOC; }1283 YY_BREAK1284case 24:1285YY_RULE_SETUP1297#line 68 "src/lexer.l"1298{ return BREAK; }1286#line 64 "src/lexer.l"1287{ return SETPIPE; }1288 YY_BREAK1289case 25:1290YY_RULE_SETUP1302#line 69 "src/lexer.l"1303{ return LOC; }1291#line 65 "src/lexer.l"1292{ return SETPLUS; }1293 YY_BREAK1294case 26:1295YY_RULE_SETUP1307#line 70 "src/lexer.l"1308{ return SETPIPE; }1296#line 66 "src/lexer.l"1297{ return SETMINUS; }1298 YY_BREAK1299case 27:1300YY_RULE_SETUP1312#line 71 "src/lexer.l"1313{ return SETPLUS; }1301#line 67 "src/lexer.l"1302{ return SETMULT; }1303 YY_BREAK1304case 28:1305YY_RULE_SETUP1317#line 72 "src/lexer.l"1318{ return SETMINUS; }1306#line 68 "src/lexer.l"1307{ return SETDIV; }1308 YY_BREAK1309case 29:1310YY_RULE_SETUP1322#line 73 "src/lexer.l"1323{ return SETMULT; }1311#line 69 "src/lexer.l"1312{ return SETMOD; }1313 YY_BREAK1314case 30:1315YY_RULE_SETUP1327#line 74 "src/lexer.l"1328{ return SETDIV; }1316#line 70 "src/lexer.l"1317{ return SETDEFINEDOR; }1318 YY_BREAK1319case 31:1320YY_RULE_SETUP1332#line 75 "src/lexer.l"1333{ return SETMOD; }1321#line 71 "src/lexer.l"1322{ return LESSEQ; }1323 YY_BREAK1324case 32:1325YY_RULE_SETUP1337#line 76 "src/lexer.l"1338{ return SETDEFINEDOR; }1326#line 72 "src/lexer.l"1327{ return GREATEREQ; }1328 YY_BREAK1329case 33:1330YY_RULE_SETUP1342#line 77 "src/lexer.l"1343{ return LESSEQ; }1331#line 73 "src/lexer.l"1332{ return REC; }1333 YY_BREAK1334case 34:1335YY_RULE_SETUP1347#line 78 "src/lexer.l"1348{ return GREATEREQ; }1336#line 74 "src/lexer.l"1337{ return ALTERNATION; }1338 YY_BREAK1339case 35:1340YY_RULE_SETUP1352#line 79 "src/lexer.l"1353{ return REC; }1341#line 75 "src/lexer.l"1342{ return yytext[0];}1343 YY_BREAK1344case 36:1345YY_RULE_SETUP1357#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"1346#line 77 "src/lexer.l"1347{1348 return enter(yytext[0], YY_START, yyscanner);1349}1350 YY_BREAK1372case 39:1351case 37:1352YY_RULE_SETUP1374#line 87 "src/lexer.l"1353#line 81 "src/lexer.l"1354{1355 return try_exit(yytext[0], YY_START, yyscanner);1356}1357 YY_BREAK1379case 40:1358case 38:1359YY_RULE_SETUP1381#line 91 "src/lexer.l"1360#line 85 "src/lexer.l"1361{1362 yylval->literal = jv_string_sized(yytext + 1, yyleng - 1); return FORMAT;1363}1364 YY_BREAK1386case 41:1365case 39:1366YY_RULE_SETUP1388#line 95 "src/lexer.l"1367#line 89 "src/lexer.l"1368{1369 yylval->literal = jv_parse_sized(yytext, yyleng); return LITERAL;1370}1371 YY_BREAK1393case 42:1372case 40:1373YY_RULE_SETUP1395#line 99 "src/lexer.l"1374#line 93 "src/lexer.l"1375{1376 yy_push_state(IN_QQSTRING, yyscanner);1377 return QQSTRING_START;1378}1379 YY_BREAK13801402case 43:1381case 41:1382YY_RULE_SETUP1404#line 105 "src/lexer.l"1383#line 99 "src/lexer.l"1384{1385 return enter(QQSTRING_INTERP_START, YY_START, yyscanner);1386 }1387 YY_BREAK1409case 44:1388case 42:1389YY_RULE_SETUP1411#line 108 "src/lexer.l"1390#line 102 "src/lexer.l"1391{1392 yy_pop_state(yyscanner);1393 return QQSTRING_END;1394 }1395 YY_BREAK1417case 45:1418/* rule 45 can match eol */1396case 43:1397/* rule 43 can match eol */1398YY_RULE_SETUP1420#line 112 "src/lexer.l"1399#line 106 "src/lexer.l"1400{1401 /* pass escapes to the json parser */1402 jv escapes = jv_string_fmt("\"%.*s\"", (int)yyleng, yytext);1403 yylval->literal = jv_parse_sized(jv_string_value(escapes), jv_string_length_bytes(jv_copy(escapes)));1404 jv_free(escapes);1405 return QQSTRING_TEXT;1406 }1407 YY_BREAK1429case 46:1430/* rule 46 can match eol */1408case 44:1409/* rule 44 can match eol */1410YY_RULE_SETUP1432#line 119 "src/lexer.l"1411#line 113 "src/lexer.l"1412{1413 yylval->literal = jv_string_sized(yytext, yyleng);1414 return QQSTRING_TEXT;1415 }1416 YY_BREAK1438case 47:1417case 45:1418YY_RULE_SETUP1440#line 123 "src/lexer.l"1419#line 117 "src/lexer.l"1420{1421 return INVALID_CHARACTER;1422 }1423 YY_BREAK14241446case 48:1425case 46:1426YY_RULE_SETUP1448#line 129 "src/lexer.l"1427#line 123 "src/lexer.l"1428{ yylval->literal = jv_string(yytext); return IDENT;}1429 YY_BREAK1451case 49:1430case 47:1431YY_RULE_SETUP1453#line 130 "src/lexer.l"1432#line 124 "src/lexer.l"1433{ yylval->literal = jv_string(yytext+1); return FIELD;}1434 YY_BREAK1456case 50:1435case 48:1436YY_RULE_SETUP1458#line 131 "src/lexer.l"1437#line 125 "src/lexer.l"1438{ yylval->literal = jv_string(yytext+1); return BINDING;}1439 YY_BREAK1461case 51:1462/* rule 51 can match eol */1440case 49:1441/* rule 49 can match eol */1442YY_RULE_SETUP1464#line 133 "src/lexer.l"1443#line 127 "src/lexer.l"1444{}1445 YY_BREAK1467case 52:1446case 50:1447YY_RULE_SETUP1469#line 135 "src/lexer.l"1448#line 129 "src/lexer.l"1449{ return INVALID_CHARACTER; }1450 YY_BREAK1472case 53:1451case 51:1452YY_RULE_SETUP1474#line 137 "src/lexer.l"1453#line 131 "src/lexer.l"1454YY_FATAL_ERROR( "flex scanner jammed" );1455 YY_BREAK1477#line 1477 "src/lexer.c"1456#line 1456 "src/lexer.c"1457case YY_STATE_EOF(INITIAL):1458case YY_STATE_EOF(IN_PAREN):1459case YY_STATE_EOF(IN_BRACKET):1460case YY_STATE_EOF(IN_BRACE):
295 unmodified lines
1756 }1757 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )1758 {1759 yy_current_state = (int) yy_def[yy_current_state];1781 if ( yy_current_state >= 168 )1760 if ( yy_current_state >= 163 )1761 yy_c = yy_meta[yy_c];1762 }1763 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];1764 }
20 unmodified lines
1785 }1786 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )1787 {1788 yy_current_state = (int) yy_def[yy_current_state];1810 if ( yy_current_state >= 168 )1789 if ( yy_current_state >= 163 )1790 yy_c = yy_meta[yy_c];1791 }1792 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];1814 yy_is_jam = (yy_current_state == 167);1793 yy_is_jam = (yy_current_state == 162);17941795 (void)yyg;1796 return yy_is_jam ? 0 : yy_current_state;1797}
826 unmodified lines
2624#endif26252626#define YYTABLES_NAME "yytables"26272649#line 137 "src/lexer.l"2628#line 131 "src/lexer.l"26292630/* perhaps these should be calls... */2631/*2632"true" { return TRUE; }
53 unmodified lines
modified:src/lexer.h+2 added-3 removed
460 unmodified lines
461#define IN_BRACKET 2462#define IN_BRACE 3463#define IN_QQINTERP 4464#define IN_QQSTRING 5465#define IN_COMMENT 6465466#endif467468#ifndef YY_NO_UNISTD_H
261 unmodified lines
730#ifndef jq_yyTABLES_NAME_ALREADY_DEFINED731#undef yyTABLES_NAME732#endif733735#line 137 "src/lexer.l"734#line 131 "src/lexer.l"735736738#line 738 "src/lexer.h"737#line 737 "src/lexer.h"738#undef jq_yyIN_HEADER739#endif /* jq_yyHEADER_H */
modified:src/lexer.l+1 added-7 removed
19 unmodified lines
20%s IN_BRACKET21%s IN_BRACE22%s IN_QQINTERP23%x IN_QQSTRING24%x IN_COMMENT24%{25 static int enter(int opening, int state, yyscan_t yyscanner);26 static int try_exit(int closing, int state, yyscan_t yyscanner);27%}
8 unmodified lines
363738%%3941"#" { 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); }40"#"[^\n]* { /* comments */ }4142"!=" { return NEQ; }43"==" { return EQ; }44"as" { return AS; }
142 unmodified lines
modified:src/main.c+16 added-1 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}195196static int process(jq_state *jq, jv value, int flags, int dumpopts, int options) {197 int ret = JQ_OK_NO_OUTPUT; // No valid results && -e -> exit(4)198 jq_start(jq, value, flags);199 jv result;
484 unmodified lines
684 if (!jv_object_has(jv_copy(program_arguments), jv_string("JQ_BUILD_CONFIGURATION")))685 program_arguments = jv_object_set(program_arguments,686 jv_string("JQ_BUILD_CONFIGURATION"),687 jv_string(JQ_CONFIG)); /* named arguments */673 compiled = jq_compile_args(jq, jv_string_value(data), jv_copy(program_arguments));688 compiled = jq_compile_args(jq, skip_shebang(jv_string_value(data)), jv_copy(program_arguments));689 free(program_origin);690 jv_free(data);691 } else {692 jq_set_attr(jq, jv_string("PROGRAM_ORIGIN"), jq_realpath(jv_string("."))); // XXX is this good?
95 unmodified lines
modified:tests/shtest-18 removed
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 1613fi614597# Allow passing the inline jq script before -- #2919598if ! r=$($JQ --args -rn -- '$ARGS.positional[0]' bar) || [ "$r" != bar ]; then599 echo "passing the inline script after -- didn't work"600 exit 1
7 unmodified lines
modified:jq.1.prebuilt+1 added-69 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\.169Read filter from the file rather than from a command line, like awk\'s \-f option\. You can also use \'#\' to make comments\.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.3958.SH "MODULES"3959jq has a library/module system\. Modules are files whose names end in \fB\.jq\fR\.3960.3961.P
170 unmodified lines