@@ -22,71 +22,69 @@ public section
2222
2323namespace String.Slice.Pattern
2424
25- structure ForwardCharPredSearcher (s : Slice) where
25+ structure ForwardCharPredSearcher (p : Char → Bool) ( s : Slice) where
2626 currPos : s.Pos
27- needle : Char → Bool
2827deriving Inhabited
2928
3029namespace ForwardCharPredSearcher
3130
3231@[inline]
33- def iter (p : Char → Bool) (s : Slice) : Std.Iter (α := ForwardCharPredSearcher s) (SearchStep s) :=
34- { internalState := { currPos := s.startPos, needle := p }}
32+ def iter (p : Char → Bool) (s : Slice) : Std.Iter (α := ForwardCharPredSearcher p s) (SearchStep s) :=
33+ { internalState := { currPos := s.startPos }}
3534
36- instance (s : Slice) : Std.Iterators.Iterator (ForwardCharPredSearcher s) Id (SearchStep s) where
35+ instance (s : Slice) : Std.Iterators.Iterator (ForwardCharPredSearcher p s) Id (SearchStep s) where
3736 IsPlausibleStep it
3837 | .yield it' out =>
39- it.internalState.needle = it'.internalState.needle ∧
4038 ∃ h1 : it.internalState.currPos ≠ s.endPos,
4139 it'.internalState.currPos = it.internalState.currPos.next h1 ∧
4240 match out with
4341 | .matched startPos endPos =>
4442 it.internalState.currPos = startPos ∧
4543 it'.internalState.currPos = endPos ∧
46- it.internalState.needle (it.internalState.currPos.get h1)
44+ p (it.internalState.currPos.get h1)
4745 | .rejected startPos endPos =>
4846 it.internalState.currPos = startPos ∧
4947 it'.internalState.currPos = endPos ∧
50- ¬ it.internalState.needle (it.internalState.currPos.get h1)
48+ ¬ p (it.internalState.currPos.get h1)
5149 | .skip _ => False
5250 | .done => it.internalState.currPos = s.endPos
53- step := fun ⟨currPos, needle ⟩ =>
51+ step := fun ⟨⟨ currPos⟩ ⟩ =>
5452 if h1 : currPos = s.endPos then
5553 pure (.deflate ⟨.done, by simp [h1]⟩)
5654 else
5755 let nextPos := currPos.next h1
58- let nextIt := ⟨nextPos, needle ⟩
59- if h2 : needle <| currPos.get h1 then
56+ let nextIt := ⟨⟨ nextPos⟩ ⟩
57+ if h2 : p <| currPos.get h1 then
6058 pure (.deflate ⟨.yield nextIt (.matched currPos nextPos), by simp [h1, h2, nextPos, nextIt]⟩)
6159 else
6260 pure (.deflate ⟨.yield nextIt (.rejected currPos nextPos), by simp [h1, h2, nextPos, nextIt]⟩)
6361
6462
65- def finitenessRelation : Std.Iterators.FinitenessRelation (ForwardCharPredSearcher s) Id where
63+ def finitenessRelation : Std.Iterators.FinitenessRelation (ForwardCharPredSearcher p s) Id where
6664 rel := InvImage WellFoundedRelation.rel (fun it => it.internalState.currPos)
6765 wf := InvImage.wf _ WellFoundedRelation.wf
6866 subrelation {it it'} h := by
6967 simp_wf
7068 obtain ⟨step, h, h'⟩ := h
7169 cases step
7270 · cases h
73- obtain ⟨_, h1, h2, _⟩ := h'
71+ obtain ⟨_, h2, _⟩ := h'
7472 simp [h2]
7573 · cases h'
7674 · cases h
7775
78- instance : Std.Iterators.Finite (ForwardCharPredSearcher s) Id :=
76+ instance : Std.Iterators.Finite (ForwardCharPredSearcher p s) Id :=
7977 .of_finitenessRelation finitenessRelation
8078
81- instance : Std.Iterators.IteratorLoop (ForwardCharPredSearcher s) Id Id :=
79+ instance : Std.Iterators.IteratorLoop (ForwardCharPredSearcher p s) Id Id :=
8280 .defaultImplementation
8381
84- instance {p : Char → Bool} : ToForwardSearcher p ForwardCharPredSearcher where
82+ instance {p : Char → Bool} : ToForwardSearcher p ( ForwardCharPredSearcher p) where
8583 toSearcher := iter p
8684
8785instance {p : Char → Bool} : ForwardPattern p := .defaultImplementation
8886
89- instance {p : Char → Prop} [DecidablePred p] : ToForwardSearcher p ForwardCharPredSearcher where
87+ instance {p : Char → Prop} [DecidablePred p] : ToForwardSearcher p ( ForwardCharPredSearcher p) where
9088 toSearcher := iter (decide <| p ·)
9189
9290instance {p : Char → Prop} [DecidablePred p] : ForwardPattern p :=
0 commit comments