From 12c1d179f32c38a929fcc9adb326a9f44c8288ae Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 21 Apr 2023 16:22:16 +0100 Subject: Replaces the interfaces implementation of Atom with a tagged union based implementation --- subex/subexstate.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'subex/subexstate.go') diff --git a/subex/subexstate.go b/subex/subexstate.go index b5e1e9b..56063c0 100644 --- a/subex/subexstate.go +++ b/subex/subexstate.go @@ -153,8 +153,7 @@ type SubexCopyBoolState struct { next SubexState } func (state SubexCopyBoolState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { - _, isBool := char.(walk.ValueBool) - if isBool { + if char.Typ == walk.AtomBool { return []SubexBranch{{ state: state.next, outputStack: topAppend(outputStack, []walk.Atom{char}), @@ -172,8 +171,7 @@ type SubexCopyNumberState struct { next SubexState } func (state SubexCopyNumberState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { - _, isNumber := char.(walk.ValueNumber) - if isNumber { + if char.Typ == walk.AtomNumber { return []SubexBranch{{ state: state.next, outputStack: topAppend(outputStack, []walk.Atom{char}), @@ -191,8 +189,7 @@ type SubexCopyStringAtomState struct { next SubexState } func (state SubexCopyStringAtomState) eat(store Store, outputStack OutputStack, char walk.Atom) []SubexBranch { - _, isStringAtom := char.(walk.StringAtom) - if isStringAtom { + if char.Typ == walk.AtomStringRune { return []SubexBranch{{ state: state.next, outputStack: topAppend(outputStack, []walk.Atom{char}), @@ -210,9 +207,7 @@ 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 { + if char.Typ == walk.AtomStringRune || char.Typ == walk.AtomStringTerminal { return nil } return []SubexBranch{{ -- cgit v1.2.3