<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/filter.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-02-19 09:27:55 +0000
committerCharlie Stanton <charlie@shtanton.xyz>2023-02-19 09:27:55 +0000
commit3bd45dc49a35b82dcc4ae93796c3e152d799bc0b (patch)
tree3a681ac5dbd777d2b6b116429cfbd934815661ce /main/filter.go
parenta5a4db8283fda88c5bd42272de0258e5d134c5bd (diff)
downloadstred-go-3bd45dc49a35b82dcc4ae93796c3e152d799bc0b.tar
Move JSON serialising, deserialising and walking code into a separate package
Diffstat (limited to 'main/filter.go')
-rw-r--r--main/filter.go42
1 files changed, 23 insertions, 19 deletions
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