From 094c9a8921fb5f54a34d8cdcb924b5dbacd336d8 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 26 Aug 2022 18:15:56 +0100 Subject: Adds a bunch of new path pattern features - Bracketting in expressions - OR with | - Optional with ? --- main/pathfilterast.go | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'main/pathfilterast.go') 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 } -- cgit v1.2.3