# lawref.query.parser

*module*

Рекурсивный спуск LawQL без внешних зависимостей (Ф2/Ф3/Ф5).

## lawref.query.parser.KEYWORDS

*attribute* · *module attribute*

```python
KEYWORDS = {'from', 'in', 'where', 'select', 'as', 'and', 'or', 'exists', 'not', 'let', 'eval', 'true', 'false', 'null', 'query', 'over'}
```

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

## lawref.query.parser.TOKEN_RE

*attribute* · *module attribute*

```python
TOKEN_RE = re.compile('(?P<SPACE>[ \\t\\r\\n]+)|(?P<COMMENT>\\#[^\\n]*)|(?P<STRING>\\"(?:\\\\.|[^\\"\\\\])*\\"|\'(?:\\\\.|[^\'\\\\])*\')|(?P<NUMBER>-?[0-9]+(?:\\.[0-9]+)?)|(?P<OP>==|!=|>=|<=|>|<)|(?P<PUNCT>[(),.={}\\[\\]:;])|(?P<IDENT>[A-Za-z_][A-Za-z0-9_-]*)|(?P<BAD>.)')
```

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

## lawref.query.parser.Binding

*class* · *dataclass*

```python
class Binding
```

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

### lawref.query.parser.Binding.name

*attribute* · *instance attribute*

```python
name: str
```

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

### lawref.query.parser.Binding.source

*attribute* · *instance attribute*

```python
source: Source
```

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

## lawref.query.parser.Expr

*class* · *dataclass*

```python
class Expr
```

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

### lawref.query.parser.Expr.args

*attribute* · *class attribute* · *instance attribute*

```python
args: tuple['Expr', ...] = ()
```

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

### lawref.query.parser.Expr.kind

*attribute* · *instance attribute*

```python
kind: str
```

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

### lawref.query.parser.Expr.left

*attribute* · *class attribute* · *instance attribute*

```python
left: 'Expr | None' = None
```

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

### lawref.query.parser.Expr.right

*attribute* · *class attribute* · *instance attribute*

```python
right: 'Expr | None' = None
```

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

### lawref.query.parser.Expr.value

*attribute* · *class attribute* · *instance attribute*

```python
value: Any = None
```

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

## lawref.query.parser.InferenceQuery

*class* · *dataclass*

```python
class InferenceQuery
```

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

### lawref.query.parser.InferenceQuery.body

*attribute* · *instance attribute*

```python
body: str
```

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

### lawref.query.parser.InferenceQuery.metadata

*attribute* · *instance attribute*

```python
metadata: dict[str, str]
```

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

### lawref.query.parser.InferenceQuery.name

*attribute* · *instance attribute*

```python
name: str
```

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

### lawref.query.parser.InferenceQuery.package

*attribute* · *instance attribute*

```python
package: str
```

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

### lawref.query.parser.InferenceQuery.source

*attribute* · *instance attribute*

```python
source: str
```

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

## lawref.query.parser.Materialization

*class* · *dataclass*

```python
class Materialization
```

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

### lawref.query.parser.Materialization.case

*attribute* · *instance attribute*

```python
case: str
```

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

### lawref.query.parser.Materialization.name

*attribute* · *instance attribute*

```python
name: str
```

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

### lawref.query.parser.Materialization.package

*attribute* · *instance attribute*

```python
package: str
```

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

## lawref.query.parser.Parser

*class*

```python
class Parser
```

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

### lawref.query.parser.Parser.index

*attribute* · *instance attribute*

```python
index = 0
```

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

### lawref.query.parser.Parser.source

*attribute* · *instance attribute*

```python
source = source
```

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

### lawref.query.parser.Parser.tokens

*attribute* · *instance attribute*

```python
tokens = tokenize(source)
```

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

### lawref.query.parser.Parser.current

*property*

```python
current: Token
```

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

### lawref.query.parser.Parser.accept

*method*

