From b2ce005d227a10a9b8a6f5362c87a0e34ee07acc Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 18 Oct 2025 09:41:50 +0100 Subject: Implement numbers properly --- subex/subexstate.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'subex/subexstate.go') 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 { -- cgit v1.2.3