math_spec.resolution
Name resolution — the pass that makes the core AST fully typed.
Parsers emit unresolved names; this module rewrites each into the typed node its kind asks for, so the AST reaching a consumer holds none. The rules live in the language reference.
DeclarationKind = Literal['variable', 'parameter', 'dimension', 'lookup']
module-attribute
#
Namespace(variables, parameters, dimensions, lookups, dtypes, leaf_dims)
#
The declared names of one schema, by kind.
A name has one kind: model.py refuses one declared under two sections.
Source code in src/math_spec/resolution.py
dimensions = frozenset(dimensions)
instance-attribute
#
dtypes = dict(dtypes)
instance-attribute
#
leaf_dims = dict(leaf_dims)
instance-attribute
#
lookups = dict(lookups)
instance-attribute
#
parameters = frozenset(parameters)
instance-attribute
#
variables = frozenset(variables)
instance-attribute
#
groupable()
#
The lookups a by= may name: name -> the dimension it maps into.
A label space is absent, which is what makes naming one in a by=
answerable with the promotion rewrite rather than "no such lookup".
Source code in src/math_spec/resolution.py
into_of(lookup)
#
kind(name)
#
What name was declared as, or None where the file declares it nowhere.
Source code in src/math_spec/resolution.py
of(schema)
classmethod
#
Build the namespace of schema, the whole of what a file may name.
A targeted lookup's values are labels of its target, so its dtype is the target's.
Source code in src/math_spec/resolution.py
over_of(lookup)
#
unknown(name, context, *, allow_dims, formals=())
#
The refusal for a name declared nowhere, listing what it could have been.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
The name the file wrote.
TYPE:
|
context
|
The declaration it was found in.
TYPE:
|
allow_dims
|
Whether a dimension would have been accepted there.
TYPE:
|
formals
|
A macro's formals, listed first when there are any. |
Source code in src/math_spec/resolution.py
expression_of(text, schema, ns, context)
#
Parse, expand and resolve text — the only way a consumer gets an AST.
| RAISES | DESCRIPTION |
|---|---|
LanguageError
|
Listing every problem the text has. |
Source code in src/math_spec/resolution.py
resolve_expression(node, ns, context, errors)
#
Rewrite every NameNode under node to a typed node, checking operator call shapes on the way.
| RETURNS | DESCRIPTION |
|---|---|
ParsedNode | None
|
The typed tree, or |
ParsedNode | None
|
errors rather than raising, so a caller collecting problems across a |
ParsedNode | None
|
whole schema reports them together. |
Source code in src/math_spec/resolution.py
resolve_where(node, ns, context, errors, self_variable=None)
#
Rewrite a parsed where AST into typed predicates, folded as :class:~math_spec.program.Mask folds.
| RETURNS | DESCRIPTION |
|---|---|
WhereNode | None
|
The typed tree — a mask admitting every row or none comes back as the |
WhereNode | None
|
one |
WhereNode | None
|
problems appended to errors. |
Source code in src/math_spec/resolution.py
resolve_where_text(text, ns, context, errors, self_variable=None)
#
Parse and resolve one where string as :func:resolve_where does, a parse failure appended to errors.
| RETURNS | DESCRIPTION |
|---|---|
WhereNode | None
|
|
Source code in src/math_spec/resolution.py
where_of(text, ns, context, self_variable=None)
#
Parse and resolve a where string into the :class:~math_spec.program.Mask a declaration carries.
None for no mask, however the file spelled it: a mask that admits every
row is dropped, and one that admits none arrives as a mask over
BooleanLiteralNode(False).
| RAISES | DESCRIPTION |
|---|---|
LanguageError
|
Listing every problem the predicate has. |