From ececdecdaf6c6f6295d31a92f0663d703e7760dd Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Tue, 23 Aug 2022 22:09:14 +0100 Subject: 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 --- main/filter.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 main/filter.go (limited to 'main/filter.go') 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 -- cgit v1.2.3