:>> [[ABIO]] → ABIO Docs → ABIO spec_lang
Spec Language Module¶
What remains of the M1 spec language after M47.7 — the distribution builtins, the inline-expression allowlist (safe_eval), lexical Scope and the @biotype registry — the pieces Expr stands on.
alienbio.spec_lang
¶
What remains of the M1 spec language after M47.7: the pieces the Expr
language stands on — the distribution builtins, the inline-expression
allowlist (validate_expression), lexical Scope, and the @biotype class
registry. The old YAML loader, evaluator, typed keys, rate compiler and
Bio facade are gone; alienbio.expr is the one language.
UnsafeExpressionError
¶
Scope
¶
Bases: dict
A dict with lexical scoping (parent chain lookup).
Variables are inherited through the scope chain. Lookups check the current scope first, then climb to parent scopes until found.
The scope hierarchy is built by the loader (a file is a scope, a template call is a child scope); lookups are dynamic - they climb the hierarchy at access time.
Attributes:
| Name | Type | Description |
|---|---|---|
parent |
Optional parent Scope for inheritance chain |
|
name |
Optional name for this scope (for debugging) |
Source code in src/alienbio/spec_lang/scope.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
__init__(data=None, parent=None, name=None)
¶
Create a new Scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any] | None
|
Initial dict content |
None
|
parent
|
Scope | None
|
Parent scope for inheritance |
None
|
name
|
str | None
|
Optional name for debugging |
None
|
Source code in src/alienbio/spec_lang/scope.py
__getitem__(key)
¶
Get item, climbing parent chain if not found locally.
get(key, default=None)
¶
__contains__(key)
¶
Check if key exists in this scope or any parent.
local_keys()
¶
all_keys()
¶
child(data=None, name=None)
¶
Create a child scope that inherits from this one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any] | None
|
Initial content for child scope |
None
|
name
|
str | None
|
Optional name for the child scope |
None
|
Returns:
| Type | Description |
|---|---|
Scope
|
New Scope with this scope as parent |
Source code in src/alienbio/spec_lang/scope.py
resolve(key)
¶
Resolve a key and return (value, defining_scope).
Useful for debugging to see where a value comes from.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key to look up |
required |
Returns:
| Type | Description |
|---|---|
tuple[Any, Scope | None]
|
Tuple of (value, scope_that_defined_it) |
Raises:
| Type | Description |
|---|---|
KeyError
|
If key not found in any scope |
Source code in src/alienbio/spec_lang/scope.py
biotype(arg=None)
¶
Register a class for hydration from YAML.
Usage
@biotype class Chemistry: ...
@biotype("custom_name") class World: ...
Source code in src/alienbio/spec_lang/decorators.py
get_biotype(name)
¶
Get a biotype class by name.
Raises:
| Type | Description |
|---|---|
KeyError
|
If name not registered |
validate_expression(source)
¶
Parse source and validate every node against the allowlist.
Returns the parsed ast.Expression (for reuse in compilation).
Raises:
| Type | Description |
|---|---|
SyntaxError
|
If |
UnsafeExpressionError
|
If any node is outside the allowlist. |