Documentation
¶
Overview ¶
Package regexlit decides cheaply that a regular expression cannot match a text, so the expression is not run.
Most catalog patterns (an import statement, an API call) have no literal prefix, so Go's regexp runs its automaton over every byte of every file even though the match would have to contain a word such as "openai". A Filter holds such words, derived from the pattern's syntax tree: every match of the pattern contains at least one of them. When a text holds none, the pattern cannot match it and is skipped. When nothing can be derived, the filter lets every text through. A filter therefore only ever skips work whose answer was "no match"; TestFilterNeverHidesAMatch checks that on random texts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MatchString ¶
MatchString is re.MatchString(t), skipped when the filter rules a match out.
func SampleTexts ¶
SampleTexts builds n texts likely to match re, for proving that re is filtered soundly: re's literal pieces, in mixed case and beside the non-ASCII runes that fold to k and s, joined with the separators patterns look for. A test runs re over each text and requires MayMatch wherever MatchString holds.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is the literals one of which every match of a pattern contains.
func For ¶
For returns the filter of re, or a filter that passes every text when no literal can be derived. The result is cached per expression.
func (*Filter) MayMatch ¶
MayMatch reports whether the pattern could match t. False means it cannot.
func (*Filter) MayMatchString ¶
MayMatchString is MayMatch for a text tested against one filter only.