Allow number literals as duration

Signed-off-by: darshanime <deathbullet@gmail.com>
pull/9138/head
darshanime 2024-01-30 13:07:49 +05:30 committed by beorn7
parent 398f42de5f
commit 8c8860d2d6
9 changed files with 343 additions and 247 deletions

View File

@ -905,6 +905,10 @@ duration : DURATION
yylex.(*parser).addParseErr($1.PositionRange(), err) yylex.(*parser).addParseErr($1.PositionRange(), err)
} }
} }
| number
{
$$ = yylex.(*parser).parseNumberLiteral($1);
}
; ;

View File

@ -324,209 +324,209 @@ var yyExca = [...]int16{
78, 187, 78, 187,
84, 187, 84, 187,
-2, 123, -2, 123,
-1, 199,
12, 237,
13, 237,
18, 237,
19, 237,
25, 237,
40, 237,
46, 237,
47, 237,
50, 237,
56, 237,
61, 237,
62, 237,
63, 237,
64, 237,
65, 237,
66, 237,
67, 237,
68, 237,
69, 237,
70, 237,
71, 237,
72, 237,
73, 237,
74, 237,
78, 237,
82, 237,
84, 237,
87, 237,
88, 237,
-2, 0,
-1, 200, -1, 200,
12, 237, 12, 238,
13, 237, 13, 238,
18, 237, 18, 238,
19, 237, 19, 238,
25, 237, 25, 238,
40, 237, 40, 238,
46, 237, 46, 238,
47, 237, 47, 238,
50, 237, 50, 238,
56, 237, 56, 238,
61, 237, 61, 238,
62, 237, 62, 238,
63, 237, 63, 238,
64, 237, 64, 238,
65, 237, 65, 238,
66, 237, 66, 238,
67, 237, 67, 238,
68, 237, 68, 238,
69, 237, 69, 238,
70, 237, 70, 238,
71, 237, 71, 238,
72, 237, 72, 238,
73, 237, 73, 238,
74, 237, 74, 238,
78, 237, 78, 238,
82, 237, 82, 238,
84, 237, 84, 238,
87, 237, 87, 238,
88, 237, 88, 238,
-2, 0, -2, 0,
-1, 221, -1, 201,
21, 235, 12, 238,
13, 238,
18, 238,
19, 238,
25, 238,
40, 238,
46, 238,
47, 238,
50, 238,
56, 238,
61, 238,
62, 238,
63, 238,
64, 238,
65, 238,
66, 238,
67, 238,
68, 238,
69, 238,
70, 238,
71, 238,
72, 238,
73, 238,
74, 238,
78, 238,
82, 238,
84, 238,
87, 238,
88, 238,
-2, 0, -2, 0,
-1, 292, -1, 222,
21, 236, 21, 236,
-2, 0, -2, 0,
-1, 293,
21, 237,
-2, 0,
} }
const yyPrivate = 57344 const yyPrivate = 57344
const yyLast = 793 const yyLast = 794
var yyAct = [...]int16{ var yyAct = [...]int16{
155, 330, 328, 274, 335, 152, 225, 39, 191, 148, 152, 331, 329, 275, 336, 154, 226, 39, 192, 148,
288, 287, 156, 117, 81, 177, 227, 106, 105, 6, 289, 288, 158, 117, 81, 178, 228, 106, 105, 6,
154, 108, 107, 197, 132, 198, 237, 109, 199, 200, 156, 108, 198, 132, 199, 153, 238, 109, 200, 201,
159, 59, 243, 325, 324, 110, 321, 159, 189, 268, 300, 107, 244, 120, 326, 325, 322, 153, 190, 59,
348, 301, 265, 127, 159, 192, 349, 264, 290, 195, 320, 302, 266, 118, 110, 193, 161, 349, 297, 196,
176, 160, 159, 269, 308, 175, 319, 195, 160, 347, 127, 260, 153, 296, 291, 259, 121, 153, 161, 350,
239, 240, 346, 112, 241, 113, 299, 161, 174, 270, 240, 241, 162, 112, 242, 113, 348, 330, 295, 347,
263, 111, 254, 160, 161, 228, 230, 232, 233, 234, 258, 111, 255, 161, 162, 229, 231, 233, 234, 235,
242, 244, 247, 248, 249, 250, 251, 255, 256, 161, 243, 245, 248, 249, 250, 251, 252, 256, 257, 162,
114, 229, 231, 235, 236, 238, 245, 246, 108, 266, 153, 230, 232, 236, 237, 239, 246, 247, 114, 300,
258, 252, 253, 329, 109, 157, 158, 159, 2, 3, 308, 253, 254, 309, 157, 159, 160, 108, 2, 3,
4, 5, 307, 160, 162, 257, 262, 299, 172, 166, 4, 5, 223, 109, 163, 307, 222, 150, 173, 167,
169, 217, 104, 164, 110, 165, 150, 306, 193, 161, 170, 196, 306, 165, 151, 166, 104, 151, 194, 218,
178, 104, 179, 151, 305, 183, 196, 179, 185, 261, 337, 221, 110, 76, 153, 184, 197, 153, 186, 104,
194, 201, 202, 203, 204, 205, 206, 207, 208, 209, 195, 202, 203, 204, 205, 206, 207, 208, 209, 210,
210, 211, 212, 213, 214, 215, 128, 227, 88, 216, 211, 212, 213, 214, 215, 216, 269, 128, 228, 217,
120, 218, 219, 100, 336, 103, 168, 237, 97, 98, 35, 267, 219, 220, 265, 86, 88, 100, 238, 103,
118, 181, 100, 243, 103, 87, 181, 224, 259, 167, 270, 149, 263, 188, 244, 161, 97, 98, 225, 83,
149, 180, 182, 121, 187, 76, 180, 182, 120, 260, 100, 101, 103, 87, 7, 319, 271, 264, 169, 82,
102, 35, 124, 7, 10, 296, 151, 123, 118, 102, 261, 162, 321, 177, 102, 262, 187, 185, 176, 318,
295, 239, 240, 267, 78, 241, 116, 186, 285, 286, 317, 168, 240, 241, 268, 10, 242, 102, 316, 286,
122, 121, 289, 254, 318, 294, 228, 230, 232, 233, 287, 175, 315, 290, 255, 78, 314, 229, 231, 233,
234, 242, 244, 247, 248, 249, 250, 251, 255, 256, 234, 235, 243, 245, 248, 249, 250, 251, 252, 256,
317, 292, 229, 231, 235, 236, 238, 245, 246, 316, 257, 313, 293, 230, 232, 236, 237, 239, 246, 247,
315, 314, 252, 253, 133, 134, 135, 136, 137, 138, 179, 312, 180, 253, 254, 133, 134, 135, 136, 137,
139, 140, 141, 142, 143, 144, 145, 146, 147, 313, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
312, 311, 310, 309, 320, 293, 297, 298, 300, 273, 120, 311, 310, 126, 85, 125, 83, 298, 299, 301,
302, 222, 151, 8, 85, 221, 272, 37, 303, 304, 118, 303, 124, 36, 1, 292, 82, 123, 116, 304,
276, 277, 275, 282, 284, 281, 283, 278, 279, 280, 305, 182, 274, 121, 80, 49, 48, 47, 46, 273,
220, 163, 126, 50, 125, 36, 1, 291, 151, 77, 122, 181, 183, 277, 278, 276, 283, 285, 282, 284,
83, 49, 322, 323, 48, 83, 47, 104, 46, 327, 279, 280, 281, 323, 324, 180, 131, 8, 104, 294,
82, 131, 332, 333, 334, 82, 331, 45, 184, 338, 328, 37, 157, 333, 334, 335, 151, 332, 50, 45,
337, 340, 339, 80, 44, 43, 341, 342, 129, 53, 339, 338, 341, 340, 77, 44, 153, 342, 343, 43,
76, 343, 55, 86, 88, 22, 54, 345, 170, 171, 53, 76, 344, 55, 129, 88, 22, 54, 346, 171,
42, 130, 56, 41, 97, 98, 40, 350, 100, 101, 172, 42, 130, 56, 182, 97, 98, 41, 351, 100,
103, 87, 58, 51, 190, 9, 9, 74, 344, 271, 164, 103, 87, 40, 181, 183, 58, 151, 74, 9,
84, 188, 223, 18, 19, 79, 119, 20, 153, 57, 9, 51, 191, 345, 18, 19, 272, 153, 20, 84,
226, 52, 115, 75, 0, 102, 0, 0, 60, 61, 189, 224, 79, 119, 75, 155, 102, 57, 227, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 52, 115, 0, 13, 0, 0, 0,
24, 0, 30, 0, 0, 31, 32, 38, 0, 53,
76, 0, 55, 327, 0, 22, 54, 0, 0, 0,
0, 0, 56, 0, 277, 278, 276, 283, 285, 282,
284, 279, 280, 281, 0, 0, 0, 74, 0, 0,
0, 0, 0, 18, 19, 0, 0, 20, 0, 0,
0, 0, 0, 75, 0, 0, 0, 0, 60, 61,
62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 0, 0, 0, 13, 0, 0, 0, 24, 72, 73, 0, 0, 0, 13, 0, 0, 0, 24,
0, 30, 0, 0, 31, 32, 38, 0, 53, 76, 0, 30, 0, 0, 31, 32, 53, 76, 0, 55,
0, 55, 326, 0, 22, 54, 0, 0, 0, 0, 0, 0, 22, 54, 0, 0, 0, 0, 0, 56,
0, 56, 0, 276, 277, 275, 282, 284, 281, 283,
278, 279, 280, 0, 0, 0, 74, 0, 0, 0,
0, 0, 18, 19, 0, 0, 20, 0, 0, 0,
0, 0, 75, 0, 0, 0, 0, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 0, 0, 0, 13, 0, 0, 0, 24, 0,
30, 0, 0, 31, 32, 53, 76, 0, 55, 0,
0, 22, 54, 0, 0, 0, 0, 0, 56, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 74, 0, 17, 76, 0, 0, 18, 0, 0, 0, 0, 74, 0, 17, 76, 0, 0,
19, 22, 0, 20, 0, 0, 0, 0, 0, 75, 18, 19, 22, 0, 20, 0, 0, 0, 0, 0,
0, 0, 0, 0, 60, 61, 62, 63, 64, 65, 75, 0, 0, 0, 0, 60, 61, 62, 63, 64,
66, 67, 68, 69, 70, 71, 72, 73, 0, 18, 65, 66, 67, 68, 69, 70, 71, 72, 73, 0,
19, 13, 0, 20, 0, 24, 0, 30, 0, 0, 18, 19, 13, 0, 20, 0, 24, 0, 30, 0,
31, 32, 0, 0, 11, 12, 14, 15, 16, 21, 0, 31, 32, 0, 0, 11, 12, 14, 15, 16,
23, 25, 26, 27, 28, 29, 33, 34, 17, 35, 21, 23, 25, 26, 27, 28, 29, 33, 34, 17,
0, 13, 0, 0, 22, 24, 0, 30, 0, 0, 35, 0, 13, 0, 0, 22, 24, 0, 30, 0,
31, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 32, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 18, 19, 0, 0, 20, 0, 0, 0, 0, 0, 0, 18, 19, 0, 0, 20, 0, 0,
0, 0, 0, 0, 0, 0, 0, 11, 12, 14, 0, 0, 0, 0, 0, 0, 0, 0, 11, 12,
15, 16, 21, 23, 25, 26, 27, 28, 29, 33, 14, 15, 16, 21, 23, 25, 26, 27, 28, 29,
34, 104, 0, 0, 13, 0, 0, 0, 24, 173, 33, 34, 104, 0, 0, 13, 0, 0, 0, 24,
30, 0, 0, 31, 32, 0, 0, 0, 0, 0, 174, 30, 0, 0, 31, 32, 0, 0, 0, 0,
104, 0, 0, 0, 0, 0, 0, 86, 88, 89, 0, 104, 0, 0, 0, 0, 0, 0, 86, 88,
89, 0, 90, 91, 92, 93, 94, 95, 96, 97,
98, 99, 0, 100, 101, 103, 87, 86, 88, 89,
0, 90, 91, 92, 93, 94, 95, 96, 97, 98, 0, 90, 91, 92, 93, 94, 95, 96, 97, 98,
99, 0, 100, 101, 103, 87, 86, 88, 89, 0, 99, 0, 100, 101, 103, 87, 104, 0, 0, 0,
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 100, 101, 103, 87, 104, 0, 0, 0, 102, 0, 0, 0, 0, 0, 104, 0, 0, 0, 102,
0, 0, 86, 88, 89, 0, 90, 91, 92, 0,
94, 95, 96, 97, 98, 99, 0, 100, 101, 103,
87, 86, 88, 89, 0, 90, 91, 0, 0, 94,
95, 0, 97, 98, 99, 0, 100, 101, 103, 87,
0, 0, 0, 0, 102, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 104, 0, 0, 0, 102, 0, 0, 0, 0, 102,
0, 86, 88, 89, 0, 90, 91, 92, 0, 94,
95, 96, 97, 98, 99, 0, 100, 101, 103, 87,
86, 88, 89, 0, 90, 91, 0, 0, 94, 95,
0, 97, 98, 99, 0, 100, 101, 103, 87, 0,
0, 0, 0, 102, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 102,
} }
var yyPact = [...]int16{ var yyPact = [...]int16{
17, 183, 566, 566, 396, 503, -1000, -1000, -1000, 178, 17, 174, 567, 567, 397, 504, -1000, -1000, -1000, 147,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, 303, -1000, 272, -1000, 646, -1000, -1000, -1000, -1000, -1000, 264, -1000, 262, -1000, 647,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, 20, 109, -1000, 473, -1000, 473, 172, -1000, -1000, -1000, 29, 117, -1000, 474, -1000, 474, 120, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, 186, -1000, -1000, 190, -1000, -1000, -1000, -1000, -1000, -1000, 258, -1000, -1000, 270,
-1000, -1000, 290, -1000, 19, -1000, -53, -53, -53, -53, -1000, -1000, 261, -1000, 26, -1000, -54, -54, -54, -54,
-53, -53, -53, -53, -53, -53, -53, -53, -53, -53, -54, -54, -54, -54, -54, -54, -54, -54, -54, -54,
-53, -53, 124, 18, 289, 109, -57, -1000, 164, 164, -54, -54, 115, 18, 348, 117, -57, -1000, 186, 186,
317, -1000, 627, 108, -1000, 48, -1000, -1000, 128, 133, 318, -1000, 628, 112, -1000, 191, -1000, -1000, 238, 301,
-1000, -1000, -1000, 298, -1000, 182, -1000, 33, 473, -1000, -1000, -1000, -1000, 177, -1000, 171, -1000, 33, 474, -1000,
-58, -51, -1000, 473, 473, 473, 473, 473, 473, 473, -59, -51, -1000, 474, 474, 474, 474, 474, 474, 474,
473, 473, 473, 473, 473, 473, 473, 473, -1000, 187, 474, 474, 474, 474, 474, 474, 474, 474, -1000, 118,
-1000, -1000, -1000, 106, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 114, -1000, -1000, -1000, -1000,
88, 88, 269, -1000, -1000, -1000, -1000, 155, -1000, -1000, -1000, 71, 71, 110, -1000, -1000, -1000, -1000, 156, -1000,
93, -1000, 646, -1000, -1000, 158, -1000, 114, -1000, -1000, -1000, 48, -1000, 647, -1000, -1000, 31, -1000, 170, -1000,
-1000, -1000, -1000, 45, -1000, -1000, -1000, -1000, -1000, 16, -1000, -1000, -1000, -1000, 162, -1000, -1000, -1000, -1000, -1000,
73, 13, -1000, -1000, -1000, 252, 117, 164, 164, 164, 16, 135, 130, -1000, -1000, -1000, 265, 294, 186, 186,
164, 108, 108, 293, 293, 293, 710, 691, 293, 293, 186, 186, 112, 112, 125, 125, 125, 711, 692, 125,
710, 108, 108, 293, 108, 117, -1000, 26, -1000, -1000, 125, 711, 112, 112, 125, 112, 294, -1000, 32, -1000,
-1000, 263, -1000, 193, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 307, -1000, 46, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 473, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 474,
-1000, -1000, -1000, -1000, -1000, 98, 98, 15, 98, 41, -1000, -1000, -1000, -1000, -1000, -1000, 80, 80, 15, 80,
41, 110, 37, -1000, -1000, 257, 256, 255, 254, 253, 105, 105, 98, 86, -1000, -1000, 256, 255, 235, 225,
235, 234, 233, 224, 208, -1000, -1000, -1000, -1000, -1000, 210, 206, 202, 194, 193, 179, -1000, -1000, -1000, -1000,
-1000, 35, 262, -1000, -1000, 14, -1000, 646, -1000, -1000, -1000, -1000, 19, 190, -1000, -1000, 14, -1000, 647, -1000,
-1000, 98, -1000, 8, 7, 395, -1000, -1000, -1000, 47, -1000, -1000, 80, -1000, 9, 8, 396, -1000, -1000, -1000,
11, 88, 88, 88, 150, 150, 47, 150, 47, -1000, 11, 6, 71, 71, 71, 116, 116, 11, 116, 11,
-1000, -1000, -1000, -1000, 98, 98, -1000, -1000, -1000, 98, -1000, -1000, -1000, -1000, -1000, 80, 80, -1000, -1000, -1000,
-1000, -1000, -1000, -1000, -1000, -1000, 88, -1000, -1000, -1000, 80, -1000, -1000, -1000, -1000, -1000, -1000, 71, -1000, -1000,
-1000, -1000, -1000, -1000, 38, -1000, 25, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, 45, -1000, 38, -1000, -1000,
-1000, -1000, -1000,
} }
var yyPgo = [...]int16{ var yyPgo = [...]int16{
0, 372, 13, 371, 6, 15, 370, 352, 369, 368, 0, 394, 13, 393, 6, 15, 378, 356, 377, 375,
366, 194, 273, 365, 14, 362, 10, 11, 361, 360, 373, 205, 307, 372, 14, 371, 10, 11, 370, 369,
8, 359, 3, 4, 358, 2, 1, 0, 354, 12, 8, 366, 3, 4, 363, 2, 1, 0, 362, 12,
5, 353, 346, 18, 156, 343, 341, 7, 340, 338, 5, 361, 353, 18, 157, 347, 342, 7, 341, 339,
17, 328, 31, 325, 324, 317, 311, 308, 306, 304, 17, 334, 39, 329, 325, 319, 306, 288, 287, 286,
301, 293, 9, 297, 296, 295, 285, 318, 9, 275, 274, 273,
} }
var yyR1 = [...]int8{ var yyR1 = [...]int8{
@ -553,7 +553,7 @@ var yyR1 = [...]int8{
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 8, 8, 5, 6, 6, 6, 6, 6, 6, 6, 8, 8, 5,
5, 5, 5, 44, 27, 29, 29, 30, 30, 26, 5, 5, 5, 44, 27, 29, 29, 30, 30, 26,
25, 25, 52, 48, 10, 53, 53, 17, 17, 25, 25, 52, 52, 48, 10, 53, 53, 17, 17,
} }
var yyR2 = [...]int8{ var yyR2 = [...]int8{
@ -580,7 +580,7 @@ var yyR2 = [...]int8{
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1,
2, 1, 1, 1, 1, 0, 1, 0, 1, 2, 1, 1, 1, 1, 1, 0, 1, 0, 1,
} }
var yyChk = [...]int16{ var yyChk = [...]int16{
@ -599,27 +599,27 @@ var yyChk = [...]int16{
2, 25, 20, 7, 2, 4, 2, 24, -34, -41, 2, 25, 20, 7, 2, 4, 2, 24, -34, -41,
-36, -46, 77, -34, -34, -34, -34, -34, -34, -34, -36, -46, 77, -34, -34, -34, -34, -34, -34, -34,
-34, -34, -34, -34, -34, -34, -34, -34, -52, 56, -34, -34, -34, -34, -34, -34, -34, -34, -52, 56,
2, 9, -30, -9, 2, -27, -29, 87, 88, 19, 2, 9, -27, 19, -30, -9, 2, -27, -29, 87,
40, 56, -52, 2, -40, -33, -16, 15, 2, -16, 88, 40, 56, -52, 2, -40, -33, -16, 15, 2,
-39, 22, -37, 22, 20, 7, 2, -5, 2, 4, -16, -39, 22, -37, 22, 20, 7, 2, -5, 2,
53, 43, 54, -5, 20, -14, 25, 2, -18, 5, 4, 53, 43, 54, -5, 20, -14, 25, 2, -18,
-28, -20, 12, -27, -29, 16, -37, 81, 83, 79, 5, -28, -20, 12, -27, -29, 16, -37, 81, 83,
80, -37, -37, -37, -37, -37, -37, -37, -37, -37, 79, 80, -37, -37, -37, -37, -37, -37, -37, -37,
-37, -37, -37, -37, -37, -37, -52, 15, -27, -27, -37, -37, -37, -37, -37, -37, -37, -52, 15, -27,
21, 6, 2, -15, 22, -4, -6, 2, 61, 77, -27, 21, 6, 2, -15, 22, -4, -6, 2, 61,
62, 78, 63, 64, 65, 79, 80, 12, 81, 46, 77, 62, 78, 63, 64, 65, 79, 80, 12, 81,
47, 50, 66, 18, 67, 82, 83, 68, 69, 70, 46, 47, 50, 66, 18, 67, 82, 83, 68, 69,
71, 72, 87, 88, 58, 73, 74, 22, 7, 20, 70, 71, 72, 87, 88, 58, 73, 74, 22, 7,
-2, 25, 2, 25, 2, 26, 26, -29, 26, 40, 20, -2, 25, 2, 25, 2, 26, 26, -29, 26,
56, -21, 24, 17, -22, 30, 28, 29, 35, 36, 40, 56, -21, 24, 17, -22, 30, 28, 29, 35,
37, 33, 31, 34, 32, -16, -16, -17, -16, -17, 36, 37, 33, 31, 34, 32, -16, -16, -17, -16,
22, -53, -52, 2, 22, 7, 2, -37, -26, 19, -17, 22, -53, -52, 2, 22, 7, 2, -37, -26,
-26, 26, -26, -20, -20, 24, 17, 2, 17, 6, 19, -26, 26, -26, -20, -20, 24, 17, 2, 17,
6, 6, 6, 6, 6, 6, 6, 6, 6, 21, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
2, 22, -4, -26, 26, 26, 17, -22, -25, 56, 21, 2, 22, -4, -26, 26, 26, 17, -22, -25,
-26, -30, -27, -27, -27, -23, 14, -23, -25, -23, 56, -26, -30, -27, -27, -27, -23, 14, -23, -25,
-25, -26, -26, -26, -24, -27, 24, 21, 2, 21, -23, -25, -26, -26, -26, -24, -27, 24, 21, 2,
-27, 21, -27,
} }
var yyDef = [...]int16{ var yyDef = [...]int16{
@ -628,37 +628,37 @@ var yyDef = [...]int16{
109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123, 0, 2, -2, 3, 4, 119, 120, 121, 122, 123, 0, 2, -2, 3, 4,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
18, 19, 0, 106, 223, 0, 233, 0, 83, 84, 18, 19, 0, 106, 223, 0, 234, 0, 83, 84,
-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
-2, -2, -2, -2, 217, 218, 0, 5, 98, 0, -2, -2, -2, -2, 217, 218, 0, 5, 98, 0,
126, 129, 0, 134, 135, 139, 43, 43, 43, 43, 126, 129, 0, 134, 135, 139, 43, 43, 43, 43,
43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
43, 43, 0, 0, 0, 0, 22, 23, 0, 0, 43, 43, 0, 0, 0, 0, 22, 23, 0, 0,
0, 60, 0, 81, 82, 0, 87, 89, 0, 93, 0, 60, 0, 81, 82, 0, 87, 89, 0, 93,
97, 234, 124, 0, 130, 0, 133, 138, 0, 42, 97, 235, 124, 0, 130, 0, 133, 138, 0, 42,
47, 48, 44, 0, 0, 0, 0, 0, 0, 0, 47, 48, 44, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67, 0,
69, 232, 70, 0, 72, 227, 228, 73, 74, 224, 69, 232, 233, 224, 70, 0, 72, 227, 228, 73,
0, 0, 0, 80, 20, 21, 24, 0, 54, 25, 74, 0, 0, 0, 80, 20, 21, 24, 0, 54,
0, 62, 64, 66, 85, 0, 90, 0, 96, 219, 25, 0, 62, 64, 66, 85, 0, 90, 0, 96,
220, 221, 222, 0, 125, 128, 131, 132, 137, 140, 219, 220, 221, 222, 0, 125, 128, 131, 132, 137,
142, 145, 149, 150, 151, 0, 26, 0, 0, -2, 140, 142, 145, 149, 150, 151, 0, 26, 0, 0,
-2, 27, 28, 29, 30, 31, 32, 33, 34, 35, -2, -2, 27, 28, 29, 30, 31, 32, 33, 34,
36, 37, 38, 39, 40, 41, 68, 0, 225, 226, 35, 36, 37, 38, 39, 40, 41, 68, 0, 225,
75, -2, 79, 0, 53, 56, 58, 59, 188, 189, 226, 75, -2, 79, 0, 53, 56, 58, 59, 188,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208,
210, 211, 212, 213, 214, 215, 216, 61, 65, 86, 209, 210, 211, 212, 213, 214, 215, 216, 61, 65,
88, 91, 95, 92, 94, 0, 0, 0, 0, 0, 86, 88, 91, 95, 92, 94, 0, 0, 0, 0,
0, 0, 0, 155, 157, 0, 0, 0, 0, 0, 0, 0, 0, 0, 155, 157, 0, 0, 0, 0,
0, 0, 0, 0, 0, 45, 46, 49, 238, 50, 0, 0, 0, 0, 0, 0, 45, 46, 49, 239,
71, 0, -2, 78, 51, 0, 57, 63, 141, 229, 50, 71, 0, -2, 78, 51, 0, 57, 63, 141,
143, 0, 146, 0, 0, 0, 153, 158, 154, 0, 229, 143, 0, 146, 0, 0, 0, 153, 158, 154,
0, 0, 0, 0, 0, 0, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
77, 52, 55, 144, 0, 0, 152, 156, 159, 0, 76, 77, 52, 55, 144, 0, 0, 152, 156, 159,
231, 160, 161, 162, 163, 164, 0, 165, 166, 167, 0, 231, 160, 161, 162, 163, 164, 0, 165, 166,
168, 147, 148, 230, 0, 172, 0, 170, 173, 169, 167, 168, 147, 148, 230, 0, 172, 0, 170, 173,
171, 169, 171,
} }
var yyTok1 = [...]int8{ var yyTok1 = [...]int8{
@ -1866,6 +1866,11 @@ yydefault:
} }
} }
case 233: case 233:
yyDollar = yyS[yypt-1 : yypt+1]
{
yyVAL.duration = yylex.(*parser).parseNumberLiteral(yyDollar[1].float)
}
case 234:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
{ {
yyVAL.node = &StringLiteral{ yyVAL.node = &StringLiteral{
@ -1873,7 +1878,7 @@ yydefault:
PosRange: yyDollar[1].item.PositionRange(), PosRange: yyDollar[1].item.PositionRange(),
} }
} }
case 234: case 235:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
{ {
yyVAL.item = Item{ yyVAL.item = Item{
@ -1882,12 +1887,12 @@ yydefault:
Val: yylex.(*parser).unquoteString(yyDollar[1].item.Val), Val: yylex.(*parser).unquoteString(yyDollar[1].item.Val),
} }
} }
case 235: case 236:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
{ {
yyVAL.duration = 0 yyVAL.duration = 0
} }
case 237: case 238:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
{ {
yyVAL.strings = nil yyVAL.strings = nil

View File

@ -478,7 +478,7 @@ func lexStatements(l *Lexer) stateFn {
skipSpaces(l) skipSpaces(l)
} }
l.bracketOpen = true l.bracketOpen = true
return lexDuration return lexNumberOrDuration
case r == ']': case r == ']':
if !l.bracketOpen { if !l.bracketOpen {
return l.errorf("unexpected right bracket %q", r) return l.errorf("unexpected right bracket %q", r)
@ -846,18 +846,6 @@ func lexLineComment(l *Lexer) stateFn {
return lexStatements return lexStatements
} }
func lexDuration(l *Lexer) stateFn {
if l.scanNumber() {
return l.errorf("missing unit character in duration")
}
if !acceptRemainingDuration(l) {
return l.errorf("bad duration syntax: %q", l.input[l.start:l.pos])
}
l.backup()
l.emit(DURATION)
return lexStatements
}
// lexNumber scans a number: decimal, hex, oct or float. // lexNumber scans a number: decimal, hex, oct or float.
func lexNumber(l *Lexer) stateFn { func lexNumber(l *Lexer) stateFn {
if !l.scanNumber() { if !l.scanNumber() {
@ -909,6 +897,7 @@ func acceptRemainingDuration(l *Lexer) bool {
// scanNumber scans numbers of different formats. The scanned Item is // scanNumber scans numbers of different formats. The scanned Item is
// not necessarily a valid number. This case is caught by the parser. // not necessarily a valid number. This case is caught by the parser.
func (l *Lexer) scanNumber() bool { func (l *Lexer) scanNumber() bool {
initialPos := l.pos
// Modify the digit pattern if the number is hexadecimal. // Modify the digit pattern if the number is hexadecimal.
digitPattern := "0123456789" digitPattern := "0123456789"
// Disallow hexadecimal in series descriptions as the syntax is ambiguous. // Disallow hexadecimal in series descriptions as the syntax is ambiguous.
@ -980,7 +969,10 @@ func (l *Lexer) scanNumber() bool {
// Handle digits at the end since we already consumed before this loop. // Handle digits at the end since we already consumed before this loop.
l.acceptRun(digitPattern) l.acceptRun(digitPattern)
} }
// empty string is not a valid number
if l.pos == initialPos {
return false
}
// Next thing must not be alphanumeric unless it's the times token // Next thing must not be alphanumeric unless it's the times token
// for series repetitions. // for series repetitions.
if r := l.peek(); (l.seriesDesc && r == 'x') || !isAlphaNumeric(r) { if r := l.peek(); (l.seriesDesc && r == 'x') || !isAlphaNumeric(r) {

View File

@ -849,6 +849,10 @@ func parseDuration(ds string) (time.Duration, error) {
return time.Duration(dur), nil return time.Duration(dur), nil
} }
func (p *parser) parseNumberLiteral(ts float64) time.Duration {
return time.Duration(ts * float64(time.Second))
}
// parseGenerated invokes the yacc generated parser. // parseGenerated invokes the yacc generated parser.
// The generated parser gets the provided startSymbol injected into // The generated parser gets the provided startSymbol injected into
// the lexer stream, based on which grammar will be used. // the lexer stream, based on which grammar will be used.

View File

@ -2133,6 +2133,25 @@ var testExpr = []struct {
EndPos: 25, EndPos: 25,
}, },
}, },
{
input: `test{a="b"}[5m] OFFSET 3600`,
expected: &MatrixSelector{
VectorSelector: &VectorSelector{
Name: "test",
OriginalOffset: 1 * time.Hour,
LabelMatchers: []*labels.Matcher{
MustLabelMatcher(labels.MatchEqual, "a", "b"),
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "test"),
},
PosRange: posrange.PositionRange{
Start: 0,
End: 11,
},
},
Range: 5 * time.Minute,
EndPos: 27,
},
},
{ {
input: `test{a="b"}[5y] @ 1603774699`, input: `test{a="b"}[5y] @ 1603774699`,
expected: &MatrixSelector{ expected: &MatrixSelector{
@ -2152,15 +2171,32 @@ var testExpr = []struct {
EndPos: 28, EndPos: 28,
}, },
}, },
{
input: "test[5]",
expected: &MatrixSelector{
VectorSelector: &VectorSelector{
Name: "test",
LabelMatchers: []*labels.Matcher{
MustLabelMatcher(labels.MatchEqual, model.MetricNameLabel, "test"),
},
PosRange: posrange.PositionRange{
Start: 0,
End: 4,
},
},
Range: 5 * time.Second,
EndPos: 7,
},
},
{ {
input: `foo[5mm]`, input: `foo[5mm]`,
fail: true, fail: true,
errMsg: "bad duration syntax: \"5mm\"", errMsg: "bad number or duration syntax: \"5mm\"",
}, },
{ {
input: `foo[5m1]`, input: `foo[5m1]`,
fail: true, fail: true,
errMsg: "bad duration syntax: \"5m1\"", errMsg: "bad number or duration syntax: \"5m1\"",
}, },
{ {
input: `foo[5m:1m1]`, input: `foo[5m:1m1]`,
@ -2194,17 +2230,12 @@ var testExpr = []struct {
{ {
input: `foo[]`, input: `foo[]`,
fail: true, fail: true,
errMsg: "missing unit character in duration", errMsg: "bad number or duration syntax: \"\"",
}, },
{ {
input: `foo[1]`, input: `foo[-1]`,
fail: true, fail: true,
errMsg: "missing unit character in duration", errMsg: "bad number or duration syntax: \"\"",
},
{
input: `some_metric[5m] OFFSET 1`,
fail: true,
errMsg: "unexpected number \"1\" in offset, expected duration",
}, },
{ {
input: `some_metric[5m] OFFSET 1mm`, input: `some_metric[5m] OFFSET 1mm`,

View File

@ -14,18 +14,42 @@ eval instant at 10s metric @ 100 offset 50s
metric{job="1"} 5 metric{job="1"} 5
metric{job="2"} 10 metric{job="2"} 10
eval instant at 10s metric @ 100 offset 50
metric{job="1"} 5
metric{job="2"} 10
eval instant at 10s metric offset 50s @ 100 eval instant at 10s metric offset 50s @ 100
metric{job="1"} 5 metric{job="1"} 5
metric{job="2"} 10 metric{job="2"} 10
eval instant at 10s metric offset 50 @ 100
metric{job="1"} 5
metric{job="2"} 10
eval instant at 10s metric @ 0 offset -50s eval instant at 10s metric @ 0 offset -50s
metric{job="1"} 5 metric{job="1"} 5
metric{job="2"} 10 metric{job="2"} 10
eval instant at 10s metric @ 0 offset -50
metric{job="1"} 5
metric{job="2"} 10
eval instant at 10s metric offset -50s @ 0 eval instant at 10s metric offset -50s @ 0
metric{job="1"} 5 metric{job="1"} 5
metric{job="2"} 10 metric{job="2"} 10
eval instant at 10s metric offset -50 @ 0
metric{job="1"} 5
metric{job="2"} 10
eval instant at 10s metric @ 0 offset -50s
metric{job="1"} 5
metric{job="2"} 10
eval instant at 10s metric @ 0 offset -50
metric{job="1"} 5
metric{job="2"} 10
eval instant at 10s -metric @ 100 eval instant at 10s -metric @ 100
{job="1"} -10 {job="1"} -10
{job="2"} -20 {job="2"} -20
@ -48,6 +72,12 @@ eval instant at 25s sum_over_time(metric{job="1"}[100s] @ 100 offset 50s)
eval instant at 25s sum_over_time(metric{job="1"}[100s] offset 50s @ 100) eval instant at 25s sum_over_time(metric{job="1"}[100s] offset 50s @ 100)
{job="1"} 15 {job="1"} 15
eval instant at 25s sum_over_time(metric{job="1"}[100] @ 100 offset 50)
{job="1"} 15
eval instant at 25s sum_over_time(metric{job="1"}[100] offset 50s @ 100)
{job="1"} 15
# Different timestamps. # Different timestamps.
eval instant at 25s metric{job="1"} @ 50 + metric{job="1"} @ 100 eval instant at 25s metric{job="1"} @ 50 + metric{job="1"} @ 100
{job="1"} 15 {job="1"} 15
@ -58,6 +88,9 @@ eval instant at 25s rate(metric{job="1"}[100s] @ 100) + label_replace(rate(metri
eval instant at 25s sum_over_time(metric{job="1"}[100s] @ 100) + label_replace(sum_over_time(metric{job="2"}[100s] @ 100), "job", "1", "", "") eval instant at 25s sum_over_time(metric{job="1"}[100s] @ 100) + label_replace(sum_over_time(metric{job="2"}[100s] @ 100), "job", "1", "", "")
{job="1"} 165 {job="1"} 165
eval instant at 25s sum_over_time(metric{job="1"}[100] @ 100) + label_replace(sum_over_time(metric{job="2"}[100] @ 100), "job", "1", "", "")
{job="1"} 165
# Subqueries. # Subqueries.
# 10*(1+2+...+9) + 10. # 10*(1+2+...+9) + 10.
@ -72,6 +105,10 @@ eval instant at 25s sum_over_time(metric{job="1"}[100s:1s] @ 100 offset 20s)
eval instant at 25s sum_over_time(metric{job="1"}[100s:1s] offset 20s @ 100) eval instant at 25s sum_over_time(metric{job="1"}[100s:1s] offset 20s @ 100)
{job="1"} 288 {job="1"} 288
# 10*(1+2+...+7) + 8.
eval instant at 25s sum_over_time(metric{job="1"}[100:1] offset 20 @ 100)
{job="1"} 288
# Subquery with different timestamps. # Subquery with different timestamps.
# Since vector selector has timestamp, the result value does not depend on the timestamp of subqueries. # Since vector selector has timestamp, the result value does not depend on the timestamp of subqueries.

View File

@ -10,6 +10,11 @@ eval instant at 50m resets(http_requests[5m])
{path="/bar"} 0 {path="/bar"} 0
{path="/biz"} 0 {path="/biz"} 0
eval instant at 50m resets(http_requests[300])
{path="/foo"} 0
{path="/bar"} 0
{path="/biz"} 0
eval instant at 50m resets(http_requests[20m]) eval instant at 50m resets(http_requests[20m])
{path="/foo"} 1 {path="/foo"} 1
{path="/bar"} 0 {path="/bar"} 0

View File

@ -32,6 +32,9 @@ eval instant at 20s count_over_time(metric[1s])
eval instant at 20s count_over_time(metric[10s]) eval instant at 20s count_over_time(metric[10s])
{} 1 {} 1
eval instant at 20s count_over_time(metric[10])
{} 1
clear clear

View File

@ -76,6 +76,21 @@ eval instant at 1010s sum_over_time(metric1[30s:10s] offset 3s)
eval instant at 1010s sum_over_time((metric1)[30s:10s] offset 3s) eval instant at 1010s sum_over_time((metric1)[30s:10s] offset 3s)
{} 297 {} 297
eval instant at 1010s sum_over_time(metric1[30:10] offset 3)
{} 297
eval instant at 1010s sum_over_time((metric1)[30:10s] offset 3s)
{} 297
eval instant at 1010s sum_over_time((metric1)[30:10s] offset 3s)
{} 297
eval instant at 1010s sum_over_time((metric1)[30:10] offset 3s)
{} 297
eval instant at 1010s sum_over_time((metric1)[30:10] offset 3)
{} 297
# Nested subqueries # Nested subqueries
eval instant at 1000s rate(sum_over_time(metric1[30s:10s])[50s:10s]) eval instant at 1000s rate(sum_over_time(metric1[30s:10s])[50s:10s])
{} 0.4 {} 0.4