A step taken during the traversal of a Slice by a forward or backward searcher.
- rejected {s : Slice} (startPos endPos : s.Pos) : SearchStep s
- matched {s : Slice} (startPos endPos : s.Pos) : SearchStep s
Instances For
Equations
- String.Slice.Pattern.instBEqSearchStep.beq (String.Slice.Pattern.SearchStep.rejected a a_1) (String.Slice.Pattern.SearchStep.rejected b b_1) = (a == b && a_1 == b_1)
- String.Slice.Pattern.instBEqSearchStep.beq (String.Slice.Pattern.SearchStep.matched a a_1) (String.Slice.Pattern.SearchStep.matched b b_1) = (a == b && a_1 == b_1)
- String.Slice.Pattern.instBEqSearchStep.beq x✝¹ x✝ = false
Instances For
The start position of a SearchStep.
Equations
- (String.Slice.Pattern.SearchStep.rejected startPos endPos).startPos = startPos
- (String.Slice.Pattern.SearchStep.matched startPos endPos).startPos = startPos
Instances For
The end position of a SearchStep.
Equations
- (String.Slice.Pattern.SearchStep.rejected startPos endPos).endPos = endPos
- (String.Slice.Pattern.SearchStep.matched startPos endPos).endPos = endPos
Instances For
Converts a SearchStep (s.sliceFrom p) into a SearchStep s by applying
Slice.Pos.ofSliceFrom to the start and end position.
Equations
- (String.Slice.Pattern.SearchStep.rejected l r).ofSliceFrom = String.Slice.Pattern.SearchStep.rejected (String.Slice.Pos.ofSliceFrom l) (String.Slice.Pos.ofSliceFrom r)
- (String.Slice.Pattern.SearchStep.matched l r).ofSliceFrom = String.Slice.Pattern.SearchStep.matched (String.Slice.Pos.ofSliceFrom l) (String.Slice.Pos.ofSliceFrom r)
Instances For
Provides simple pattern matching capabilities from the start of a Slice.
Checks whether the slice starts with the pattern. If it does, the slice is returned with the prefix removed; otherwise the result is
none.Checks whether the slice starts with the pattern. If it does, the slice is returned with the prefix removed; otherwise the result is
none.Checks whether the slice starts with the pattern.
Instances
A lawful forward pattern is one where the three functions ForwardPattern.dropPrefix?,
ForwardPattern.dropPrefixOfNonempty? and ForwardPattern.startsWith agree for any
given input slice.
Note that this is a relatively weak condition. It is non-uniform in the sense that the functions can still return completely different results on different slices, even if they represent the same string.
There is a stronger lawfulness typeclass LawfulForwardPatternModel that asserts that the
ForwardPattern.dropPrefix? function behaves like a function that drops the longest prefix
according to some notion of matching.
- 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
Instances
A strict forward pattern is one which never drops an empty prefix.
This condition ensures that the default searcher derived from the forward pattern is a finite iterator.
Instances
Provides a conversion from a pattern to an iterator of SearchStep that searches for matches
of the pattern from the start towards the end of a Slice.
While these operations can be implemented on top of ForwardPattern, some patterns allow
for more efficient implementations. For example, a searcher for String patterns derived
from the ForwardPattern instance on strings would try to match the pattern at every
position in the string, but more efficient string matching routines are known. Indeed, the Lean
standard library uses the Knuth-Morris-Pratt algorithm. See the module
Init.Data.String.Pattern.String for the implementation.
This class can be used to provide such an efficient implementation. If there is no
need to specialize in this fashion, then
ToForwardSearcher.defaultImplementation can be
used to automatically derive an instance.
- toSearcher (s : Slice) : Std.Iter (SearchStep s)
Builds an iterator of
SearchStepcorresponding to matches ofpatalong the slices. TheSearchSteps returned by this iterator must contain ranges that are adjacent, non-overlapping and cover all ofs.
Instances
Equations
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
The default implementation of ToForwardSearcher repeatedly tries to match the pattern using
the given ForwardPattern instance.
It is sometimes possible to give a more efficient implementation; see ToForwardSearcher
for more details.
Equations
Instances For
Equations
- String.Slice.Pattern.Internal.memcmpStr lhs rhs lstart rstart len h1 h2 = String.Slice.Pattern.Internal.memcmpStr.go✝ lhs rhs lstart rstart len h1 h2 0
Instances For
Provides simple pattern matching capabilities from the end of a Slice.
Checks whether the slice ends with the pattern. If it does, the slice is returned with the suffix removed; otherwise the result is
none.Checks whether the slice ends with the pattern. If it does, the slice is returned with the suffix removed; otherwise the result is
none.Checks whether the slice ends with the pattern.
Instances
A lawful backward pattern is one where the three functions BackwardPattern.dropSuffix?,
BackwardPattern.dropSuffixOfNonempty? and BackwardPattern.endsWith agree for any
given input slice.
Note that this is a relatively weak condition. It is non-uniform in the sense that the functions can still return completely different results on different slices, even if they represent the same string.
There is a stronger lawfulness typeclass LawfulBackwardPatternModel that asserts that the
BackwardPattern.dropSuffix? function behaves like a function that drops the longest prefix
according to some notion of matching.
- dropSuffixOfNonempty?_eq {s : Slice} (h : s.isEmpty = false) : BackwardPattern.dropSuffixOfNonempty? pat s h = BackwardPattern.dropSuffix? pat s
- endsWith_eq (s : Slice) : BackwardPattern.endsWith pat s = (BackwardPattern.dropSuffix? pat s).isSome
Instances
A strict backward pattern is one which never drops an empty suffix.
This condition ensures that the default searcher derived from the backward pattern is a finite iterator.
Instances
Provides a conversion from a pattern to an iterator of SearchStep searching for matches of
the pattern from the end towards the start of a Slice.
While these operations can be implemented on top of BackwardPattern, some patterns allow
for more efficient implementations. For example, a searcher for String patterns derived
from the BackwardPattern instance on strings would try to match the pattern at every
position in the string, but more efficient string matching routines are known. Indeed, the Lean
standard library uses the Knuth-Morris-Pratt algorithm. See the module
Init.Data.String.Pattern.String for the implementation.
This class can be used to provide such an efficient implementation. If there is no
need to specialize in this fashion, then
ToBackwardSearcher.defaultImplementation can be
used to automatically derive an instance.
- toSearcher (s : Slice) : Std.Iter (SearchStep s)
Build an iterator of
SearchStepcorresponding to matches ofpatalong the slices. TheSearchSteps returned by this iterator must contain ranges that are adjacent, non-overlapping and cover all ofs.
Instances
Equations
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
The default implementation of ToBackwardSearcher repeatedly tries to match the pattern using
the given BackwardPattern instance.
It is sometimes possible to give a more efficient implementation; see ToBackwardSearcher
for more details.