2018-10-04 09:57:47 -07:00
|
|
|
%{
|
2018-10-09 06:09:44 -07:00
|
|
|
// Copyright 2018 The Prometheus Authors
|
2018-10-04 09:57:47 -07:00
|
|
|
// 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 textparse
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Lex is called by the parser generated by "go tool yacc" to obtain each
|
|
|
|
// token. The method is opened before the matching rules block and closed at
|
|
|
|
// the end of the file.
|
2018-10-09 06:09:44 -07:00
|
|
|
func (l *openMetricsLexer) Lex() token {
|
2018-10-04 09:57:47 -07:00
|
|
|
if l.i >= len(l.b) {
|
|
|
|
return tEOF
|
|
|
|
}
|
|
|
|
c := l.b[l.i]
|
|
|
|
l.start = l.i
|
|
|
|
|
|
|
|
%}
|
|
|
|
|
|
|
|
D [0-9]
|
|
|
|
L [a-zA-Z_]
|
|
|
|
M [a-zA-Z_:]
|
|
|
|
C [^\n]
|
|
|
|
S [ ]
|
|
|
|
|
2019-11-19 01:33:30 -08:00
|
|
|
%x sComment sMeta1 sMeta2 sLabels sLValue sValue sTimestamp sExemplar sEValue sETimestamp
|
2018-10-04 09:57:47 -07:00
|
|
|
|
|
|
|
%yyc c
|
|
|
|
%yyn c = l.next()
|
|
|
|
%yyt l.state
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
#{S} l.state = sComment
|
|
|
|
<sComment>HELP{S} l.state = sMeta1; return tHelp
|
|
|
|
<sComment>TYPE{S} l.state = sMeta1; return tType
|
|
|
|
<sComment>UNIT{S} l.state = sMeta1; return tUnit
|
2020-03-23 07:47:11 -07:00
|
|
|
<sComment>"EOF"\n? l.state = sInit; return tEOFWord
|
2024-02-15 11:25:12 -08:00
|
|
|
<sMeta1>\"(\\.|[^\\"])*\" l.state = sMeta2; return tMName
|
2018-10-04 09:57:47 -07:00
|
|
|
<sMeta1>{M}({M}|{D})* l.state = sMeta2; return tMName
|
|
|
|
<sMeta2>{S}{C}*\n l.state = sInit; return tText
|
|
|
|
|
|
|
|
{M}({M}|{D})* l.state = sValue; return tMName
|
|
|
|
<sValue>\{ l.state = sLabels; return tBraceOpen
|
2024-02-15 11:25:12 -08:00
|
|
|
\{ l.state = sLabels; return tBraceOpen
|
2018-10-04 09:57:47 -07:00
|
|
|
<sLabels>{L}({L}|{D})* return tLName
|
2024-02-15 11:25:12 -08:00
|
|
|
<sLabels>\"(\\.|[^\\"])*\" l.state = sLabels; return tQString
|
2018-10-04 09:57:47 -07:00
|
|
|
<sLabels>\} l.state = sValue; return tBraceClose
|
|
|
|
<sLabels>= l.state = sLValue; return tEqual
|
|
|
|
<sLabels>, return tComma
|
|
|
|
<sLValue>\"(\\.|[^\\"\n])*\" l.state = sLabels; return tLValue
|
|
|
|
<sValue>{S}[^ \n]+ l.state = sTimestamp; return tValue
|
|
|
|
<sTimestamp>{S}[^ \n]+ return tTimestamp
|
|
|
|
<sTimestamp>\n l.state = sInit; return tLinebreak
|
2019-11-19 01:33:30 -08:00
|
|
|
<sTimestamp>{S}#{S}\{ l.state = sExemplar; return tComment
|
|
|
|
|
|
|
|
<sExemplar>{L}({L}|{D})* return tLName
|
|
|
|
<sExemplar>\} l.state = sEValue; return tBraceClose
|
|
|
|
<sExemplar>= l.state = sEValue; return tEqual
|
|
|
|
<sEValue>\"(\\.|[^\\"\n])*\" l.state = sExemplar; return tLValue
|
|
|
|
<sExemplar>, return tComma
|
|
|
|
<sEValue>{S}[^ \n]+ l.state = sETimestamp; return tValue
|
|
|
|
<sETimestamp>{S}[^ \n]+ return tTimestamp
|
|
|
|
<sETimestamp>\n l.state = sInit; return tLinebreak
|
2018-10-04 09:57:47 -07:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
return tInvalid
|
|
|
|
}
|