@rcrsr/rill 0.7.1 → 0.8.0

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 (73) hide show
  1. package/README.md +1 -1
  2. package/dist/ast-nodes.d.ts +635 -0
  3. package/dist/ast-nodes.d.ts.map +1 -0
  4. package/dist/ast-nodes.js +2 -0
  5. package/dist/ast-nodes.js.map +1 -0
  6. package/dist/ast-unions.d.ts +6 -0
  7. package/dist/ast-unions.d.ts.map +1 -0
  8. package/dist/ast-unions.js +6 -0
  9. package/dist/ast-unions.js.map +1 -0
  10. package/dist/error-classes.d.ts +90 -0
  11. package/dist/error-classes.d.ts.map +1 -0
  12. package/dist/error-classes.js +185 -0
  13. package/dist/error-classes.js.map +1 -0
  14. package/dist/error-registry.d.ts +93 -0
  15. package/dist/error-registry.d.ts.map +1 -0
  16. package/dist/error-registry.js +712 -0
  17. package/dist/error-registry.js.map +1 -0
  18. package/dist/generated/introspection-data.d.ts +1 -1
  19. package/dist/generated/introspection-data.d.ts.map +1 -1
  20. package/dist/generated/introspection-data.js +509 -481
  21. package/dist/generated/introspection-data.js.map +1 -1
  22. package/dist/generated/version-data.d.ts +1 -1
  23. package/dist/generated/version-data.js +3 -3
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/parser/parser-expr.js +9 -6
  29. package/dist/parser/parser-expr.js.map +1 -1
  30. package/dist/runtime/core/callable.d.ts +5 -5
  31. package/dist/runtime/core/callable.d.ts.map +1 -1
  32. package/dist/runtime/core/callable.js +2 -1
  33. package/dist/runtime/core/callable.js.map +1 -1
  34. package/dist/runtime/core/eval/mixins/collections.d.ts.map +1 -1
  35. package/dist/runtime/core/eval/mixins/collections.js +5 -1
  36. package/dist/runtime/core/eval/mixins/collections.js.map +1 -1
  37. package/dist/runtime/core/eval/mixins/literals.d.ts.map +1 -1
  38. package/dist/runtime/core/eval/mixins/literals.js +5 -1
  39. package/dist/runtime/core/eval/mixins/literals.js.map +1 -1
  40. package/dist/runtime/core/eval/mixins/variables.js +12 -12
  41. package/dist/runtime/core/eval/mixins/variables.js.map +1 -1
  42. package/dist/runtime/core/values.d.ts +31 -3
  43. package/dist/runtime/core/values.d.ts.map +1 -1
  44. package/dist/runtime/core/values.js +47 -1
  45. package/dist/runtime/core/values.js.map +1 -1
  46. package/dist/runtime/ext/builtins.d.ts.map +1 -1
  47. package/dist/runtime/ext/builtins.js +202 -1
  48. package/dist/runtime/ext/builtins.js.map +1 -1
  49. package/dist/runtime/ext/extensions.d.ts +39 -3
  50. package/dist/runtime/ext/extensions.d.ts.map +1 -1
  51. package/dist/runtime/ext/extensions.js +77 -12
  52. package/dist/runtime/ext/extensions.js.map +1 -1
  53. package/dist/runtime/index.d.ts +5 -5
  54. package/dist/runtime/index.d.ts.map +1 -1
  55. package/dist/runtime/index.js +2 -2
  56. package/dist/runtime/index.js.map +1 -1
  57. package/dist/source-location.d.ts +10 -0
  58. package/dist/source-location.d.ts.map +1 -0
  59. package/dist/source-location.js +5 -0
  60. package/dist/source-location.js.map +1 -0
  61. package/dist/token-types.d.ts +68 -0
  62. package/dist/token-types.d.ts.map +1 -0
  63. package/dist/token-types.js +79 -0
  64. package/dist/token-types.js.map +1 -0
  65. package/dist/types.d.ts +9 -882
  66. package/dist/types.d.ts.map +1 -1
  67. package/dist/types.js +8 -958
  68. package/dist/types.js.map +1 -1
  69. package/dist/value-types.d.ts +3 -0
  70. package/dist/value-types.d.ts.map +1 -0
  71. package/dist/value-types.js +2 -0
  72. package/dist/value-types.js.map +1 -0
  73. package/package.json +15 -2
package/dist/types.d.ts CHANGED
@@ -2,887 +2,15 @@
2
2
  * Rill AST Types
3
3
  * Based on docs/grammar.ebnf
4
4
  */
