From f075b188fde9e201f3825b16ce9f562282854a49 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 23 May 2026 20:28:36 +0300 Subject: refactor: replace hardcoded operator whitelist with registry lookups (OCP) Add IsStandardOperator/IsHyperOperator forwarding methods on *RPN that delegate to OperatorRegistry. Replace the hardcoded string literal whitelist in RPNHandler.Handle() with dynamic registry lookups. New operators are now automatically recognized without updating handlers.go. Also fixes missing operators in the old whitelist (e.g., comparison operators, assignment operators). --- internal/repl/handlers.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'internal/repl') diff --git a/internal/repl/handlers.go b/internal/repl/handlers.go index 5e568a3..78f07dd 100644 --- a/internal/repl/handlers.go +++ b/internal/repl/handlers.go @@ -172,14 +172,7 @@ func (h *RPNHandler) Handle(repl *REPL, input string) (output string, handled bo fields := strings.Fields(input) if len(fields) == 1 { op := strings.ToLower(fields[0]) - // Check if it's a known operator (standard or hyper) - isStandardOp := op == "+" || op == "-" || op == "*" || op == "/" || op == "^" || op == "%" || - op == "dup" || op == "swap" || op == "pop" || op == "show" || op == "clear" || op == "vars" || - op == "lg" || op == "log" || op == "ln" - isHyperOp := op == "[+]" || op == "[-]" || op == "[*]" || op == "[/]" || op == "[^]" || op == "[%]" || - op == "[lg]" || op == "[log]" || op == "[ln]" - - if isStandardOp || isHyperOp { + if repl.rpnState.rpnCalc.IsStandardOperator(op) || repl.rpnState.rpnCalc.IsHyperOperator(op) { result, err := repl.rpnState.rpnCalc.EvalOperator(op) if err != nil { return "", true, err -- cgit v1.2.3