final class TextGeneralization
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Collapses several patterns into the one shape that covers all of them.

Joining branches or iterations of a loop can produce more strings than a catalog should list. Generalization keeps the text the alternatives agree on and replaces the part they disagree on with a single gap, so the reported shape still matches every string the code can build.

Properties§

public Origin $origin

Methods§

public function __construct(public Origin $origin)

Parameters

$originOriginThe origin recorded on gaps this generalization introduces
public function mergeResolved(TextPattern $left, TextPattern $right): ?TextPattern

The narrowest pattern covering two fully resolved strings, or null when either has a gap.

Statements are long and are merged often, so the common case of two resolved strings is answered by comparing the strings themselves rather than by walking them character by character.

Parameters

Returns

Test cases 1
Called from 1
Calls 10
public function sharedPrefixLength(string $left, string $right): int
public function mergeAll(list<TextPattern> $patterns): TextPattern
public function atoms(TextPattern $pattern): list<string|TextHole>
public function commonPrefixLength(
    list<string|TextHole> $left,
    list<string|TextHole> $right,
): int

How many leading atoms the two sides share.

Parameters

$leftlist<string|TextHole>
$rightlist<string|TextHole>

Returns

int
Test cases 1
Called from 1
Calls 3
public function commonSuffixLength(
    list<string|TextHole> $left,
    list<string|TextHole> $right,
    int $limit,
): int

How many trailing atoms the two sides share, without reaching into the prefix.

Parameters

$leftlist<string|TextHole>
$rightlist<string|TextHole>
$limitintThe atoms still available after the shared prefix

Returns

int
Test cases 1
Called from 1
Calls 2

Test cases 33§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 13
Other tests reaching this symbol 20

Relations§

Instantiated in 1
Method calls 1