summaryrefslogtreecommitdiff
path: root/internal/repl
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-23 20:28:36 +0300
committerPaul Buetow <paul@buetow.org>2026-05-23 20:28:36 +0300
commitf075b188fde9e201f3825b16ce9f562282854a49 (patch)
tree89303f7779d7ab8b43881f79de277dbed69a1902 /internal/repl
parent1042acacd2d875afec9e56a021cd3d254044de9d (diff)
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).
Diffstat (limited to 'internal/repl')
-rw-r--r--internal/repl/handlers.go9
1 files changed, 1 insertions, 8 deletions
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