diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-27 18:11:10 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-27 18:11:10 +0100 |
commit | cfbe645715114234510bda068d2f30ffbe208eae (patch) | |
tree | c8be19865a676c7bd53bd121c3f5a2be43206a7e /main/filter.go | |
parent | 094c9a8921fb5f54a34d8cdcb924b5dbacd336d8 (diff) | |
download | stred-go-cfbe645715114234510bda068d2f30ffbe208eae.tar |
Adds new filters
- Begin terminals
- End terminals
- All terminals
- Negate
- AND
Diffstat (limited to 'main/filter.go')
-rw-r--r-- | main/filter.go | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/main/filter.go b/main/filter.go index 662fa7b..796f558 100644 --- a/main/filter.go +++ b/main/filter.go @@ -32,31 +32,6 @@ func (filter MapTerminalFilter) exec(space WalkItem) bool { 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) @@ -75,6 +50,32 @@ func (filter EndTerminalFilter) exec(space WalkItem) bool { return terminal == ArrayEnd || terminal == MapEnd } +type TerminalFilter struct {} +func (filter TerminalFilter) exec(space WalkItem) bool { + _, isTerminal := space.value.(TerminalValue) + return isTerminal +} + +type RootFilter struct {} +func (filter RootFilter) exec(space WalkItem) bool { + return len(space.path) == 0 +} + +type AndFilter struct { + left Filter + right Filter +} +func (filter AndFilter) exec(space WalkItem) bool { + return filter.left.exec(space) && filter.right.exec(space) +} + +type NotFilter struct { + content Filter +} +func (filter NotFilter) exec(space WalkItem) bool { + return !filter.content.exec(space) +} + type Filter interface { exec(WalkItem) bool }
\ No newline at end of file |