Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
type Matcher interface {
MatchString(s string) (bool, error)
FindLine(content string) (int, bool, error)
// FindIndex reports the byte offset where the first match starts, so a
// caller can inspect the text immediately before it (params.denied_by,
// #4). Returns -1 when there is no match; a matcher that cannot report a
// position returns -1 with ok=true, which the denial stage treats as
// undecidable and therefore not a denial.
FindIndex(s string) (int, bool, error)
// CountMatches reports how many non-overlapping matches s holds. The
// pair-consistency `countable` obligation needs it: count(requires) must be
// >= count(trigger) inside a unit, so a second trigger cannot free-ride on
// one companion. Returns an error for the same reason MatchString does — a
// regexp2 timeout must not read as "zero matches", which would clear the
// obligation it was meant to enforce.
CountMatches(s string) (int, error)
String() string
}
Package rxmatch is the ONE regex backend every rule type compiles through.
It was internal to package pattern until #17979: pair-consistency compiled with regexp.Compile directly, so `syntax: regexp2` and `multiline: true` were accepted by forbidden-pattern and refused by pair-consistency. A repo converting a rule from one to the other had to drop those params, and dropping multiline SILENTLY DISABLES a cross-line trigger — the rule still loads, still reports OK, and no longer matches anything. Extracting the matcher rather than copying it is the point: two regex backends are how two answers to one question start to disagree.
Matcher matches text (spec §5 pattern semantics). Two backends: Go's RE2 (default — fast, linear-time, no catastrophic backtracking) and the regexp2 engine, opt-in via `syntax: regexp2`, for the minority of rules that need PCRE2 lookaround/backreferences the shell (pcre2) gates used. MatchString is the per-line path; FindLine (used by `multiline: true`) matches over whole file content and returns the 1-based line where the first match starts. Both return an error so a regexp2 backtracking timeout fails closed (exit 2) rather than reading as a clean pass — a rule that failed to evaluate must never look like one that found nothing (#22).