diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-26 18:15:56 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-26 18:15:56 +0100 |
commit | 094c9a8921fb5f54a34d8cdcb924b5dbacd336d8 (patch) | |
tree | 1ceb06246b2d5bd196746de7f300bdfe32a4a18a /main/pathfilterast.go | |
parent | ce5c224211a94bfd4c898b51d15febdf2ed9d6f2 (diff) | |
download | stred-go-094c9a8921fb5f54a34d8cdcb924b5dbacd336d8.tar |
Adds a bunch of new path pattern features
- Bracketting in expressions
- OR with |
- Optional with ?
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 } |