diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml index bfbde89607..6e6cb4a110 100644 --- a/docs/content/manual/manual.yml +++ b/docs/content/manual/manual.yml @@ -2139,7 +2139,7 @@ sections: `if A then B end` is the same as `if A then B else . end`. That is, the `else` branch is optional, and if absent is the - same as `.`. + same as `.`. This also applies to `elif` with absent ending `else` branch. Checking for false or null is a simpler notion of "truthiness" than is found in JavaScript or Python, but it diff --git a/src/parser.c b/src/parser.c index 28d47c5016..4c1bfa0fdc 100644 --- a/src/parser.c +++ b/src/parser.c @@ -900,9 +900,9 @@ union yyalloc /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 30 /* YYNRULES -- Number of rules. */ -#define YYNRULES 170 +#define YYNRULES 171 /* YYNSTATES -- Number of states. */ -#define YYNSTATES 326 +#define YYNSTATES 327 /* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 302 @@ -963,17 +963,17 @@ static const yytype_int16 yyrline[] = 474, 478, 482, 486, 490, 494, 498, 502, 506, 511, 514, 531, 540, 547, 555, 566, 571, 577, 580, 585, 589, 593, 600, 600, 604, 604, 611, 614, 617, 623, - 626, 631, 634, 637, 643, 646, 649, 657, 661, 664, - 667, 670, 673, 676, 679, 682, 685, 689, 695, 698, + 626, 629, 634, 637, 640, 646, 649, 652, 660, 664, + 667, 670, 673, 676, 679, 682, 685, 688, 692, 698, 701, 704, 707, 710, 713, 716, 719, 722, 725, 728, - 731, 734, 737, 740, 743, 746, 749, 771, 775, 779, - 788, 800, 805, 806, 807, 808, 811, 814, 819, 824, - 827, 832, 835, 840, 844, 847, 852, 855, 860, 863, - 868, 871, 874, 877, 880, 883, 891, 897, 900, 903, + 731, 734, 737, 740, 743, 746, 749, 752, 774, 778, + 782, 791, 803, 808, 809, 810, 811, 814, 817, 822, + 827, 830, 835, 838, 843, 847, 850, 855, 858, 863, + 866, 871, 874, 877, 880, 883, 886, 894, 900, 903, 906, 909, 912, 915, 918, 921, 924, 927, 930, 933, - 936, 939, 942, 945, 948, 951, 956, 959, 960, 961, - 964, 967, 970, 973, 977, 981, 985, 989, 993, 997, - 1005 + 936, 939, 942, 945, 948, 951, 954, 959, 962, 963, + 964, 967, 970, 973, 976, 980, 984, 988, 992, 996, + 1000, 1008 }; #endif @@ -1019,7 +1019,7 @@ yysymbol_name (yysymbol_kind_t yysymbol) #define yypact_value_is_default(Yyn) \ ((Yyn) == YYPACT_NINF) -#define YYTABLE_NINF (-157) +#define YYTABLE_NINF (-158) #define yytable_value_is_error(Yyn) \ ((Yyn) == YYTABLE_NINF) @@ -1060,7 +1060,7 @@ static const yytype_int16 yypact[] = 1544, 1595, -120, 119, 119, -120, -120, -120, 140, -20, -120, -120, -120, -120, -120, -120, 143, 1646, -120, 775, 775, 775, -20, -120, -120, -120, 1747, 1323, 1168, -120, - -120, -120, 775, -120, 1357, -120 + -120, -120, -120, 775, -120, 1357, -120 }; /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. @@ -1068,39 +1068,39 @@ static const yytype_int16 yypact[] = means the default is an error. */ static const yytype_uint8 yydefact[] = { - 4, 0, 0, 6, 110, 83, 100, 102, 75, 0, + 4, 0, 0, 6, 111, 84, 101, 103, 76, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, - 0, 0, 0, 0, 0, 101, 48, 1, 0, 0, - 8, 6, 0, 0, 79, 64, 0, 0, 0, 0, - 19, 0, 77, 0, 66, 33, 0, 0, 108, 137, - 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, - 148, 149, 150, 151, 152, 153, 154, 155, 0, 109, - 86, 0, 0, 85, 0, 105, 0, 0, 167, 0, - 0, 163, 168, 0, 157, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 102, 48, 1, 0, 0, + 8, 6, 0, 0, 80, 64, 0, 0, 0, 0, + 19, 0, 78, 0, 66, 33, 0, 0, 109, 138, + 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, + 149, 150, 151, 152, 153, 154, 155, 156, 0, 110, + 87, 0, 0, 86, 0, 106, 0, 0, 168, 0, + 0, 164, 169, 0, 158, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, - 5, 10, 82, 0, 0, 0, 0, 54, 53, 3, - 2, 8, 7, 49, 0, 118, 0, 116, 66, 0, - 0, 0, 0, 0, 0, 0, 76, 0, 112, 103, - 0, 87, 81, 113, 104, 0, 0, 115, 0, 0, - 165, 166, 0, 0, 106, 0, 41, 42, 43, 26, + 5, 10, 83, 0, 0, 0, 0, 54, 53, 3, + 2, 8, 7, 49, 0, 119, 0, 117, 66, 0, + 0, 0, 0, 0, 0, 0, 77, 0, 113, 104, + 0, 88, 82, 114, 105, 0, 0, 116, 0, 0, + 166, 167, 0, 0, 107, 0, 41, 42, 43, 26, 25, 24, 28, 32, 35, 37, 40, 27, 46, 47, 29, 30, 23, 44, 45, 31, 34, 36, 38, 39, - 78, 0, 0, 0, 0, 0, 122, 0, 84, 0, - 0, 93, 0, 0, 9, 50, 0, 111, 0, 61, + 79, 0, 0, 0, 0, 0, 123, 0, 85, 0, + 0, 94, 0, 0, 9, 50, 0, 112, 0, 61, 0, 0, 57, 0, 17, 0, 0, 0, 20, 18, - 0, 67, 0, 63, 0, 0, 159, 0, 170, 73, - 160, 0, 0, 162, 161, 158, 123, 126, 0, 0, - 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, - 80, 114, 0, 92, 0, 89, 52, 0, 117, 65, + 0, 67, 0, 63, 0, 0, 160, 0, 171, 74, + 161, 0, 0, 163, 162, 159, 124, 127, 0, 0, + 0, 0, 0, 0, 0, 129, 0, 0, 0, 0, + 81, 115, 0, 93, 0, 90, 52, 0, 118, 65, 59, 60, 0, 0, 55, 0, 0, 16, 15, 0, - 0, 21, 0, 107, 72, 0, 0, 164, 0, 124, - 0, 0, 0, 130, 0, 0, 125, 0, 121, 11, - 91, 99, 98, 0, 88, 51, 58, 0, 0, 0, - 0, 0, 68, 71, 169, 127, 136, 132, 0, 0, - 134, 129, 133, 90, 96, 95, 97, 0, 70, 0, - 0, 0, 0, 131, 94, 56, 0, 0, 0, 135, - 69, 12, 0, 14, 0, 13 + 0, 21, 0, 108, 73, 0, 0, 165, 0, 125, + 0, 0, 0, 131, 0, 0, 126, 0, 122, 11, + 92, 100, 99, 0, 89, 51, 58, 0, 0, 0, + 0, 0, 68, 72, 170, 128, 137, 133, 0, 0, + 135, 130, 134, 91, 97, 96, 98, 0, 71, 0, + 0, 0, 0, 132, 95, 56, 0, 0, 0, 136, + 70, 69, 12, 0, 14, 0, 13 }; /* YYPGOTO[NTERM-NUM]. */ @@ -1139,13 +1139,13 @@ static const yytype_int16 yytable[] = 106, 107, 108, 140, 109, 141, 142, 148, 143, 203, 205, 154, 152, 209, 153, 155, 180, 210, 193, 214, 109, 219, 226, 219, 222, 237, 238, 219, 219, 295, - 81, 296, 297, -120, 240, 300, 293, 294, 302, 241, + 81, 296, 297, -121, 240, 300, 293, 294, 302, 241, 81, 243, 259, 263, 260, 236, 265, 273, 284, 285, 189, 266, 270, 4, 5, 6, 7, 8, 271, 274, 313, 277, 251, 9, 287, 299, 239, 10, 233, 242, - -119, 11, 12, 319, 303, 125, 13, 304, 14, 15, + -120, 11, 12, 319, 303, 125, 13, 304, 14, 15, 305, 314, 122, 312, 194, 118, 286, 301, 198, 261, - 16, 262, 219, 320, 0, 0, 0, 219, 248, 0, + 16, 262, 219, 321, 0, 0, 0, 219, 248, 0, 0, 0, 17, 85, 86, 87, 88, 0, 0, 18, 272, 19, 190, 20, 21, 191, 22, 279, 0, 89, 90, 0, 0, 283, 0, 0, 91, 92, 93, 94, @@ -1153,26 +1153,26 @@ static const yytype_int16 yytable[] = 219, 219, 0, 101, 102, 103, 104, 105, 106, 107, 108, 0, 109, 0, 0, 0, 0, 0, 0, 0, 233, 0, 0, 0, 0, 0, 307, 0, 0, 0, - 0, 0, -74, 70, 0, 0, 71, -74, 0, 72, - 0, -74, -74, -74, -74, -74, 0, 0, 316, 317, - 318, -74, -74, -74, 0, 0, -74, -74, -74, 0, - -74, 324, 0, 0, -74, -74, -74, -74, -74, -74, - -74, -74, 0, 16, 0, 0, -74, 0, 0, -74, - -74, -74, -74, -74, -74, -74, -74, -74, -74, 0, - -74, -74, 0, -74, 0, -74, -74, -74, -74, 77, - -74, 0, 78, -157, -157, 72, 0, 0, 0, 0, + 0, 0, -75, 70, 0, 0, 71, -75, 0, 72, + 0, -75, -75, -75, -75, -75, 0, 0, 316, 317, + 318, -75, -75, -75, 0, 0, -75, -75, -75, 0, + -75, 0, 325, 0, -75, -75, -75, -75, -75, -75, + -75, -75, 0, 16, 0, 0, -75, 0, 0, -75, + -75, -75, -75, -75, -75, -75, -75, -75, -75, 0, + -75, -75, 0, -75, 0, -75, -75, -75, -75, 77, + -75, 0, 78, -158, -158, 72, 0, 0, 0, 0, 0, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 0, -157, -157, 0, 0, 0, 0, 0, 0, 16, - 0, 0, 0, -157, -157, 104, 105, 106, 107, 108, + 0, -158, -158, 0, 0, 0, 0, 0, 0, 16, + 0, 0, 0, -158, -158, 104, 105, 106, 107, 108, 0, 109, 0, 0, 0, 0, 215, 0, 79, 78, - 80, 0, 72, 0, 0, 0, -156, 0, 49, 50, + 80, 0, 72, 0, 0, 0, -157, 0, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 4, 5, 6, 7, 8, 0, 0, 0, 0, 16, 0, 0, 74, 0, 0, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 9, 15, 0, 79, 10, 80, 0, 0, - 11, 12, 0, -156, 16, 13, 0, 14, 15, 0, + 11, 12, 0, -157, 16, 13, 0, 14, 15, 0, 0, 0, 0, 0, 0, 0, 217, 0, 0, 16, 0, 0, 0, 18, 0, 19, 0, 20, 21, 0, 22, 17, 4, 5, 6, 7, 8, 0, 18, 0, @@ -1246,7 +1246,7 @@ static const yytype_int16 yytable[] = 0, 0, 0, 89, 90, 0, 0, 0, 0, 0, 91, 92, 93, 94, 95, 96, 97, 98, 0, 0, 0, 0, 0, 0, 0, 99, 100, 101, 102, 103, - 104, 105, 106, 107, 108, 0, 109, 322, 0, 323, + 104, 105, 106, 107, 108, 0, 109, 323, 0, 324, 85, 86, 87, 88, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 89, 90, 0, 0, 0, 0, 0, 91, 92, 93, 94, 95, 96, 97, @@ -1262,10 +1262,10 @@ static const yytype_int16 yytable[] = 298, 0, 0, 0, 0, 91, 92, 93, 94, 95, 96, 97, 98, 0, 0, 0, 85, 86, 87, 88, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, - 0, 109, 89, 90, 321, 0, 0, 0, 0, 91, + 0, 109, 89, 90, 322, 0, 0, 0, 0, 91, 92, 93, 94, 95, 96, 97, 98, 0, 0, 0, 85, 86, 87, 88, 99, 100, 101, 102, 103, 104, - 105, 106, 107, 108, 0, 109, 89, 90, 325, 0, + 105, 106, 107, 108, 0, 109, 89, 90, 326, 0, 0, 0, 0, 91, 92, 93, 94, 95, 96, 97, 98, 0, 0, 0, 0, 0, 0, 0, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 0, 109, @@ -1301,7 +1301,7 @@ static const yytype_int16 yytable[] = 0, 0, 0, 0, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 0, 109, 85, 86, 87, 88, 0, 0, 0, 0, 0, 0, 0, 255, 256, 0, - 0, 0, 89, 90, 0, 0, 0, 0, 0, 91, + 0, 320, 89, 90, 0, 0, 0, 0, 0, 91, 92, 93, 94, 95, 96, 97, 98, 0, 0, 0, 0, 0, 0, 0, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 0, 109, 85, 86, 87, 88, @@ -1324,11 +1324,11 @@ static const yytype_int16 yytable[] = 98, 0, 0, 0, 85, 86, 87, 88, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 0, 109, 89, 90, 0, 0, 0, 0, 0, 91, 92, 93, - 94, 95, 96, 97, 98, 0, 0, 0, -157, 86, + 94, 95, 96, 97, 98, 0, 0, 0, -158, 86, 87, 0, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 0, 109, 89, 90, 0, 0, 0, 0, - 0, -157, -157, -157, -157, -157, -157, 97, 98, 0, - 0, 86, 87, 0, 0, 0, 0, 0, -157, 102, + 0, -158, -158, -158, -158, -158, -158, 97, 98, 0, + 0, 86, 87, 0, 0, 0, 0, 0, -158, 102, 103, 104, 105, 106, 107, 108, 89, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -1375,7 +1375,7 @@ static const yytype_int16 yycheck[] = -1, -1, 0, 1, -1, -1, 4, 5, -1, 7, -1, 9, 10, 11, 12, 13, -1, -1, 309, 310, 311, 19, 20, 21, -1, -1, 24, 25, 26, -1, - 28, 322, -1, -1, 32, 33, 34, 35, 36, 37, + 28, -1, 323, -1, 32, 33, 34, 35, 36, 37, 38, 39, -1, 41, -1, -1, 44, -1, -1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, -1, 58, 59, -1, 61, -1, 63, 64, 65, 66, 1, @@ -1520,7 +1520,7 @@ static const yytype_int16 yycheck[] = -1, -1, -1, -1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, -1, 58, 9, 10, 11, 12, -1, -1, -1, -1, -1, -1, -1, 20, 21, -1, - -1, -1, 25, 26, -1, -1, -1, -1, -1, 32, + -1, 24, 25, 26, -1, -1, -1, -1, -1, 32, 33, 34, 35, 36, 37, 38, 39, -1, -1, -1, -1, -1, -1, -1, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, -1, 58, 9, 10, 11, 12, @@ -1596,7 +1596,7 @@ static const yytype_int8 yystos[] = 74, 74, 44, 86, 86, 92, 92, 92, 61, 63, 92, 95, 92, 58, 58, 58, 66, 74, 24, 19, 59, 59, 63, 92, 58, 59, 74, 74, 74, 92, - 85, 61, 59, 61, 74, 61 + 24, 85, 61, 59, 61, 74, 61 }; /* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */ @@ -1609,17 +1609,17 @@ static const yytype_int8 yyr1[] = 74, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 76, 76, 76, 77, 78, 78, 79, 79, 80, 80, 80, 82, 81, 83, 81, 84, 84, 84, 85, - 85, 86, 86, 86, 87, 87, 87, 87, 87, 87, + 85, 85, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, 87, - 87, 87, 87, 87, 87, 87, 88, 88, 89, 90, - 90, 91, 91, 92, 92, 92, 93, 93, 94, 94, - 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, + 87, 87, 87, 87, 87, 87, 87, 88, 88, 89, + 90, 90, 91, 91, 92, 92, 92, 93, 93, 94, + 94, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, - 96, 96, 96, 96, 96, 96, 97, 97, 97, 97, - 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, - 98 + 96, 96, 96, 96, 96, 96, 96, 97, 97, 97, + 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, + 98, 98 }; /* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */ @@ -1632,17 +1632,17 @@ static const yytype_int8 yyr2[] = 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 3, 5, 4, 2, 1, 5, 8, 1, 3, 2, 2, 1, 0, 4, 0, 5, 0, 2, 4, 5, - 3, 3, 2, 1, 1, 1, 3, 2, 3, 2, - 4, 3, 2, 1, 3, 2, 2, 3, 5, 4, - 6, 5, 4, 3, 7, 6, 6, 6, 5, 5, - 1, 1, 1, 3, 3, 2, 3, 5, 2, 2, - 1, 4, 3, 3, 4, 3, 1, 3, 1, 3, - 1, 3, 1, 2, 3, 3, 1, 3, 1, 3, - 2, 4, 3, 3, 3, 5, 3, 1, 1, 1, + 5, 3, 3, 2, 1, 1, 1, 3, 2, 3, + 2, 4, 3, 2, 1, 3, 2, 2, 3, 5, + 4, 6, 5, 4, 3, 7, 6, 6, 6, 5, + 5, 1, 1, 1, 3, 3, 2, 3, 5, 2, + 2, 1, 4, 3, 3, 4, 3, 1, 3, 1, + 3, 1, 3, 1, 2, 3, 3, 1, 3, 1, + 3, 2, 4, 3, 3, 3, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 0, 1, 3, 3, - 3, 3, 3, 1, 4, 2, 2, 1, 1, 5, - 3 + 1, 1, 1, 1, 1, 1, 1, 0, 1, 3, + 3, 3, 3, 3, 1, 4, 2, 2, 1, 1, + 5, 3 }; @@ -3294,56 +3294,64 @@ YYLTYPE yylloc = yyloc_default; #line 3295 "src/parser.c" break; - case 70: /* ElseBody: "else" Exp "end" */ + case 70: /* ElseBody: "elif" Exp "then" Exp "end" */ #line 626 "src/parser.y" + { + (yyval.blk) = gen_cond((yyvsp[-3].blk), (yyvsp[-1].blk), gen_noop()); +} +#line 3303 "src/parser.c" + break; + + case 71: /* ElseBody: "else" Exp "end" */ +#line 629 "src/parser.y" { (yyval.blk) = (yyvsp[-1].blk); } -#line 3303 "src/parser.c" +#line 3311 "src/parser.c" break; - case 71: /* ExpD: ExpD '|' ExpD */ -#line 631 "src/parser.y" + case 72: /* ExpD: ExpD '|' ExpD */ +#line 634 "src/parser.y" { (yyval.blk) = block_join((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3311 "src/parser.c" +#line 3319 "src/parser.c" break; - case 72: /* ExpD: '-' ExpD */ -#line 634 "src/parser.y" + case 73: /* ExpD: '-' ExpD */ +#line 637 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[0].blk), gen_call("_negate", gen_noop())); } -#line 3319 "src/parser.c" +#line 3327 "src/parser.c" break; - case 73: /* ExpD: Term */ -#line 637 "src/parser.y" + case 74: /* ExpD: Term */ +#line 640 "src/parser.y" { (yyval.blk) = (yyvsp[0].blk); } -#line 3327 "src/parser.c" +#line 3335 "src/parser.c" break; - case 74: /* Term: '.' */ -#line 643 "src/parser.y" + case 75: /* Term: '.' */ +#line 646 "src/parser.y" { (yyval.blk) = gen_noop(); } -#line 3335 "src/parser.c" +#line 3343 "src/parser.c" break; - case 75: /* Term: ".." */ -#line 646 "src/parser.y" + case 76: /* Term: ".." */ +#line 649 "src/parser.y" { (yyval.blk) = gen_call("recurse", gen_noop()); } -#line 3343 "src/parser.c" +#line 3351 "src/parser.c" break; - case 76: /* Term: "break" '$' IDENT */ -#line 649 "src/parser.y" + case 77: /* Term: "break" '$' IDENT */ +#line 652 "src/parser.y" { jv v = jv_string_fmt("*label-%s", jv_string_value((yyvsp[0].literal))); // impossible symbol (yyval.blk) = gen_location((yyloc), locations, @@ -3352,247 +3360,247 @@ YYLTYPE yylloc = yyloc_default; jv_free(v); jv_free((yyvsp[0].literal)); } -#line 3356 "src/parser.c" +#line 3364 "src/parser.c" break; - case 77: /* Term: "break" error */ -#line 657 "src/parser.y" + case 78: /* Term: "break" error */ +#line 660 "src/parser.y" { FAIL((yyloc), "break requires a label to break to"); (yyval.blk) = gen_noop(); } -#line 3365 "src/parser.c" +#line 3373 "src/parser.c" break; - case 78: /* Term: Term FIELD '?' */ -#line 661 "src/parser.y" + case 79: /* Term: Term FIELD '?' */ +#line 664 "src/parser.y" { (yyval.blk) = gen_index_opt((yyvsp[-2].blk), gen_const((yyvsp[-1].literal))); } -#line 3373 "src/parser.c" +#line 3381 "src/parser.c" break; - case 79: /* Term: FIELD '?' */ -#line 664 "src/parser.y" + case 80: /* Term: FIELD '?' */ +#line 667 "src/parser.y" { (yyval.blk) = gen_index_opt(gen_noop(), gen_const((yyvsp[-1].literal))); } -#line 3381 "src/parser.c" +#line 3389 "src/parser.c" break; - case 80: /* Term: Term '.' String '?' */ -#line 667 "src/parser.y" + case 81: /* Term: Term '.' String '?' */ +#line 670 "src/parser.y" { (yyval.blk) = gen_index_opt((yyvsp[-3].blk), (yyvsp[-1].blk)); } -#line 3389 "src/parser.c" +#line 3397 "src/parser.c" break; - case 81: /* Term: '.' String '?' */ -#line 670 "src/parser.y" + case 82: /* Term: '.' String '?' */ +#line 673 "src/parser.y" { (yyval.blk) = gen_index_opt(gen_noop(), (yyvsp[-1].blk)); } -#line 3397 "src/parser.c" +#line 3405 "src/parser.c" break; - case 82: /* Term: Term FIELD */ -#line 673 "src/parser.y" + case 83: /* Term: Term FIELD */ +#line 676 "src/parser.y" { (yyval.blk) = gen_index((yyvsp[-1].blk), gen_const((yyvsp[0].literal))); } -#line 3405 "src/parser.c" +#line 3413 "src/parser.c" break; - case 83: /* Term: FIELD */ -#line 676 "src/parser.y" + case 84: /* Term: FIELD */ +#line 679 "src/parser.y" { (yyval.blk) = gen_index(gen_noop(), gen_const((yyvsp[0].literal))); } -#line 3413 "src/parser.c" +#line 3421 "src/parser.c" break; - case 84: /* Term: Term '.' String */ -#line 679 "src/parser.y" + case 85: /* Term: Term '.' String */ +#line 682 "src/parser.y" { (yyval.blk) = gen_index((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3421 "src/parser.c" +#line 3429 "src/parser.c" break; - case 85: /* Term: '.' String */ -#line 682 "src/parser.y" + case 86: /* Term: '.' String */ +#line 685 "src/parser.y" { (yyval.blk) = gen_index(gen_noop(), (yyvsp[0].blk)); } -#line 3429 "src/parser.c" +#line 3437 "src/parser.c" break; - case 86: /* Term: '.' error */ -#line 685 "src/parser.y" + case 87: /* Term: '.' error */ +#line 688 "src/parser.y" { FAIL((yyloc), "try .[\"field\"] instead of .field for unusually named fields"); (yyval.blk) = gen_noop(); } -#line 3438 "src/parser.c" +#line 3446 "src/parser.c" break; - case 87: /* Term: '.' IDENT error */ -#line 689 "src/parser.y" + case 88: /* Term: '.' IDENT error */ +#line 692 "src/parser.y" { jv_free((yyvsp[-1].literal)); FAIL((yyloc), "try .[\"field\"] instead of .field for unusually named fields"); (yyval.blk) = gen_noop(); } -#line 3448 "src/parser.c" - break; - - case 88: /* Term: Term '[' Exp ']' '?' */ -#line 695 "src/parser.y" - { - (yyval.blk) = gen_index_opt((yyvsp[-4].blk), (yyvsp[-2].blk)); -} #line 3456 "src/parser.c" break; - case 89: /* Term: Term '[' Exp ']' */ + case 89: /* Term: Term '[' Exp ']' '?' */ #line 698 "src/parser.y" - { - (yyval.blk) = gen_index((yyvsp[-3].blk), (yyvsp[-1].blk)); + { + (yyval.blk) = gen_index_opt((yyvsp[-4].blk), (yyvsp[-2].blk)); } #line 3464 "src/parser.c" break; - case 90: /* Term: Term '.' '[' Exp ']' '?' */ + case 90: /* Term: Term '[' Exp ']' */ #line 701 "src/parser.y" - { - (yyval.blk) = gen_index_opt((yyvsp[-5].blk), (yyvsp[-2].blk)); + { + (yyval.blk) = gen_index((yyvsp[-3].blk), (yyvsp[-1].blk)); } #line 3472 "src/parser.c" break; - case 91: /* Term: Term '.' '[' Exp ']' */ + case 91: /* Term: Term '.' '[' Exp ']' '?' */ #line 704 "src/parser.y" - { - (yyval.blk) = gen_index((yyvsp[-4].blk), (yyvsp[-1].blk)); + { + (yyval.blk) = gen_index_opt((yyvsp[-5].blk), (yyvsp[-2].blk)); } #line 3480 "src/parser.c" break; - case 92: /* Term: Term '[' ']' '?' */ + case 92: /* Term: Term '.' '[' Exp ']' */ #line 707 "src/parser.y" - { - (yyval.blk) = block_join((yyvsp[-3].blk), gen_op_simple(EACH_OPT)); + { + (yyval.blk) = gen_index((yyvsp[-4].blk), (yyvsp[-1].blk)); } #line 3488 "src/parser.c" break; - case 93: /* Term: Term '[' ']' */ + case 93: /* Term: Term '[' ']' '?' */ #line 710 "src/parser.y" - { - (yyval.blk) = block_join((yyvsp[-2].blk), gen_op_simple(EACH)); + { + (yyval.blk) = block_join((yyvsp[-3].blk), gen_op_simple(EACH_OPT)); } #line 3496 "src/parser.c" break; - case 94: /* Term: Term '[' Exp ':' Exp ']' '?' */ + case 94: /* Term: Term '[' ']' */ #line 713 "src/parser.y" - { - (yyval.blk) = gen_slice_index((yyvsp[-6].blk), (yyvsp[-4].blk), (yyvsp[-2].blk), INDEX_OPT); + { + (yyval.blk) = block_join((yyvsp[-2].blk), gen_op_simple(EACH)); } #line 3504 "src/parser.c" break; - case 95: /* Term: Term '[' Exp ':' ']' '?' */ + case 95: /* Term: Term '[' Exp ':' Exp ']' '?' */ #line 716 "src/parser.y" - { - (yyval.blk) = gen_slice_index((yyvsp[-5].blk), (yyvsp[-3].blk), gen_const(jv_null()), INDEX_OPT); + { + (yyval.blk) = gen_slice_index((yyvsp[-6].blk), (yyvsp[-4].blk), (yyvsp[-2].blk), INDEX_OPT); } #line 3512 "src/parser.c" break; - case 96: /* Term: Term '[' ':' Exp ']' '?' */ + case 96: /* Term: Term '[' Exp ':' ']' '?' */ #line 719 "src/parser.y" { - (yyval.blk) = gen_slice_index((yyvsp[-5].blk), gen_const(jv_null()), (yyvsp[-2].blk), INDEX_OPT); + (yyval.blk) = gen_slice_index((yyvsp[-5].blk), (yyvsp[-3].blk), gen_const(jv_null()), INDEX_OPT); } #line 3520 "src/parser.c" break; - case 97: /* Term: Term '[' Exp ':' Exp ']' */ + case 97: /* Term: Term '[' ':' Exp ']' '?' */ #line 722 "src/parser.y" - { - (yyval.blk) = gen_slice_index((yyvsp[-5].blk), (yyvsp[-3].blk), (yyvsp[-1].blk), INDEX); + { + (yyval.blk) = gen_slice_index((yyvsp[-5].blk), gen_const(jv_null()), (yyvsp[-2].blk), INDEX_OPT); } #line 3528 "src/parser.c" break; - case 98: /* Term: Term '[' Exp ':' ']' */ + case 98: /* Term: Term '[' Exp ':' Exp ']' */ #line 725 "src/parser.y" - { - (yyval.blk) = gen_slice_index((yyvsp[-4].blk), (yyvsp[-2].blk), gen_const(jv_null()), INDEX); + { + (yyval.blk) = gen_slice_index((yyvsp[-5].blk), (yyvsp[-3].blk), (yyvsp[-1].blk), INDEX); } #line 3536 "src/parser.c" break; - case 99: /* Term: Term '[' ':' Exp ']' */ + case 99: /* Term: Term '[' Exp ':' ']' */ #line 728 "src/parser.y" { - (yyval.blk) = gen_slice_index((yyvsp[-4].blk), gen_const(jv_null()), (yyvsp[-1].blk), INDEX); + (yyval.blk) = gen_slice_index((yyvsp[-4].blk), (yyvsp[-2].blk), gen_const(jv_null()), INDEX); } #line 3544 "src/parser.c" break; - case 100: /* Term: LITERAL */ + case 100: /* Term: Term '[' ':' Exp ']' */ #line 731 "src/parser.y" - { - (yyval.blk) = gen_const((yyvsp[0].literal)); + { + (yyval.blk) = gen_slice_index((yyvsp[-4].blk), gen_const(jv_null()), (yyvsp[-1].blk), INDEX); } #line 3552 "src/parser.c" break; - case 101: /* Term: String */ + case 101: /* Term: LITERAL */ #line 734 "src/parser.y" - { - (yyval.blk) = (yyvsp[0].blk); + { + (yyval.blk) = gen_const((yyvsp[0].literal)); } #line 3560 "src/parser.c" break; - case 102: /* Term: FORMAT */ + case 102: /* Term: String */ #line 737 "src/parser.y" { - (yyval.blk) = gen_format(gen_noop(), (yyvsp[0].literal)); + (yyval.blk) = (yyvsp[0].blk); } #line 3568 "src/parser.c" break; - case 103: /* Term: '(' Exp ')' */ + case 103: /* Term: FORMAT */ #line 740 "src/parser.y" - { - (yyval.blk) = (yyvsp[-1].blk); + { + (yyval.blk) = gen_format(gen_noop(), (yyvsp[0].literal)); } #line 3576 "src/parser.c" break; - case 104: /* Term: '[' Exp ']' */ + case 104: /* Term: '(' Exp ')' */ #line 743 "src/parser.y" { - (yyval.blk) = gen_collect((yyvsp[-1].blk)); + (yyval.blk) = (yyvsp[-1].blk); } #line 3584 "src/parser.c" break; - case 105: /* Term: '[' ']' */ + case 105: /* Term: '[' Exp ']' */ #line 746 "src/parser.y" - { - (yyval.blk) = gen_const(jv_array()); + { + (yyval.blk) = gen_collect((yyvsp[-1].blk)); } #line 3592 "src/parser.c" break; - case 106: /* Term: '{' MkDict '}' */ + case 106: /* Term: '[' ']' */ #line 749 "src/parser.y" + { + (yyval.blk) = gen_const(jv_array()); +} +#line 3600 "src/parser.c" + break; + + case 107: /* Term: '{' MkDict '}' */ +#line 752 "src/parser.y" { block o = gen_const_object((yyvsp[-1].blk)); if (o.first != NULL) @@ -3600,29 +3608,29 @@ YYLTYPE yylloc = yyloc_default; else (yyval.blk) = BLOCK(gen_subexp(gen_const(jv_object())), (yyvsp[-1].blk), gen_op_simple(POP)); } -#line 3604 "src/parser.c" +#line 3612 "src/parser.c" break; - case 107: /* Term: '$' '$' '$' '$' IDENT */ -#line 771 "src/parser.y" + case 108: /* Term: '$' '$' '$' '$' IDENT */ +#line 774 "src/parser.y" { (yyval.blk) = gen_location((yyloc), locations, gen_op_unbound(LOADVN, jv_string_value((yyvsp[0].literal)))); jv_free((yyvsp[0].literal)); } -#line 3613 "src/parser.c" +#line 3621 "src/parser.c" break; - case 108: /* Term: '$' IDENT */ -#line 775 "src/parser.y" + case 109: /* Term: '$' IDENT */ +#line 778 "src/parser.y" { (yyval.blk) = gen_location((yyloc), locations, gen_op_unbound(LOADV, jv_string_value((yyvsp[0].literal)))); jv_free((yyvsp[0].literal)); } -#line 3622 "src/parser.c" +#line 3630 "src/parser.c" break; - case 109: /* Term: '$' Keyword */ -#line 779 "src/parser.y" + case 110: /* Term: '$' Keyword */ +#line 782 "src/parser.y" { if (strcmp(jv_string_value((yyvsp[0].literal)), "__loc__") == 0) { (yyval.blk) = gen_const(JV_OBJECT(jv_string("file"), jv_copy(locations->fname), @@ -3632,11 +3640,11 @@ YYLTYPE yylloc = yyloc_default; } jv_free((yyvsp[0].literal)); } -#line 3636 "src/parser.c" +#line 3644 "src/parser.c" break; - case 110: /* Term: IDENT */ -#line 788 "src/parser.y" + case 111: /* Term: IDENT */ +#line 791 "src/parser.y" { const char *s = jv_string_value((yyvsp[0].literal)); if (strcmp(s, "false") == 0) @@ -3649,198 +3657,198 @@ YYLTYPE yylloc = yyloc_default; (yyval.blk) = gen_location((yyloc), locations, gen_call(s, gen_noop())); jv_free((yyvsp[0].literal)); } -#line 3653 "src/parser.c" +#line 3661 "src/parser.c" break; - case 111: /* Term: IDENT '(' Args ')' */ -#line 800 "src/parser.y" + case 112: /* Term: IDENT '(' Args ')' */ +#line 803 "src/parser.y" { (yyval.blk) = gen_call(jv_string_value((yyvsp[-3].literal)), (yyvsp[-1].blk)); (yyval.blk) = gen_location((yylsp[-3]), locations, (yyval.blk)); jv_free((yyvsp[-3].literal)); } -#line 3663 "src/parser.c" +#line 3671 "src/parser.c" break; - case 112: /* Term: '(' error ')' */ -#line 805 "src/parser.y" + case 113: /* Term: '(' error ')' */ +#line 808 "src/parser.y" { (yyval.blk) = gen_noop(); } -#line 3669 "src/parser.c" +#line 3677 "src/parser.c" break; - case 113: /* Term: '[' error ']' */ -#line 806 "src/parser.y" + case 114: /* Term: '[' error ']' */ +#line 809 "src/parser.y" { (yyval.blk) = gen_noop(); } -#line 3675 "src/parser.c" +#line 3683 "src/parser.c" break; - case 114: /* Term: Term '[' error ']' */ -#line 807 "src/parser.y" + case 115: /* Term: Term '[' error ']' */ +#line 810 "src/parser.y" { (yyval.blk) = (yyvsp[-3].blk); } -#line 3681 "src/parser.c" +#line 3689 "src/parser.c" break; - case 115: /* Term: '{' error '}' */ -#line 808 "src/parser.y" + case 116: /* Term: '{' error '}' */ +#line 811 "src/parser.y" { (yyval.blk) = gen_noop(); } -#line 3687 "src/parser.c" +#line 3695 "src/parser.c" break; - case 116: /* Args: Arg */ -#line 811 "src/parser.y" + case 117: /* Args: Arg */ +#line 814 "src/parser.y" { (yyval.blk) = (yyvsp[0].blk); } -#line 3695 "src/parser.c" +#line 3703 "src/parser.c" break; - case 117: /* Args: Args ';' Arg */ -#line 814 "src/parser.y" + case 118: /* Args: Args ';' Arg */ +#line 817 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3703 "src/parser.c" +#line 3711 "src/parser.c" break; - case 118: /* Arg: Exp */ -#line 819 "src/parser.y" + case 119: /* Arg: Exp */ +#line 822 "src/parser.y" { (yyval.blk) = gen_lambda((yyvsp[0].blk)); } -#line 3711 "src/parser.c" +#line 3719 "src/parser.c" break; - case 119: /* RepPatterns: RepPatterns "?//" Pattern */ -#line 824 "src/parser.y" + case 120: /* RepPatterns: RepPatterns "?//" Pattern */ +#line 827 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[-2].blk), gen_destructure_alt((yyvsp[0].blk))); } -#line 3719 "src/parser.c" +#line 3727 "src/parser.c" break; - case 120: /* RepPatterns: Pattern */ -#line 827 "src/parser.y" + case 121: /* RepPatterns: Pattern */ +#line 830 "src/parser.y" { (yyval.blk) = gen_destructure_alt((yyvsp[0].blk)); } -#line 3727 "src/parser.c" +#line 3735 "src/parser.c" break; - case 121: /* Patterns: RepPatterns "?//" Pattern */ -#line 832 "src/parser.y" + case 122: /* Patterns: RepPatterns "?//" Pattern */ +#line 835 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3735 "src/parser.c" +#line 3743 "src/parser.c" break; - case 122: /* Patterns: Pattern */ -#line 835 "src/parser.y" + case 123: /* Patterns: Pattern */ +#line 838 "src/parser.y" { (yyval.blk) = (yyvsp[0].blk); } -#line 3743 "src/parser.c" +#line 3751 "src/parser.c" break; - case 123: /* Pattern: '$' IDENT */ -#line 840 "src/parser.y" + case 124: /* Pattern: '$' IDENT */ +#line 843 "src/parser.y" { (yyval.blk) = gen_op_unbound(STOREV, jv_string_value((yyvsp[0].literal))); jv_free((yyvsp[0].literal)); } -#line 3752 "src/parser.c" +#line 3760 "src/parser.c" break; - case 124: /* Pattern: '[' ArrayPats ']' */ -#line 844 "src/parser.y" + case 125: /* Pattern: '[' ArrayPats ']' */ +#line 847 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[-1].blk), gen_op_simple(POP)); } -#line 3760 "src/parser.c" +#line 3768 "src/parser.c" break; - case 125: /* Pattern: '{' ObjPats '}' */ -#line 847 "src/parser.y" + case 126: /* Pattern: '{' ObjPats '}' */ +#line 850 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[-1].blk), gen_op_simple(POP)); } -#line 3768 "src/parser.c" +#line 3776 "src/parser.c" break; - case 126: /* ArrayPats: Pattern */ -#line 852 "src/parser.y" + case 127: /* ArrayPats: Pattern */ +#line 855 "src/parser.y" { (yyval.blk) = gen_array_matcher(gen_noop(), (yyvsp[0].blk)); } -#line 3776 "src/parser.c" +#line 3784 "src/parser.c" break; - case 127: /* ArrayPats: ArrayPats ',' Pattern */ -#line 855 "src/parser.y" + case 128: /* ArrayPats: ArrayPats ',' Pattern */ +#line 858 "src/parser.y" { (yyval.blk) = gen_array_matcher((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3784 "src/parser.c" +#line 3792 "src/parser.c" break; - case 128: /* ObjPats: ObjPat */ -#line 860 "src/parser.y" + case 129: /* ObjPats: ObjPat */ +#line 863 "src/parser.y" { (yyval.blk) = (yyvsp[0].blk); } -#line 3792 "src/parser.c" +#line 3800 "src/parser.c" break; - case 129: /* ObjPats: ObjPats ',' ObjPat */ -#line 863 "src/parser.y" + case 130: /* ObjPats: ObjPats ',' ObjPat */ +#line 866 "src/parser.y" { (yyval.blk) = BLOCK((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3800 "src/parser.c" +#line 3808 "src/parser.c" break; - case 130: /* ObjPat: '$' IDENT */ -#line 868 "src/parser.y" + case 131: /* ObjPat: '$' IDENT */ +#line 871 "src/parser.y" { (yyval.blk) = gen_object_matcher(gen_const((yyvsp[0].literal)), gen_op_unbound(STOREV, jv_string_value((yyvsp[0].literal)))); } -#line 3808 "src/parser.c" +#line 3816 "src/parser.c" break; - case 131: /* ObjPat: '$' IDENT ':' Pattern */ -#line 871 "src/parser.y" + case 132: /* ObjPat: '$' IDENT ':' Pattern */ +#line 874 "src/parser.y" { (yyval.blk) = gen_object_matcher(gen_const((yyvsp[-2].literal)), BLOCK(gen_op_simple(DUP), gen_op_unbound(STOREV, jv_string_value((yyvsp[-2].literal))), (yyvsp[0].blk))); } -#line 3816 "src/parser.c" +#line 3824 "src/parser.c" break; - case 132: /* ObjPat: IDENT ':' Pattern */ -#line 874 "src/parser.y" + case 133: /* ObjPat: IDENT ':' Pattern */ +#line 877 "src/parser.y" { (yyval.blk) = gen_object_matcher(gen_const((yyvsp[-2].literal)), (yyvsp[0].blk)); } -#line 3824 "src/parser.c" +#line 3832 "src/parser.c" break; - case 133: /* ObjPat: Keyword ':' Pattern */ -#line 877 "src/parser.y" + case 134: /* ObjPat: Keyword ':' Pattern */ +#line 880 "src/parser.y" { (yyval.blk) = gen_object_matcher(gen_const((yyvsp[-2].literal)), (yyvsp[0].blk)); } -#line 3832 "src/parser.c" +#line 3840 "src/parser.c" break; - case 134: /* ObjPat: String ':' Pattern */ -#line 880 "src/parser.y" + case 135: /* ObjPat: String ':' Pattern */ +#line 883 "src/parser.y" { (yyval.blk) = gen_object_matcher((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 3840 "src/parser.c" +#line 3848 "src/parser.c" break; - case 135: /* ObjPat: '(' Exp ')' ':' Pattern */ -#line 883 "src/parser.y" + case 136: /* ObjPat: '(' Exp ')' ':' Pattern */ +#line 886 "src/parser.y" { jv msg = check_object_key((yyvsp[-3].blk)); if (jv_is_valid(msg)) { @@ -3849,276 +3857,276 @@ YYLTYPE yylloc = yyloc_default; jv_free(msg); (yyval.blk) = gen_object_matcher((yyvsp[-3].blk), (yyvsp[0].blk)); } -#line 3853 "src/parser.c" +#line 3861 "src/parser.c" break; - case 136: /* ObjPat: error ':' Pattern */ -#line 891 "src/parser.y" + case 137: /* ObjPat: error ':' Pattern */ +#line 894 "src/parser.y" { FAIL((yyloc), "May need parentheses around object key expression"); (yyval.blk) = (yyvsp[0].blk); } -#line 3862 "src/parser.c" - break; - - case 137: /* Keyword: "as" */ -#line 897 "src/parser.y" - { - (yyval.literal) = jv_string("as"); -} #line 3870 "src/parser.c" break; - case 138: /* Keyword: "def" */ + case 138: /* Keyword: "as" */ #line 900 "src/parser.y" - { - (yyval.literal) = jv_string("def"); + { + (yyval.literal) = jv_string("as"); } #line 3878 "src/parser.c" break; - case 139: /* Keyword: "module" */ + case 139: /* Keyword: "def" */ #line 903 "src/parser.y" - { - (yyval.literal) = jv_string("module"); + { + (yyval.literal) = jv_string("def"); } #line 3886 "src/parser.c" break; - case 140: /* Keyword: "import" */ + case 140: /* Keyword: "module" */ #line 906 "src/parser.y" { - (yyval.literal) = jv_string("import"); + (yyval.literal) = jv_string("module"); } #line 3894 "src/parser.c" break; - case 141: /* Keyword: "include" */ + case 141: /* Keyword: "import" */ #line 909 "src/parser.y" - { - (yyval.literal) = jv_string("include"); + { + (yyval.literal) = jv_string("import"); } #line 3902 "src/parser.c" break; - case 142: /* Keyword: "if" */ + case 142: /* Keyword: "include" */ #line 912 "src/parser.y" - { - (yyval.literal) = jv_string("if"); + { + (yyval.literal) = jv_string("include"); } #line 3910 "src/parser.c" break; - case 143: /* Keyword: "then" */ + case 143: /* Keyword: "if" */ #line 915 "src/parser.y" - { - (yyval.literal) = jv_string("then"); + { + (yyval.literal) = jv_string("if"); } #line 3918 "src/parser.c" break; - case 144: /* Keyword: "else" */ + case 144: /* Keyword: "then" */ #line 918 "src/parser.y" { - (yyval.literal) = jv_string("else"); + (yyval.literal) = jv_string("then"); } #line 3926 "src/parser.c" break; - case 145: /* Keyword: "elif" */ + case 145: /* Keyword: "else" */ #line 921 "src/parser.y" { - (yyval.literal) = jv_string("elif"); + (yyval.literal) = jv_string("else"); } #line 3934 "src/parser.c" break; - case 146: /* Keyword: "reduce" */ + case 146: /* Keyword: "elif" */ #line 924 "src/parser.y" - { - (yyval.literal) = jv_string("reduce"); + { + (yyval.literal) = jv_string("elif"); } #line 3942 "src/parser.c" break; - case 147: /* Keyword: "foreach" */ + case 147: /* Keyword: "reduce" */ #line 927 "src/parser.y" - { - (yyval.literal) = jv_string("foreach"); + { + (yyval.literal) = jv_string("reduce"); } #line 3950 "src/parser.c" break; - case 148: /* Keyword: "end" */ + case 148: /* Keyword: "foreach" */ #line 930 "src/parser.y" - { - (yyval.literal) = jv_string("end"); + { + (yyval.literal) = jv_string("foreach"); } #line 3958 "src/parser.c" break; - case 149: /* Keyword: "and" */ + case 149: /* Keyword: "end" */ #line 933 "src/parser.y" { - (yyval.literal) = jv_string("and"); + (yyval.literal) = jv_string("end"); } #line 3966 "src/parser.c" break; - case 150: /* Keyword: "or" */ + case 150: /* Keyword: "and" */ #line 936 "src/parser.y" - { - (yyval.literal) = jv_string("or"); + { + (yyval.literal) = jv_string("and"); } #line 3974 "src/parser.c" break; - case 151: /* Keyword: "try" */ + case 151: /* Keyword: "or" */ #line 939 "src/parser.y" - { - (yyval.literal) = jv_string("try"); + { + (yyval.literal) = jv_string("or"); } #line 3982 "src/parser.c" break; - case 152: /* Keyword: "catch" */ + case 152: /* Keyword: "try" */ #line 942 "src/parser.y" - { - (yyval.literal) = jv_string("catch"); + { + (yyval.literal) = jv_string("try"); } #line 3990 "src/parser.c" break; - case 153: /* Keyword: "label" */ + case 153: /* Keyword: "catch" */ #line 945 "src/parser.y" { - (yyval.literal) = jv_string("label"); + (yyval.literal) = jv_string("catch"); } #line 3998 "src/parser.c" break; - case 154: /* Keyword: "break" */ + case 154: /* Keyword: "label" */ #line 948 "src/parser.y" { - (yyval.literal) = jv_string("break"); + (yyval.literal) = jv_string("label"); } #line 4006 "src/parser.c" break; - case 155: /* Keyword: "__loc__" */ + case 155: /* Keyword: "break" */ #line 951 "src/parser.y" + { + (yyval.literal) = jv_string("break"); +} +#line 4014 "src/parser.c" + break; + + case 156: /* Keyword: "__loc__" */ +#line 954 "src/parser.y" { (yyval.literal) = jv_string("__loc__"); } -#line 4014 "src/parser.c" +#line 4022 "src/parser.c" break; - case 156: /* MkDict: %empty */ -#line 956 "src/parser.y" + case 157: /* MkDict: %empty */ +#line 959 "src/parser.y" { (yyval.blk)=gen_noop(); } -#line 4022 "src/parser.c" +#line 4030 "src/parser.c" break; - case 157: /* MkDict: MkDictPair */ -#line 959 "src/parser.y" + case 158: /* MkDict: MkDictPair */ +#line 962 "src/parser.y" { (yyval.blk) = (yyvsp[0].blk); } -#line 4028 "src/parser.c" +#line 4036 "src/parser.c" break; - case 158: /* MkDict: MkDictPair ',' MkDict */ -#line 960 "src/parser.y" + case 159: /* MkDict: MkDictPair ',' MkDict */ +#line 963 "src/parser.y" { (yyval.blk)=block_join((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 4034 "src/parser.c" +#line 4042 "src/parser.c" break; - case 159: /* MkDict: error ',' MkDict */ -#line 961 "src/parser.y" + case 160: /* MkDict: error ',' MkDict */ +#line 964 "src/parser.y" { (yyval.blk) = (yyvsp[0].blk); } -#line 4040 "src/parser.c" +#line 4048 "src/parser.c" break; - case 160: /* MkDictPair: IDENT ':' ExpD */ -#line 964 "src/parser.y" + case 161: /* MkDictPair: IDENT ':' ExpD */ +#line 967 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_const((yyvsp[-2].literal)), (yyvsp[0].blk)); } -#line 4048 "src/parser.c" +#line 4056 "src/parser.c" break; - case 161: /* MkDictPair: Keyword ':' ExpD */ -#line 967 "src/parser.y" + case 162: /* MkDictPair: Keyword ':' ExpD */ +#line 970 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_const((yyvsp[-2].literal)), (yyvsp[0].blk)); } -#line 4056 "src/parser.c" +#line 4064 "src/parser.c" break; - case 162: /* MkDictPair: String ':' ExpD */ -#line 970 "src/parser.y" + case 163: /* MkDictPair: String ':' ExpD */ +#line 973 "src/parser.y" { (yyval.blk) = gen_dictpair((yyvsp[-2].blk), (yyvsp[0].blk)); } -#line 4064 "src/parser.c" +#line 4072 "src/parser.c" break; - case 163: /* MkDictPair: String */ -#line 973 "src/parser.y" + case 164: /* MkDictPair: String */ +#line 976 "src/parser.y" { (yyval.blk) = gen_dictpair((yyvsp[0].blk), BLOCK(gen_op_simple(POP), gen_op_simple(DUP2), gen_op_simple(DUP2), gen_op_simple(INDEX))); } -#line 4073 "src/parser.c" +#line 4081 "src/parser.c" break; - case 164: /* MkDictPair: '$' IDENT ':' ExpD */ -#line 977 "src/parser.y" + case 165: /* MkDictPair: '$' IDENT ':' ExpD */ +#line 980 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_location((yyloc), locations, gen_op_unbound(LOADV, jv_string_value((yyvsp[-2].literal)))), (yyvsp[0].blk)); } -#line 4082 "src/parser.c" +#line 4090 "src/parser.c" break; - case 165: /* MkDictPair: '$' IDENT */ -#line 981 "src/parser.y" + case 166: /* MkDictPair: '$' IDENT */ +#line 984 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_const((yyvsp[0].literal)), gen_location((yyloc), locations, gen_op_unbound(LOADV, jv_string_value((yyvsp[0].literal))))); } -#line 4091 "src/parser.c" +#line 4099 "src/parser.c" break; - case 166: /* MkDictPair: '$' Keyword */ -#line 985 "src/parser.y" + case 167: /* MkDictPair: '$' Keyword */ +#line 988 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_const((yyvsp[0].literal)), gen_location((yyloc), locations, gen_op_unbound(LOADV, jv_string_value((yyvsp[0].literal))))); } -#line 4100 "src/parser.c" +#line 4108 "src/parser.c" break; - case 167: /* MkDictPair: IDENT */ -#line 989 "src/parser.y" + case 168: /* MkDictPair: IDENT */ +#line 992 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_const(jv_copy((yyvsp[0].literal))), gen_index(gen_noop(), gen_const((yyvsp[0].literal)))); } -#line 4109 "src/parser.c" +#line 4117 "src/parser.c" break; - case 168: /* MkDictPair: Keyword */ -#line 993 "src/parser.y" + case 169: /* MkDictPair: Keyword */ +#line 996 "src/parser.y" { (yyval.blk) = gen_dictpair(gen_const(jv_copy((yyvsp[0].literal))), gen_index(gen_noop(), gen_const((yyvsp[0].literal)))); } -#line 4118 "src/parser.c" +#line 4126 "src/parser.c" break; - case 169: /* MkDictPair: '(' Exp ')' ':' ExpD */ -#line 997 "src/parser.y" + case 170: /* MkDictPair: '(' Exp ')' ':' ExpD */ +#line 1000 "src/parser.y" { jv msg = check_object_key((yyvsp[-3].blk)); if (jv_is_valid(msg)) { @@ -4127,20 +4135,20 @@ YYLTYPE yylloc = yyloc_default; jv_free(msg); (yyval.blk) = gen_dictpair((yyvsp[-3].blk), (yyvsp[0].blk)); } -#line 4131 "src/parser.c" +#line 4139 "src/parser.c" break; - case 170: /* MkDictPair: error ':' ExpD */ -#line 1005 "src/parser.y" + case 171: /* MkDictPair: error ':' ExpD */ +#line 1008 "src/parser.y" { FAIL((yyloc), "May need parentheses around object key expression"); (yyval.blk) = (yyvsp[0].blk); } -#line 4140 "src/parser.c" +#line 4148 "src/parser.c" break; -#line 4144 "src/parser.c" +#line 4152 "src/parser.c" default: break; } @@ -4369,7 +4377,7 @@ YYLTYPE yylloc = yyloc_default; return yyresult; } -#line 1009 "src/parser.y" +#line 1012 "src/parser.y" int jq_parse(struct locfile* locations, block* answer) { diff --git a/src/parser.y b/src/parser.y index a5fc9da9dc..b3ed666bb6 100644 --- a/src/parser.y +++ b/src/parser.y @@ -623,6 +623,9 @@ ElseBody: "elif" Exp "then" Exp ElseBody { $$ = gen_cond($2, $4, $5); } | +"elif" Exp "then" Exp "end" { + $$ = gen_cond($2, $4, gen_noop()); +} | "else" Exp "end" { $$ = $2; } diff --git a/tests/jq.test b/tests/jq.test index ca8e27059f..8426628aea 100644 --- a/tests/jq.test +++ b/tests/jq.test @@ -1116,6 +1116,13 @@ null 7 [7] +[if false then 3 elif false then 4 end] +7 +[7] + +[if false then 3 elif false then 4 else . end] +7 +[7] [.[] | [.foo[] // .bar]] [{"foo":[1,2], "bar": 42}, {"foo":[1], "bar": null}, {"foo":[null,false,3], "bar": 18}, {"foo":[], "bar":42}, {"foo": [null,false,null], "bar": 41}]