summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-20 21:55:57 +0200
committerPaul Buetow <paul@buetow.org>2026-03-20 21:55:57 +0200
commit15b87ea17d96856d3ed9f2dbfbc80343b01b78df (patch)
treecc5b1fbbb722ddbab49450d308d6945d99f3c01c /cmd
parent9a282b74a179517c009f855c14d3fa63ad805871 (diff)
cmd/perc/main.go: try RPN parsing before percentage calculation in command mode
- Bare expressions like '1 2 +' now work without 'calc' prefix - Assignment format 'name value =' requires 'calc' subcommand prefix
Diffstat (limited to 'cmd')
-rw-r--r--cmd/perc/main.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/cmd/perc/main.go b/cmd/perc/main.go
index d33593c..2cee268 100644
--- a/cmd/perc/main.go
+++ b/cmd/perc/main.go
@@ -56,6 +56,13 @@ func runCommand(args []string) (string, error) {
}
input := strings.Join(args[1:], " ")
+
+ // Try RPN parsing first (for bare RPN expressions like "3 4 +")
+ if rpnResult, rpnErr := runRPN(input); rpnErr == nil {
+ return rpnResult, nil
+ }
+
+ // Fall back to percentage calculation
result, err := calculator.Parse(input)
if err != nil {
return "", err