Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/main/subexast.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2022-09-23 14:55:58 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2022-09-23 14:55:58 +0100
commitf3911888915f6aa96e6b28bd2a98a662faf20f47 (patch)
tree55373234480b057e1615c0d51316be256b1d6d29 /main/subexast.go
parent0a8690993d572a50b95dd4f1c1903ed00ddb9c2b (diff)
downloadsubex-f3911888915f6aa96e6b28bd2a98a662faf20f47.tar
Adds try, maybe and join operators with !, ? and ; respectively
Diffstat (limited to 'main/subexast.go')
-rw-r--r--main/subexast.go36
1 files changed, 36 insertions, 0 deletions
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,
+ }
+}