From ce5c224211a94bfd4c898b51d15febdf2ed9d6f2 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 26 Aug 2022 11:51:46 +0100 Subject: Refactors some stuff and adds lexing and parsing --- main/pathfilter.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'main/pathfilter.go') 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 -- cgit v1.2.3