// Copyright 2019 The Prometheus Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. %{ package promql import ( "github.com/prometheus/prometheus/pkg/labels" ) %} %union { node Node item item matchers []*labels.Matcher matcher *labels.Matcher } %token ERROR %token EOF %token COMMENT %token IDENTIFIER %token METRIC_IDENTIFIER %token LEFT_PAREN %token RIGHT_PAREN %token LEFT_BRACE %token RIGHT_BRACE %token LEFT_BRACKET %token RIGHT_BRACKET %token COMMA %token ASSIGN %token COLON %token SEMICOLON %token STRING %token NUMBER %token DURATION %token BLANK %token TIMES %token SPACE %token operatorsStart // Operators. %token SUB %token ADD %token MUL %token MOD %token DIV %token LAND %token LOR %token LUNLESS %token EQL %token NEQ %token LTE %token LSS %token GTE %token GTR %token EQL_REGEX %token NEQ_REGEX %token POW %token operatorsEnd %token aggregatorsStart // Aggregators. %token AVG %token COUNT %token SUM %token MIN %token MAX %token STDDEV %token STDVAR %token TOPK %token BOTTOMK %token COUNT_VALUES %token QUANTILE %token aggregatorsEnd %token keywordsStart // Keywords. %token OFFSET %token BY %token WITHOUT %token ON %token IGNORING %token GROUP_LEFT %token GROUP_RIGHT %token BOOL %token keywordsEnd %token startSymbolsStart // Start symbols for the generated parser. %token START_LABELS %token startSymbolsEnd %type label_matchers label_match_list %type label_matcher %type match_op %start start %% start : START_LABELS label_matchers {yylex.(*parser).generatedParserResult.(*VectorSelector).LabelMatchers = $2} | error { yylex.(*parser).errorf("unknown syntax error after parsing %v", yylex.(*parser).token.desc()) } ; label_match_list: label_match_list COMMA label_matcher { $$ = append($1, $3)} | label_matcher { $$ = []*labels.Matcher{$1}} ; label_matchers : LEFT_BRACE label_match_list RIGHT_BRACE { $$ = $2 } | LEFT_BRACE RIGHT_BRACE { $$ = []*labels.Matcher{} } ; label_matcher : IDENTIFIER match_op STRING { $$ = yylex.(*parser).newLabelMatcher($1, $2, $3) } | IDENTIFIER match_op error { yylex.(*parser).errorf("unexpected %v in label matching, expected string", yylex.(*parser).token.desc())} ; match_op : EQL {$$ =$1} | NEQ {$$=$1} | EQL_REGEX {$$=$1} | NEQ_REGEX {$$=$1} | error { yylex.(*parser).errorf("expected label matching operator but got %s", yylex.(*parser).token.val) } ; %%