@rcrsr/rill 0.7.2 → 0.8.1
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.
- package/README.md +29 -1
- package/dist/ast-nodes.d.ts +635 -0
- package/dist/ast-nodes.d.ts.map +1 -0
- package/dist/ast-nodes.js +2 -0
- package/dist/ast-nodes.js.map +1 -0
- package/dist/ast-unions.d.ts +6 -0
- package/dist/ast-unions.d.ts.map +1 -0
- package/dist/ast-unions.js +6 -0
- package/dist/ast-unions.js.map +1 -0
- package/dist/error-classes.d.ts +90 -0
- package/dist/error-classes.d.ts.map +1 -0
- package/dist/error-classes.js +185 -0
- package/dist/error-classes.js.map +1 -0
- package/dist/error-registry.d.ts +93 -0
- package/dist/error-registry.d.ts.map +1 -0
- package/dist/error-registry.js +876 -0
- package/dist/error-registry.js.map +1 -0
- package/dist/ext/crypto/index.d.ts +32 -0
- package/dist/ext/crypto/index.d.ts.map +1 -0
- package/dist/ext/crypto/index.js +143 -0
- package/dist/ext/crypto/index.js.map +1 -0
- package/dist/ext/exec/index.d.ts +45 -0
- package/dist/ext/exec/index.d.ts.map +1 -0
- package/dist/ext/exec/index.js +168 -0
- package/dist/ext/exec/index.js.map +1 -0
- package/dist/ext/exec/runner.d.ts +62 -0
- package/dist/ext/exec/runner.d.ts.map +1 -0
- package/dist/ext/exec/runner.js +168 -0
- package/dist/ext/exec/runner.js.map +1 -0
- package/dist/ext/fetch/index.d.ts +68 -0
- package/dist/ext/fetch/index.d.ts.map +1 -0
- package/dist/ext/fetch/index.js +259 -0
- package/dist/ext/fetch/index.js.map +1 -0
- package/dist/ext/fetch/request.d.ts +90 -0
- package/dist/ext/fetch/request.d.ts.map +1 -0
- package/dist/ext/fetch/request.js +413 -0
- package/dist/ext/fetch/request.js.map +1 -0
- package/dist/ext/fs/index.d.ts +39 -0
- package/dist/ext/fs/index.d.ts.map +1 -0
- package/dist/ext/fs/index.js +560 -0
- package/dist/ext/fs/index.js.map +1 -0
- package/dist/ext/fs/sandbox.d.ts +78 -0
- package/dist/ext/fs/sandbox.d.ts.map +1 -0
- package/dist/ext/fs/sandbox.js +208 -0
- package/dist/ext/fs/sandbox.js.map +1 -0
- package/dist/ext/kv/index.d.ts +46 -0
- package/dist/ext/kv/index.d.ts.map +1 -0
- package/dist/ext/kv/index.js +215 -0
- package/dist/ext/kv/index.js.map +1 -0
- package/dist/ext/kv/store.d.ts +46 -0
- package/dist/ext/kv/store.d.ts.map +1 -0
- package/dist/ext/kv/store.js +256 -0
- package/dist/ext/kv/store.js.map +1 -0
- package/dist/generated/introspection-data.d.ts +1 -1
- package/dist/generated/introspection-data.d.ts.map +1 -1
- package/dist/generated/introspection-data.js +509 -481
- package/dist/generated/introspection-data.js.map +1 -1
- package/dist/generated/version-data.d.ts +1 -1
- package/dist/generated/version-data.js +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/runtime/core/callable.d.ts +5 -5
- package/dist/runtime/core/callable.d.ts.map +1 -1
- package/dist/runtime/core/callable.js +2 -1
- package/dist/runtime/core/callable.js.map +1 -1
- package/dist/runtime/core/eval/mixins/collections.d.ts.map +1 -1
- package/dist/runtime/core/eval/mixins/collections.js +5 -1
- package/dist/runtime/core/eval/mixins/collections.js.map +1 -1
- package/dist/runtime/core/eval/mixins/literals.d.ts.map +1 -1
- package/dist/runtime/core/eval/mixins/literals.js +5 -1
- package/dist/runtime/core/eval/mixins/literals.js.map +1 -1
- package/dist/runtime/core/eval/mixins/variables.js +12 -12
- package/dist/runtime/core/eval/mixins/variables.js.map +1 -1
- package/dist/runtime/core/values.d.ts +31 -3
- package/dist/runtime/core/values.d.ts.map +1 -1
- package/dist/runtime/core/values.js +47 -1
- package/dist/runtime/core/values.js.map +1 -1
- package/dist/runtime/ext/builtins.d.ts.map +1 -1
- package/dist/runtime/ext/builtins.js +202 -1
- package/dist/runtime/ext/builtins.js.map +1 -1
- package/dist/runtime/ext/extensions.d.ts +39 -3
- package/dist/runtime/ext/extensions.d.ts.map +1 -1
- package/dist/runtime/ext/extensions.js +77 -12
- package/dist/runtime/ext/extensions.js.map +1 -1
- package/dist/runtime/index.d.ts +5 -5
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/index.js.map +1 -1
- package/dist/source-location.d.ts +10 -0
- package/dist/source-location.d.ts.map +1 -0
- package/dist/source-location.js +5 -0
- package/dist/source-location.js.map +1 -0
- package/dist/token-types.d.ts +68 -0
- package/dist/token-types.d.ts.map +1 -0
- package/dist/token-types.js +79 -0
- package/dist/token-types.js.map +1 -0
- package/dist/types.d.ts +9 -882
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -958
- package/dist/types.js.map +1 -1
- package/dist/value-types.d.ts +3 -0
- package/dist/value-types.d.ts.map +1 -0
- package/dist/value-types.js +2 -0
- package/dist/value-types.js.map +1 -0
- package/package.json +50 -11
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @rcrsr/rill
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Core runtime for [rill](https://rill.run) — scripting designed for machine-generated code. Zero dependencies. Browser and Node.js compatible.
|
|
4
4
|
|
|
5
5
|
> **Experimental.** Breaking changes will occur before stabilization.
|
|
6
6
|
|
|
@@ -135,6 +135,34 @@ try {
|
|
|
135
135
|
| `isScriptCallable(value)` | Check if value is a script-defined closure |
|
|
136
136
|
| `isApplicationCallable(value)` | Check if value is a host-provided callable |
|
|
137
137
|
|
|
138
|
+
## Bundled Extensions
|
|
139
|
+
|
|
140
|
+
rill ships with 5 Node.js-only extensions available as sub-path imports. These extensions provide pre-built host functions for common tasks and are not available in the browser bundle.
|
|
141
|
+
|
|
142
|
+
### Import Pattern
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { createFsExtension } from '@rcrsr/rill/ext/fs';
|
|
146
|
+
import { createFetchExtension } from '@rcrsr/rill/ext/fetch';
|
|
147
|
+
import { createExecExtension } from '@rcrsr/rill/ext/exec';
|
|
148
|
+
import { createKvExtension } from '@rcrsr/rill/ext/kv';
|
|
149
|
+
import { createCryptoExtension } from '@rcrsr/rill/ext/crypto';
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Available Extensions
|
|
153
|
+
|
|
154
|
+
| Sub-Path | Factory | Description |
|
|
155
|
+
|----------|---------|-------------|
|
|
156
|
+
| `@rcrsr/rill/ext/fs` | `createFsExtension(config)` | Sandboxed filesystem operations via mount-based access control |
|
|
157
|
+
| `@rcrsr/rill/ext/fetch` | `createFetchExtension(config)` | HTTP requests with endpoint configuration and rate limiting |
|
|
158
|
+
| `@rcrsr/rill/ext/exec` | `createExecExtension(config)` | Sandboxed command execution via allowlist/blocklist controls |
|
|
159
|
+
| `@rcrsr/rill/ext/kv` | `createKvExtension(config)` | Key-value store with JSON persistence and schema validation |
|
|
160
|
+
| `@rcrsr/rill/ext/crypto` | `createCryptoExtension(config)` | Cryptographic functions (hash, hmac, uuid, random) |
|
|
161
|
+
|
|
162
|
+
Each factory returns an `ExtensionResult` with host function definitions ready to integrate into your runtime context.
|
|
163
|
+
|
|
164
|
+
> **Note:** These extensions require Node.js APIs and are not compatible with browser environments.
|
|
165
|
+
|
|
138
166
|
## Documentation
|
|
139
167
|
|
|
140
168
|
| Document | Description |
|
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
import type { SourceSpan } from './source-location.js';
|
|
2
|
+
import type { RillTypeName } from './value-types.js';
|
|
3
|
+
interface BaseNode {
|
|
4
|
+
readonly span: SourceSpan;
|
|
5
|
+
}
|
|
6
|
+
export interface ScriptNode extends BaseNode {
|
|
7
|
+
readonly type: 'Script';
|
|
8
|
+
readonly frontmatter: FrontmatterNode | null;
|
|
9
|
+
/** Statements in the script. May include RecoveryErrorNode when parsed with recoveryMode. */
|
|
10
|
+
readonly statements: (StatementNode | AnnotatedStatementNode | RecoveryErrorNode)[];
|
|
11
|
+
}
|
|
12
|
+
export interface FrontmatterNode extends BaseNode {
|
|
13
|
+
readonly type: 'Frontmatter';
|
|
14
|
+
readonly content: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Closure: |params| body
|
|
18
|
+
* First-class closure with optional typed parameters and defaults.
|
|
19
|
+
* Scope rules: captures outer (read-only), local mutable.
|
|
20
|
+
*
|
|
21
|
+
* Body can be:
|
|
22
|
+
* - Simple: |x| $x (postfix-expr)
|
|
23
|
+
* - Grouped: |x| ($x * 2) (compound expression)
|
|
24
|
+
* - Block: |x| { $a ↵ $b } (multiple statements)
|
|
25
|
+
*/
|
|
26
|
+
export interface ClosureNode extends BaseNode {
|
|
27
|
+
readonly type: 'Closure';
|
|
28
|
+
readonly params: ClosureParamNode[];
|
|
29
|
+
readonly body: BodyNode;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Function parameter with optional type and default value.
|
|
33
|
+
* - (x) { } -- untyped
|
|
34
|
+
* - (x: string) { } -- typed
|
|
35
|
+
* - (x: string = "hi") { } -- typed with default
|
|
36
|
+
* - ^(key: value) (x) { } -- with parameter annotations
|
|
37
|
+
*/
|
|
38
|
+
export interface ClosureParamNode extends BaseNode {
|
|
39
|
+
readonly type: 'ClosureParam';
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly typeName: 'string' | 'number' | 'bool' | null;
|
|
42
|
+
readonly defaultValue: LiteralNode | null;
|
|
43
|
+
readonly annotations?: AnnotationArg[] | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Statement: a pipe chain expression.
|
|
47
|
+
* Termination (capture/break/return) is now part of PipeChainNode.
|
|
48
|
+
*/
|
|
49
|
+
export interface StatementNode extends BaseNode {
|
|
50
|
+
readonly type: 'Statement';
|
|
51
|
+
readonly expression: PipeChainNode;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Recovery error node for parse error recovery mode.
|
|
55
|
+
* Represents unparseable content that was skipped during error recovery.
|
|
56
|
+
* Only appears in ASTs when parsing with `recoveryMode: true`.
|
|
57
|
+
*/
|
|
58
|
+
export interface RecoveryErrorNode extends BaseNode {
|
|
59
|
+
readonly type: 'RecoveryError';
|
|
60
|
+
/** The error message describing what went wrong */
|
|
61
|
+
readonly message: string;
|
|
62
|
+
/** The raw source text that could not be parsed */
|
|
63
|
+
readonly text: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Annotated statement: ^(key: value, ...) statement
|
|
67
|
+
* Annotations modify operational parameters for statements.
|
|
68
|
+
* They prefix statements and bind to the immediately following construct.
|
|
69
|
+
*
|
|
70
|
+
* Examples:
|
|
71
|
+
* ^(limit: 100) $items @ process()
|
|
72
|
+
* ^(timeout: 30) fetch($url)
|
|
73
|
+
* ^(retry: 3, backoff: 1.5) api_call()
|
|
74
|
+
*/
|
|
75
|
+
export interface AnnotatedStatementNode extends BaseNode {
|
|
76
|
+
readonly type: 'AnnotatedStatement';
|
|
77
|
+
readonly annotations: AnnotationArg[];
|
|
78
|
+
readonly statement: StatementNode;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Annotation argument: named or spread
|
|
82
|
+
* Reuses similar structure to dict entries but with spread support.
|
|
83
|
+
*/
|
|
84
|
+
export type AnnotationArg = NamedArgNode | SpreadArgNode;
|
|
85
|
+
/**
|
|
86
|
+
* Named annotation argument: key: value
|
|
87
|
+
* Example: limit: 100, timeout: 30
|
|
88
|
+
*/
|
|
89
|
+
export interface NamedArgNode extends BaseNode {
|
|
90
|
+
readonly type: 'NamedArg';
|
|
91
|
+
readonly name: string;
|
|
92
|
+
readonly value: ExpressionNode;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Spread annotation argument: *expr
|
|
96
|
+
* Example: *$opts spreads tuple keys as annotations
|
|
97
|
+
*/
|
|
98
|
+
export interface SpreadArgNode extends BaseNode {
|
|
99
|
+
readonly type: 'SpreadArg';
|
|
100
|
+
readonly expression: ExpressionNode;
|
|
101
|
+
}
|
|
102
|
+
export interface CaptureNode extends BaseNode {
|
|
103
|
+
readonly type: 'Capture';
|
|
104
|
+
readonly name: string;
|
|
105
|
+
/** Optional explicit type annotation: $name:string */
|
|
106
|
+
readonly typeName: RillTypeName | null;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Break: exit loop with current pipe value.
|
|
110
|
+
* Used as chain terminator: $x -> break
|
|
111
|
+
* Or bare: break (implicit $ -> break)
|
|
112
|
+
*/
|
|
113
|
+
export interface BreakNode extends BaseNode {
|
|
114
|
+
readonly type: 'Break';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Return: exit closure with current pipe value.
|
|
118
|
+
* Used as chain terminator: $x -> return
|
|
119
|
+
* Or bare: return (implicit $ -> return)
|
|
120
|
+
*/
|
|
121
|
+
export interface ReturnNode extends BaseNode {
|
|
122
|
+
readonly type: 'Return';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Pass: pass through pipe value unchanged.
|
|
126
|
+
* Used as chain terminator: $x -> pass
|
|
127
|
+
* Or bare: pass (implicit $ -> pass)
|
|
128
|
+
*/
|
|
129
|
+
export interface PassNode extends BaseNode {
|
|
130
|
+
readonly type: 'Pass';
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Assert: halt execution if condition is false.
|
|
134
|
+
* Syntax: assert condition
|
|
135
|
+
* Or: assert condition "custom error message"
|
|
136
|
+
*/
|
|
137
|
+
export interface AssertNode extends BaseNode {
|
|
138
|
+
readonly type: 'Assert';
|
|
139
|
+
readonly condition: ExpressionNode;
|
|
140
|
+
readonly message: StringLiteralNode | null;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Error: explicitly raise an error with a message.
|
|
144
|
+
* Syntax: error "message"
|
|
145
|
+
* Or: error "interpolated {$var} message"
|
|
146
|
+
*/
|
|
147
|
+
export interface ErrorNode extends BaseNode {
|
|
148
|
+
readonly type: 'Error';
|
|
149
|
+
readonly message: StringLiteralNode | null;
|
|
150
|
+
}
|
|
151
|
+
export type ExpressionNode = PipeChainNode;
|
|
152
|
+
/** Chain terminator: capture, break, or return */
|
|
153
|
+
export type ChainTerminator = CaptureNode | BreakNode | ReturnNode;
|
|
154
|
+
export interface PipeChainNode extends BaseNode {
|
|
155
|
+
readonly type: 'PipeChain';
|
|
156
|
+
readonly head: ArithHead;
|
|
157
|
+
/**
|
|
158
|
+
* Pipe targets and inline captures.
|
|
159
|
+
* Inline captures act as implicit .set() — store value and return unchanged.
|
|
160
|
+
* Semantically: "-> $a ->" ≡ "-> $a.set($) ->"
|
|
161
|
+
*/
|
|
162
|
+
readonly pipes: (PipeTargetNode | CaptureNode)[];
|
|
163
|
+
/**
|
|
164
|
+
* Chain terminator: final capture, break, or return.
|
|
165
|
+
* Examples:
|
|
166
|
+
* $x -> $y terminator = Capture($y)
|
|
167
|
+
* $x -> break terminator = Break
|
|
168
|
+
* $x -> return terminator = Return
|
|
169
|
+
* $x -> .method terminator = null
|
|
170
|
+
*/
|
|
171
|
+
readonly terminator: ChainTerminator | null;
|
|
172
|
+
}
|
|
173
|
+
export interface PostfixExprNode extends BaseNode {
|
|
174
|
+
readonly type: 'PostfixExpr';
|
|
175
|
+
readonly primary: PrimaryNode;
|
|
176
|
+
readonly methods: (MethodCallNode | InvokeNode)[];
|
|
177
|
+
readonly defaultValue: BodyNode | null;
|
|
178
|
+
}
|
|
179
|
+
export type PrimaryNode = LiteralNode | VariableNode | HostCallNode | ClosureCallNode | MethodCallNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | AssertNode | ErrorNode | PassNode | GroupedExprNode | SpreadNode | TypeAssertionNode | TypeCheckNode;
|
|
180
|
+
export type PipeTargetNode = HostCallNode | ClosureCallNode | MethodCallNode | PipeInvokeNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | ClosureNode | StringLiteralNode | DictNode | TupleNode | GroupedExprNode | ClosureChainNode | DestructureNode | SliceNode | SpreadNode | TypeAssertionNode | TypeCheckNode | EachExprNode | MapExprNode | FoldExprNode | FilterExprNode | PostfixExprNode | VariableNode | AssertNode | ErrorNode;
|
|
181
|
+
/** Invoke pipe value as a closure: -> $() or -> $(arg1, arg2) */
|
|
182
|
+
export interface PipeInvokeNode extends BaseNode {
|
|
183
|
+
readonly type: 'PipeInvoke';
|
|
184
|
+
readonly args: ExpressionNode[];
|
|
185
|
+
}
|
|
186
|
+
export type LiteralNode = StringLiteralNode | NumberLiteralNode | BoolLiteralNode | TupleNode | DictNode | ClosureNode;
|
|
187
|
+
export interface StringLiteralNode extends BaseNode {
|
|
188
|
+
readonly type: 'StringLiteral';
|
|
189
|
+
readonly parts: (string | InterpolationNode)[];
|
|
190
|
+
readonly isMultiline: boolean;
|
|
191
|
+
}
|
|
192
|
+
export interface InterpolationNode extends BaseNode {
|
|
193
|
+
readonly type: 'Interpolation';
|
|
194
|
+
readonly expression: ExpressionNode;
|
|
195
|
+
}
|
|
196
|
+
export interface NumberLiteralNode extends BaseNode {
|
|
197
|
+
readonly type: 'NumberLiteral';
|
|
198
|
+
readonly value: number;
|
|
199
|
+
}
|
|
200
|
+
export interface BoolLiteralNode extends BaseNode {
|
|
201
|
+
readonly type: 'BoolLiteral';
|
|
202
|
+
readonly value: boolean;
|
|
203
|
+
}
|
|
204
|
+
export interface TupleNode extends BaseNode {
|
|
205
|
+
readonly type: 'Tuple';
|
|
206
|
+
readonly elements: (ExpressionNode | ListSpreadNode)[];
|
|
207
|
+
readonly defaultValue: BodyNode | null;
|
|
208
|
+
}
|
|
209
|
+
export interface ListSpreadNode extends BaseNode {
|
|
210
|
+
readonly type: 'ListSpread';
|
|
211
|
+
readonly expression: ExpressionNode;
|
|
212
|
+
}
|
|
213
|
+
export interface DictNode extends BaseNode {
|
|
214
|
+
readonly type: 'Dict';
|
|
215
|
+
readonly entries: DictEntryNode[];
|
|
216
|
+
readonly defaultValue: BodyNode | null;
|
|
217
|
+
}
|
|
218
|
+
export interface DictKeyVariable {
|
|
219
|
+
readonly kind: 'variable';
|
|
220
|
+
readonly variableName: string;
|
|
221
|
+
}
|
|
222
|
+
export interface DictKeyComputed {
|
|
223
|
+
readonly kind: 'computed';
|
|
224
|
+
readonly expression: ExpressionNode;
|
|
225
|
+
}
|
|
226
|
+
export interface DictEntryNode extends BaseNode {
|
|
227
|
+
readonly type: 'DictEntry';
|
|
228
|
+
readonly key: string | number | boolean | TupleNode | DictKeyVariable | DictKeyComputed;
|
|
229
|
+
readonly value: ExpressionNode;
|
|
230
|
+
}
|
|
231
|
+
export type BinaryOp = '+' | '-' | '*' | '/' | '%' | '&&' | '||' | '==' | '!=' | '<' | '>' | '<=' | '>=';
|
|
232
|
+
/**
|
|
233
|
+
* Expression head types for binary/unary expressions.
|
|
234
|
+
* Includes arithmetic (+, -, *, /, %) and logical (&&, ||, !) operators.
|
|
235
|
+
*/
|
|
236
|
+
export type ArithHead = BinaryExprNode | UnaryExprNode | PostfixExprNode;
|
|
237
|
+
/**
|
|
238
|
+
* Binary expression: left op right
|
|
239
|
+
* Arithmetic: ($x + 5), ($a * $b), (2 + 3 * 4)
|
|
240
|
+
* Logical: ($a && $b), ($x || $y)
|
|
241
|
+
*/
|
|
242
|
+
export interface BinaryExprNode extends BaseNode {
|
|
243
|
+
readonly type: 'BinaryExpr';
|
|
244
|
+
readonly op: BinaryOp;
|
|
245
|
+
readonly left: ArithHead;
|
|
246
|
+
readonly right: ArithHead;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Unary expression: -operand or !operand
|
|
250
|
+
* Examples: (-5), (-$x), (!$ready)
|
|
251
|
+
*/
|
|
252
|
+
export interface UnaryExprNode extends BaseNode {
|
|
253
|
+
readonly type: 'UnaryExpr';
|
|
254
|
+
readonly op: '-' | '!';
|
|
255
|
+
readonly operand: UnaryExprNode | PostfixExprNode;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Grouped expression: ( expression )
|
|
259
|
+
* Single-expression block with () delimiters.
|
|
260
|
+
* Provides scoping — captures inside are local and not visible outside.
|
|
261
|
+
*
|
|
262
|
+
* Scoping rules identical to blocks:
|
|
263
|
+
* ("hello" -> $local) — $local is scoped to group, returns "hello"
|
|
264
|
+
*/
|
|
265
|
+
export interface GroupedExprNode extends BaseNode {
|
|
266
|
+
readonly type: 'GroupedExpr';
|
|
267
|
+
readonly expression: PipeChainNode;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Simple body: expression that can follow closure params, conditionals, or loops.
|
|
271
|
+
* No naked compound expressions — arithmetic/pipes/booleans must be grouped.
|
|
272
|
+
*
|
|
273
|
+
* Valid: block, grouped, or postfix-expr (variable, literal, method, function call)
|
|
274
|
+
* Examples:
|
|
275
|
+
* |x| $x — postfix-expr
|
|
276
|
+
* |x| ($x * 2) — grouped (compound)
|
|
277
|
+
* |x| { $a ↵ $b } — block (multiple statements)
|
|
278
|
+
*/
|
|
279
|
+
export type BodyNode = BlockNode | GroupedExprNode | PostfixExprNode | PipeChainNode;
|
|
280
|
+
export interface VariableNode extends BaseNode {
|
|
281
|
+
readonly type: 'Variable';
|
|
282
|
+
readonly name: string | null;
|
|
283
|
+
readonly isPipeVar: boolean;
|
|
284
|
+
/** Ordered chain of property accesses: .name, [0], .$var, etc. */
|
|
285
|
+
readonly accessChain: PropertyAccess[];
|
|
286
|
+
/**
|
|
287
|
+
* Default value for null-coalescing: $data.path ?? default
|
|
288
|
+
* If property access returns null/missing, use this value instead.
|
|
289
|
+
*/
|
|
290
|
+
readonly defaultValue: BodyNode | null;
|
|
291
|
+
/**
|
|
292
|
+
* Existence check on final path element: $data.?path
|
|
293
|
+
* Returns boolean (true if path exists).
|
|
294
|
+
* When set, implies safe traversal (no error on missing intermediate paths).
|
|
295
|
+
*/
|
|
296
|
+
readonly existenceCheck: ExistenceCheck | null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Existence check configuration.
|
|
300
|
+
* For .?path (just exists) or .?path&type (exists AND type matches).
|
|
301
|
+
*/
|
|
302
|
+
export interface ExistenceCheck {
|
|
303
|
+
/** The final field/index being checked for existence */
|
|
304
|
+
readonly finalAccess: FieldAccess;
|
|
305
|
+
/** Optional type check: returns true only if exists AND matches type */
|
|
306
|
+
readonly typeName: RillTypeName | null;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Field access element in a property access chain (dot-based).
|
|
310
|
+
*
|
|
311
|
+
* Access forms:
|
|
312
|
+
* - literal: .identifier (string key)
|
|
313
|
+
* - variable: .$var (variable as key)
|
|
314
|
+
* - computed: .(expr) (computed expression)
|
|
315
|
+
* - block: .{block} (block returning key)
|
|
316
|
+
* - alternatives: .(a || b) (try keys left-to-right)
|
|
317
|
+
*
|
|
318
|
+
* Note: Numeric indices use bracket syntax [0], [-1] instead of dot.
|
|
319
|
+
*/
|
|
320
|
+
export type FieldAccess = FieldAccessLiteral | FieldAccessVariable | FieldAccessComputed | FieldAccessBlock | FieldAccessAlternatives | FieldAccessAnnotation;
|
|
321
|
+
/** Literal field access: .identifier */
|
|
322
|
+
export interface FieldAccessLiteral {
|
|
323
|
+
readonly kind: 'literal';
|
|
324
|
+
readonly field: string;
|
|
325
|
+
}
|
|
326
|
+
/** Variable as key: .$var or .$ (pipe variable) */
|
|
327
|
+
export interface FieldAccessVariable {
|
|
328
|
+
readonly kind: 'variable';
|
|
329
|
+
readonly variableName: string | null;
|
|
330
|
+
}
|
|
331
|
+
/** Computed expression: .(expr) */
|
|
332
|
+
export interface FieldAccessComputed {
|
|
333
|
+
readonly kind: 'computed';
|
|
334
|
+
readonly expression: ExpressionNode;
|
|
335
|
+
}
|
|
336
|
+
/** Block returning key: .{block} */
|
|
337
|
+
export interface FieldAccessBlock {
|
|
338
|
+
readonly kind: 'block';
|
|
339
|
+
readonly block: BlockNode;
|
|
340
|
+
}
|
|
341
|
+
/** Alternatives (try keys left-to-right): .(a || b) */
|
|
342
|
+
export interface FieldAccessAlternatives {
|
|
343
|
+
readonly kind: 'alternatives';
|
|
344
|
+
readonly alternatives: string[];
|
|
345
|
+
}
|
|
346
|
+
/** Annotation reflection: .^key */
|
|
347
|
+
export interface FieldAccessAnnotation {
|
|
348
|
+
readonly kind: 'annotation';
|
|
349
|
+
readonly key: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Bracket index access: [expr]
|
|
353
|
+
* Used for numeric indexing into lists/strings.
|
|
354
|
+
* Expression can be positive (from start) or negative (from end).
|
|
355
|
+
*/
|
|
356
|
+
export interface BracketAccess {
|
|
357
|
+
/** Discriminator for the unified PropertyAccess type */
|
|
358
|
+
readonly accessKind: 'bracket';
|
|
359
|
+
/** The index expression (evaluates to number) */
|
|
360
|
+
readonly expression: ExpressionNode;
|
|
361
|
+
/** Source span from opening [ to closing ] (inclusive) */
|
|
362
|
+
readonly span: SourceSpan;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Unified property access type.
|
|
366
|
+
* Used to maintain order of mixed dot and bracket accesses.
|
|
367
|
+
* e.g., $data[0].name[1] has accesses: [bracket(0), field(name), bracket(1)]
|
|
368
|
+
*/
|
|
369
|
+
export type PropertyAccess = FieldAccess | BracketAccess;
|
|
370
|
+
export interface HostCallNode extends BaseNode {
|
|
371
|
+
readonly type: 'HostCall';
|
|
372
|
+
readonly name: string;
|
|
373
|
+
readonly args: ExpressionNode[];
|
|
374
|
+
}
|
|
375
|
+
export interface MethodCallNode extends BaseNode {
|
|
376
|
+
readonly type: 'MethodCall';
|
|
377
|
+
readonly name: string;
|
|
378
|
+
readonly args: ExpressionNode[];
|
|
379
|
+
readonly receiverSpan: SourceSpan | null;
|
|
380
|
+
}
|
|
381
|
+
/** Postfix invocation: expr(args) - calls the result of expr as a closure */
|
|
382
|
+
export interface InvokeNode extends BaseNode {
|
|
383
|
+
readonly type: 'Invoke';
|
|
384
|
+
readonly args: ExpressionNode[];
|
|
385
|
+
}
|
|
386
|
+
/** Call a closure stored in a variable: $fn(args) or $obj.method(args) */
|
|
387
|
+
export interface ClosureCallNode extends BaseNode {
|
|
388
|
+
readonly type: 'ClosureCall';
|
|
389
|
+
readonly name: string;
|
|
390
|
+
readonly accessChain: string[];
|
|
391
|
+
readonly args: ExpressionNode[];
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Conditional: ?($cond) body : else
|
|
395
|
+
* Body can be any simple-body (block, grouped, or postfix-expr).
|
|
396
|
+
*
|
|
397
|
+
* Examples:
|
|
398
|
+
* ?($x > 0) "positive" : "negative" — literals
|
|
399
|
+
* ?($x > 0) ($x * 2) : ($x / 2) — grouped
|
|
400
|
+
* ?($x > 0) { complex } : { other } — blocks
|
|
401
|
+
*/
|
|
402
|
+
export interface ConditionalNode extends BaseNode {
|
|
403
|
+
readonly type: 'Conditional';
|
|
404
|
+
readonly input: ExpressionNode | null;
|
|
405
|
+
readonly condition: BodyNode | null;
|
|
406
|
+
readonly thenBranch: BodyNode;
|
|
407
|
+
readonly elseBranch: BodyNode | ConditionalNode | null;
|
|
408
|
+
}
|
|
409
|
+
export interface WhileLoopNode extends BaseNode {
|
|
410
|
+
readonly type: 'WhileLoop';
|
|
411
|
+
readonly condition: ExpressionNode;
|
|
412
|
+
readonly body: BodyNode;
|
|
413
|
+
}
|
|
414
|
+
export interface DoWhileLoopNode extends BaseNode {
|
|
415
|
+
readonly type: 'DoWhileLoop';
|
|
416
|
+
readonly input: ExpressionNode | null;
|
|
417
|
+
readonly body: BodyNode;
|
|
418
|
+
readonly condition: BodyNode;
|
|
419
|
+
}
|
|
420
|
+
export interface BlockNode extends BaseNode {
|
|
421
|
+
readonly type: 'Block';
|
|
422
|
+
readonly statements: (StatementNode | AnnotatedStatementNode)[];
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Collection operator body types.
|
|
426
|
+
* These are the valid forms for the body of each/map/fold operators.
|
|
427
|
+
*/
|
|
428
|
+
export type IteratorBody = ClosureNode | BlockNode | GroupedExprNode | VariableNode | PostfixExprNode | SpreadNode | HostCallNode;
|
|
429
|
+
/**
|
|
430
|
+
* Each expression: sequential iteration returning list of all results.
|
|
431
|
+
*
|
|
432
|
+
* Syntax forms:
|
|
433
|
+
* collection -> each |x| body
|
|
434
|
+
* collection -> each { body }
|
|
435
|
+
* collection -> each (expr)
|
|
436
|
+
* collection -> each $fn
|
|
437
|
+
* collection -> each $
|
|
438
|
+
*
|
|
439
|
+
* With accumulator:
|
|
440
|
+
* collection -> each(init) { body } -- $@ is accumulator
|
|
441
|
+
* collection -> each |x, acc = init| body -- $acc is accumulator
|
|
442
|
+
*
|
|
443
|
+
* Returns: list of all body results (or scan results if accumulator)
|
|
444
|
+
*/
|
|
445
|
+
export interface EachExprNode extends BaseNode {
|
|
446
|
+
readonly type: 'EachExpr';
|
|
447
|
+
/** The body to execute for each element */
|
|
448
|
+
readonly body: IteratorBody;
|
|
449
|
+
/**
|
|
450
|
+
* Optional accumulator initial value (for block form with $@ access).
|
|
451
|
+
* null when using inline closure with accumulator (it's in the closure params)
|
|
452
|
+
* or when no accumulator is used.
|
|
453
|
+
*/
|
|
454
|
+
readonly accumulator: ExpressionNode | null;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Map expression: parallel iteration returning list of all results.
|
|
458
|
+
*
|
|
459
|
+
* Syntax forms:
|
|
460
|
+
* collection -> map |x| body
|
|
461
|
+
* collection -> map { body }
|
|
462
|
+
* collection -> map (expr)
|
|
463
|
+
* collection -> map $fn
|
|
464
|
+
* collection -> map $
|
|
465
|
+
*
|
|
466
|
+
* No accumulator (parallel execution has no "previous").
|
|
467
|
+
* Concurrency limit via ^(limit: N) annotation.
|
|
468
|
+
*
|
|
469
|
+
* Returns: list of all body results (order preserved)
|
|
470
|
+
*/
|
|
471
|
+
export interface MapExprNode extends BaseNode {
|
|
472
|
+
readonly type: 'MapExpr';
|
|
473
|
+
/** The body to execute for each element (in parallel) */
|
|
474
|
+
readonly body: IteratorBody;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Fold expression: sequential reduction returning final result only.
|
|
478
|
+
*
|
|
479
|
+
* Syntax forms:
|
|
480
|
+
* collection -> fold |x, acc = init| body -- $acc is accumulator
|
|
481
|
+
* collection -> fold(init) { body } -- $@ is accumulator
|
|
482
|
+
* collection -> fold $fn -- fn must have accumulator param
|
|
483
|
+
*
|
|
484
|
+
* Accumulator is required.
|
|
485
|
+
*
|
|
486
|
+
* Returns: final accumulated value only
|
|
487
|
+
*/
|
|
488
|
+
export interface FoldExprNode extends BaseNode {
|
|
489
|
+
readonly type: 'FoldExpr';
|
|
490
|
+
/** The body to execute for each element */
|
|
491
|
+
readonly body: IteratorBody;
|
|
492
|
+
/**
|
|
493
|
+
* Accumulator initial value (for block form with $@ access).
|
|
494
|
+
* null when using inline closure (accumulator is in closure params).
|
|
495
|
+
*/
|
|
496
|
+
readonly accumulator: ExpressionNode | null;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Filter expression: parallel filtering returning elements where predicate is truthy.
|
|
500
|
+
*
|
|
501
|
+
* Syntax forms:
|
|
502
|
+
* collection -> filter |x| body
|
|
503
|
+
* collection -> filter { body }
|
|
504
|
+
* collection -> filter (expr)
|
|
505
|
+
* collection -> filter $fn
|
|
506
|
+
*
|
|
507
|
+
* Predicate returns truthy/falsy. Elements where predicate is truthy are kept.
|
|
508
|
+
*
|
|
509
|
+
* Returns: list of elements where body was truthy
|
|
510
|
+
*/
|
|
511
|
+
export interface FilterExprNode extends BaseNode {
|
|
512
|
+
readonly type: 'FilterExpr';
|
|
513
|
+
/** The predicate body to evaluate for each element */
|
|
514
|
+
readonly body: IteratorBody;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Sequential spread: $input -> @$closures
|
|
518
|
+
* Chains closures where each receives the previous result.
|
|
519
|
+
*
|
|
520
|
+
* Equivalent to a fold: $input -> [$f, $g, $h] -> @ { $() }
|
|
521
|
+
* - With stored closures: the $ is the current closure, $() invokes it
|
|
522
|
+
* - With inline blocks: $ is the accumulated value directly
|
|
523
|
+
*/
|
|
524
|
+
export interface ClosureChainNode extends BaseNode {
|
|
525
|
+
readonly type: 'ClosureChain';
|
|
526
|
+
readonly target: ExpressionNode;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Destructure operator: *<...>
|
|
530
|
+
* Extracts elements from tuples/dicts into variables.
|
|
531
|
+
*
|
|
532
|
+
* Tuple: [1, 2, 3] -> *<$a, $b, $c>
|
|
533
|
+
* Dict: [name: "x"] -> *<name: $n>
|
|
534
|
+
* Nested: [[1, 2], 3] -> *<*<$a, $b>, $c>
|
|
535
|
+
*/
|
|
536
|
+
export interface DestructureNode extends BaseNode {
|
|
537
|
+
readonly type: 'Destructure';
|
|
538
|
+
readonly elements: DestructPatternNode[];
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Element in a destructure pattern.
|
|
542
|
+
* Can be: typed variable, key-variable pair, skip placeholder, or nested destructure.
|
|
543
|
+
*/
|
|
544
|
+
export interface DestructPatternNode extends BaseNode {
|
|
545
|
+
readonly type: 'DestructPattern';
|
|
546
|
+
readonly kind: 'variable' | 'keyValue' | 'skip' | 'nested';
|
|
547
|
+
/** Variable name (for 'variable' and 'keyValue' kinds) */
|
|
548
|
+
readonly name: string | null;
|
|
549
|
+
/** Key name (for 'keyValue' kind - dict destructuring) */
|
|
550
|
+
readonly key: string | null;
|
|
551
|
+
/** Type annotation (for 'variable' and 'keyValue' kinds) */
|
|
552
|
+
readonly typeName: RillTypeName | null;
|
|
553
|
+
/** Nested destructure pattern (for 'nested' kind) */
|
|
554
|
+
readonly nested: DestructureNode | null;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Slice operator: /<start:stop:step>
|
|
558
|
+
* Extracts a portion of a tuple or string using Python-style slicing.
|
|
559
|
+
*
|
|
560
|
+
* Examples:
|
|
561
|
+
* $tuple -> /<0:3> # elements 0, 1, 2
|
|
562
|
+
* $tuple -> /<::-1> # reversed
|
|
563
|
+
* "hello" -> /<1:4> # "ell"
|
|
564
|
+
*/
|
|
565
|
+
export interface SliceNode extends BaseNode {
|
|
566
|
+
readonly type: 'Slice';
|
|
567
|
+
/** Start index (null = from beginning) */
|
|
568
|
+
readonly start: SliceBoundNode | null;
|
|
569
|
+
/** Stop index (null = to end) */
|
|
570
|
+
readonly stop: SliceBoundNode | null;
|
|
571
|
+
/** Step (null = 1) */
|
|
572
|
+
readonly step: SliceBoundNode | null;
|
|
573
|
+
}
|
|
574
|
+
/** A slice bound: number, variable, or grouped expression */
|
|
575
|
+
export type SliceBoundNode = NumberLiteralNode | VariableNode | GroupedExprNode;
|
|
576
|
+
/**
|
|
577
|
+
* Spread operator: *expr or -> *
|
|
578
|
+
* Converts tuple or dict to args type for unpacking at closure invocation.
|
|
579
|
+
*
|
|
580
|
+
* Prefix form: *[1, 2, 3], *$tuple, *[x: 1, y: 2]
|
|
581
|
+
* Pipe target form: [1, 2, 3] -> *
|
|
582
|
+
*
|
|
583
|
+
* Creates an args value that unpacks into separate arguments when passed to a closure.
|
|
584
|
+
*/
|
|
585
|
+
export interface SpreadNode extends BaseNode {
|
|
586
|
+
readonly type: 'Spread';
|
|
587
|
+
/** The expression to spread (null when used as pipe target: -> *) */
|
|
588
|
+
readonly operand: ExpressionNode | null;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Type assertion: expr:type
|
|
592
|
+
* Asserts that the expression evaluates to the specified type.
|
|
593
|
+
* Returns the value unchanged if assertion passes, errors on mismatch.
|
|
594
|
+
*
|
|
595
|
+
* Examples:
|
|
596
|
+
* fetchData():string # assert result is string
|
|
597
|
+
* $val -> :number -> process() # assert pipe value is number
|
|
598
|
+
* "hello":string # "hello" (pass)
|
|
599
|
+
* "hello":number # Error: expected number, got string
|
|
600
|
+
*
|
|
601
|
+
* When operand is null, it acts on the implicit $:
|
|
602
|
+
* :string ≡ $:string
|
|
603
|
+
*/
|
|
604
|
+
export interface TypeAssertionNode extends BaseNode {
|
|
605
|
+
readonly type: 'TypeAssertion';
|
|
606
|
+
/** The expression to assert (null for bare :type which uses $) */
|
|
607
|
+
readonly operand: PostfixExprNode | null;
|
|
608
|
+
/** The expected type */
|
|
609
|
+
readonly typeName: RillTypeName;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Type check: expr:?type
|
|
613
|
+
* Checks if the expression evaluates to the specified type.
|
|
614
|
+
* Returns true if types match, false otherwise.
|
|
615
|
+
*
|
|
616
|
+
* Examples:
|
|
617
|
+
* fetchData():?string # is result a string?
|
|
618
|
+
* $val -> :?number -> process() # is pipe value a number?
|
|
619
|
+
* "hello":?string # true
|
|
620
|
+
* "hello":?number # false
|
|
621
|
+
*
|
|
622
|
+
* When operand is null, it checks the implicit $:
|
|
623
|
+
* :?string ≡ $:?string
|
|
624
|
+
*/
|
|
625
|
+
export interface TypeCheckNode extends BaseNode {
|
|
626
|
+
readonly type: 'TypeCheck';
|
|
627
|
+
/** The expression to check (null for bare :?type which uses $) */
|
|
628
|
+
readonly operand: PostfixExprNode | null;
|
|
629
|
+
/** The type to check for */
|
|
630
|
+
readonly typeName: RillTypeName;
|
|
631
|
+
}
|
|
632
|
+
export type SimplePrimaryNode = LiteralNode | VariableNode | HostCallNode | MethodCallNode | BlockNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | PostfixExprNode | TypeAssertionNode | TypeCheckNode;
|
|
633
|
+
export type ASTNode = ScriptNode | FrontmatterNode | ClosureNode | ClosureParamNode | StatementNode | CaptureNode | BreakNode | ReturnNode | PassNode | AssertNode | PipeChainNode | PostfixExprNode | MethodCallNode | InvokeNode | HostCallNode | ClosureCallNode | PipeInvokeNode | VariableNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | StringLiteralNode | InterpolationNode | NumberLiteralNode | BoolLiteralNode | TupleNode | ListSpreadNode | DictNode | DictEntryNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | ClosureChainNode | DestructureNode | DestructPatternNode | SliceNode | SpreadNode | TypeAssertionNode | TypeCheckNode | AnnotatedStatementNode | NamedArgNode | SpreadArgNode | EachExprNode | MapExprNode | FoldExprNode | FilterExprNode | RecoveryErrorNode | ErrorNode;
|
|
634
|
+
export {};
|
|
635
|
+
//# sourceMappingURL=ast-nodes.d.ts.map
|