diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-26 11:51:46 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-26 11:51:46 +0100 |
commit | ce5c224211a94bfd4c898b51d15febdf2ed9d6f2 (patch) | |
tree | 8d1c9db463d9c1793bd3aad2b6875a22d4add90c /main/pathfilterast.go | |
parent | ececdecdaf6c6f6295d31a92f0663d703e7760dd (diff) | |
download | stred-go-ce5c224211a94bfd4c898b51d15febdf2ed9d6f2.tar |
Refactors some stuff and adds lexing and parsing
Diffstat (limited to 'main/pathfilterast.go')
-rw-r--r-- | main/pathfilterast.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/main/pathfilterast.go b/main/pathfilterast.go new file mode 100644 index 0000000..c2ddc7f --- /dev/null +++ b/main/pathfilterast.go @@ -0,0 +1,56 @@ +package main + +type StringSegmentPathFilterAST struct { + index string +} +func (ast StringSegmentPathFilterAST) compileWith(next PathFilterState) PathFilterState { + return StringSegmentPathFilter { + index: ast.index, + next: next, + } +} + +type IntegerSegmentPathFilterAST struct { + index int +} +func (ast IntegerSegmentPathFilterAST) compileWith(next PathFilterState) PathFilterState { + return IntegerSegmentPathFilter { + index: ast.index, + next: next, + } +} + +type RepeatPathFilterAST struct { + content PathFilterAST +} +func (ast RepeatPathFilterAST) compileWith(next PathFilterState) PathFilterState { + nextGroup := &GroupPathFilter{} + repeatStart := ast.content.compileWith(nextGroup) + nextGroup.filters = []PathFilterState{next, repeatStart} + return nextGroup +} + +type SequencePathFilterAST struct { + sequence []PathFilterAST +} +func (ast SequencePathFilterAST) compileWith(next PathFilterState) PathFilterState { + for i := len(ast.sequence) - 1; i >= 0; i -= 1 { + next = ast.sequence[i].compileWith(next) + } + return next +} + +type AnySegmentPathFilterAST struct {} +func (ast AnySegmentPathFilterAST) compileWith(next PathFilterState) PathFilterState { + return AnySegmentPathFilter{next: next} +} + +type PathFilterAST interface { + compileWith(PathFilterState) PathFilterState +} + +func compilePathFilterAST(ast PathFilterAST) PathFilter { + return PathFilter{ + initial: ast.compileWith(NonePathFilter{}), + } +} |