From 184118c1522ee4e78a0588fcac8eb235f512b599 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 21 Apr 2023 11:19:18 +0100 Subject: Add :xyz: replacement syntax that removes whatever is before it and inserts whatever is inside it --- subex/subexstate.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'subex/subexstate.go') diff --git a/subex/subexstate.go b/subex/subexstate.go index 997e6ce..b5e1e9b 100644 --- a/subex/subexstate.go +++ b/subex/subexstate.go @@ -36,6 +36,19 @@ func (state SubexCaptureBeginState) accepting(store Store, outputStack OutputSta return state.next.accepting(store, outputStack.push(nil)) } +// Discard the top of the OutputStack +type SubexDiscardState struct { + next SubexState +} +func (state SubexDiscardState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { + _, newStack := outputStack.pop() + return state.next.eat(store, newStack, char) +} +func (state SubexDiscardState) accepting(store Store, outputStack OutputStack) []OutputStack { + _, newStack := outputStack.pop() + return state.next.accepting(store, newStack) +} + // Pop the top of the OutputStack which contains the stuff outputted since the start of the store // This outputted data gets stored in a slot type SubexStoreEndState struct { -- cgit v1.2.3