From cfbe645715114234510bda068d2f30ffbe208eae Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 27 Aug 2022 18:11:10 +0100 Subject: Adds new filters - Begin terminals - End terminals - All terminals - Negate - AND --- main/filter.go | 51 ++++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'main/filter.go') 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 -- cgit v1.2.3