From f1e5bc37723a4faa30bbfeed392c31489914eb50 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 21 Apr 2023 09:53:04 +0100 Subject: Add subex syntax to copy across booleans, numbers, strings and values --- subex/subexstate.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'subex/subexstate.go') diff --git a/subex/subexstate.go b/subex/subexstate.go index cca7a88..997e6ce 100644 --- a/subex/subexstate.go +++ b/subex/subexstate.go @@ -135,6 +135,83 @@ func (state SubexCopyAtomState) accepting(store Store, outputStack OutputStack) return nil } +// Read in a boolean atom and output it +type SubexCopyBoolState struct { + next SubexState +} +func (state SubexCopyBoolState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { + _, isBool := char.(walk.ValueBool) + if isBool { + return []SubexBranch{{ + state: state.next, + outputStack: topAppend(outputStack, []walk.Atom{char}), + store: store, + }} + } + return nil +} +func (state SubexCopyBoolState) accepting(store Store, outputStack OutputStack) []OutputStack { + return nil +} + +// Read in a number atom and output it +type SubexCopyNumberState struct { + next SubexState +} +func (state SubexCopyNumberState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { + _, isNumber := char.(walk.ValueNumber) + if isNumber { + return []SubexBranch{{ + state: state.next, + outputStack: topAppend(outputStack, []walk.Atom{char}), + store: store, + }} + } + return nil +} +func (state SubexCopyNumberState) accepting(store Store, outputStack OutputStack) []OutputStack { + return nil +} + +// Read in a string atom and output it +type SubexCopyStringAtomState struct { + next SubexState +} +func (state SubexCopyStringAtomState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { + _, isStringAtom := char.(walk.StringAtom) + if isStringAtom { + return []SubexBranch{{ + state: state.next, + outputStack: topAppend(outputStack, []walk.Atom{char}), + store: store, + }} + } + return nil +} +func (state SubexCopyStringAtomState) accepting(store Store, outputStack OutputStack) []OutputStack { + return nil +} + +// Read in an atom and copy it out as long as it is not part of a string +type SubexCopyNonStringAtomState struct { + next SubexState +} +func (state SubexCopyNonStringAtomState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { + _, isStringAtom := char.(walk.StringAtom) + _, isStringTerminal := char.(walk.StringTerminal) + if isStringAtom || isStringTerminal { + return nil + } + return []SubexBranch{{ + state: state.next, + outputStack: topAppend(outputStack, []walk.Atom{char}), + store: store, + }} +} +func (state SubexCopyNonStringAtomState) accepting(store Store, outputStack OutputStack) []OutputStack { + return nil +} + // Read in any Atom and output it type SubexCopyAnyState struct { next SubexState -- cgit v1.2.3