From f3911888915f6aa96e6b28bd2a98a662faf20f47 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 23 Sep 2022 14:55:58 +0100 Subject: Adds try, maybe and join operators with !, ? and ; respectively --- main/subexast.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'main/subexast.go') diff --git a/main/subexast.go b/main/subexast.go index 7e2f33c..54cc5fe 100644 --- a/main/subexast.go +++ b/main/subexast.go @@ -115,3 +115,39 @@ func (ast SubexASTOutput) compileWith(next SubexState) SubexState { next: next, } } + +type SubexASTTry struct { + content SubexAST +} +func (ast SubexASTTry) compileWith(next SubexState) SubexState { + return SubexGroupState { + ast.content.compileWith(next), + next, + } +} + +type SubexASTMaybe struct { + content SubexAST +} +func (ast SubexASTMaybe) compileWith(next SubexState) SubexState { + return SubexGroupState { + next, + ast.content.compileWith(next), + } +} + +type SubexASTJoin struct { + content, delimiter SubexAST +} +func (ast SubexASTJoin) compileWith(next SubexState) SubexState { + afterContentState := &SubexGroupState { + nil, + next, + } + manyContentsState := ast.content.compileWith(afterContentState) + afterContentState.first = ast.delimiter.compileWith(manyContentsState) + return SubexGroupState { + manyContentsState, + next, + } +} -- cgit v1.2.3