This data-carrying typeclass is used to give semantics to a pattern type that implements
ForwardPattern and/or ToForwardSearcher by providing an abstract, not necessarily
decidable ForwardPatternModel.Matches predicate that implementates of ForwardPattern
and ToForwardSearcher can be validated against.
Correctness results for generic functions relying on the pattern infrastructure, for example the
correctness result for String.Slice.split, are then
stated in terms of ForwardPatternModel.Matches, and can be specialized to specific patterns
from there.
The corresponding compatibility typeclasses are
String.Slice.Pattern.Model.LawfulForwardPatternModel
and
String.Slice.Pattern.Model.LawfulToForwardSearcherModel.
We include the condition that the empty string is not a match. This is necessary for the theory to work out as there is just no reasonable notion of searching that works for the empty string that is still specific enough to yield reasonably strong correctness results for operations based on searching.
This means that pattern types that allow searching for the empty string will have to special-case the empty string in their correctness statements.
The predicate that says which strings match the pattern.
Instances
Predicate stating that the region between the start of the slice s and the position
endPos matches the pattern pat. Note that there might be a longer match, see
String.Slice.Pattern.IsLongestMatch.
- matches_copy : ForwardPatternModel.Matches pat (s.sliceTo endPos).copy
Instances For
Predicate stating that the region between the start of the slice s and the position
endPos matches that pattern pat, and that there is no longer match starting at the
beginning of the slice. This is what a correct matcher should match.
In some cases, being a match and being a longest match will coincide, see
String.Slice.Pattern.Model.NoPrefixForwardPatternModel.
- isMatch : IsMatch pat pos
Instances For
Predicate stating that a match for a given pattern is never a proper prefix of another match.
This implies that the notion of match and longest match coincide.
- eq_empty (s t : String) : ForwardPatternModel.Matches pat s → ForwardPatternModel.Matches pat (s ++ t) → t = ""
Instances
Predicate stating that the slice formed by startPos and endPos contains is a match
of pat in s and it is longest among matches starting at startPos.
- isLongestMatch_sliceFrom : IsLongestMatch pat (startPos.sliceFrom endPos ⋯)
Instances For
Predicate stating that there is a (longest) match starting at the given position.
Instances For
Noncomputable model function returning the end point of the longest match starting at the given
position, or none if there is no match.
Equations
Instances For
Predicate stating compatibility between ForwardPatternModel and ForwardPattern.
This extends LawfulForwardPattern, but it is much stronger because it forces the
ForwardPattern to match the longest prefix of the given slice that matches the property
supplied by the ForwardPatternModel instance.
- dropPrefixOfNonempty?_eq {s : Slice} (h : s.isEmpty = false) : ForwardPattern.dropPrefixOfNonempty? pat s h = ForwardPattern.dropPrefix? pat s
- startsWith_eq (s : Slice) : ForwardPattern.startsWith pat s = (ForwardPattern.dropPrefix? pat s).isSome
- dropPrefix?_eq_some_iff {s : Slice} (pos : s.Pos) : ForwardPattern.dropPrefix? pat s = some pos ↔ IsLongestMatch pat pos
Instances
Inductive predicate stating that a list of search steps represents a valid search from a given position in a slice.
"Searching" here means always taking the longest match at the first position where the pattern matches.
Hence, this predicate determines the list of search steps up to grouping of rejections.
- endPos {ρ : Type} {pat : ρ} [ForwardPatternModel pat] {s : Slice} : IsValidSearchFrom pat s.endPos []
- matched {ρ : Type} {pat : ρ} [ForwardPatternModel pat] {s : Slice} {l : List (SearchStep s)} {startPos endPos : s.Pos} : IsLongestMatchAt pat startPos endPos → IsValidSearchFrom pat endPos l → IsValidSearchFrom pat startPos (SearchStep.matched startPos endPos :: l)
- mismatched {ρ : Type} {pat : ρ} [ForwardPatternModel pat] {s : Slice} {l : List (SearchStep s)} {startPos endPos : s.Pos} : startPos < endPos → (∀ (pos : s.Pos), startPos ≤ pos → pos < endPos → ¬MatchesAt pat pos) → IsValidSearchFrom pat endPos l → IsValidSearchFrom pat startPos (SearchStep.rejected startPos endPos :: l)
Instances For
Predicate stating compatibility between ForwardPatternModel and ToForwardSearcher.
We require the searcher to always match the longest match at the first position where the pattern
matches; see IsValidSearchFrom.
- isValidSearchFrom_toList (s : Slice) : IsValidSearchFrom pat s.startPos (ToForwardSearcher.toSearcher pat s).toList