```python
def accept(kind: str, value: str | None = None) -> Token | None
```

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

### lawref.query.parser.Parser.and_expr

*method*

```python
def and_expr() -> Expr
```

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

### lawref.query.parser.Parser.comparison

*method*

```python
def comparison() -> Expr
```

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

### lawref.query.parser.Parser.exists_expr

*method*

```python
def exists_expr() -> Expr
```

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

### lawref.query.parser.Parser.expect

*method*

```python
def expect(kind: str, message: str | None = None) -> Token
```

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

### lawref.query.parser.Parser.expression

*method*

```python
def expression() -> Expr
```

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

### lawref.query.parser.Parser.field_name

*method*

```python
def field_name(message: str) -> str
```

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

### lawref.query.parser.Parser.inference

*method*

```python
def inference() -> InferenceQuery
```

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

### lawref.query.parser.Parser.or_expr

*method*

```python
def or_expr() -> Expr
```

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

### lawref.query.parser.Parser.parse

*method*

```python
def parse() -> Query | InferenceQuery
```

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

### lawref.query.parser.Parser.primary

*method*

```python
def primary() -> Expr
```

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

### lawref.query.parser.Parser.selection

*method*

```python
def selection() -> Selection
```

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

### lawref.query.parser.Parser.source_expr

*method*

```python
def source_expr() -> Source
```

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

### lawref.query.parser.Parser.string

*method*

```python
def string() -> str
```

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

## lawref.query.parser.Query

*class* · *dataclass*

```python
class Query
```

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

### lawref.query.parser.Query.bindings

*attribute* · *instance attribute*

```python
bindings: list[Binding]
```

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

### lawref.query.parser.Query.materializations

*attribute* · *class attribute* · *instance attribute*

```python
materializations: list[Materialization] = field(default_factory=list)
```

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

### lawref.query.parser.Query.metadata

*attribute* · *class attribute* · *instance attribute*

```python
metadata: dict[str, str] = field(default_factory=dict)
```

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

### lawref.query.parser.Query.selections

*attribute* · *instance attribute*

```python
selections: list[Selection]
```

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

### lawref.query.parser.Query.source

*attribute* · *class attribute* · *instance attribute*

```python
source: str = ''
```

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

### lawref.query.parser.Query.where

*attribute* · *instance attribute*

```python
where: Expr | None
```

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

## lawref.query.parser.Selection

*class* · *dataclass*

```python
class Selection
```

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

### lawref.query.parser.Selection.alias

*attribute* · *instance attribute*

```python
alias: str
```

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

### lawref.query.parser.Selection.expression

*attribute* · *instance attribute*

```python
expression: Expr
```

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

## lawref.query.parser.Source

*class* · *dataclass*

```python
class Source
```

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

### lawref.query.parser.Source.document

*attribute* · *class attribute* · *instance attribute*

```python
document: str | None = None
```

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

### lawref.query.parser.Source.package_glob

*attribute* · *class attribute* · *instance attribute*

```python
package_glob: str = '*'
```

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

### lawref.query.parser.Source.relation

*attribute* · *instance attribute*

```python
relation: str
```

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

## lawref.query.parser.Token

*class* · *dataclass*

```python
class Token
```

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

### lawref.query.parser.Token.column

*attribute* · *instance attribute*

```python
column: int
```

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

### lawref.query.parser.Token.kind

*attribute* · *instance attribute*

```python
kind: str
```

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

### lawref.query.parser.Token.line

*attribute* · *instance attribute*

```python
line: int
```

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

### lawref.query.parser.Token.value

*attribute* · *instance attribute*

```python
value: str
```

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

## lawref.query.parser.metadata

*function*

```python
def metadata(source: str) -> dict[str, str]
```

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

## lawref.query.parser.parse

*function*

```python
def parse(source: str) -> Query | InferenceQuery
```

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

## lawref.query.parser.tokenize

*function*

```python
def tokenize(source: str) -> list[Token]
```

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