diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-21 09:53:04 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-21 09:53:04 +0100 |
commit | f1e5bc37723a4faa30bbfeed392c31489914eb50 (patch) | |
tree | 3515317bfd9a509d4bef0392ec0cbf3da35d71eb /subex/subexast.go | |
parent | 3cb886859e9b4df4ece183583dfd8b5ba7a59584 (diff) | |
download | stred-go-f1e5bc37723a4faa30bbfeed392c31489914eb50.tar |
Add subex syntax to copy across booleans, numbers, strings and values
Diffstat (limited to 'subex/subexast.go')
-rw-r--r-- | subex/subexast.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/subex/subexast.go b/subex/subexast.go index 87686b1..baf7a3b 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -134,6 +134,55 @@ func (ast SubexASTCopyAtom) compileWith(next SubexState) SubexState { } } +// Read in a single atom that must be a boolean and output it unchanged +type SubexASTCopyBool struct {} +func (ast SubexASTCopyBool) compileWith(next SubexState) SubexState { + return &SubexCopyBoolState {next} +} + +// Read in a single atom that must be a number and output it unchanged +type SubexASTCopyNumber struct {} +func (ast SubexASTCopyNumber) compileWith(next SubexState) SubexState { + return &SubexCopyNumberState {next} +} + +// Read in a single atom that must be a string atom and output it unchanged +type SubexASTCopyStringAtom struct {} +func (ast SubexASTCopyStringAtom) compileWith(next SubexState) SubexState { + return &SubexCopyStringAtomState {next} +} + +// Read in a full string value and copy it out unchanged +// # is equivalent to "_{-0}" +type SubexASTCopyString struct {} +func (ast SubexASTCopyString) compileWith(next SubexState) SubexState { + stringAtomState := &SubexCopyStringAtomState { + next: nil, + } + stringContentState := &SubexGroupState { + &SubexCopyAtomState { + atom: walk.StringTerminal{}, + next: next, + }, + stringAtomState, + } + stringAtomState.next = stringContentState + return &SubexCopyAtomState { + atom: walk.StringTerminal{}, + next: stringContentState, + } +} + +// Read in a value and copy it out unchanged +// , is equivalent to `null`|?|%|#|[`{}[]`] +type SubexASTCopyValue struct {} +func (ast SubexASTCopyValue) compileWith(next SubexState) SubexState { + return &SubexGroupState { + SubexASTCopyString{}.compileWith(next), + &SubexCopyNonStringAtomState {next}, + } +} + // Read in any single Atom and output it unchanged type SubexASTCopyAny struct {} func (ast SubexASTCopyAny) compileWith(next SubexState) SubexState { |