package main import ( "main/walk" ) type AnySegmentPathFilter struct { next PathFilterState } func (filter AnySegmentPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { res := make(map[PathFilterState]struct{}) res[filter.next] = struct{}{} return res } func (filter AnySegmentPathFilter) accept() bool { return false } type OrPathFilter struct { filters [2]PathFilterState } func (filter OrPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { res := make(map[PathFilterState]struct{}) for _, f := range filter.filters { for r := range f.eat(segment) { res[r] = struct{}{} } } return res } func (filter OrPathFilter) accept() bool { for _, f := range filter.filters { if f.accept() { return true } } return false } type NonePathFilter struct {} func (filter NonePathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { return make(map[PathFilterState]struct{}) } func (filter NonePathFilter) accept() bool { return true } type StringSegmentPathFilter struct { index string next PathFilterState } func (filter StringSegmentPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { s, isString := segment.(string) res := make(map[PathFilterState]struct{}) if isString && s == filter.index { res[filter.next] = struct{}{} } return res } func (filter StringSegmentPathFilter) accept() bool { return false } type IntegerSegmentPathFilter struct { index int next PathFilterState } func (filter IntegerSegmentPathFilter) eat(segment walk.PathSegment) map[PathFilterState]struct{} { i, isInteger := segment.(int) res := make(map[PathFilterState]struct{}) if isInteger && i == filter.index { res[filter.next] = struct{}{} } return res } func (filter IntegerSegmentPathFilter) accept() bool { return false } type PathFilterState interface { eat(walk.PathSegment) map[PathFilterState]struct{} accept() bool }