reduce addOffst to 2 parameters

Signed-off-by: schou <pschou@users.noreply.github.com>
This commit is contained in:
schou 2021-02-23 20:46:52 -05:00
parent 75d932a172
commit efbf3af05d
3 changed files with 6 additions and 6 deletions

View file

@ -383,12 +383,12 @@ paren_expr : LEFT_PAREN expr RIGHT_PAREN
offset_expr: expr OFFSET duration offset_expr: expr OFFSET duration
{ {
yylex.(*parser).addOffset($1, $3, 1) yylex.(*parser).addOffset($1, $3)
$$ = $1 $$ = $1
} }
| expr OFFSET SUB duration | expr OFFSET SUB duration
{ {
yylex.(*parser).addOffset($1, $4, -1) yylex.(*parser).addOffset($1, -$4)
$$ = $1 $$ = $1
} }
| expr OFFSET error | expr OFFSET error

View file

@ -1241,14 +1241,14 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line generated_parser.y:385 //line generated_parser.y:385
{ {
yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[3].duration, 1) yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[3].duration)
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 67: case 67:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
//line generated_parser.y:390 //line generated_parser.y:390
{ {
yylex.(*parser).addOffset(yyDollar[1].node, yyDollar[4].duration, -1) yylex.(*parser).addOffset(yyDollar[1].node, -yyDollar[4].duration)
yyVAL.node = yyDollar[1].node yyVAL.node = yyDollar[1].node
} }
case 68: case 68:

View file

@ -683,7 +683,7 @@ func (p *parser) newLabelMatcher(label Item, operator Item, value Item) *labels.
} }
// addOffset is used to set the offset in the generated parser. // addOffset is used to set the offset in the generated parser.
func (p *parser) addOffset(e Node, offset time.Duration, direction int) { func (p *parser) addOffset(e Node, offset time.Duration) {
var orgoffsetp *time.Duration var orgoffsetp *time.Duration
var endPosp *Pos var endPosp *Pos
@ -711,7 +711,7 @@ func (p *parser) addOffset(e Node, offset time.Duration, direction int) {
if *orgoffsetp != 0 { if *orgoffsetp != 0 {
p.addParseErrf(e.PositionRange(), "offset may not be set multiple times") p.addParseErrf(e.PositionRange(), "offset may not be set multiple times")
} else if orgoffsetp != nil { } else if orgoffsetp != nil {
*orgoffsetp = offset * time.Duration(direction) *orgoffsetp = offset
} }
*endPosp = p.lastClosing *endPosp = p.lastClosing