From 3bd45dc49a35b82dcc4ae93796c3e152d799bc0b Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 19 Feb 2023 09:27:55 +0000 Subject: Move JSON serialising, deserialising and walking code into a separate package --- main/filter.go | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'main/filter.go') diff --git a/main/filter.go b/main/filter.go index f69d01a..d80ae8f 100644 --- a/main/filter.go +++ b/main/filter.go @@ -1,12 +1,16 @@ package main +import ( + "main/walk" +) + type PathFilter struct { initial PathFilterState } -func (filter PathFilter) exec(space WalkItem) bool { +func (filter PathFilter) exec(space walk.WalkItem) bool { pathFilterState := make(map[PathFilterState]struct{}) pathFilterState[filter.initial] = struct{}{} - for _, segment := range space.path { + for _, segment := range space.Path { nextPathFilterState := make(map[PathFilterState]struct{}) for curState := range pathFilterState { for nextState := range curState.eat(segment) { @@ -24,48 +28,48 @@ func (filter PathFilter) exec(space WalkItem) bool { } type MapTerminalFilter struct {} -func (filter MapTerminalFilter) exec(space WalkItem) bool { - terminal, isTerminal := space.value.(TerminalValue) +func (filter MapTerminalFilter) exec(space walk.WalkItem) bool { + terminal, isTerminal := space.Value.(walk.TerminalValue) if !isTerminal { return false } - return terminal == MapBegin || terminal == MapEnd + return terminal == walk.MapBegin || terminal == walk.MapEnd } type BeginTerminalFilter struct {} -func (filter BeginTerminalFilter) exec(space WalkItem) bool { - terminal, isTerminal := space.value.(TerminalValue) +func (filter BeginTerminalFilter) exec(space walk.WalkItem) bool { + terminal, isTerminal := space.Value.(walk.TerminalValue) if !isTerminal { return false } - return terminal == ArrayBegin || terminal == MapBegin + return terminal == walk.ArrayBegin || terminal == walk.MapBegin } type EndTerminalFilter struct {} -func (filter EndTerminalFilter) exec(space WalkItem) bool { - terminal, isTerminal := space.value.(TerminalValue) +func (filter EndTerminalFilter) exec(space walk.WalkItem) bool { + terminal, isTerminal := space.Value.(walk.TerminalValue) if !isTerminal { return false } - return terminal == ArrayEnd || terminal == MapEnd + return terminal == walk.ArrayEnd || terminal == walk.MapEnd } type TerminalFilter struct {} -func (filter TerminalFilter) exec(space WalkItem) bool { - _, isTerminal := space.value.(TerminalValue) +func (filter TerminalFilter) exec(space walk.WalkItem) bool { + _, isTerminal := space.Value.(walk.TerminalValue) return isTerminal } type RootFilter struct {} -func (filter RootFilter) exec(space WalkItem) bool { - return len(space.path) == 0 +func (filter RootFilter) exec(space walk.WalkItem) bool { + return len(space.Path) == 0 } type AndFilter struct { left Filter right Filter } -func (filter AndFilter) exec(space WalkItem) bool { +func (filter AndFilter) exec(space walk.WalkItem) bool { return filter.left.exec(space) && filter.right.exec(space) } @@ -73,17 +77,17 @@ type OrFilter struct { left Filter right Filter } -func (filter OrFilter) exec(space WalkItem) bool { +func (filter OrFilter) exec(space walk.WalkItem) bool { return filter.left.exec(space) || filter.right.exec(space) } type NotFilter struct { content Filter } -func (filter NotFilter) exec(space WalkItem) bool { +func (filter NotFilter) exec(space walk.WalkItem) bool { return !filter.content.exec(space) } type Filter interface { - exec(WalkItem) bool + exec(walk.WalkItem) bool } \ No newline at end of file -- cgit v1.2.3