Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/subexstate.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2025-10-18 09:41:50 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2025-10-18 09:41:50 +0100
commitb2ce005d227a10a9b8a6f5362c87a0e34ee07acc (patch)
tree454c7dcafc02759b90d083ab1d72c0bbfb65f578 /subex/subexstate.go
parent62aa738be03845f96c40edde087ea39693b27e4e (diff)
downloadstred-go-b2ce005d227a10a9b8a6f5362c87a0e34ee07acc.tar
Implement numbers properlyHEADnumbersmain
Diffstat (limited to 'subex/subexstate.go')
-rw-r--r--subex/subexstate.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/subex/subexstate.go b/subex/subexstate.go
index 3bcbdee..bf5bab9 100644
--- a/subex/subexstate.go
+++ b/subex/subexstate.go
@@ -104,6 +104,29 @@ func (state SubexCopyNumberState) accepting(aux auxiliaryState) []OutputStack {
return nil
}
+type SubexNumberMappingState struct {
+ Range NumberExpr
+ Replace []NumberExpr
+ next SubexState
+}
+func (state SubexNumberMappingState) eat(aux auxiliaryState, edible walk.Edible) []SubexBranch {
+ number, isNumber := edible.(walk.NumberValue)
+ if !isNumber || state.Range.Eval(float64(number)) == 0.0 {
+ return nil
+ }
+ var res []walk.Value
+ for _, expr := range state.Replace {
+ res = append(res, walk.NumberValue(expr.Eval(float64(number))))
+ }
+ return []SubexBranch {{
+ state: state.next,
+ aux: aux.topAppend(res),
+ }}
+}
+func (state SubexNumberMappingState) accepting(aux auxiliaryState) []OutputStack {
+ return nil
+}
+
// Just pushes to the OutputStack and hands over to the next state
// Used to capture the output of the state being handed over to
type SubexCaptureBeginState struct {