diff options
Diffstat (limited to 'main/pathfilterast.go')
-rw-r--r-- | main/pathfilterast.go | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/main/pathfilterast.go b/main/pathfilterast.go index c2ddc7f..c84b8af 100644 --- a/main/pathfilterast.go +++ b/main/pathfilterast.go @@ -24,19 +24,19 @@ type RepeatPathFilterAST struct { content PathFilterAST } func (ast RepeatPathFilterAST) compileWith(next PathFilterState) PathFilterState { - nextGroup := &GroupPathFilter{} + nextGroup := &OrPathFilter{} repeatStart := ast.content.compileWith(nextGroup) - nextGroup.filters = []PathFilterState{next, repeatStart} + nextGroup.filters = [2]PathFilterState{next, repeatStart} return nextGroup } type SequencePathFilterAST struct { - sequence []PathFilterAST + first PathFilterAST + second PathFilterAST } func (ast SequencePathFilterAST) compileWith(next PathFilterState) PathFilterState { - for i := len(ast.sequence) - 1; i >= 0; i -= 1 { - next = ast.sequence[i].compileWith(next) - } + next = ast.second.compileWith(next) + next = ast.first.compileWith(next) return next } @@ -45,6 +45,24 @@ func (ast AnySegmentPathFilterAST) compileWith(next PathFilterState) PathFilterS return AnySegmentPathFilter{next: next} } +type OrPathFilterAST struct { + first PathFilterAST + second PathFilterAST +} +func (ast OrPathFilterAST) compileWith(next PathFilterState) PathFilterState { + return OrPathFilter { + filters: [2]PathFilterState{ + ast.first.compileWith(next), + ast.second.compileWith(next), + }, + } +} + +type NonePathFilterAST struct {} +func (ast NonePathFilterAST) compileWith(next PathFilterState) PathFilterState { + return next +} + type PathFilterAST interface { compileWith(PathFilterState) PathFilterState } |