<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/main/pathfilter.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2022-08-26 11:51:46 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2022-08-26 11:51:46 +0100
commitce5c224211a94bfd4c898b51d15febdf2ed9d6f2 (patch)
tree8d1c9db463d9c1793bd3aad2b6875a22d4add90c /main/pathfilter.go
parentececdecdaf6c6f6295d31a92f0663d703e7760dd (diff)
downloadstred-go-ce5c224211a94bfd4c898b51d15febdf2ed9d6f2.tar
Refactors some stuff and adds lexing and parsing
Diffstat (limited to 'main/pathfilter.go')
-rw-r--r--main/pathfilter.go31
1 files changed, 16 insertions, 15 deletions
diff --git a/main/pathfilter.go b/main/pathfilter.go
index 7b6c64f..b64872e 100644
--- a/main/pathfilter.go
+++ b/main/pathfilter.go
@@ -1,20 +1,5 @@
package main
-type MapTerminalFilter struct {}
-func (filter MapTerminalFilter) exec(state *ProgramState) bool {
- terminal, isTerminal := state.space.value.(TerminalValue)
- if !isTerminal {
- return false
- }
- return terminal == MapBegin || terminal == MapEnd
-}
-
-type NonTerminalFilter struct {}
-func (filter NonTerminalFilter) exec(state *ProgramState) bool {
- _, isTerminal := state.space.value.(TerminalValue)
- return !isTerminal
-}
-
type AnySegmentPathFilter struct {
next PathFilterState
}
@@ -72,6 +57,22 @@ func (filter StringSegmentPathFilter) accept() bool {
return false
}
+type IntegerSegmentPathFilter struct {
+ index int
+ next PathFilterState
+}
+func (filter IntegerSegmentPathFilter) eat(segment PathSegment) map[PathFilterState]struct{} {
+ i, isInteger := segment.(int)
+ res := make(map[PathFilterState]struct{})
+ if isInteger && i == filter.index {
+ res[filter.next] = struct{}{}
+ }
+ return res
+}
+func (filter IntegerSegmentPathFilter) accept() bool {
+ return false
+}
+
type PathFilterState interface {
eat(PathSegment) map[PathFilterState]struct{}
accept() bool