summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-24 10:57:40 +0300
committerPaul Buetow <paul@buetow.org>2026-05-24 10:57:40 +0300
commit065dd252af1d2f1c70f8929058ea364481ab0658 (patch)
treeb7265b53152e5a4b4393e454fffda581352a74e5
parent2664151ece7c9f0d3617c6c7873918cb920e2211 (diff)
fix: replace fragile string matching in ResultStack with registry check
ResultStack used strings.Contains(err.Error(), "unknown token") to decide whether to fall through to variable lookup. This is fragile and breaks if error messages change. Use the same pattern as handleOperator: check IsStandardOperator/IsHyperOperator directly.
-rw-r--r--internal/rpn/rpn_ops.go5
1 files changed, 2 insertions, 3 deletions
diff --git a/internal/rpn/rpn_ops.go b/internal/rpn/rpn_ops.go
index 9104eea..9208195 100644
--- a/internal/rpn/rpn_ops.go
+++ b/internal/rpn/rpn_ops.go
@@ -34,9 +34,8 @@ func (r *RPN) ResultStack(tokens []string) (string, error) {
// Handle operator (common logic from executeOperator)
if result, handled, err := r.executeOperator(stack, token); err != nil {
- // If the error is not "unknown token", return it
- // Otherwise, fall through to check for variable
- if !strings.Contains(err.Error(), "unknown token") {
+ // If not a recognized operator, fall through to check for variable
+ if r.opRegistry.IsStandardOperator(token) || r.opRegistry.IsHyperOperator(token) {
return "", err
}
} else if handled {