dynos-ddl 0.1.3__tar.gz

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.
Files changed (30) hide show
  1. dynos_ddl-0.1.3/PKG-INFO +53 -0
  2. dynos_ddl-0.1.3/README.md +37 -0
  3. dynos_ddl-0.1.3/pyproject.toml +33 -0
  4. dynos_ddl-0.1.3/setup.cfg +4 -0
  5. dynos_ddl-0.1.3/src/dynos_ddl/__init__.py +34 -0
  6. dynos_ddl-0.1.3/src/dynos_ddl/ast.py +346 -0
  7. dynos_ddl-0.1.3/src/dynos_ddl/cli.py +238 -0
  8. dynos_ddl-0.1.3/src/dynos_ddl/completer.py +429 -0
  9. dynos_ddl-0.1.3/src/dynos_ddl/env.py +687 -0
  10. dynos_ddl-0.1.3/src/dynos_ddl/errors.py +70 -0
  11. dynos_ddl-0.1.3/src/dynos_ddl/eval.py +1675 -0
  12. dynos_ddl-0.1.3/src/dynos_ddl/goal.py +59 -0
  13. dynos_ddl-0.1.3/src/dynos_ddl/grammar.lark +216 -0
  14. dynos_ddl-0.1.3/src/dynos_ddl/lexer.py +106 -0
  15. dynos_ddl-0.1.3/src/dynos_ddl/parser.py +418 -0
  16. dynos_ddl-0.1.3/src/dynos_ddl/protocol.py +132 -0
  17. dynos_ddl-0.1.3/src/dynos_ddl/render/__init__.py +0 -0
  18. dynos_ddl-0.1.3/src/dynos_ddl/render/gloss.py +318 -0
  19. dynos_ddl-0.1.3/src/dynos_ddl/render/json.py +99 -0
  20. dynos_ddl-0.1.3/src/dynos_ddl/render/text.py +278 -0
  21. dynos_ddl-0.1.3/src/dynos_ddl/render_source.py +133 -0
  22. dynos_ddl-0.1.3/src/dynos_ddl/repl.py +749 -0
  23. dynos_ddl-0.1.3/src/dynos_ddl/resolve.py +88 -0
  24. dynos_ddl-0.1.3/src/dynos_ddl/typecheck.py +295 -0
  25. dynos_ddl-0.1.3/src/dynos_ddl.egg-info/PKG-INFO +53 -0
  26. dynos_ddl-0.1.3/src/dynos_ddl.egg-info/SOURCES.txt +28 -0
  27. dynos_ddl-0.1.3/src/dynos_ddl.egg-info/dependency_links.txt +1 -0
  28. dynos_ddl-0.1.3/src/dynos_ddl.egg-info/entry_points.txt +3 -0
  29. dynos_ddl-0.1.3/src/dynos_ddl.egg-info/requires.txt +10 -0
  30. dynos_ddl-0.1.3/src/dynos_ddl.egg-info/top_level.txt +1 -0
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.1
2
+ Name: dynos-ddl
3
+ Version: 0.1.3
4
+ Summary: The DYNOS Domain Language: parser, evaluator, and REPL for DYNOS
5
+ License: Apache-2.0
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: dynos-core>=0.1.3
9
+ Requires-Dist: lark
10
+ Provides-Extra: repl
11
+ Requires-Dist: prompt_toolkit; extra == "repl"
12
+ Requires-Dist: requests; extra == "repl"
13
+ Requires-Dist: rich; extra == "repl"
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest; extra == "dev"
16
+
17
+ # dynos-ddl
18
+
19
+ The DYNOS Domain Language (DDL): an operator surface for the DYNOS
20
+ architecture. Parser, evaluator, type-checker, source renderer, and
21
+ (via the `[repl]` extra) an interactive REPL plus protocol client.
22
+
23
+ ## Install
24
+
25
+ Minimal install (parser, evaluator, render - no REPL, no networking):
26
+
27
+ ```
28
+ pip install dynos-ddl
29
+ ```
30
+
31
+ With the operator console + protocol-mode REPL:
32
+
33
+ ```
34
+ pip install dynos-ddl[repl]
35
+ ```
36
+
37
+ The `[repl]` extra pulls in `prompt_toolkit`, `requests`, and `rich`.
38
+
39
+ ## Public surface
40
+
41
+ ```python
42
+ from dynos_ddl import parse, evaluate, Environment, Result, MockEvalBackend
43
+ from dynos_ddl.errors import DDLError
44
+ from dynos_ddl.ast import Program # AST node types
45
+ ```
46
+
47
+ ## CLI
48
+
49
+ When installed alongside `dynos-client`, this package contributes the
50
+ `dynos repl` and `dynos ddl` subcommands via the `dynos.cli` entry-point
51
+ group. With `--connect <url>` the REPL talks to a remote `dynos host`;
52
+ without `--connect` it uses the in-process orchestrator (which requires
53
+ the `dynos` backend package to be installed).
@@ -0,0 +1,37 @@
1
+ # dynos-ddl
2
+
3
+ The DYNOS Domain Language (DDL): an operator surface for the DYNOS
4
+ architecture. Parser, evaluator, type-checker, source renderer, and
5
+ (via the `[repl]` extra) an interactive REPL plus protocol client.
6
+
7
+ ## Install
8
+
9
+ Minimal install (parser, evaluator, render - no REPL, no networking):
10
+
11
+ ```
12
+ pip install dynos-ddl
13
+ ```
14
+
15
+ With the operator console + protocol-mode REPL:
16
+
17
+ ```
18
+ pip install dynos-ddl[repl]
19
+ ```
20
+
21
+ The `[repl]` extra pulls in `prompt_toolkit`, `requests`, and `rich`.
22
+
23
+ ## Public surface
24
+
25
+ ```python
26
+ from dynos_ddl import parse, evaluate, Environment, Result, MockEvalBackend
27
+ from dynos_ddl.errors import DDLError
28
+ from dynos_ddl.ast import Program # AST node types
29
+ ```
30
+
31
+ ## CLI
32
+
33
+ When installed alongside `dynos-client`, this package contributes the
34
+ `dynos repl` and `dynos ddl` subcommands via the `dynos.cli` entry-point
35
+ group. With `--connect <url>` the REPL talks to a remote `dynos host`;
36
+ without `--connect` it uses the in-process orchestrator (which requires
37
+ the `dynos` backend package to be installed).
@@ -0,0 +1,33 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "dynos-ddl"
7
+ version = "0.1.3"
8
+ description = "The DYNOS Domain Language: parser, evaluator, and REPL for DYNOS"
9
+ readme = "README.md"
10
+ license = { text = "Apache-2.0" }
11
+ requires-python = ">=3.8"
12
+ dependencies = [
13
+ "dynos-core>=0.1.3",
14
+ "lark",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ repl = [
19
+ "prompt_toolkit",
20
+ "requests",
21
+ "rich",
22
+ ]
23
+ dev = ["pytest"]
24
+
25
+ [project.entry-points."dynos.cli"]
26
+ repl = "dynos_ddl.cli:register_repl"
27
+ ddl = "dynos_ddl.cli:register_ddl"
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["src"]
31
+
32
+ [tool.setuptools.package-data]
33
+ dynos_ddl = ["grammar.lark"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,34 @@
1
+ """Dynos Domain Language (DDL).
2
+
3
+ Public interface:
4
+ - `parse(source)`: Program AST
5
+ - `ast`: the AST module (node types)
6
+ - `errors`: DDL exception classes
7
+ """
8
+
9
+ from . import ast, errors
10
+ from .env import Environment, EvalBackend, MockEvalBackend, make_test_env
11
+ from .eval import Result, evaluate
12
+ from .parser import parse
13
+ from .render_source import render_source
14
+ from .resolve import RESERVED_ATTRS, Resolution, ResolverEnv, Tier, resolve
15
+ from .typecheck import typecheck
16
+
17
+ __all__ = [
18
+ "parse",
19
+ "render_source",
20
+ "typecheck",
21
+ "resolve",
22
+ "evaluate",
23
+ "Result",
24
+ "Environment",
25
+ "EvalBackend",
26
+ "MockEvalBackend",
27
+ "make_test_env",
28
+ "ast",
29
+ "errors",
30
+ "Resolution",
31
+ "ResolverEnv",
32
+ "Tier",
33
+ "RESERVED_ATTRS",
34
+ ]
@@ -0,0 +1,346 @@
1
+ """DDL AST node types."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Optional, Tuple, Union
7
+
8
+ # Base classes ---------------------------------------------------------
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class Node:
13
+ """Base for every AST node."""
14
+
15
+
16
+ class Stmt(Node):
17
+ """A top-level statement."""
18
+
19
+
20
+ class Expr(Node):
21
+ """An expression."""
22
+
23
+
24
+ class CtxLhs(Node):
25
+ """A context-LHS expression (target of a block or broadcast)."""
26
+
27
+
28
+ class FilterPred(Node):
29
+ """A predicate inside a filter `{...}`."""
30
+
31
+
32
+ # Program --------------------------------------------------------------
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class Program(Node):
37
+ """Top-level statement list."""
38
+
39
+ stmts: Tuple[Stmt, ...] = ()
40
+
41
+
42
+ # Statements -----------------------------------------------------------
43
+
44
+
45
+ @dataclass(frozen=True)
46
+ class Mutation(Stmt):
47
+ """`lhs op rhs` where op is `+`, `-`, or `=`.
48
+
49
+ Position-bound: covers rule 1 (mutation LHS) and the
50
+ universal mutation rule of.
51
+ """
52
+
53
+ op: str = "" # '+', '-', '='
54
+ lhs: Expr = field(default_factory=lambda: Ident(name=""))
55
+ rhs: Expr = field(default_factory=lambda: Nil())
56
+
57
+
58
+ @dataclass(frozen=True)
59
+ class Block(Stmt):
60
+ """`target:(stmts...)` block-scope form."""
61
+
62
+ target: CtxLhs = field(default_factory=lambda: ActiveContext())
63
+ stmts: Tuple[Stmt, ...] = ()
64
+
65
+
66
+ @dataclass(frozen=True)
67
+ class CreateBlock(Stmt):
68
+ """`@+name(=source)?:(stmts)`; create-and-run form."""
69
+
70
+ name: str = ""
71
+ source: Optional[str] = None # for the `=src` form; None if absent
72
+ stmts: Tuple[Stmt, ...] = ()
73
+
74
+
75
+ @dataclass(frozen=True)
76
+ class Prefix(Stmt, Expr):
77
+ """`<prefix> <body>`; a query (`?`), guard (`??`), cost (`$`),"""
78
+
79
+ op: str = "" # '?', '??', '$', '$%', '%', '#'
80
+ body: Union[Expr, "Batch"] = field(default_factory=lambda: Nil())
81
+
82
+
83
+ @dataclass(frozen=True)
84
+ class Batch(Node):
85
+ """`(a, b, c)`; only valid as a Prefix body. The grammar requires"""
86
+
87
+ items: Tuple[Expr, ...] = ()
88
+
89
+
90
+ @dataclass(frozen=True)
91
+ class Command(Stmt):
92
+ """`!cmd(args, kwargs)`; ensure current action."""
93
+
94
+ call: "Call" = field(default_factory=lambda: Call(target=Ident(name="")))
95
+
96
+
97
+ @dataclass(frozen=True)
98
+ class Halt(Stmt):
99
+ """`!!`; clear `.A` and `.G` in one keystroke."""
100
+
101
+
102
+ @dataclass(frozen=True)
103
+ class Promote(Stmt):
104
+ """`!@<name>`; commit a staged clone into the live mission. The
105
+ snapshot's state and goal become the live orchestrator's state and
106
+ goal; the snapshot itself is archived (one-way: this is the
107
+ "commit a staged variant" workflow).
108
+
109
+ `!@` (active) promotes whichever context is currently active;
110
+ common when the operator did `@=staged` then wants the staged
111
+ edits to take effect.
112
+
113
+ Mirrors `!cmd(...)` syntactically: `!` is "do this thing now."
114
+ """
115
+
116
+ target: "Expr" = field(default_factory=lambda: ActiveContext())
117
+
118
+
119
+ @dataclass(frozen=True)
120
+ class Import(Stmt):
121
+ """`/import "path"` directive.
122
+
123
+ Decision 11: v1 evaluator returns DDLRuntimeError; parser still
124
+ accepts the form so the language surface is consistent across
125
+ versions.
126
+ """
127
+
128
+ path: str = ""
129
+
130
+
131
+ @dataclass(frozen=True)
132
+ class Extend(Stmt):
133
+ """`/extend "name" as alias?` directive.
134
+
135
+ Decision 11: v1 evaluator returns DDLRuntimeError.
136
+ """
137
+
138
+ name: str = ""
139
+ alias: Optional[str] = None
140
+
141
+
142
+ @dataclass(frozen=True)
143
+ class ExtCall(Stmt):
144
+ """`/alias::keyword payload?`; dispatch to a loaded extension."""
145
+
146
+ path: Tuple[str, ...] = () # e.g. ('ep', 'tell')
147
+ payload: Optional[Union[Expr, Block, Command, "TupleArgs"]] = None
148
+
149
+
150
+ @dataclass(frozen=True)
151
+ class TupleArgs(Node):
152
+ """`( args, kwargs )` payload form for extension calls."""
153
+
154
+ args: Tuple[Expr, ...] = ()
155
+ kwargs: Tuple[Tuple[str, Expr], ...] = ()
156
+
157
+
158
+ @dataclass(frozen=True)
159
+ class CommentStmt(Stmt):
160
+ """A bare string literal on its own as a statement. Parsed and
161
+ discarded by the runtime; preserved in the AST for round-trip and
162
+ transcript replay."""
163
+
164
+ text: str = ""
165
+
166
+
167
+ @dataclass(frozen=True)
168
+ class ContextSwitch(Stmt):
169
+ """`@=name`; switch the active context. Client-side state change;"""
170
+
171
+ name: str = ""
172
+
173
+
174
+ # Context-LHS ----------------------------------------------------------
175
+
176
+
177
+ @dataclass(frozen=True)
178
+ class ActiveContext(CtxLhs, Expr):
179
+ """`@`; the active context. Valid in both ctx-LHS and expression"""
180
+
181
+
182
+ @dataclass(frozen=True)
183
+ class AllContexts(CtxLhs, Expr):
184
+ """`@*`; the set of all known contexts."""
185
+
186
+
187
+ @dataclass(frozen=True)
188
+ class NamedContext(CtxLhs, Expr):
189
+ """`@name`; a named context by binding name."""
190
+
191
+ name: str = ""
192
+
193
+
194
+ # Expressions ----------------------------------------------------------
195
+
196
+
197
+ @dataclass(frozen=True)
198
+ class BinaryOp(Expr):
199
+ """Binary infix expression. `op` is one of the set / comparison /"""
200
+
201
+ op: str = "" # '+', '-', '^', '&', '<', '<=', '>', '>=', 'in', '!in', '==', '!='
202
+ lhs: Expr = field(default_factory=lambda: Nil())
203
+ rhs: Expr = field(default_factory=lambda: Nil())
204
+
205
+
206
+ # Postfix operators are each their own node, applied to a base Expr.
207
+ # This keeps the AST flat (no nested PostfixChain).
208
+
209
+
210
+ @dataclass(frozen=True)
211
+ class AttrAccess(Expr):
212
+ """`target.attr`; attribute access."""
213
+
214
+ target: Expr = field(default_factory=lambda: Nil())
215
+ attr: str = ""
216
+
217
+
218
+ @dataclass(frozen=True)
219
+ class MetaAccess(Expr):
220
+ """`target::attr`; shorthand for `target.meta.attr`."""
221
+
222
+ target: Expr = field(default_factory=lambda: Nil())
223
+ attr: str = ""
224
+
225
+
226
+ @dataclass(frozen=True)
227
+ class Index(Expr):
228
+ """`target[i]`; list/sequence index."""
229
+
230
+ target: Expr = field(default_factory=lambda: Nil())
231
+ index: Expr = field(default_factory=lambda: Nil())
232
+
233
+
234
+ @dataclass(frozen=True)
235
+ class Slice(Expr):
236
+ """`target[start:stop]`; slice access."""
237
+
238
+ target: Expr = field(default_factory=lambda: Nil())
239
+ start: Optional[Expr] = None
240
+ stop: Optional[Expr] = None
241
+
242
+
243
+ @dataclass(frozen=True)
244
+ class Filter(Expr):
245
+ """`target{pred1, pred2, ...}`; set filter."""
246
+
247
+ target: Expr = field(default_factory=lambda: Nil())
248
+ preds: Tuple[FilterPred, ...] = ()
249
+
250
+
251
+ @dataclass(frozen=True)
252
+ class Call(Expr):
253
+ """`target(arg, ..., kwarg=val, ...)`; function call.
254
+
255
+ `target` is typically an Ident (bare-name call like `goto(z)`) but
256
+ may be any Expr for postfix-chain calls.
257
+ """
258
+
259
+ target: Expr = field(default_factory=lambda: Ident(name=""))
260
+ args: Tuple[Expr, ...] = ()
261
+ kwargs: Tuple[Tuple[str, Expr], ...] = ()
262
+
263
+
264
+ # Primaries ------------------------------------------------------------
265
+
266
+
267
+ @dataclass(frozen=True)
268
+ class Ident(Expr):
269
+ """A bare identifier. Resolution happens at eval time via the"""
270
+
271
+ name: str = ""
272
+
273
+
274
+ @dataclass(frozen=True)
275
+ class Wildcard(Expr):
276
+ """`_`; the iteration placeholder. Admissible only inside filter"""
277
+
278
+
279
+ @dataclass(frozen=True)
280
+ class PatternVar(Expr):
281
+ """`_NAME`; a pattern variable. Admissible only inside schema-"""
282
+
283
+ name: str = ""
284
+
285
+
286
+ @dataclass(frozen=True)
287
+ class Number(Expr):
288
+ """A numeric literal."""
289
+
290
+ value: Union[int, float] = 0
291
+
292
+
293
+ @dataclass(frozen=True)
294
+ class String(Expr):
295
+ """A string literal."""
296
+
297
+ value: str = ""
298
+
299
+
300
+ @dataclass(frozen=True)
301
+ class Nil(Expr):
302
+ """The `nil` literal."""
303
+
304
+
305
+ @dataclass(frozen=True)
306
+ class SetLiteral(Expr):
307
+ """`{a, b, c}` set literal."""
308
+
309
+ items: Tuple[Expr, ...] = ()
310
+
311
+
312
+ @dataclass(frozen=True)
313
+ class ListLiteral(Expr):
314
+ """`[a, b, c]` list literal."""
315
+
316
+ items: Tuple[Expr, ...] = ()
317
+
318
+
319
+ @dataclass(frozen=True)
320
+ class LitNegation(Expr):
321
+ """`~call(...)`; literal-position negation.
322
+
323
+ rule 7 /, admissible only in literal-set
324
+ slots (.G, pre, conds, adds/removes). The grammar accepts it
325
+ anywhere; the typechecker enforces the position constraint.
326
+ """
327
+
328
+ call: Call = field(default_factory=lambda: Call())
329
+
330
+
331
+ # Filter predicates ----------------------------------------------------
332
+
333
+
334
+ @dataclass(frozen=True)
335
+ class FilterQuery(FilterPred):
336
+ """`?expr` form; interpreted as a one-statement block per member."""
337
+
338
+ expr: Expr = field(default_factory=lambda: Nil())
339
+
340
+
341
+ @dataclass(frozen=True)
342
+ class FilterExpr(FilterPred):
343
+ """An arbitrary boolean expression evaluated against the iteration
344
+ member (bound to `_` and accessible via `_.attr`)."""
345
+
346
+ expr: Expr = field(default_factory=lambda: Nil())