5
- export interface SourceLocation {
6
- readonly line: number;
7
- readonly column: number;
8
- readonly offset: number;
9
- }
10
- export interface SourceSpan {
11
- readonly start: SourceLocation;
12
- readonly end: SourceLocation;
13
- }
14
- /** Error category determining error ID prefix */
15
- export type ErrorCategory = 'lexer' | 'parse' | 'runtime' | 'check';
16
- /** Error severity level */
17
- export type ErrorSeverity = 'error' | 'warning';
18
- /**
19
- * Call stack frame information for error reporting.
20
- * Represents a single frame in the call stack with location and context.
21
- */
22
- export interface CallFrame {
23
- /** Source location of the call */
24
- readonly location: SourceSpan;
25
- /** Name of the function (closure or host function) */
26
- readonly functionName?: string | undefined;
27
- /** Additional context (e.g., "in each body") */
28
- readonly context?: string | undefined;
29
- }
30
- /**
31
- * Example demonstrating an error condition.
32
- * Used in error documentation to show common scenarios.
33
- */
34
- export interface ErrorExample {
35
- /** Description of the example scenario (max 100 characters) */
36
- readonly description: string;
37
- /** Example code demonstrating the error (max 500 characters) */
38
- readonly code: string;
39
- }
40
- /** Error registry entry containing all metadata for a single error condition */
41
- export interface ErrorDefinition {
42
- /** Format: RILL-{category}{3-digit} (e.g., RILL-R001) */
43
- readonly errorId: string;
44
- /** Error category (determines ID prefix) */
45
- readonly category: ErrorCategory;
46
- /** Severity level (defaults to 'error' when omitted) */
47
- readonly severity?: ErrorSeverity | undefined;
48
- /** Human-readable description (max 50 characters) */
49
- readonly description: string;
50
- /** Message template with {placeholder} syntax */
51
- readonly messageTemplate: string;
52
- /** What causes this error (max 200 characters) */
53
- readonly cause?: string | undefined;
54
- /** How to resolve this error (max 300 characters) */
55
- readonly resolution?: string | undefined;
56
- /** Example scenarios demonstrating this error (max 3 entries) */
57
- readonly examples?: ErrorExample[] | undefined;
58
- }
59
- /**
60
- * Central registry for all error definitions with O(1) lookup.
61
- * Immutable after initialization.
62
- */
63
- export interface ErrorRegistry {
64
- get(errorId: string): ErrorDefinition | undefined;
65
- has(errorId: string): boolean;
66
- readonly size: number;
67
- entries(): IterableIterator<[string, ErrorDefinition]>;
68
- }
69
- /**
70
- * Global error registry instance.
71
- * Read-only singleton initialized at module load.
72
- */
73
- export declare const ERROR_REGISTRY: ErrorRegistry;
74
- /**
75
- * Renders a message template by replacing placeholders with context values.
76
- *
77
- * Placeholder format: {varName}
78
- * Missing context values render as empty string.
79
- * Non-string values are coerced via String().
80
- * Invalid templates (unclosed braces) return template unchanged.
81
- *
82
- * @param template - Template string with {placeholder} syntax
83
- * @param context - Key-value pairs for placeholder replacement
84
- * @returns Rendered message with placeholders replaced
85
- *
86
- * @example
87
- * renderMessage("Expected {expected}, got {actual}", {expected: "string", actual: "number"})
88
- * // Returns: "Expected string, got number"
89
- *
90
- * @example
91
- * renderMessage("Hello {name}", {})
92
- * // Returns: "Hello "
93
- */
94
- export declare function renderMessage(template: string, context: Record<string, unknown>): string;
95
- /**
96
- * Generates documentation URL for an error ID.
97
- *
98
- * Format: https://github.com/rcrsr/rill/blob/v{version}/docs/ref-errors.md#{errorId}
99
- * Error ID is lowercased in anchor.
100
- *
101
- * @param errorId - Error identifier (format: RILL-{category}{3-digit}, e.g., RILL-R001)
102
- * @param version - Semver version (format: X.Y.Z)
103
- * @returns Documentation URL, or empty string if inputs are invalid
104
- *
105
- * @example
106
- * getHelpUrl("RILL-R001", "0.4.1")
107
- * // Returns: "https://github.com/rcrsr/rill/blob/v0.4.1/docs/ref-errors.md#rill-r001"
108
- *
109
- * @example
110
- * getHelpUrl("invalid", "0.4.1")
111
- * // Returns: ""
112
- */
113
- export declare function getHelpUrl(errorId: string, version: string): string;
114
- /**
115
- * Factory function for creating errors from registry.
116
- *
117
- * Looks up error definition from registry, renders message template with context,
118
- * and creates RillError with structured metadata.
119
- *
120
- * @param errorId - Error identifier (format: RILL-{category}{3-digit})
121
- * @param context - Key-value pairs for template placeholder replacement
122
- * @param location - Source location where error occurred (optional)
123
- * @returns RillError instance with rendered message
124
- * @throws TypeError if errorId is not found in registry
125
- *
126
- * @example
127
- * createError("RILL-R005", { name: "foo" }, location)
128
- * // Creates RuntimeError: "Variable foo is not defined at 1:5"
129
- *
130
- * @example
131
- * createError("RILL-X999", {})
132
- * // Throws: TypeError("Unknown error ID: RILL-X999")
133
- */
134
- export declare function createError(errorId: string, context: Record<string, unknown>, location?: SourceLocation | undefined): RillError;
135
- /** Structured error data for host applications */
136
- export interface RillErrorData {
137
- readonly errorId: string;
138
- readonly helpUrl?: string | undefined;
139
- readonly message: string;
140
- readonly location?: SourceLocation | undefined;
141
- readonly context?: Record<string, unknown> | undefined;
142
- }
143
- /**
144
- * Base error class for all Rill errors.
145
- * Provides structured data for host applications to format as needed.
146
- */
147
- export declare class RillError extends Error {
148
- readonly errorId: string;
149
- readonly helpUrl: string | undefined;
150
- readonly location?: SourceLocation | undefined;
151
- readonly context?: Record<string, unknown> | undefined;
152
- constructor(data: RillErrorData);
153
- /** Get structured error data for custom formatting */
154
- toData(): RillErrorData;
155
- /** Format error for display (can be overridden by host) */
156
- format(formatter?: (data: RillErrorData) => string): string;
157
- }
158
- /** Parse-time errors */
159
- export declare class ParseError extends RillError {
160
- constructor(errorId: string, message: string, location: SourceLocation, context?: Record<string, unknown>);
161
- }
162
- /** Runtime execution errors */
163
- export declare class RuntimeError extends RillError {
164
- constructor(errorId: string, message: string, location?: SourceLocation, context?: Record<string, unknown>);
165
- /** Create from an AST node */
166
- static fromNode(errorId: string, message: string, node?: {
167
- span: SourceSpan;
168
- }, context?: Record<string, unknown>): RuntimeError;
169
- }
170
- /** Timeout errors */
171
- export declare class TimeoutError extends RuntimeError {
172
- readonly functionName: string;
173
- readonly timeoutMs: number;
174
- constructor(functionName: string, timeoutMs: number, location?: SourceLocation);
175
- }
176
- /** Auto-exception errors (when $_ matches a pattern) */
177
- export declare class AutoExceptionError extends RuntimeError {
178
- readonly pattern: string;
179
- readonly matchedValue: string;
180
- constructor(pattern: string, matchedValue: string, location?: SourceLocation);
181
- }
182
- /** Abort errors (when execution is cancelled via AbortSignal) */
183
- export declare class AbortError extends RuntimeError {
184
- constructor(location?: SourceLocation);
185
- }
186
- export declare const TOKEN_TYPES: {
187
- readonly STRING: "STRING";
188
- readonly NUMBER: "NUMBER";
189
- readonly TRUE: "TRUE";
190
- readonly FALSE: "FALSE";
191
- readonly IDENTIFIER: "IDENTIFIER";
192
- readonly DOLLAR: "DOLLAR";
193
- readonly PIPE_VAR: "PIPE_VAR";
194
- readonly ARROW: "ARROW";
195
- readonly CAPTURE_ARROW: "CAPTURE_ARROW";
196
- readonly DOT: "DOT";
197
- readonly QUESTION: "QUESTION";
198
- readonly AT: "AT";
199
- readonly CARET: "CARET";
200
- readonly COLON: "COLON";
201
- readonly DOUBLE_COLON: "DOUBLE_COLON";
202
- readonly COMMA: "COMMA";
203
- readonly BANG: "BANG";
204
- readonly AND: "AND";
205
- readonly OR: "OR";
206
- readonly NULLISH_COALESCE: "NULLISH_COALESCE";
207
- readonly DOT_QUESTION: "DOT_QUESTION";
208
- readonly AMPERSAND: "AMPERSAND";
209
- readonly ASSIGN: "ASSIGN";
210
- readonly EQ: "EQ";
211
- readonly NE: "NE";
212
- readonly LT: "LT";
213
- readonly GT: "GT";
214
- readonly LE: "LE";
215
- readonly GE: "GE";
216
- readonly STAR_LT: "STAR_LT";
217
- readonly SLASH_LT: "SLASH_LT";
218
- readonly UNDERSCORE: "UNDERSCORE";
219
- readonly ELLIPSIS: "ELLIPSIS";
220
- readonly PIPE_BAR: "PIPE_BAR";
221
- readonly PLUS: "PLUS";
222
- readonly MINUS: "MINUS";
223
- readonly STAR: "STAR";
224
- readonly SLASH: "SLASH";
225
- readonly PERCENT: "PERCENT";
226
- readonly LPAREN: "LPAREN";
227
- readonly RPAREN: "RPAREN";
228
- readonly LBRACE: "LBRACE";
229
- readonly RBRACE: "RBRACE";
230
- readonly LBRACKET: "LBRACKET";
231
- readonly RBRACKET: "RBRACKET";
232
- readonly BREAK: "BREAK";
233
- readonly RETURN: "RETURN";
234
- readonly PASS: "PASS";
235
- readonly ASSERT: "ASSERT";
236
- readonly ERROR: "ERROR";
237
- readonly EACH: "EACH";
238
- readonly MAP: "MAP";
239
- readonly FOLD: "FOLD";
240
- readonly FILTER: "FILTER";
241
- readonly FRONTMATTER_DELIM: "FRONTMATTER_DELIM";
242
- readonly NEWLINE: "NEWLINE";
243
- readonly COMMENT: "COMMENT";
244
- readonly EOF: "EOF";
245
- };
246
- export type TokenType = (typeof TOKEN_TYPES)[keyof typeof TOKEN_TYPES];
247
- export interface Token {
248
- readonly type: TokenType;
249
- readonly value: string;
250
- readonly span: SourceSpan;
251
- }
252
- export type NodeType = 'Script' | 'Frontmatter' | 'Closure' | 'ClosureParam' | 'Statement' | 'PipeChain' | 'PostfixExpr' | 'MethodCall' | 'Invoke' | 'HostCall' | 'ClosureCall' | 'PipeInvoke' | 'Variable' | 'Capture' | 'Conditional' | 'WhileLoop' | 'DoWhileLoop' | 'Block' | 'StringLiteral' | 'Interpolation' | 'NumberLiteral' | 'BoolLiteral' | 'Tuple' | 'ListSpread' | 'Dict' | 'DictEntry' | 'Break' | 'Return' | 'Pass' | 'Assert' | 'BinaryExpr' | 'UnaryExpr' | 'InnerExpr' | 'GroupedExpr' | 'ClosureChain' | 'Destructure' | 'DestructPattern' | 'Slice' | 'Enumerate' | 'Spread' | 'TypeAssertion' | 'TypeCheck' | 'AnnotatedStatement' | 'NamedArg' | 'SpreadArg' | 'EachExpr' | 'MapExpr' | 'FoldExpr' | 'FilterExpr' | 'RecoveryError' | 'Error';
253
- interface BaseNode {
254
- readonly span: SourceSpan;
255
- }
256
- export interface ScriptNode extends BaseNode {
257
- readonly type: 'Script';
258
- readonly frontmatter: FrontmatterNode | null;
259
- /** Statements in the script. May include RecoveryErrorNode when parsed with recoveryMode. */
260
- readonly statements: (StatementNode | AnnotatedStatementNode | RecoveryErrorNode)[];
261
- }
262
- export interface FrontmatterNode extends BaseNode {
263
- readonly type: 'Frontmatter';
264
- readonly content: string;
265
- }
266
- /**
267
- * Closure: |params| body
268
- * First-class closure with optional typed parameters and defaults.
269
- * Scope rules: captures outer (read-only), local mutable.
270
- *
271
- * Body can be:
272
- * - Simple: |x| $x (postfix-expr)
273
- * - Grouped: |x| ($x * 2) (compound expression)
274
- * - Block: |x| { $a ↵ $b } (multiple statements)
275
- */
276
- export interface ClosureNode extends BaseNode {
277
- readonly type: 'Closure';
278
- readonly params: ClosureParamNode[];
279
- readonly body: BodyNode;
280
- }
281
- /**
282
- * Function parameter with optional type and default value.
283
- * - (x) { } -- untyped
284
- * - (x: string) { } -- typed
285
- * - (x: string = "hi") { } -- typed with default
286
- * - ^(key: value) (x) { } -- with parameter annotations
287
- */
288
- export interface ClosureParamNode extends BaseNode {
289
- readonly type: 'ClosureParam';
290
- readonly name: string;
291
- readonly typeName: 'string' | 'number' | 'bool' | null;
292
- readonly defaultValue: LiteralNode | null;
293
- readonly annotations?: AnnotationArg[] | undefined;
294
- }
295
- /**
296
- * Statement: a pipe chain expression.
297
- * Termination (capture/break/return) is now part of PipeChainNode.
298
- */
299
- export interface StatementNode extends BaseNode {
300
- readonly type: 'Statement';
301
- readonly expression: PipeChainNode;
302
- }
303
- /**
304
- * Recovery error node for parse error recovery mode.
305
- * Represents unparseable content that was skipped during error recovery.
306
- * Only appears in ASTs when parsing with `recoveryMode: true`.
307
- */
308
- export interface RecoveryErrorNode extends BaseNode {
309
- readonly type: 'RecoveryError';
310
- /** The error message describing what went wrong */
311
- readonly message: string;
312
- /** The raw source text that could not be parsed */
313
- readonly text: string;
314
- }
315
- /**
316
- * Annotated statement: ^(key: value, ...) statement
317
- * Annotations modify operational parameters for statements.
318
- * They prefix statements and bind to the immediately following construct.
319
- *
320
- * Examples:
321
- * ^(limit: 100) $items @ process()
322
- * ^(timeout: 30) fetch($url)
323
- * ^(retry: 3, backoff: 1.5) api_call()
324
- */
325
- export interface AnnotatedStatementNode extends BaseNode {
326
- readonly type: 'AnnotatedStatement';
327
- readonly annotations: AnnotationArg[];
328
- readonly statement: StatementNode;
329
- }
330
- /**
331
- * Annotation argument: named or spread
332
- * Reuses similar structure to dict entries but with spread support.
333
- */
334
- export type AnnotationArg = NamedArgNode | SpreadArgNode;
335
- /**
336
- * Named annotation argument: key: value
337
- * Example: limit: 100, timeout: 30
338
- */
339
- export interface NamedArgNode extends BaseNode {
340
- readonly type: 'NamedArg';
341
- readonly name: string;
342
- readonly value: ExpressionNode;
343
- }
344
- /**
345
- * Spread annotation argument: *expr
346
- * Example: *$opts spreads tuple keys as annotations
347
- */
348
- export interface SpreadArgNode extends BaseNode {
349
- readonly type: 'SpreadArg';
350
- readonly expression: ExpressionNode;
351
- }
352
- /** Rill type names for type annotations */
353
- export type RillTypeName = 'string' | 'number' | 'bool' | 'closure' | 'list' | 'dict' | 'tuple';
354
- export interface CaptureNode extends BaseNode {
355
- readonly type: 'Capture';
356
- readonly name: string;
357
- /** Optional explicit type annotation: $name:string */
358
- readonly typeName: RillTypeName | null;
359
- }
360
- /**
361
- * Break: exit loop with current pipe value.
362
- * Used as chain terminator: $x -> break
363
- * Or bare: break (implicit $ -> break)
364
- */
365
- export interface BreakNode extends BaseNode {
366
- readonly type: 'Break';
367
- }
368
- /**
369
- * Return: exit closure with current pipe value.
370
- * Used as chain terminator: $x -> return
371
- * Or bare: return (implicit $ -> return)
372
- */
373
- export interface ReturnNode extends BaseNode {
374
- readonly type: 'Return';
375
- }
376
- /**
377
- * Pass: pass through pipe value unchanged.
378
- * Used as chain terminator: $x -> pass
379
- * Or bare: pass (implicit $ -> pass)
380
- */
381
- export interface PassNode extends BaseNode {
382
- readonly type: 'Pass';
383
- }
384
- /**
385
- * Assert: halt execution if condition is false.
386
- * Syntax: assert condition
387
- * Or: assert condition "custom error message"
388
- */
389
- export interface AssertNode extends BaseNode {
390
- readonly type: 'Assert';
391
- readonly condition: ExpressionNode;
392
- readonly message: StringLiteralNode | null;
393
- }
394
- /**
395
- * Error: explicitly raise an error with a message.
396
- * Syntax: error "message"
397
- * Or: error "interpolated {$var} message"
398
- */
399
- export interface ErrorNode extends BaseNode {
400
- readonly type: 'Error';
401
- readonly message: StringLiteralNode | null;
402
- }
403
- export type ExpressionNode = PipeChainNode;
404
- /** Chain terminator: capture, break, or return */
405
- export type ChainTerminator = CaptureNode | BreakNode | ReturnNode;
406
- export interface PipeChainNode extends BaseNode {
407
- readonly type: 'PipeChain';
408
- readonly head: ArithHead;
409
- /**
410
- * Pipe targets and inline captures.
411
- * Inline captures act as implicit .set() — store value and return unchanged.
412
- * Semantically: "-> $a ->" ≡ "-> $a.set($) ->"
413
- */
414
- readonly pipes: (PipeTargetNode | CaptureNode)[];
415
- /**
416
- * Chain terminator: final capture, break, or return.
417
- * Examples:
418
- * $x -> $y terminator = Capture($y)
419
- * $x -> break terminator = Break
420
- * $x -> return terminator = Return
421
- * $x -> .method terminator = null
422
- */
423
- readonly terminator: ChainTerminator | null;
424
- }
425
- export interface PostfixExprNode extends BaseNode {
426
- readonly type: 'PostfixExpr';
427
- readonly primary: PrimaryNode;
428
- readonly methods: (MethodCallNode | InvokeNode)[];
429
- readonly defaultValue: BodyNode | null;
430
- }
431
- export type PrimaryNode = LiteralNode | VariableNode | HostCallNode | ClosureCallNode | MethodCallNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | AssertNode | ErrorNode | PassNode | GroupedExprNode | SpreadNode | TypeAssertionNode | TypeCheckNode;
432
- 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;
433
- /** Invoke pipe value as a closure: -> $() or -> $(arg1, arg2) */
434
- export interface PipeInvokeNode extends BaseNode {
435
- readonly type: 'PipeInvoke';
436
- readonly args: ExpressionNode[];
437
- }
438
- export type LiteralNode = StringLiteralNode | NumberLiteralNode | BoolLiteralNode | TupleNode | DictNode | ClosureNode;
439
- export interface StringLiteralNode extends BaseNode {
440
- readonly type: 'StringLiteral';
441
- readonly parts: (string | InterpolationNode)[];
442
- readonly isMultiline: boolean;
443
- }
444
- export interface InterpolationNode extends BaseNode {
445
- readonly type: 'Interpolation';
446
- readonly expression: ExpressionNode;
447
- }
448
- export interface NumberLiteralNode extends BaseNode {
449
- readonly type: 'NumberLiteral';
450
- readonly value: number;
451
- }
452
- export interface BoolLiteralNode extends BaseNode {
453
- readonly type: 'BoolLiteral';
454
- readonly value: boolean;
455
- }
456
- export interface TupleNode extends BaseNode {
457
- readonly type: 'Tuple';
458
- readonly elements: (ExpressionNode | ListSpreadNode)[];
459
- readonly defaultValue: BodyNode | null;
460
- }
461
- export interface ListSpreadNode extends BaseNode {
462
- readonly type: 'ListSpread';
463
- readonly expression: ExpressionNode;
464
- }
465
- export interface DictNode extends BaseNode {
466
- readonly type: 'Dict';
467
- readonly entries: DictEntryNode[];
468
- readonly defaultValue: BodyNode | null;
469
- }
470
- export interface DictKeyVariable {
471
- readonly kind: 'variable';
472
- readonly variableName: string;
473
- }
474
- export interface DictKeyComputed {
475
- readonly kind: 'computed';
476
- readonly expression: ExpressionNode;
477
- }
478
- export interface DictEntryNode extends BaseNode {
479
- readonly type: 'DictEntry';
480
- readonly key: string | number | boolean | TupleNode | DictKeyVariable | DictKeyComputed;
481
- readonly value: ExpressionNode;
482
- }
483
- export type BinaryOp = '+' | '-' | '*' | '/' | '%' | '&&' | '||' | '==' | '!=' | '<' | '>' | '<=' | '>=';
484
- /**
485
- * Expression head types for binary/unary expressions.
486
- * Includes arithmetic (+, -, *, /, %) and logical (&&, ||, !) operators.
487
- */
488
- export type ArithHead = BinaryExprNode | UnaryExprNode | PostfixExprNode;
489
- /**
490
- * Binary expression: left op right
491
- * Arithmetic: ($x + 5), ($a * $b), (2 + 3 * 4)
492
- * Logical: ($a && $b), ($x || $y)
493
- */
494
- export interface BinaryExprNode extends BaseNode {
495
- readonly type: 'BinaryExpr';
496
- readonly op: BinaryOp;
497
- readonly left: ArithHead;
498
- readonly right: ArithHead;
499
- }
500
- /**
501
- * Unary expression: -operand or !operand
502
- * Examples: (-5), (-$x), (!$ready)
503
- */
504
- export interface UnaryExprNode extends BaseNode {
505
- readonly type: 'UnaryExpr';
506
- readonly op: '-' | '!';
507
- readonly operand: UnaryExprNode | PostfixExprNode;
508
- }
509
- /**
510
- * Grouped expression: ( expression )
511
- * Single-expression block with () delimiters.
512
- * Provides scoping — captures inside are local and not visible outside.
513
- *
514
- * Scoping rules identical to blocks:
515
- * ("hello" -> $local) — $local is scoped to group, returns "hello"
516
- */
517
- export interface GroupedExprNode extends BaseNode {
518
- readonly type: 'GroupedExpr';
519
- readonly expression: PipeChainNode;
520
- }
521
- /**
522
- * Simple body: expression that can follow closure params, conditionals, or loops.
523
- * No naked compound expressions — arithmetic/pipes/booleans must be grouped.
524
- *
525
- * Valid: block, grouped, or postfix-expr (variable, literal, method, function call)
526
- * Examples:
527
- * |x| $x — postfix-expr
528
- * |x| ($x * 2) — grouped (compound)
529
- * |x| { $a ↵ $b } — block (multiple statements)
530
- */
531
- export type BodyNode = BlockNode | GroupedExprNode | PostfixExprNode | PipeChainNode;
532
- export interface VariableNode extends BaseNode {
533
- readonly type: 'Variable';
534
- readonly name: string | null;
535
- readonly isPipeVar: boolean;
536
- /** Ordered chain of property accesses: .name, [0], .$var, etc. */
537
- readonly accessChain: PropertyAccess[];
538
- /**
539
- * Default value for null-coalescing: $data.path ?? default
540
- * If property access returns null/missing, use this value instead.
541
- */
542
- readonly defaultValue: BodyNode | null;
543
- /**
544
- * Existence check on final path element: $data.?path
545
- * Returns boolean (true if path exists).
546
- * When set, implies safe traversal (no error on missing intermediate paths).
547
- */
548
- readonly existenceCheck: ExistenceCheck | null;
549
- }
550
- /**
551
- * Existence check configuration.
552
- * For .?path (just exists) or .?path&type (exists AND type matches).
553
- */
554
- export interface ExistenceCheck {
555
- /** The final field/index being checked for existence */
556
- readonly finalAccess: FieldAccess;
557
- /** Optional type check: returns true only if exists AND matches type */
558
- readonly typeName: RillTypeName | null;
559
- }
560
- /**
561
- * Field access element in a property access chain (dot-based).
562
- *
563
- * Access forms:
564
- * - literal: .identifier (string key)
565
- * - variable: .$var (variable as key)
566
- * - computed: .(expr) (computed expression)
567
- * - block: .{block} (block returning key)
568
- * - alternatives: .(a || b) (try keys left-to-right)
569
- *
570
- * Note: Numeric indices use bracket syntax [0], [-1] instead of dot.
571
- */
572
- export type FieldAccess = FieldAccessLiteral | FieldAccessVariable | FieldAccessComputed | FieldAccessBlock | FieldAccessAlternatives | FieldAccessAnnotation;
573
- /** Literal field access: .identifier */
574
- export interface FieldAccessLiteral {
575
- readonly kind: 'literal';
576
- readonly field: string;
577
- }
578
- /** Variable as key: .$var or .$ (pipe variable) */
579
- export interface FieldAccessVariable {
580
- readonly kind: 'variable';
581
- readonly variableName: string | null;
582
- }
583
- /** Computed expression: .(expr) */
584
- export interface FieldAccessComputed {
585
- readonly kind: 'computed';
586
- readonly expression: ExpressionNode;
587
- }
588
- /** Block returning key: .{block} */
589
- export interface FieldAccessBlock {
590
- readonly kind: 'block';
591
- readonly block: BlockNode;
592
- }
593
- /** Alternatives (try keys left-to-right): .(a || b) */
594
- export interface FieldAccessAlternatives {
595
- readonly kind: 'alternatives';
596
- readonly alternatives: string[];
597
- }
598
- /** Annotation reflection: .^key */
599
- export interface FieldAccessAnnotation {
600
- readonly kind: 'annotation';
601
- readonly key: string;
602
- }
603
- /**
604
- * Bracket index access: [expr]
605
- * Used for numeric indexing into lists/strings.
606
- * Expression can be positive (from start) or negative (from end).
607
- */
608
- export interface BracketAccess {
609
- /** Discriminator for the unified PropertyAccess type */
610
- readonly accessKind: 'bracket';
611
- /** The index expression (evaluates to number) */
612
- readonly expression: ExpressionNode;
613
- /** Source span from opening [ to closing ] (inclusive) */
614
- readonly span: SourceSpan;
615
- }
616
- /**
617
- * Unified property access type.
618
- * Used to maintain order of mixed dot and bracket accesses.
619
- * e.g., $data[0].name[1] has accesses: [bracket(0), field(name), bracket(1)]
620
- */
621
- export type PropertyAccess = FieldAccess | BracketAccess;
622
- export interface HostCallNode extends BaseNode {
623
- readonly type: 'HostCall';
624
- readonly name: string;
625
- readonly args: ExpressionNode[];
626
- }
627
- export interface MethodCallNode extends BaseNode {
628
- readonly type: 'MethodCall';
629
- readonly name: string;
630
- readonly args: ExpressionNode[];
631
- readonly receiverSpan: SourceSpan | null;
632
- }
633
- /** Postfix invocation: expr(args) - calls the result of expr as a closure */
634
- export interface InvokeNode extends BaseNode {
635
- readonly type: 'Invoke';
636
- readonly args: ExpressionNode[];
637
- }
638
- /** Call a closure stored in a variable: $fn(args) or $obj.method(args) */
639
- export interface ClosureCallNode extends BaseNode {
640
- readonly type: 'ClosureCall';
641
- readonly name: string;
642
- readonly accessChain: string[];
643
- readonly args: ExpressionNode[];
644
- }
645
- /**
646
- * Conditional: ?($cond) body : else
647
- * Body can be any simple-body (block, grouped, or postfix-expr).
648
- *
649
- * Examples:
650
- * ?($x > 0) "positive" : "negative" — literals
651
- * ?($x > 0) ($x * 2) : ($x / 2) — grouped
652
- * ?($x > 0) { complex } : { other } — blocks
653
- */
654
- export interface ConditionalNode extends BaseNode {
655
- readonly type: 'Conditional';
656
- readonly input: ExpressionNode | null;
657
- readonly condition: BodyNode | null;
658
- readonly thenBranch: BodyNode;
659
- readonly elseBranch: BodyNode | ConditionalNode | null;
660
- }
661
- export interface WhileLoopNode extends BaseNode {
662
- readonly type: 'WhileLoop';
663
- readonly condition: ExpressionNode;
664
- readonly body: BodyNode;
665
- }
666
- export interface DoWhileLoopNode extends BaseNode {
667
- readonly type: 'DoWhileLoop';
668
- readonly input: ExpressionNode | null;
669
- readonly body: BodyNode;
670
- readonly condition: BodyNode;
671
- }
672
- export interface BlockNode extends BaseNode {
673
- readonly type: 'Block';
674
- readonly statements: (StatementNode | AnnotatedStatementNode)[];
675
- }
676
- /**
677
- * Collection operator body types.
678
- * These are the valid forms for the body of each/map/fold operators.
679
- */
680
- export type IteratorBody = ClosureNode | BlockNode | GroupedExprNode | VariableNode | PostfixExprNode | SpreadNode | HostCallNode;
681
- /**
682
- * Each expression: sequential iteration returning list of all results.
683
- *
684
- * Syntax forms:
685
- * collection -> each |x| body
686
- * collection -> each { body }
687
- * collection -> each (expr)
688
- * collection -> each $fn
689
- * collection -> each $
690
- *
691
- * With accumulator:
692
- * collection -> each(init) { body } -- $@ is accumulator
693
- * collection -> each |x, acc = init| body -- $acc is accumulator
694
- *
695
- * Returns: list of all body results (or scan results if accumulator)
696
- */
697
- export interface EachExprNode extends BaseNode {
698
- readonly type: 'EachExpr';
699
- /** The body to execute for each element */
700
- readonly body: IteratorBody;
701
- /**
702
- * Optional accumulator initial value (for block form with $@ access).
703
- * null when using inline closure with accumulator (it's in the closure params)
704
- * or when no accumulator is used.
705
- */
706
- readonly accumulator: ExpressionNode | null;
707
- }
708
- /**
709
- * Map expression: parallel iteration returning list of all results.
710
- *
711
- * Syntax forms:
712
- * collection -> map |x| body
713
- * collection -> map { body }
714
- * collection -> map (expr)
715
- * collection -> map $fn
716
- * collection -> map $
717
- *
718
- * No accumulator (parallel execution has no "previous").
719
- * Concurrency limit via ^(limit: N) annotation.
720
- *
721
- * Returns: list of all body results (order preserved)
722
- */
723
- export interface MapExprNode extends BaseNode {
724
- readonly type: 'MapExpr';
725
- /** The body to execute for each element (in parallel) */
726
- readonly body: IteratorBody;
727
- }
728
- /**
729
- * Fold expression: sequential reduction returning final result only.
730
- *
731
- * Syntax forms:
732
- * collection -> fold |x, acc = init| body -- $acc is accumulator
733
- * collection -> fold(init) { body } -- $@ is accumulator
734
- * collection -> fold $fn -- fn must have accumulator param
735
- *
736
- * Accumulator is required.
737
- *
738
- * Returns: final accumulated value only
739
- */
740
- export interface FoldExprNode extends BaseNode {
741
- readonly type: 'FoldExpr';
742
- /** The body to execute for each element */
743
- readonly body: IteratorBody;
744
- /**
745
- * Accumulator initial value (for block form with $@ access).
746
- * null when using inline closure (accumulator is in closure params).
747
- */
748
- readonly accumulator: ExpressionNode | null;
749
- }
750
- /**
751
- * Filter expression: parallel filtering returning elements where predicate is truthy.
752
- *
753
- * Syntax forms:
754
- * collection -> filter |x| body
755
- * collection -> filter { body }
756
- * collection -> filter (expr)
757
- * collection -> filter $fn
758
- *
759
- * Predicate returns truthy/falsy. Elements where predicate is truthy are kept.
760
- *
761
- * Returns: list of elements where body was truthy
762
- */
763
- export interface FilterExprNode extends BaseNode {
764
- readonly type: 'FilterExpr';
765
- /** The predicate body to evaluate for each element */
766
- readonly body: IteratorBody;
767
- }
768
- /**
769
- * Sequential spread: $input -> @$closures
770
- * Chains closures where each receives the previous result.
771
- *
772
- * Equivalent to a fold: $input -> [$f, $g, $h] -> @ { $() }
773
- * - With stored closures: the $ is the current closure, $() invokes it
774
- * - With inline blocks: $ is the accumulated value directly
775
- */
776
- export interface ClosureChainNode extends BaseNode {
777
- readonly type: 'ClosureChain';
778
- readonly target: ExpressionNode;
779
- }
780
- /**
781
- * Destructure operator: *<...>
782
- * Extracts elements from tuples/dicts into variables.
783
- *
784
- * Tuple: [1, 2, 3] -> *<$a, $b, $c>
785
- * Dict: [name: "x"] -> *<name: $n>
786
- * Nested: [[1, 2], 3] -> *<*<$a, $b>, $c>
787
- */
788
- export interface DestructureNode extends BaseNode {
789
- readonly type: 'Destructure';
790
- readonly elements: DestructPatternNode[];
791
- }
792
- /**
793
- * Element in a destructure pattern.
794
- * Can be: typed variable, key-variable pair, skip placeholder, or nested destructure.
795
- */
796
- export interface DestructPatternNode extends BaseNode {
797
- readonly type: 'DestructPattern';
798
- readonly kind: 'variable' | 'keyValue' | 'skip' | 'nested';
799
- /** Variable name (for 'variable' and 'keyValue' kinds) */
800
- readonly name: string | null;
801
- /** Key name (for 'keyValue' kind - dict destructuring) */
802
- readonly key: string | null;
803
- /** Type annotation (for 'variable' and 'keyValue' kinds) */
804
- readonly typeName: RillTypeName | null;
805
- /** Nested destructure pattern (for 'nested' kind) */
806
- readonly nested: DestructureNode | null;
807
- }
808
- /**
809
- * Slice operator: /<start:stop:step>
810
- * Extracts a portion of a tuple or string using Python-style slicing.
811
- *
812
- * Examples:
813
- * $tuple -> /<0:3> # elements 0, 1, 2
814
- * $tuple -> /<::-1> # reversed
815
- * "hello" -> /<1:4> # "ell"
816
- */
817
- export interface SliceNode extends BaseNode {
818
- readonly type: 'Slice';
819
- /** Start index (null = from beginning) */
820
- readonly start: SliceBoundNode | null;
821
- /** Stop index (null = to end) */
822
- readonly stop: SliceBoundNode | null;
823
- /** Step (null = 1) */
824
- readonly step: SliceBoundNode | null;
825
- }
826
- /** A slice bound: number, variable, or grouped expression */
827
- export type SliceBoundNode = NumberLiteralNode | VariableNode | GroupedExprNode;
828
- /**
829
- * Spread operator: *expr or -> *
830
- * Converts tuple or dict to args type for unpacking at closure invocation.
831
- *
832
- * Prefix form: *[1, 2, 3], *$tuple, *[x: 1, y: 2]
833
- * Pipe target form: [1, 2, 3] -> *
834
- *
835
- * Creates an args value that unpacks into separate arguments when passed to a closure.
836
- */
837
- export interface SpreadNode extends BaseNode {
838
- readonly type: 'Spread';
839
- /** The expression to spread (null when used as pipe target: -> *) */
840
- readonly operand: ExpressionNode | null;
841
- }
842
- /**
843
- * Type assertion: expr:type
844
- * Asserts that the expression evaluates to the specified type.
845
- * Returns the value unchanged if assertion passes, errors on mismatch.
846
- *
847
- * Examples:
848
- * fetchData():string # assert result is string
849
- * $val -> :number -> process() # assert pipe value is number
850
- * "hello":string # "hello" (pass)
851
- * "hello":number # Error: expected number, got string
852
- *
853
- * When operand is null, it acts on the implicit $:
854
- * :string ≡ $:string
855
- */
856
- export interface TypeAssertionNode extends BaseNode {
857
- readonly type: 'TypeAssertion';
858
- /** The expression to assert (null for bare :type which uses $) */
859
- readonly operand: PostfixExprNode | null;
860
- /** The expected type */
861
- readonly typeName: RillTypeName;
862
- }
863
- /**
864
- * Type check: expr:?type
865
- * Checks if the expression evaluates to the specified type.
866
- * Returns true if types match, false otherwise.
867
- *
868
- * Examples:
869
- * fetchData():?string # is result a string?
870
- * $val -> :?number -> process() # is pipe value a number?
871
- * "hello":?string # true
872
- * "hello":?number # false
873
- *
874
- * When operand is null, it checks the implicit $:
875
- * :?string ≡ $:?string
876
- */
877
- export interface TypeCheckNode extends BaseNode {
878
- readonly type: 'TypeCheck';
879
- /** The expression to check (null for bare :?type which uses $) */
880
- readonly operand: PostfixExprNode | null;
881
- /** The type to check for */
882
- readonly typeName: RillTypeName;
883
- }
884
- export type SimplePrimaryNode = LiteralNode | VariableNode | HostCallNode | MethodCallNode | BlockNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | PostfixExprNode | TypeAssertionNode | TypeCheckNode;
885
- 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;
5
+ export * from './source-location.js';
6
+ export * from './error-registry.js';
7
+ export * from './value-types.js';
8
+ export * from './token-types.js';
9
+ export * from './ast-nodes.js';
10
+ export * from './ast-unions.js';
11
+ export * from './error-classes.js';
12
+ import type { ScriptNode } from './ast-nodes.js';
13
+ import type { ParseError } from './error-classes.js';
886
14
  /**
887
15
  * Options for the parser.
888
16
  */
@@ -907,5 +35,4 @@ export interface ParseResult {
907
35
  /** True if parsing completed without errors */
908
36
  readonly success: boolean;
909
37
  }
910
- export {};
911
38
  //# sourceMappingURL=types.d.ts.map