diff options
| author | Charlie Stanton <charlie@shtanton.xyz> | 2025-10-18 09:41:50 +0100 |
|---|---|---|
| committer | Charlie Stanton <charlie@shtanton.xyz> | 2025-10-18 09:41:50 +0100 |
| commit | b2ce005d227a10a9b8a6f5362c87a0e34ee07acc (patch) | |
| tree | 454c7dcafc02759b90d083ab1d72c0bbfb65f578 /subex/subexstate.go | |
| parent | 62aa738be03845f96c40edde087ea39693b27e4e (diff) | |
| download | stred-go-b2ce005d227a10a9b8a6f5362c87a0e34ee07acc.tar | |
Implement numbers properlynumbers
Diffstat (limited to 'subex/subexstate.go')
| -rw-r--r-- | subex/subexstate.go | 23 |
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 { |
