mirror of https://github.com/prometheus/prometheus
77 lines
1.7 KiB
Plaintext
77 lines
1.7 KiB
Plaintext
%{
|
|
package textparse
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"strconv"
|
|
)
|
|
|
|
//type lstate int
|
|
|
|
|
|
// 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.
|
|
func (l *lexer) Lex() int {
|
|
const (
|
|
lstateInit = iota
|
|
lstateValue
|
|
lstateLabels
|
|
lstateLName
|
|
lstateLValue
|
|
)
|
|
s := lstateInit
|
|
|
|
if l.i >= len(l.b) {
|
|
return eof
|
|
}
|
|
c := l.b[l.i]
|
|
%}
|
|
|
|
D [0-9]
|
|
L [a-zA-Z_]
|
|
M [a-zA-Z_:]
|
|
|
|
%x lstateValue lstateLabels lstateLName lstateLValue
|
|
|
|
|
|
%yyc c
|
|
%yyn c = l.next()
|
|
%yyt s
|
|
|
|
|
|
%%
|
|
|
|
\0 return 0
|
|
#[^\r\n]*\n l.mstart = l.i
|
|
[\r\n \t]+ l.mstart = l.i
|
|
|
|
{L}({L}|{D})*\{ s = lstateLName
|
|
{L}({L}|{D})* s = lstateValue
|
|
l.mend = l.i
|
|
|
|
<lstateLabels>[ \t]+
|
|
<lstateLabels>\} s = lstateValue
|
|
l.mend = l.i
|
|
<lstateLabels>,? s = lstateLName
|
|
|
|
<lstateLName>{M}({M}|{D})*= s = lstateLValue
|
|
|
|
<lstateLValue>\"(\\.|[^\\"])*\" s = lstateLabels
|
|
<lstateLValue>\'(\\.|[^\\'])*\' s = lstateLabels
|
|
|
|
<lstateValue>[ \t]+ l.vstart = l.i
|
|
<lstateValue>(NaN) l.val = math.NaN()
|
|
return 1
|
|
<lstateValue>[^\n \t\r]+ // We don't parse strictly correct floats as the conversion
|
|
// repeats the effort anyway.
|
|
l.val, l.err = strconv.ParseFloat(yoloString(l.b[l.vstart:l.i]), 64)
|
|
if l.err != nil {
|
|
return -1
|
|
}
|
|
return 1
|
|
|
|
%%
|
|
return -1
|
|
} |