-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery.bnf
59 lines (42 loc) · 2.2 KB
/
query.bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Lexical elements */
_letter : 'a'-'z' | 'A'-'Z' ;
_digit : '0'-'9';
_lineComment : '/' '/' {.} '\n' ;
_blockComment : '/' '*' {. | '*'} '*' '/' ;
int64 : ( '1'-'9' | '-') {_digit};
varname : '/' (_letter | _digit) {_letter | _digit | '/' | '_' | '-'};
varlabel : (_letter | _digit | '/' | '_' | '-' | '*') {_letter | _digit | '/' | '_' | '-' | '*'};
!whitespace : ' ' | '\t' | '\n' | '\r';
!comment : _lineComment | _blockComment;
/* Syntax Part */
<< import "github.com/dparrish/openinstrument/query/ast" >>
Query : VariableList << ast.NewQuery($0) >>
| Mutation << ast.NewQuery($0) >>
| Aggregation << ast.NewQuery($0) >> ;
Aggregation :
// sum (/test/foo)
AggregationType "(" Query ")" << ast.NewAggregation($0, nil, $2) >>
// sum by (foo) (/test/foo{foo=bar})
| AggregationType "by" "(" LabelList ")" "(" Query ")" << ast.NewAggregation($0, $3, $6) >>
;
Mutation : MutationType "(" Duration "," Query ")" << ast.NewMutation($0, $2, $4) >>
| MutationType "(" Query ")" << ast.NewMutation($0, nil, $2) >>;
LabelList : varlabel << ast.NewLabelList($0) >>
| LabelList "," varlabel << ast.AppendStringToList($0, $2) >> ;
AggregationType : "sum" | "mean" | "median" | "min" | "max" | "stddev" | Percentile;
MutationType: "rate" | "rate_signed" | "latest" | "regularize" | "interpolate";
Percentile : "percentile" "(" Int64 ")" << ast.NewPercentile($2) >>;
Variable : VarName
| VarName "[" int64 ":" int64 "]" << ast.AddRangeToVariable($0, $2, $4) >>
| VarName "[" int64 "]" << ast.AddRangeToVariable($0, $2, nil) >>
;
VarName : varname << ast.NewVariable($0, nil) >>
| varname "{}" << ast.NewVariable($0, nil) >>
| varname "{" KeyValues "}" << ast.NewVariable($0, $2) >> ;
KeyValues : KeyValue << ast.NewKeyValueList($0) >>
| KeyValues "," KeyValue << ast.AppendKeyValueList($0, $2) >> ;
KeyValue : varlabel "=" varlabel << ast.NewKeyValue($0, $2) >>;
VariableList : Variable << ast.NewVariableList($0) >>
| VariableList "," Variable << ast.AddVariableToVariableList($0, $2) >>;
Duration: varlabel << ast.NewDuration($0) >>;
Int64: int64 << ast.NewInt64($0) >>;