From a963fd6f854d476ec838fbde7ae3c28cd4270c97 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 24 May 2026 10:11:42 +0300 Subject: refactor(rpn): have ResultStack reuse pushLiteral ResultStack reimplemented boolean and number parsing that already existed in pushLiteral. This duplication also meant it missed metric-suffixed numbers (e.g. 100Mbps) and @metric prefixes (e.g. @GB). Replace the duplicated logic with a call to pushLiteral, which handles booleans, plain numbers, metric-suffixed numbers, and @metric prefixes in one place. --- internal/rpn/rpn_ops.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/internal/rpn/rpn_ops.go b/internal/rpn/rpn_ops.go index 8620197..caf1e87 100644 --- a/internal/rpn/rpn_ops.go +++ b/internal/rpn/rpn_ops.go @@ -5,7 +5,6 @@ package rpn import ( "fmt" - "strconv" "strings" ) @@ -26,22 +25,10 @@ func (r *RPN) ResultStack(tokens []string) (string, error) { stack := NewStack() for _, token := range tokens { - // Check if it's a boolean literal - if token == "true" { - stack.Push(NewFloatFromBool(true)) - continue - } - if token == "false" { - stack.Push(NewFloatFromBool(false)) - continue - } - - // Check if it's a number - if num, err := strconv.ParseFloat(token, 64); err == nil { - if stack.Len() >= r.maxStack { - return "", fmt.Errorf("stack overflow") - } - stack.Push(NewNumber(num, mode)) + // Push literal values (numbers, booleans, metric values, @metric prefix) + if pushed, err := r.pushLiteral(stack, token); err != nil { + return "", err + } else if pushed { continue } -- cgit v1.2.3