# lawref.textpattern

*module*

Образец текста [§257.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/34-part-xxxiii-standard-library.ru.md#2571-образец-текста-errata-e-0166) (errata E-0166): разбор и полное совпадение.

Закрытый детерминированный диалект, определённый prose, а не regex-движком:
литеральные кодовые точки с экранированием `\`, `.` — любая кодовая точка,
`\d` — цифра `0`–`9` (только ASCII), классы `[…]` с диапазонами и `^`,
счётчики `?`, `{n}`, `{n,m}`. Ни чередования, ни групп, ни обратных ссылок,
ни незамкнутых счётчиков: у каждого образца конечное множество длин, и
совпадение всегда завершается. Совпадение — по кодовым точкам после NFC [§13](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/05-part-v-lexis-and-basic-syntax.ru.md#13-кодировка-и-нормализация);
документы канона [§208](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/28-part-xxvii-canonical-legal-ir.ru.md#208-canonical-serialization) уже несут NFC, поэтому здесь ничего не нормализуется.

Формулировки отказов — БАЙТОВЫЙ КОНТРАКТ: движок (`law_canon::text_pattern`)
повторяет их дословно, и `check_differential` сверяет тотальный `TYPE_ERROR`
над образцом-значением слово в слово.

## lawref.textpattern.COUNT_MAX

*attribute* · *module attribute*

```python
COUNT_MAX = 65535
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L22-L22)

## lawref.textpattern.Pattern

*class* · *dataclass*

```python
class Pattern
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L53-L78)

### lawref.textpattern.Pattern.pieces

*attribute* · *instance attribute*

```python
pieces: tuple[tuple[_Atom, int, int], ...]
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L55-L55)

### lawref.textpattern.Pattern.matches

*method*

```python
def matches(text: str) -> bool
```

Полное совпадение: весь текст против всего образца (якоря подразумеваются).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L57-L78)

## lawref.textpattern.PatternError

*class*

```python
class PatternError(ValueError)
```

Bases: `ValueError`

Образец не по грамматике [§257.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/34-part-xxxiii-standard-library.ru.md#2571-образец-текста-errata-e-0166); `reason` — фиксированная формулировка.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L27-L32)

### lawref.textpattern.PatternError.reason

*attribute* · *instance attribute*

```python
reason = reason
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L32-L32)

## lawref.textpattern.compile_pattern

*function*

```python
def compile_pattern(pattern: str) -> Pattern
```

Разбор по грамматике [§257.1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/34-part-xxxiii-standard-library.ru.md#2571-образец-текста-errata-e-0166); отказ — `PatternError` с фиксированной причиной.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L94-L196)

## lawref.textpattern.text_matches

*function*

```python
def text_matches(text: str, pattern: str) -> bool
```

Удобная форма: разбор и совпадение за один вызов (исключение — `PatternError`).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/textpattern.py#L199-L201)
