PromQL: Fix parser panic (#6931)

Signed-off-by: Tobias Guggenmos <tobias.guggenmos@uni-ulm.de>
This commit is contained in:
Brian Brazil 2020-03-05 08:03:38 +00:00 committed by GitHub
parent 0193b746b1
commit 7164b58945
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 97 deletions

View file

@ -199,7 +199,10 @@ aggregate_expr : aggregate_op aggregate_modifier function_call_body
| aggregate_op function_call_body | aggregate_op function_call_body
{ $$ = yylex.(*parser).newAggregateExpr($1, &AggregateExpr{}, $2) } { $$ = yylex.(*parser).newAggregateExpr($1, &AggregateExpr{}, $2) }
| aggregate_op error | aggregate_op error
{ yylex.(*parser).unexpected("aggregation",""); $$ = nil } {
yylex.(*parser).unexpected("aggregation","");
$$ = yylex.(*parser).newAggregateExpr($1, &AggregateExpr{}, Expressions{})
}
; ;
aggregate_modifier: aggregate_modifier:

View file

@ -183,7 +183,7 @@ const yyEofCode = 1
const yyErrCode = 2 const yyErrCode = 2
const yyInitialStackSize = 16 const yyInitialStackSize = 16
//line generated_parser.y:706 //line generated_parser.y:709
//line yacctab:1 //line yacctab:1
var yyExca = [...]int{ var yyExca = [...]int{
@ -837,11 +837,11 @@ yydefault:
//line generated_parser.y:202 //line generated_parser.y:202
{ {
yylex.(*parser).unexpected("aggregation", "") yylex.(*parser).unexpected("aggregation", "")
yyVAL.node = nil yyVAL.node = yylex.(*parser).newAggregateExpr(yyDollar[1].item, &AggregateExpr{}, Expressions{})
} }
case 23: case 23:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:207 //line generated_parser.y:210
{ {
yyVAL.node = &AggregateExpr{ yyVAL.node = &AggregateExpr{
Grouping: yyDollar[2].strings, Grouping: yyDollar[2].strings,
@ -849,7 +849,7 @@ yydefault:
} }
case 24: case 24:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:213 //line generated_parser.y:216
{ {
yyVAL.node = &AggregateExpr{ yyVAL.node = &AggregateExpr{
Grouping: yyDollar[2].strings, Grouping: yyDollar[2].strings,
@ -858,97 +858,97 @@ yydefault:
} }
case 25: case 25:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:226 //line generated_parser.y:229
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 26: case 26:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:227 //line generated_parser.y:230
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 27: case 27:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:228 //line generated_parser.y:231
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 28: case 28:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:229 //line generated_parser.y:232
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 29: case 29:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:230 //line generated_parser.y:233
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 30: case 30:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:231 //line generated_parser.y:234
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 31: case 31:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:232 //line generated_parser.y:235
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 32: case 32:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:233 //line generated_parser.y:236
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 33: case 33:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:234 //line generated_parser.y:237
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 34: case 34:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:235 //line generated_parser.y:238
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 35: case 35:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:236 //line generated_parser.y:239
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 36: case 36:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:237 //line generated_parser.y:240
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 37: case 37:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:238 //line generated_parser.y:241
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 38: case 38:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:239 //line generated_parser.y:242
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 39: case 39:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:240 //line generated_parser.y:243
{ {
yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node) yyVAL.node = yylex.(*parser).newBinaryExpression(yyDollar[1].node, yyDollar[2].item, yyDollar[3].node, yyDollar[4].node)
} }
case 41: case 41:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
//line generated_parser.y:248 //line generated_parser.y:251
{ {
yyVAL.node = &BinaryExpr{ yyVAL.node = &BinaryExpr{
VectorMatching: &VectorMatching{Card: CardOneToOne}, VectorMatching: &VectorMatching{Card: CardOneToOne},
@ -956,7 +956,7 @@ yydefault:
} }
case 42: case 42:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:253 //line generated_parser.y:256
{ {
yyVAL.node = &BinaryExpr{ yyVAL.node = &BinaryExpr{
VectorMatching: &VectorMatching{Card: CardOneToOne}, VectorMatching: &VectorMatching{Card: CardOneToOne},
@ -965,14 +965,14 @@ yydefault:
} }
case 43: case 43:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:261 //line generated_parser.y:264
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
yyVAL.node.(*BinaryExpr).VectorMatching.MatchingLabels = yyDollar[3].strings yyVAL.node.(*BinaryExpr).VectorMatching.MatchingLabels = yyDollar[3].strings
} }
case 44: case 44:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:266 //line generated_parser.y:269
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
yyVAL.node.(*BinaryExpr).VectorMatching.MatchingLabels = yyDollar[3].strings yyVAL.node.(*BinaryExpr).VectorMatching.MatchingLabels = yyDollar[3].strings
@ -980,7 +980,7 @@ yydefault:
} }
case 47: case 47:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:276 //line generated_parser.y:279
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
yyVAL.node.(*BinaryExpr).VectorMatching.Card = CardManyToOne yyVAL.node.(*BinaryExpr).VectorMatching.Card = CardManyToOne
@ -988,7 +988,7 @@ yydefault:
} }
case 48: case 48:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:282 //line generated_parser.y:285
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
yyVAL.node.(*BinaryExpr).VectorMatching.Card = CardOneToMany yyVAL.node.(*BinaryExpr).VectorMatching.Card = CardOneToMany
@ -996,51 +996,51 @@ yydefault:
} }
case 49: case 49:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:291 //line generated_parser.y:294
{ {
yyVAL.strings = yyDollar[2].strings yyVAL.strings = yyDollar[2].strings
} }
case 50: case 50:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:293 //line generated_parser.y:296
{ {
yyVAL.strings = yyDollar[2].strings yyVAL.strings = yyDollar[2].strings
} }
case 51: case 51:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:295 //line generated_parser.y:298
{ {
yyVAL.strings = []string{} yyVAL.strings = []string{}
} }
case 52: case 52:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:297 //line generated_parser.y:300
{ {
yylex.(*parser).unexpected("grouping opts", "\"(\"") yylex.(*parser).unexpected("grouping opts", "\"(\"")
yyVAL.strings = nil yyVAL.strings = nil
} }
case 53: case 53:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:303 //line generated_parser.y:306
{ {
yyVAL.strings = append(yyDollar[1].strings, yyDollar[3].item.Val) yyVAL.strings = append(yyDollar[1].strings, yyDollar[3].item.Val)
} }
case 54: case 54:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:305 //line generated_parser.y:308
{ {
yyVAL.strings = []string{yyDollar[1].item.Val} yyVAL.strings = []string{yyDollar[1].item.Val}
} }
case 55: case 55:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:307 //line generated_parser.y:310
{ {
yylex.(*parser).unexpected("grouping opts", "\",\" or \")\"") yylex.(*parser).unexpected("grouping opts", "\",\" or \")\"")
yyVAL.strings = yyDollar[1].strings yyVAL.strings = yyDollar[1].strings
} }
case 56: case 56:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:311 //line generated_parser.y:314
{ {
if !isLabel(yyDollar[1].item.Val) { if !isLabel(yyDollar[1].item.Val) {
yylex.(*parser).unexpected("grouping opts", "label") yylex.(*parser).unexpected("grouping opts", "label")
@ -1049,14 +1049,14 @@ yydefault:
} }
case 57: case 57:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:318 //line generated_parser.y:321
{ {
yylex.(*parser).unexpected("grouping opts", "label") yylex.(*parser).unexpected("grouping opts", "label")
yyVAL.item = Item{} yyVAL.item = Item{}
} }
case 58: case 58:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:326 //line generated_parser.y:329
{ {
fn, exist := getFunction(yyDollar[1].item.Val) fn, exist := getFunction(yyDollar[1].item.Val)
if !exist { if !exist {
@ -1073,58 +1073,58 @@ yydefault:
} }
case 59: case 59:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:343 //line generated_parser.y:346
{ {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
} }
case 60: case 60:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:345 //line generated_parser.y:348
{ {
yyVAL.node = Expressions{} yyVAL.node = Expressions{}
} }
case 61: case 61:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:349 //line generated_parser.y:352
{ {
yyVAL.node = append(yyDollar[1].node.(Expressions), yyDollar[3].node.(Expr)) yyVAL.node = append(yyDollar[1].node.(Expressions), yyDollar[3].node.(Expr))
} }
case 62: case 62:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:351 //line generated_parser.y:354
{ {
yyVAL.node = Expressions{yyDollar[1].node.(Expr)} yyVAL.node = Expressions{yyDollar[1].node.(Expr)}
} }
case 63: case 63:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:353 //line generated_parser.y:356
{ {
yylex.(*parser).addParseErrf(yyDollar[2].item.PositionRange(), "trailing commas not allowed in function call args") yylex.(*parser).addParseErrf(yyDollar[2].item.PositionRange(), "trailing commas not allowed in function call args")
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 64: case 64:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:364 //line generated_parser.y:367
{ {
yyVAL.node = &ParenExpr{Expr: yyDollar[2].node.(Expr), PosRange: mergeRanges(&yyDollar[1].item, &yyDollar[3].item)} yyVAL.node = &ParenExpr{Expr: yyDollar[2].node.(Expr), PosRange: mergeRanges(&yyDollar[1].item, &yyDollar[3].item)}
} }
case 65: case 65:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:372 //line generated_parser.y:375
{ {
yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[3].duration) yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[3].duration)
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 66: case 66:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:377 //line generated_parser.y:380
{ {
yylex.(*parser).unexpected("offset", "duration") yylex.(*parser).unexpected("offset", "duration")
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 67: case 67:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:385 //line generated_parser.y:388
{ {
var errMsg string var errMsg string
vs, ok := yyDollar[1].node.(*VectorSelector) vs, ok := yyDollar[1].node.(*VectorSelector)
@ -1147,7 +1147,7 @@ yydefault:
} }
case 68: case 68:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]
//line generated_parser.y:408 //line generated_parser.y:411
{ {
yyVAL.node = &SubqueryExpr{ yyVAL.node = &SubqueryExpr{
Expr: yyDollar[1].node.(Expr), Expr: yyDollar[1].node.(Expr),
@ -1159,35 +1159,35 @@ yydefault:
} }
case 69: case 69:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]
//line generated_parser.y:418 //line generated_parser.y:421
{ {
yylex.(*parser).unexpected("subquery selector", "\"]\"") yylex.(*parser).unexpected("subquery selector", "\"]\"")
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 70: case 70:
yyDollar = yyS[yypt-5 : yypt+1] yyDollar = yyS[yypt-5 : yypt+1]
//line generated_parser.y:420 //line generated_parser.y:423
{ {
yylex.(*parser).unexpected("subquery selector", "duration or \"]\"") yylex.(*parser).unexpected("subquery selector", "duration or \"]\"")
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 71: case 71:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:422 //line generated_parser.y:425
{ {
yylex.(*parser).unexpected("subquery or range", "\":\" or \"]\"") yylex.(*parser).unexpected("subquery or range", "\":\" or \"]\"")
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 72: case 72:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:424 //line generated_parser.y:427
{ {
yylex.(*parser).unexpected("subquery selector", "duration") yylex.(*parser).unexpected("subquery selector", "duration")
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 73: case 73:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:434 //line generated_parser.y:437
{ {
if nl, ok := yyDollar[2].node.(*NumberLiteral); ok { if nl, ok := yyDollar[2].node.(*NumberLiteral); ok {
if yyDollar[1].item.Typ == SUB { if yyDollar[1].item.Typ == SUB {
@ -1201,7 +1201,7 @@ yydefault:
} }
case 74: case 74:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:452 //line generated_parser.y:455
{ {
vs := yyDollar[2].node.(*VectorSelector) vs := yyDollar[2].node.(*VectorSelector)
vs.PosRange = mergeRanges(&yyDollar[1].item, vs) vs.PosRange = mergeRanges(&yyDollar[1].item, vs)
@ -1211,7 +1211,7 @@ yydefault:
} }
case 75: case 75:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:460 //line generated_parser.y:463
{ {
vs := &VectorSelector{ vs := &VectorSelector{
Name: yyDollar[1].item.Val, Name: yyDollar[1].item.Val,
@ -1223,7 +1223,7 @@ yydefault:
} }
case 76: case 76:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:470 //line generated_parser.y:473
{ {
vs := yyDollar[1].node.(*VectorSelector) vs := yyDollar[1].node.(*VectorSelector)
yylex.(*parser).assembleVectorSelector(vs) yylex.(*parser).assembleVectorSelector(vs)
@ -1231,7 +1231,7 @@ yydefault:
} }
case 77: case 77:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:478 //line generated_parser.y:481
{ {
yyVAL.node = &VectorSelector{ yyVAL.node = &VectorSelector{
LabelMatchers: yyDollar[2].matchers, LabelMatchers: yyDollar[2].matchers,
@ -1240,7 +1240,7 @@ yydefault:
} }
case 78: case 78:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:485 //line generated_parser.y:488
{ {
yyVAL.node = &VectorSelector{ yyVAL.node = &VectorSelector{
LabelMatchers: yyDollar[2].matchers, LabelMatchers: yyDollar[2].matchers,
@ -1249,7 +1249,7 @@ yydefault:
} }
case 79: case 79:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:492 //line generated_parser.y:495
{ {
yyVAL.node = &VectorSelector{ yyVAL.node = &VectorSelector{
LabelMatchers: []*labels.Matcher{}, LabelMatchers: []*labels.Matcher{},
@ -1258,7 +1258,7 @@ yydefault:
} }
case 80: case 80:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:501 //line generated_parser.y:504
{ {
if yyDollar[1].matchers != nil { if yyDollar[1].matchers != nil {
yyVAL.matchers = append(yyDollar[1].matchers, yyDollar[3].matcher) yyVAL.matchers = append(yyDollar[1].matchers, yyDollar[3].matcher)
@ -1268,130 +1268,130 @@ yydefault:
} }
case 81: case 81:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:509 //line generated_parser.y:512
{ {
yyVAL.matchers = []*labels.Matcher{yyDollar[1].matcher} yyVAL.matchers = []*labels.Matcher{yyDollar[1].matcher}
} }
case 82: case 82:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:511 //line generated_parser.y:514
{ {
yylex.(*parser).unexpected("label matching", "\",\" or \"}\"") yylex.(*parser).unexpected("label matching", "\",\" or \"}\"")
yyVAL.matchers = yyDollar[1].matchers yyVAL.matchers = yyDollar[1].matchers
} }
case 83: case 83:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:515 //line generated_parser.y:518
{ {
yyVAL.matcher = yylex.(*parser).newLabelMatcher(yyDollar[1].item, yyDollar[2].item, yyDollar[3].item) yyVAL.matcher = yylex.(*parser).newLabelMatcher(yyDollar[1].item, yyDollar[2].item, yyDollar[3].item)
} }
case 84: case 84:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:517 //line generated_parser.y:520
{ {
yylex.(*parser).unexpected("label matching", "string") yylex.(*parser).unexpected("label matching", "string")
yyVAL.matcher = nil yyVAL.matcher = nil
} }
case 85: case 85:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:519 //line generated_parser.y:522
{ {
yylex.(*parser).unexpected("label matching", "label matching operator") yylex.(*parser).unexpected("label matching", "label matching operator")
yyVAL.matcher = nil yyVAL.matcher = nil
} }
case 86: case 86:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:521 //line generated_parser.y:524
{ {
yylex.(*parser).unexpected("label matching", "identifier or \"}\"") yylex.(*parser).unexpected("label matching", "identifier or \"}\"")
yyVAL.matcher = nil yyVAL.matcher = nil
} }
case 87: case 87:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:529 //line generated_parser.y:532
{ {
yyVAL.labels = append(yyDollar[2].labels, labels.Label{Name: labels.MetricName, Value: yyDollar[1].item.Val}) yyVAL.labels = append(yyDollar[2].labels, labels.Label{Name: labels.MetricName, Value: yyDollar[1].item.Val})
sort.Sort(yyVAL.labels) sort.Sort(yyVAL.labels)
} }
case 88: case 88:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:531 //line generated_parser.y:534
{ {
yyVAL.labels = yyDollar[1].labels yyVAL.labels = yyDollar[1].labels
} }
case 91: case 91:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:538 //line generated_parser.y:541
{ {
yyVAL.labels = labels.New(yyDollar[2].labels...) yyVAL.labels = labels.New(yyDollar[2].labels...)
} }
case 92: case 92:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:540 //line generated_parser.y:543
{ {
yyVAL.labels = labels.New(yyDollar[2].labels...) yyVAL.labels = labels.New(yyDollar[2].labels...)
} }
case 93: case 93:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:542 //line generated_parser.y:545
{ {
yyVAL.labels = labels.New() yyVAL.labels = labels.New()
} }
case 94: case 94:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
//line generated_parser.y:544 //line generated_parser.y:547
{ {
yyVAL.labels = labels.New() yyVAL.labels = labels.New()
} }
case 95: case 95:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:548 //line generated_parser.y:551
{ {
yyVAL.labels = append(yyDollar[1].labels, yyDollar[3].label) yyVAL.labels = append(yyDollar[1].labels, yyDollar[3].label)
} }
case 96: case 96:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:550 //line generated_parser.y:553
{ {
yyVAL.labels = []labels.Label{yyDollar[1].label} yyVAL.labels = []labels.Label{yyDollar[1].label}
} }
case 97: case 97:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:552 //line generated_parser.y:555
{ {
yylex.(*parser).unexpected("label set", "\",\" or \"}\"") yylex.(*parser).unexpected("label set", "\",\" or \"}\"")
yyVAL.labels = yyDollar[1].labels yyVAL.labels = yyDollar[1].labels
} }
case 98: case 98:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:557 //line generated_parser.y:560
{ {
yyVAL.label = labels.Label{Name: yyDollar[1].item.Val, Value: yylex.(*parser).unquoteString(yyDollar[3].item.Val)} yyVAL.label = labels.Label{Name: yyDollar[1].item.Val, Value: yylex.(*parser).unquoteString(yyDollar[3].item.Val)}
} }
case 99: case 99:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:559 //line generated_parser.y:562
{ {
yylex.(*parser).unexpected("label set", "string") yylex.(*parser).unexpected("label set", "string")
yyVAL.label = labels.Label{} yyVAL.label = labels.Label{}
} }
case 100: case 100:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:561 //line generated_parser.y:564
{ {
yylex.(*parser).unexpected("label set", "\"=\"") yylex.(*parser).unexpected("label set", "\"=\"")
yyVAL.label = labels.Label{} yyVAL.label = labels.Label{}
} }
case 101: case 101:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:563 //line generated_parser.y:566
{ {
yylex.(*parser).unexpected("label set", "identifier or \"}\"") yylex.(*parser).unexpected("label set", "identifier or \"}\"")
yyVAL.label = labels.Label{} yyVAL.label = labels.Label{}
} }
case 102: case 102:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:571 //line generated_parser.y:574
{ {
yylex.(*parser).generatedParserResult = &seriesDescription{ yylex.(*parser).generatedParserResult = &seriesDescription{
labels: yyDollar[1].labels, labels: yyDollar[1].labels,
@ -1400,38 +1400,38 @@ yydefault:
} }
case 103: case 103:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
//line generated_parser.y:580 //line generated_parser.y:583
{ {
yyVAL.series = []SequenceValue{} yyVAL.series = []SequenceValue{}
} }
case 104: case 104:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:582 //line generated_parser.y:585
{ {
yyVAL.series = append(yyDollar[1].series, yyDollar[3].series...) yyVAL.series = append(yyDollar[1].series, yyDollar[3].series...)
} }
case 105: case 105:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:584 //line generated_parser.y:587
{ {
yyVAL.series = yyDollar[1].series yyVAL.series = yyDollar[1].series
} }
case 106: case 106:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:586 //line generated_parser.y:589
{ {
yylex.(*parser).unexpected("series values", "") yylex.(*parser).unexpected("series values", "")
yyVAL.series = nil yyVAL.series = nil
} }
case 107: case 107:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:590 //line generated_parser.y:593
{ {
yyVAL.series = []SequenceValue{{Omitted: true}} yyVAL.series = []SequenceValue{{Omitted: true}}
} }
case 108: case 108:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:592 //line generated_parser.y:595
{ {
yyVAL.series = []SequenceValue{} yyVAL.series = []SequenceValue{}
for i := uint64(0); i < yyDollar[3].uint; i++ { for i := uint64(0); i < yyDollar[3].uint; i++ {
@ -1440,13 +1440,13 @@ yydefault:
} }
case 109: case 109:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:599 //line generated_parser.y:602
{ {
yyVAL.series = []SequenceValue{{Value: yyDollar[1].float}} yyVAL.series = []SequenceValue{{Value: yyDollar[1].float}}
} }
case 110: case 110:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:601 //line generated_parser.y:604
{ {
yyVAL.series = []SequenceValue{} yyVAL.series = []SequenceValue{}
for i := uint64(0); i <= yyDollar[3].uint; i++ { for i := uint64(0); i <= yyDollar[3].uint; i++ {
@ -1455,7 +1455,7 @@ yydefault:
} }
case 111: case 111:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:608 //line generated_parser.y:611
{ {
yyVAL.series = []SequenceValue{} yyVAL.series = []SequenceValue{}
for i := uint64(0); i <= yyDollar[4].uint; i++ { for i := uint64(0); i <= yyDollar[4].uint; i++ {
@ -1465,7 +1465,7 @@ yydefault:
} }
case 112: case 112:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:618 //line generated_parser.y:621
{ {
if yyDollar[1].item.Val != "stale" { if yyDollar[1].item.Val != "stale" {
yylex.(*parser).unexpected("series values", "number or \"stale\"") yylex.(*parser).unexpected("series values", "number or \"stale\"")
@ -1474,7 +1474,7 @@ yydefault:
} }
case 155: case 155:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:649 //line generated_parser.y:652
{ {
yyVAL.node = &NumberLiteral{ yyVAL.node = &NumberLiteral{
Val: yylex.(*parser).number(yyDollar[1].item.Val), Val: yylex.(*parser).number(yyDollar[1].item.Val),
@ -1483,25 +1483,25 @@ yydefault:
} }
case 156: case 156:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:657 //line generated_parser.y:660
{ {
yyVAL.float = yylex.(*parser).number(yyDollar[1].item.Val) yyVAL.float = yylex.(*parser).number(yyDollar[1].item.Val)
} }
case 157: case 157:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:659 //line generated_parser.y:662
{ {
yyVAL.float = yyDollar[2].float yyVAL.float = yyDollar[2].float
} }
case 158: case 158:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line generated_parser.y:660 //line generated_parser.y:663
{ {
yyVAL.float = -yyDollar[2].float yyVAL.float = -yyDollar[2].float
} }
case 159: case 159:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:664 //line generated_parser.y:667
{ {
var err error var err error
yyVAL.uint, err = strconv.ParseUint(yyDollar[1].item.Val, 10, 64) yyVAL.uint, err = strconv.ParseUint(yyDollar[1].item.Val, 10, 64)
@ -1511,7 +1511,7 @@ yydefault:
} }
case 160: case 160:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:674 //line generated_parser.y:677
{ {
var err error var err error
yyVAL.duration, err = parseDuration(yyDollar[1].item.Val) yyVAL.duration, err = parseDuration(yyDollar[1].item.Val)
@ -1521,7 +1521,7 @@ yydefault:
} }
case 161: case 161:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line generated_parser.y:685 //line generated_parser.y:688
{ {
yyVAL.node = &StringLiteral{ yyVAL.node = &StringLiteral{
Val: yylex.(*parser).unquoteString(yyDollar[1].item.Val), Val: yylex.(*parser).unquoteString(yyDollar[1].item.Val),
@ -1530,13 +1530,13 @@ yydefault:
} }
case 162: case 162:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
//line generated_parser.y:698 //line generated_parser.y:701
{ {
yyVAL.duration = 0 yyVAL.duration = 0
} }
case 164: case 164:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
//line generated_parser.y:702 //line generated_parser.y:705
{ {
yyVAL.strings = nil yyVAL.strings = nil
} }

View file

@ -2125,6 +2125,18 @@ var testExpr = []struct {
input: "a>b()", input: "a>b()",
fail: true, fail: true,
errMsg: `unknown function`, errMsg: `unknown function`,
}, {
input: "rate(avg)",
fail: true,
errMsg: `unexpected ")"`,
}, {
input: "sum(sum)",
fail: true,
errMsg: `unexpected ")"`,
}, {
input: "a + sum",
fail: true,
errMsg: `unexpected end of input`,
}, },
// String quoting and escape sequence interpretation tests. // String quoting and escape sequence interpretation tests.
{ {