From 184368ae155fcdd50dde5c2e4b0c87e0d69acdd7 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Apr 2023 11:18:22 +0100 Subject: Replaces the parent/child implementation for operators like store and sum with an output stack Previously a store state was a parent of another state machine that it would run inside of itself in order to capture the output to be stored. This was limited as the greedyness of the child would not be transferred to the parent. The new implementation gives states more control over the output state and turns it into a stack. By pushing to the stack before the child and popping afterwards, all of the child's output can be retrieved while the child is very much part of the complete machine. --- subex/subexast.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'subex/subexast.go') diff --git a/subex/subexast.go b/subex/subexast.go index 9e7067b..cec75f7 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -27,10 +27,11 @@ type SubexASTStore struct { slot rune } func (ast SubexASTStore) compileWith(next SubexState) SubexState { - return &SubexStoreState { - match: ast.match.compileWith(&SubexNoneState{}), - slot: ast.slot, - next: next, + return &SubexStoreBeginState { + next: ast.match.compileWith(&SubexStoreEndState { + slot: ast.slot, + next: next, + }), } } func (ast SubexASTStore) String() string { @@ -188,8 +189,9 @@ type SubexASTSum struct { content SubexAST } func (ast SubexASTSum) compileWith(next SubexState) SubexState { - return &SubexSumState { - inputState: ast.content.compileWith(&SubexNoneState{}), - next: next, + return &SubexSumBeginState { + next: ast.content.compileWith(&SubexSumEndState { + next: next, + }), } } -- cgit v1.2.3