Skip to content

Commit

Permalink
Merge pull request prometheus#27 from promlabs/feature/signed-number
Browse files Browse the repository at this point in the history
support signed number in StepInvariantExpr
  • Loading branch information
juliusv authored Mar 22, 2021
2 parents 5796b4f + 7ae5567 commit 3f5ab5e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/promql.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,16 @@ MetricIdentifier {
}

StepInvariantExpr {
Expr At ( NumberLiteral | AtModifierPreprocessors "(" ")" )
Expr At ( NumberLiteral | SignedNumber | AtModifierPreprocessors "(" ")" )
}

AtModifierPreprocessors {
Start | End
Start | End
}


SignedNumber{
("+" | "-" ) NumberLiteral
}

@skip { whitespace | LineComment }

Expand Down
42 changes: 42 additions & 0 deletions test/expression.txt
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,48 @@ PromQL(
)
)

# At modifier with negative number

foo @ - 1234

==>
PromQL(
Expr(
StepInvariantExpr(
Expr(
VectorSelector(
MetricIdentifier(
Identifier
)
)
)
At,
SignedNumber(NumberLiteral)
)
)
)

# At modifier with explicit positive number

foo @ + 1234

==>
PromQL(
Expr(
StepInvariantExpr(
Expr(
VectorSelector(
MetricIdentifier(
Identifier
)
)
)
At,
SignedNumber(NumberLiteral)
)
)
)

# Mixed-case NaN.

NaN
Expand Down

0 comments on commit 3f5ab5e

Please sign in to comment.