regexlit

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func MatchString(re *regexp.Regexp, t *Text) bool

MatchString is re.MatchString(t), skipped when the filter rules a match out.

func SampleTexts

func SampleTexts(re *regexp.Regexp, n int, seed int64) []string

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

func For(re *regexp.Regexp) *Filter

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

func (f *Filter) MayMatch(t *Text) bool

MayMatch reports whether the pattern could match t. False means it cannot.

func (*Filter) MayMatchString

func (f *Filter) MayMatchString(s string) bool

MayMatchString is MayMatch for a text tested against one filter only.

type Text

type Text struct {
	// contains filtered or unexported fields
}

Text is a text tested against many filters; its ASCII lower case is computed once, on first need.

func NewText

func NewText(s string) *Text

NewText wraps s for filtering.

func (*Text) String

func (t *Text) String() string

String is the text itself.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL