diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-23 22:09:14 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2022-08-23 22:09:14 +0100 |
commit | ececdecdaf6c6f6295d31a92f0663d703e7760dd (patch) | |
tree | 4b747448e546b8fdcb0c0196d981f32369c636f8 /main/filter.go | |
download | stred-go-ececdecdaf6c6f6295d31a92f0663d703e7760dd.tar |
Initial commit
No parsing yet, but the execution is not bad
Commands:
- Print value
- Toggle terminal (switch between array and map)
- Filter command
Filters:
- Path filter
Path filters are compiled from a regex like AST
Diffstat (limited to 'main/filter.go')
-rw-r--r-- | main/filter.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/main/filter.go b/main/filter.go new file mode 100644 index 0000000..95e6d82 --- /dev/null +++ b/main/filter.go @@ -0,0 +1,34 @@ +package main + +type PathFilter struct { + initial PathFilterState +} +func (filter PathFilter) exec(state *ProgramState) bool { + pathFilterState := make(map[PathFilterState]struct{}) + pathFilterState[filter.initial] = struct{}{} + for _, segment := range state.space.path { + nextPathFilterState := make(map[PathFilterState]struct{}) + for curState := range pathFilterState { + for nextState := range curState.eat(segment) { + nextPathFilterState[nextState] = struct{}{} + } + } + pathFilterState = nextPathFilterState + } + for pathState := range pathFilterState { + if pathState.accept() { + return true + } + } + return false +} + +type RangeFilter struct { + start Filter + end Filter + active bool +} + +type Filter interface { + exec(*ProgramState) bool +}
\ No newline at end of file |