<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/filter.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2022-08-26 11:51:46 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2022-08-26 11:51:46 +0100
commitce5c224211a94bfd4c898b51d15febdf2ed9d6f2 (patch)
tree8d1c9db463d9c1793bd3aad2b6875a22d4add90c /main/filter.go
parentececdecdaf6c6f6295d31a92f0663d703e7760dd (diff)
downloadstred-go-ce5c224211a94bfd4c898b51d15febdf2ed9d6f2.tar
Refactors some stuff and adds lexing and parsing
Diffstat (limited to 'main/filter.go')
-rw-r--r--main/filter.go52
1 files changed, 49 insertions, 3 deletions
diff --git a/main/filter.go b/main/filter.go
index 95e6d82..662fa7b 100644
--- a/main/filter.go
+++ b/main/filter.go
@@ -3,10 +3,10 @@ package main
type PathFilter struct {
initial PathFilterState
}
-func (filter PathFilter) exec(state *ProgramState) bool {
+func (filter PathFilter) exec(space WalkItem) bool {
pathFilterState := make(map[PathFilterState]struct{})
pathFilterState[filter.initial] = struct{}{}
- for _, segment := range state.space.path {
+ for _, segment := range space.path {
nextPathFilterState := make(map[PathFilterState]struct{})
for curState := range pathFilterState {
for nextState := range curState.eat(segment) {
@@ -23,12 +23,58 @@ func (filter PathFilter) exec(state *ProgramState) bool {
return false
}
+type MapTerminalFilter struct {}
+func (filter MapTerminalFilter) exec(space WalkItem) bool {
+ terminal, isTerminal := space.value.(TerminalValue)
+ if !isTerminal {
+ return false
+ }
+ return terminal == MapBegin || terminal == MapEnd
+}
+
+type NonTerminalFilter struct {}
+func (filter NonTerminalFilter) exec(space WalkItem) bool {
+ _, isTerminal := space.value.(TerminalValue)
+ return !isTerminal
+}
+
type RangeFilter struct {
start Filter
end Filter
active bool
}
+func (filter *RangeFilter) exec(space WalkItem) bool {
+ if filter.active {
+ if filter.end.exec(space) {
+ filter.active = false
+ }
+ return true
+ } else {
+ if filter.start.exec(space) {
+ filter.active = true
+ }
+ return filter.active
+ }
+}
+
+type BeginTerminalFilter struct {}
+func (filter BeginTerminalFilter) exec(space WalkItem) bool {
+ terminal, isTerminal := space.value.(TerminalValue)
+ if !isTerminal {
+ return false
+ }
+ return terminal == ArrayBegin || terminal == MapBegin
+}
+
+type EndTerminalFilter struct {}
+func (filter EndTerminalFilter) exec(space WalkItem) bool {
+ terminal, isTerminal := space.value.(TerminalValue)
+ if !isTerminal {
+ return false
+ }
+ return terminal == ArrayEnd || terminal == MapEnd
+}
type Filter interface {
- exec(*ProgramState) bool
+ exec(WalkItem) bool
} \ No newline at end of file