diff options
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 |