Capture¶
bcql_py.models.capture
¶
Dealing with capturing inside variable assignment, references to it, and constraints inside capture expressions.
This includes the label:body capture operator, annotation references like A.word, and constraint expressions like A.word = "over".
CaptureNode
¶
Bases: BCQLNode
A capture label applied to a sub-query: label:body, e.g. A:[word="hello"].
Everything matched by body is captured under label in the match info.
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
The capture group name (e.g. |
body |
BCQLNodeUnion
|
The sub-query whose match is captured |
AnnotationRef
¶
Bases: BCQLNode
Reference to a captured token's annotation: label.annotation, or a bare capture label.
Examples:
- A.word refers to the word annotation of capture A.
- A as a bare label (typically used as a function argument, e.g. start(A)).
Attributes:
| Name | Type | Description |
|---|---|---|
label |
str
|
Capture group name. |
annotation |
str
|
Annotation name, or empty string for a bare label reference. |
ConstraintLiteral
¶
Bases: BCQLNode
A literal string value in a capture constraint.
Example: the "over" in A.word = "over".
Attributes:
| Name | Type | Description |
|---|---|---|
value |
str
|
The literal string (without quotes) |
quote_char |
Literal['"', "'"]
|
The quote character used in the original query, either |
ConstraintComparison
¶
Bases: BCQLNode
A comparison in a capture constraint: left op right.
Supported operators: =, !=, <, <=, >, >=.
Operators here do not get their own class; should not be needed here.
Attributes:
| Name | Type | Description |
|---|---|---|
operator |
Literal['=', '!=', '<', '<=', '>', '>=']
|
The comparison operator. |
left |
CaptureConstraintExpr
|
Left-hand operand (usually an AnnotationRef). |
right |
CaptureConstraintExpr
|
Right-hand operand (annotation ref, literal, or function call). |
ConstraintBoolean
¶
Bases: BCQLNode
Boolean combination of capture constraints: left op right.
Operators: & (AND), | (OR), -> (implication). All three share the same precedence
per Bcql.g4's booleanOperator rule. The -> implication operator is most commonly
seen in capture constraints (e.g. A.word = "cat" -> B.word = "dog") but the grammar
allows it at every level.
Attributes:
| Name | Type | Description |
|---|---|---|
operator |
Literal['&', '|', '->']
|
|
left |
CaptureConstraintExpr
|
Left operand. |
right |
CaptureConstraintExpr
|
Right operand. |
ConstraintNot
¶
Bases: BCQLNode
Logical NOT in a capture constraint
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
CaptureConstraintExpr
|
The constraint being negated. |
ConstraintInteger
¶
Bases: BCQLNode
An integer literal in a capture constraint.
Example: the 5 in focus.pos > 5.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
int
|
The integer value. |
ConstraintFunctionCall
¶
Bases: BCQLNode
A function call in a capture constraint.
Examples: start(A) or end(B) used in expressions like
start(B) < start(A).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Function name (e.g. |
args |
list[CaptureConstraintExpr]
|
Function arguments (annotation refs, literals, etc.). |
GlobalConstraintNode
¶
Bases: BCQLNode
A query with a global capture constraint.
The constraint expression follows the :: operator and relates captures defined in body.
Example: A:[] "by" B:[] :: A.word = B.word where A:[] "by" B:[] is the body and A.word = B.word is the constraint expression.
Attributes:
| Name | Type | Description |
|---|---|---|
body |
BCQLNodeUnion
|
The main query containing captures. |
constraint |
CaptureConstraintExpr
|
The constraint expression relating captures. |