ai-editor-tree-engine-dev 1.0.176__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_editor_tree_engine_dev-1.0.176.dist-info/METADATA +35 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/RECORD +121 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/WHEEL +5 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/licenses/LICENSE +21 -0
- ai_editor_tree_engine_dev-1.0.176.dist-info/top_level.txt +1 -0
- tree_engine/PUBLIC_API.md +161 -0
- tree_engine/__init__.py +327 -0
- tree_engine/checks/__init__.py +60 -0
- tree_engine/checks/builtin/__init__.py +5 -0
- tree_engine/checks/builtin/compile_check.py +53 -0
- tree_engine/checks/builtin/csv_syntax.py +51 -0
- tree_engine/checks/builtin/docstrings.py +211 -0
- tree_engine/checks/builtin/encoding.py +55 -0
- tree_engine/checks/builtin/fleet_rules.py +227 -0
- tree_engine/checks/builtin/format_syntax.py +82 -0
- tree_engine/checks/builtin/jsonl_syntax.py +49 -0
- tree_engine/checks/builtin/shipped.py +52 -0
- tree_engine/checks/builtin/syntax.py +118 -0
- tree_engine/checks/builtin/xml_wellformed.py +51 -0
- tree_engine/checks/chain.py +332 -0
- tree_engine/checks/external/__init__.py +5 -0
- tree_engine/checks/external/_base.py +61 -0
- tree_engine/checks/external/bandit.py +53 -0
- tree_engine/checks/external/black.py +48 -0
- tree_engine/checks/external/flake8.py +38 -0
- tree_engine/checks/external/isort.py +38 -0
- tree_engine/checks/external/mypy.py +45 -0
- tree_engine/checks/external/ruff.py +45 -0
- tree_engine/checks/external/runner.py +197 -0
- tree_engine/checks/model.py +110 -0
- tree_engine/checks/options.py +73 -0
- tree_engine/checks/plugin.py +171 -0
- tree_engine/checks/registry.py +349 -0
- tree_engine/core/address.py +376 -0
- tree_engine/core/identifier_map.py +266 -0
- tree_engine/core/identity.py +226 -0
- tree_engine/core/instrumentation.py +399 -0
- tree_engine/core/integrity.py +341 -0
- tree_engine/core/integrity_full.py +382 -0
- tree_engine/core/journal.py +260 -0
- tree_engine/core/journal_compose.py +571 -0
- tree_engine/core/live_tree.py +785 -0
- tree_engine/core/locking.py +188 -0
- tree_engine/core/move.py +585 -0
- tree_engine/core/move_references.py +323 -0
- tree_engine/core/node_types.py +408 -0
- tree_engine/core/nodes.py +348 -0
- tree_engine/core/offsets.py +24 -0
- tree_engine/core/operations.py +825 -0
- tree_engine/core/plugin_boundary.py +160 -0
- tree_engine/core/position_map.py +263 -0
- tree_engine/core/position_transfer.py +512 -0
- tree_engine/core/range_refresh.py +366 -0
- tree_engine/core/reference_cache.py +360 -0
- tree_engine/core/references.py +223 -0
- tree_engine/core/reparse.py +378 -0
- tree_engine/core/short_id.py +296 -0
- tree_engine/core/subtree_apply.py +397 -0
- tree_engine/core/subtree_copy.py +399 -0
- tree_engine/core/transactions.py +397 -0
- tree_engine/core/trivia.py +396 -0
- tree_engine/core/updates.py +398 -0
- tree_engine/core/validation.py +377 -0
- tree_engine/errors.py +104 -0
- tree_engine/exceptions.py +376 -0
- tree_engine/facade.py +4524 -0
- tree_engine/plugins/_statements.py +369 -0
- tree_engine/plugins/bsl/block_edit.py +449 -0
- tree_engine/plugins/bsl/blocks.py +127 -0
- tree_engine/plugins/bsl/checker.py +297 -0
- tree_engine/plugins/bsl/dialects.py +303 -0
- tree_engine/plugins/bsl/generator.py +481 -0
- tree_engine/plugins/bsl/import_map.py +995 -0
- tree_engine/plugins/bsl/plugin.py +452 -0
- tree_engine/plugins/contract.py +355 -0
- tree_engine/plugins/cpp/import_map.py +505 -0
- tree_engine/plugins/cpp/languages.py +99 -0
- tree_engine/plugins/cpp/plugin.py +501 -0
- tree_engine/plugins/csv_format.py +676 -0
- tree_engine/plugins/detachable.py +156 -0
- tree_engine/plugins/fallback.py +421 -0
- tree_engine/plugins/ini_format.py +330 -0
- tree_engine/plugins/json_format.py +813 -0
- tree_engine/plugins/json_pointer.py +203 -0
- tree_engine/plugins/jsonl_format.py +392 -0
- tree_engine/plugins/markdown_format.py +748 -0
- tree_engine/plugins/onec_query_format.py +61 -0
- tree_engine/plugins/parse_position.py +54 -0
- tree_engine/plugins/plain_text.py +1543 -0
- tree_engine/plugins/python/export_map.py +306 -0
- tree_engine/plugins/python/import_map.py +429 -0
- tree_engine/plugins/python/plugin.py +1710 -0
- tree_engine/plugins/registry.py +497 -0
- tree_engine/plugins/scan.py +87 -0
- tree_engine/plugins/selection.py +228 -0
- tree_engine/plugins/sql_format.py +61 -0
- tree_engine/plugins/toml_format.py +1072 -0
- tree_engine/plugins/xml_format.py +911 -0
- tree_engine/plugins/yaml/builder.py +49 -0
- tree_engine/plugins/yaml/emitter.py +225 -0
- tree_engine/plugins/yaml/flow.py +227 -0
- tree_engine/plugins/yaml/plugin.py +458 -0
- tree_engine/plugins/yaml/ranges.py +52 -0
- tree_engine/plugins/yaml/reader.py +359 -0
- tree_engine/plugins/yaml/scanner.py +298 -0
- tree_engine/query/adapter.py +283 -0
- tree_engine/query/engine.py +853 -0
- tree_engine/query/inspection.py +498 -0
- tree_engine/query/outline.py +288 -0
- tree_engine/query/predicates.py +263 -0
- tree_engine/query/rendered_lines.py +46 -0
- tree_engine/query/results.py +206 -0
- tree_engine/query/selector.py +400 -0
- tree_engine/query/xml_query.py +747 -0
- tree_engine/storage/codec.py +400 -0
- tree_engine/storage/document_bridge.py +579 -0
- tree_engine/storage/file_txn.py +459 -0
- tree_engine/storage/history.py +106 -0
- tree_engine/storage/lifecycle.py +622 -0
- tree_engine/storage/schema.py +403 -0
- tree_engine/storage/session_guard.py +398 -0
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
"""Extension node types outside the base LibCST subset ({p043}/{an01}/{iblr}),
|
|
2
|
+
plus the dedicated boolean ``export`` field ({p044}, context {p047}).
|
|
3
|
+
|
|
4
|
+
Defines ``PreprocessorDirectiveNode``, ``AnnotationNode``,
|
|
5
|
+
``VariableDeclarationNode``, ``VariableDeclaratorNode`` and the
|
|
6
|
+
``ExportFieldMixin`` that wires ``export`` into each of them.
|
|
7
|
+
|
|
8
|
+
Builds directly on the common-tree-model base contract in
|
|
9
|
+
``src/tree_engine/core/nodes.py`` (``Node``, ``NodeKind``, ``make_node``,
|
|
10
|
+
``NodeSchemaError``) instead of a second node model. Each type below is a
|
|
11
|
+
thin wrapper composed around exactly one immutable ``Node`` (``.node``):
|
|
12
|
+
construction goes through ``make_node``'s validation, per-field data
|
|
13
|
+
(content, ``export``, declarator ``name``, child sequences) lives in that
|
|
14
|
+
``Node``'s ``fields``/``children``, and the reserved ``extended_type`` slot
|
|
15
|
+
records which wrapper class owns a given ``Node`` -- its reserved purpose.
|
|
16
|
+
Because ``Node`` is immutable, ``set_attribute`` rebuilds the wrapped
|
|
17
|
+
``Node`` through ``make_node`` again while keeping the same
|
|
18
|
+
``node_id``/``short_id``; nothing here re-implements identity, validation
|
|
19
|
+
or traversal -- ``iter_children``/``walk`` from ``nodes.py`` operate
|
|
20
|
+
directly on ``.node``. Non-goals: BSL/1C parsing, tree-sitter integration,
|
|
21
|
+
changes to ``nodes.py``, format-plugin code, persistence/index-map
|
|
22
|
+
implementation (only a synchronous call to an injectable hook stand-in).
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
from dataclasses import replace
|
|
28
|
+
from typing import Any, Callable, ClassVar, Dict, List, Optional, Sequence, Tuple
|
|
29
|
+
from uuid import UUID
|
|
30
|
+
|
|
31
|
+
import itertools
|
|
32
|
+
|
|
33
|
+
from tree_engine.core.identity import generate_node_id
|
|
34
|
+
from tree_engine.core.nodes import Node, NodeKind, NodeSchemaError, make_node
|
|
35
|
+
from tree_engine.errors import ErrorCode
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"ExportNotApplicableError",
|
|
39
|
+
"IndexMapHookFn",
|
|
40
|
+
"ExportFieldMixin",
|
|
41
|
+
"PreprocessorDirectiveNode",
|
|
42
|
+
"AnnotationNode",
|
|
43
|
+
"VariableDeclaratorNode",
|
|
44
|
+
"VariableDeclarationNode",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
IndexMapHookFn = Callable[[Any, str, Any], None]
|
|
48
|
+
# short_id is a positive integer per {p097}; hex is only its outward rendering.
|
|
49
|
+
_short_id_counter = itertools.count(1)
|
|
50
|
+
_SEP = "\x00"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _noop_index_map_hook(node: Any, field_name: str, value: Any) -> None:
|
|
54
|
+
"""Default index-map hook: no-op stand-in for the sibling-owned
|
|
55
|
+
index-map update interface (delivered by a later artifact and not
|
|
56
|
+
present in this worktree). Callers that need real index-map
|
|
57
|
+
reflection inject their own hook via ``index_map_hook``; this module
|
|
58
|
+
only guarantees it is invoked synchronously on every field change,
|
|
59
|
+
per {p044}."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _encode_seps(separators: Sequence[str]) -> str:
|
|
63
|
+
"""Encode an ordered separator list into one ``Node.fields`` primitive
|
|
64
|
+
string, count-prefixed so an empty list and a list holding a single
|
|
65
|
+
empty separator decode distinctly."""
|
|
66
|
+
seps = list(separators)
|
|
67
|
+
return f"{len(seps)}{_SEP}" + _SEP.join(seps)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _decode_seps(encoded: str) -> List[str]:
|
|
71
|
+
count_str, _, remainder = encoded.partition(_SEP)
|
|
72
|
+
count = int(count_str) if count_str else 0
|
|
73
|
+
return [] if count == 0 else remainder.split(_SEP)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class ExportNotApplicableError(NodeSchemaError):
|
|
77
|
+
"""Raised when ``export=True`` is requested on a node kind where BSL's
|
|
78
|
+
EXPORT_KEYWORD is not semantically applicable, per {p044}/{p047}."""
|
|
79
|
+
|
|
80
|
+
def __init__(self, node_type_name: str) -> None:
|
|
81
|
+
super().__init__(
|
|
82
|
+
ErrorCode.INVALID_PARENT_TYPE,
|
|
83
|
+
f"{node_type_name} does not support export (BSL EXPORT_KEYWORD "
|
|
84
|
+
"is inapplicable here, per {p047})",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class _NodeWrapper:
|
|
89
|
+
"""Ergonomic wrapper composed around one immutable base ``Node``.
|
|
90
|
+
|
|
91
|
+
Not a second node model: every subclass sets ``_KIND`` and delegates
|
|
92
|
+
all shape/validation to ``make_node``. Identity (``node_id``,
|
|
93
|
+
``short_id``), ``extended_type`` and byte range (``buffer_range``) are
|
|
94
|
+
the reserved ``Node`` slots this module was told to use; ``parent_id``
|
|
95
|
+
has no counterpart on ``Node`` (bottom-up immutable construction keeps
|
|
96
|
+
no back-references) so it is carried as plain wrapper bookkeeping.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
_KIND: ClassVar[NodeKind]
|
|
100
|
+
|
|
101
|
+
def __init__(
|
|
102
|
+
self, *, start_byte: int, end_byte: int, content: str = "",
|
|
103
|
+
node_id: Optional[UUID] = None, parent_id: Optional[UUID] = None,
|
|
104
|
+
index_map_hook: Optional[IndexMapHookFn] = None, children: Sequence[Node] = (),
|
|
105
|
+
**extra_fields: Any,
|
|
106
|
+
) -> None:
|
|
107
|
+
if end_byte < start_byte:
|
|
108
|
+
raise NodeSchemaError(
|
|
109
|
+
ErrorCode.INVALID_POSITION,
|
|
110
|
+
f"end_byte ({end_byte}) precedes start_byte ({start_byte})",
|
|
111
|
+
)
|
|
112
|
+
resolved_id = node_id or generate_node_id()
|
|
113
|
+
# Construction must not be a back door around the export rule that
|
|
114
|
+
# set_attribute enforces: on a kind where export is inapplicable,
|
|
115
|
+
# requesting it here fails just as loudly ({p044}).
|
|
116
|
+
if extra_fields.get("export") and not getattr(self, "_export_applicable", True):
|
|
117
|
+
raise ExportNotApplicableError(type(self).__name__)
|
|
118
|
+
fields: Dict[str, Any] = {"content": content, **extra_fields}
|
|
119
|
+
base = make_node(self._KIND, fields=fields, children=tuple(children))
|
|
120
|
+
self._node: Node = replace(
|
|
121
|
+
base,
|
|
122
|
+
node_id=resolved_id,
|
|
123
|
+
short_id=next(_short_id_counter),
|
|
124
|
+
extended_type=type(self).__name__,
|
|
125
|
+
buffer_range=(start_byte, end_byte),
|
|
126
|
+
)
|
|
127
|
+
self.index_map_hook: IndexMapHookFn = index_map_hook or _noop_index_map_hook
|
|
128
|
+
self.parent_id: Optional[UUID] = parent_id
|
|
129
|
+
|
|
130
|
+
@classmethod
|
|
131
|
+
def from_node(
|
|
132
|
+
cls, node: Node, *, index_map_hook: Optional[IndexMapHookFn] = None,
|
|
133
|
+
parent_id: Optional[UUID] = None,
|
|
134
|
+
) -> "_NodeWrapper":
|
|
135
|
+
"""Wrap an already-validated ``Node`` with no re-validation, as
|
|
136
|
+
``nodes.py`` documents for sibling steps attaching identity/
|
|
137
|
+
extension data produced elsewhere."""
|
|
138
|
+
self = object.__new__(cls)
|
|
139
|
+
self._node = node
|
|
140
|
+
self.index_map_hook = index_map_hook or _noop_index_map_hook
|
|
141
|
+
self.parent_id = parent_id
|
|
142
|
+
return self
|
|
143
|
+
|
|
144
|
+
@property
|
|
145
|
+
def node(self) -> Node:
|
|
146
|
+
return self._node
|
|
147
|
+
|
|
148
|
+
@property
|
|
149
|
+
def node_id(self) -> UUID:
|
|
150
|
+
return self._node.node_id
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def short_id(self) -> int:
|
|
154
|
+
return self._node.short_id
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def byte_range(self) -> Tuple[int, int]:
|
|
158
|
+
return self._node.buffer_range
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def content(self) -> str:
|
|
162
|
+
return self._node.fields.get("content", "")
|
|
163
|
+
|
|
164
|
+
def get_attribute(self, name: str, default: Any = None) -> Any:
|
|
165
|
+
return self._node.fields.get(name, default)
|
|
166
|
+
|
|
167
|
+
def set_attribute(self, name: str, value: Any) -> None:
|
|
168
|
+
"""Rebuild the wrapped ``Node`` through ``make_node`` (reusing its
|
|
169
|
+
validation path) with ``name`` set, keeping identity/extension
|
|
170
|
+
reserved slots, then invoke the index-map hook synchronously."""
|
|
171
|
+
new_fields = dict(self._node.fields)
|
|
172
|
+
new_fields[name] = value
|
|
173
|
+
rebuilt = make_node(self._node.kind, fields=new_fields, children=self._node.children)
|
|
174
|
+
self._node = replace(
|
|
175
|
+
rebuilt,
|
|
176
|
+
node_id=self._node.node_id,
|
|
177
|
+
short_id=self._node.short_id,
|
|
178
|
+
extended_type=self._node.extended_type,
|
|
179
|
+
buffer_range=self._node.buffer_range,
|
|
180
|
+
references=self._node.references,
|
|
181
|
+
)
|
|
182
|
+
self.index_map_hook(self, name, value)
|
|
183
|
+
|
|
184
|
+
def matches(self, **predicates: Any) -> bool:
|
|
185
|
+
"""Search-predicate helper: true when every keyword matches a
|
|
186
|
+
first-class property (e.g. ``export``) or a ``fields`` entry."""
|
|
187
|
+
for key, expected in predicates.items():
|
|
188
|
+
descriptor = getattr(type(self), key, None)
|
|
189
|
+
actual = getattr(self, key) if isinstance(descriptor, property) else self._node.fields.get(key)
|
|
190
|
+
if actual != expected:
|
|
191
|
+
return False
|
|
192
|
+
return True
|
|
193
|
+
|
|
194
|
+
def copy(self, *, preserve_ids: bool = False) -> "_NodeWrapper":
|
|
195
|
+
"""Copy content, range and every field (including ``export``).
|
|
196
|
+
|
|
197
|
+
By default the copy gets a FRESH ``node_id`` and no ``short_id``:
|
|
198
|
+
two live nodes must never share an identifier, and the document
|
|
199
|
+
that receives the copy allocates its own short id. ``preserve_ids``
|
|
200
|
+
keeps the original identity for the {p074} copy mode that moves a
|
|
201
|
+
subtree into a new document under its existing UUIDs.
|
|
202
|
+
"""
|
|
203
|
+
node = self._node
|
|
204
|
+
if not preserve_ids:
|
|
205
|
+
node = replace(node, node_id=generate_node_id(), short_id=None)
|
|
206
|
+
return type(self).from_node(node, index_map_hook=self.index_map_hook, parent_id=self.parent_id)
|
|
207
|
+
|
|
208
|
+
def move_to(self, new_parent_id: Optional[UUID]) -> "_NodeWrapper":
|
|
209
|
+
"""Reparent in place; the wrapped ``Node`` (identity, range,
|
|
210
|
+
content, fields) is left completely untouched."""
|
|
211
|
+
self.parent_id = new_parent_id
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
215
|
+
start, end = self._node.buffer_range
|
|
216
|
+
return {
|
|
217
|
+
"type": type(self).__name__,
|
|
218
|
+
"node_id": str(self._node.node_id),
|
|
219
|
+
"parent_id": str(self.parent_id) if self.parent_id is not None else None,
|
|
220
|
+
"start_byte": start,
|
|
221
|
+
"end_byte": end,
|
|
222
|
+
"content": self.content,
|
|
223
|
+
"fields": {k: v for k, v in self._node.fields.items() if k != "content"},
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
@classmethod
|
|
227
|
+
def from_dict(cls, data: Dict[str, Any], **extra: Any) -> "_NodeWrapper":
|
|
228
|
+
parent_id = UUID(data["parent_id"]) if data.get("parent_id") else None
|
|
229
|
+
fields = dict(data.get("fields", {}))
|
|
230
|
+
fields.update(extra)
|
|
231
|
+
return cls(
|
|
232
|
+
start_byte=data["start_byte"],
|
|
233
|
+
end_byte=data["end_byte"],
|
|
234
|
+
content=data.get("content", ""),
|
|
235
|
+
node_id=UUID(data["node_id"]),
|
|
236
|
+
parent_id=parent_id,
|
|
237
|
+
**fields,
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _as_node(value: Any) -> Node:
|
|
242
|
+
return value.node if isinstance(value, _NodeWrapper) else value
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
class ExportFieldMixin:
|
|
246
|
+
"""Wires a dedicated boolean ``export`` field into the stable node
|
|
247
|
+
contract ({p044}): a first-class field, not a loose entry a caller
|
|
248
|
+
stumbles into. Applied in accepting form to ``VariableDeclarationNode``
|
|
249
|
+
and ``VariableDeclaratorNode`` (BSL's EXPORT_KEYWORD is semantically
|
|
250
|
+
applicable there, per {p047}), and in rejecting form -- via
|
|
251
|
+
``_export_applicable = False`` -- to ``PreprocessorDirectiveNode`` and
|
|
252
|
+
``AnnotationNode`` (export is inapplicable there).
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
_export_applicable: ClassVar[bool] = True
|
|
256
|
+
|
|
257
|
+
@property
|
|
258
|
+
def export(self) -> bool:
|
|
259
|
+
return self._node.fields.get("export", False) # type: ignore[attr-defined]
|
|
260
|
+
|
|
261
|
+
def get_attribute(self, name: str, default: Any = None) -> Any:
|
|
262
|
+
if name == "export":
|
|
263
|
+
return self._node.fields.get("export", False) # type: ignore[attr-defined]
|
|
264
|
+
return super().get_attribute(name, default) # type: ignore[misc]
|
|
265
|
+
|
|
266
|
+
def set_attribute(self, name: str, value: Any) -> None:
|
|
267
|
+
if name != "export":
|
|
268
|
+
super().set_attribute(name, value) # type: ignore[misc]
|
|
269
|
+
return
|
|
270
|
+
if not isinstance(value, bool):
|
|
271
|
+
raise NodeSchemaError(
|
|
272
|
+
ErrorCode.INVALID_PARENT_TYPE, f"export must be a bool, got {type(value).__name__}"
|
|
273
|
+
)
|
|
274
|
+
if not self._export_applicable:
|
|
275
|
+
if value:
|
|
276
|
+
raise ExportNotApplicableError(type(self).__name__)
|
|
277
|
+
return # setting False on a rejecting node type is a no-op
|
|
278
|
+
super().set_attribute("export", value) # type: ignore[misc]
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
class PreprocessorDirectiveNode(ExportFieldMixin, _NodeWrapper):
|
|
282
|
+
"""Ordinary content-bearing node for BSL/1C preprocessor directives
|
|
283
|
+
({p043}). The core applies no preprocessor semantics: no directive
|
|
284
|
+
parsing, no conditional-branch logic. Stored, addressed, copied,
|
|
285
|
+
moved and serialized exactly like any other node via ``_NodeWrapper``;
|
|
286
|
+
``export`` is inapplicable (rejecting form).
|
|
287
|
+
"""
|
|
288
|
+
|
|
289
|
+
_KIND: ClassVar[NodeKind] = NodeKind("core:preprocessor_directive")
|
|
290
|
+
_export_applicable: ClassVar[bool] = False
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class AnnotationNode(ExportFieldMixin, _NodeWrapper):
|
|
294
|
+
"""Standalone content-bearing node for BSL annotations such as
|
|
295
|
+
&НаСервере/&AtServer ({an01}), structurally distinct from
|
|
296
|
+
``PreprocessorDirectiveNode`` -- never merged or unioned with it.
|
|
297
|
+
Carries an optional ordered collection of child argument-value nodes,
|
|
298
|
+
stored via the base contract's own ``fields``/``children`` child-
|
|
299
|
+
sequence mechanism, with inter-argument separators preserved. The core
|
|
300
|
+
performs no BSL-specific recognition of annotation syntax. ``export``
|
|
301
|
+
is inapplicable (rejecting form).
|
|
302
|
+
"""
|
|
303
|
+
|
|
304
|
+
_KIND: ClassVar[NodeKind] = NodeKind("core:annotation")
|
|
305
|
+
_export_applicable: ClassVar[bool] = False
|
|
306
|
+
|
|
307
|
+
def __init__(
|
|
308
|
+
self, *, start_byte: int, end_byte: int, content: str = "",
|
|
309
|
+
node_id: Optional[UUID] = None, parent_id: Optional[UUID] = None,
|
|
310
|
+
index_map_hook: Optional[IndexMapHookFn] = None,
|
|
311
|
+
arguments: Sequence[Any] = (), argument_separators: Sequence[str] = (),
|
|
312
|
+
**extra: Any,
|
|
313
|
+
) -> None:
|
|
314
|
+
arg_nodes = tuple(_as_node(a) for a in arguments)
|
|
315
|
+
extra["arguments"] = arg_nodes
|
|
316
|
+
extra["argument_separators"] = _encode_seps(argument_separators)
|
|
317
|
+
super().__init__(
|
|
318
|
+
start_byte=start_byte, end_byte=end_byte, content=content, node_id=node_id,
|
|
319
|
+
parent_id=parent_id, index_map_hook=index_map_hook, children=arg_nodes, **extra,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
@property
|
|
323
|
+
def arguments(self) -> Tuple[Node, ...]:
|
|
324
|
+
return self._node.fields.get("arguments", ())
|
|
325
|
+
|
|
326
|
+
@property
|
|
327
|
+
def argument_separators(self) -> List[str]:
|
|
328
|
+
return _decode_seps(self._node.fields.get("argument_separators", ""))
|
|
329
|
+
|
|
330
|
+
@classmethod
|
|
331
|
+
def from_dict(cls, data: Dict[str, Any], **extra: Any) -> "AnnotationNode":
|
|
332
|
+
fields = dict(data.get("fields", {}))
|
|
333
|
+
arguments = fields.pop("arguments", ())
|
|
334
|
+
argument_separators = _decode_seps(fields.pop("argument_separators", ""))
|
|
335
|
+
parent_id = UUID(data["parent_id"]) if data.get("parent_id") else None
|
|
336
|
+
return cls(
|
|
337
|
+
start_byte=data["start_byte"], end_byte=data["end_byte"], content=data.get("content", ""),
|
|
338
|
+
node_id=UUID(data["node_id"]), parent_id=parent_id,
|
|
339
|
+
arguments=arguments, argument_separators=argument_separators, **fields, **extra,
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
class VariableDeclaratorNode(ExportFieldMixin, _NodeWrapper):
|
|
344
|
+
"""One declared variable inside a ``VariableDeclarationNode``
|
|
345
|
+
({iblr}). Carries its own identity and byte-range fields independent
|
|
346
|
+
of its siblings and of the parent declaration. ``export`` reflects
|
|
347
|
+
BSL's EXPORT_KEYWORD when present on this declarator (accepting
|
|
348
|
+
form).
|
|
349
|
+
"""
|
|
350
|
+
|
|
351
|
+
_KIND: ClassVar[NodeKind] = NodeKind("core:variable_declarator")
|
|
352
|
+
|
|
353
|
+
@property
|
|
354
|
+
def name(self) -> str:
|
|
355
|
+
return self._node.fields.get("name", "")
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class VariableDeclarationNode(ExportFieldMixin, _NodeWrapper):
|
|
359
|
+
"""Owns an ordered list of ``VariableDeclaratorNode`` children
|
|
360
|
+
({iblr}), preserving inter-declarator separators and formatting
|
|
361
|
+
exactly as stored. Represents constructs like ``Перем а, с;`` as one
|
|
362
|
+
``variable_declaration`` node with multiple declarator children --
|
|
363
|
+
never as an assignment node. ``export`` is accepting form.
|
|
364
|
+
"""
|
|
365
|
+
|
|
366
|
+
_KIND: ClassVar[NodeKind] = NodeKind("core:variable_declaration")
|
|
367
|
+
|
|
368
|
+
def __init__(
|
|
369
|
+
self, *, start_byte: int, end_byte: int, content: str = "",
|
|
370
|
+
node_id: Optional[UUID] = None, parent_id: Optional[UUID] = None,
|
|
371
|
+
index_map_hook: Optional[IndexMapHookFn] = None,
|
|
372
|
+
declarators: Sequence[Any] = (), separators: Sequence[str] = (),
|
|
373
|
+
**extra: Any,
|
|
374
|
+
) -> None:
|
|
375
|
+
expected = max(0, len(declarators) - 1)
|
|
376
|
+
if len(separators) != expected:
|
|
377
|
+
raise NodeSchemaError(
|
|
378
|
+
ErrorCode.INVALID_PARENT_TYPE,
|
|
379
|
+
f"expected {expected} separators for {len(declarators)} "
|
|
380
|
+
f"declarators, got {len(separators)}",
|
|
381
|
+
)
|
|
382
|
+
decl_nodes = tuple(_as_node(d) for d in declarators)
|
|
383
|
+
extra["declarators"] = decl_nodes
|
|
384
|
+
extra["separators"] = _encode_seps(separators)
|
|
385
|
+
super().__init__(
|
|
386
|
+
start_byte=start_byte, end_byte=end_byte, content=content, node_id=node_id,
|
|
387
|
+
parent_id=parent_id, index_map_hook=index_map_hook, children=decl_nodes, **extra,
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
@property
|
|
391
|
+
def declarators(self) -> List[VariableDeclaratorNode]:
|
|
392
|
+
return [VariableDeclaratorNode.from_node(n) for n in self._node.fields.get("declarators", ())]
|
|
393
|
+
|
|
394
|
+
@property
|
|
395
|
+
def separators(self) -> List[str]:
|
|
396
|
+
return _decode_seps(self._node.fields.get("separators", ""))
|
|
397
|
+
|
|
398
|
+
@classmethod
|
|
399
|
+
def from_dict(cls, data: Dict[str, Any], **extra: Any) -> "VariableDeclarationNode":
|
|
400
|
+
fields = dict(data.get("fields", {}))
|
|
401
|
+
declarators = fields.pop("declarators", ())
|
|
402
|
+
separators = _decode_seps(fields.pop("separators", ""))
|
|
403
|
+
parent_id = UUID(data["parent_id"]) if data.get("parent_id") else None
|
|
404
|
+
return cls(
|
|
405
|
+
start_byte=data["start_byte"], end_byte=data["end_byte"], content=data.get("content", ""),
|
|
406
|
+
node_id=UUID(data["node_id"]), parent_id=parent_id,
|
|
407
|
+
declarators=declarators, separators=separators, **fields, **extra,
|
|
408
|
+
)
|