2013-02-07 10:49:04 +00:00
|
|
|
/* Copyright 2013 Prometheus Team
|
|
|
|
* 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. */
|
|
|
|
|
2013-01-07 22:24:26 +00:00
|
|
|
%{
|
|
|
|
package rules
|
|
|
|
|
|
|
|
import (
|
2013-02-07 13:32:18 +00:00
|
|
|
"github.com/prometheus/prometheus/model"
|
2013-01-07 22:24:26 +00:00
|
|
|
"strconv"
|
2013-04-09 12:00:25 +00:00
|
|
|
"strings"
|
2013-01-07 22:24:26 +00:00
|
|
|
)
|
|
|
|
%}
|
|
|
|
|
|
|
|
D [0-9]
|
|
|
|
L [a-zA-Z_:]
|
2013-01-22 00:51:26 +00:00
|
|
|
U [smhdwy]
|
2013-01-07 22:24:26 +00:00
|
|
|
|
|
|
|
%x S_COMMENTS
|
|
|
|
|
|
|
|
%%
|
|
|
|
. { yypos++; REJECT }
|
|
|
|
\n { yyline++; yypos = 1; REJECT }
|
|
|
|
|
|
|
|
"/*" { BEGIN(S_COMMENTS) }
|
|
|
|
<S_COMMENTS>"*/" { BEGIN(0) }
|
|
|
|
<S_COMMENTS>. { /* ignore chars within multi-line comments */ }
|
|
|
|
|
|
|
|
\/\/[^\r\n]*\n { /* gobble up one-line comments */ }
|
|
|
|
|
|
|
|
permanent { return PERMANENT }
|
2013-04-15 09:56:23 +00:00
|
|
|
BY|by { return GROUP_OP }
|
2013-01-07 22:24:26 +00:00
|
|
|
AVG|SUM|MAX|MIN { yylval.str = yytext; return AGGR_OP }
|
2013-04-09 12:00:25 +00:00
|
|
|
avg|sum|max|min { yylval.str = strings.ToUpper(yytext); return AGGR_OP }
|
2013-01-07 22:24:26 +00:00
|
|
|
\<|>|AND|OR { yylval.str = yytext; return CMP_OP }
|
|
|
|
==|!=|>=|<= { yylval.str = yytext; return CMP_OP }
|
|
|
|
[+\-] { yylval.str = yytext; return ADDITIVE_OP }
|
|
|
|
[*/%] { yylval.str = yytext; return MULT_OP }
|
|
|
|
|
2013-01-22 00:51:26 +00:00
|
|
|
{D}+{U} { yylval.str = yytext; return DURATION }
|
2013-03-28 17:14:41 +00:00
|
|
|
{L}({L}|{D})* { yylval.str = yytext; return IDENTIFIER }
|
2013-01-07 22:24:26 +00:00
|
|
|
|
|
|
|
\-?{D}+(\.{D}*)? { num, err := strconv.ParseFloat(yytext, 32);
|
2013-02-13 16:41:35 +00:00
|
|
|
if (err != nil && err.(*strconv.NumError).Err == strconv.ErrSyntax) {
|
|
|
|
panic("Invalid float")
|
|
|
|
}
|
2013-01-07 22:24:26 +00:00
|
|
|
yylval.num = model.SampleValue(num)
|
|
|
|
return NUMBER }
|
|
|
|
|
|
|
|
\"(\\.|[^\\"])*\" { yylval.str = yytext[1:len(yytext) - 1]; return STRING }
|
|
|
|
\'(\\.|[^\\'])*\' { yylval.str = yytext[1:len(yytext) - 1]; return STRING }
|
|
|
|
|
|
|
|
[{}\[\]()=,] { return int(yytext[0]) }
|
|
|
|
. { /* don't print any remaining chars (whitespace) */ }
|
|
|
|
\n { /* don't print any remaining chars (whitespace) */ }
|
|
|
|
%%
|