Also support parsing float formats like "2.".

This commit is contained in:
Julius Volz 2015-03-01 22:49:06 +01:00 committed by Julius Volz
parent c2ab54e9a6
commit 0ac931aed1
3 changed files with 9 additions and 9 deletions

View File

@ -55,7 +55,7 @@ L [a-zA-Z_]
M [a-zA-Z_:]
U [smhdwy]
FLOAT [-+]?{D}*\.?{D}+{EXPONENT}?|[+-]?[iI][nN][fF]|[nN][aA][nN]
FLOAT [-+]?({D}*\.?{D}+|{D}+\.?{D}*){EXPONENT}?|[+-]?[iI][nN][fF]|[nN][aA][nN]
EXPONENT [eE][-+]?[0-9]+
STR \"(\\.|[^\\"])*\"|\'(\\.|[^\\'])*\'

View File

@ -288,7 +288,7 @@ yystate18:
default:
goto yyrule21
case c == '.':
goto yystate13
goto yystate14
case c == 'E' || c == 'e':
goto yystate15
case c >= '0' && c <= '9':
@ -353,7 +353,7 @@ yystate26:
default:
goto yyrule21
case c == '.':
goto yystate13
goto yystate14
case c == 'E' || c == 'e':
goto yystate15
case c == 'd' || c == 'h' || c == 'm' || c == 's' || c == 'w' || c == 'y':

View File

@ -36,7 +36,7 @@ var (
testEvalTime = testStartTime.Add(testSampleInterval * 10)
fixturesPath = "fixtures"
reSample = regexp.MustCompile(`^(.*)( \=\>|:) (\-?\d+\.?\d*e?\d*|[+-]Inf|NaN) \@\[(\d+)\]$`)
reSample = regexp.MustCompile(`^(.*)(?: \=\>|:) (\-?\d+\.?\d*e?\d*|[+-]Inf|NaN) \@\[(\d+)\]$`)
minNormal = math.Float64frombits(0x0010000000000000) // The smallest positive normal value of type float64.
)
@ -81,16 +81,16 @@ func samplesAlmostEqual(a, b string) bool {
if aMatches[1] != bMatches[1] {
return false // Labels don't match.
}
if aMatches[4] != bMatches[4] {
if aMatches[3] != bMatches[3] {
return false // Timestamps don't match.
}
// If we are here, we have the diff in the floats.
// We have to check if they are almost equal.
aVal, err := strconv.ParseFloat(aMatches[3], 64)
aVal, err := strconv.ParseFloat(aMatches[2], 64)
if err != nil {
panic(err)
}
bVal, err := strconv.ParseFloat(bMatches[3], 64)
bVal, err := strconv.ParseFloat(bMatches[2], 64)
if err != nil {
panic(err)
}
@ -948,7 +948,7 @@ func TestExpressions(t *testing.T) {
},
{
expr: `2.`,
shouldFail: true,
output: []string{`scalar: 2 @[%v]`},
},
{
expr: `999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999`,