@rcrsr/rill 0.1.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.
- package/LICENSE +21 -0
- package/README.md +187 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +69 -0
- package/dist/cli.js.map +1 -0
- package/dist/demo.d.ts +6 -0
- package/dist/demo.d.ts.map +1 -0
- package/dist/demo.js +121 -0
- package/dist/demo.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer/errors.d.ts +9 -0
- package/dist/lexer/errors.d.ts.map +1 -0
- package/dist/lexer/errors.js +12 -0
- package/dist/lexer/errors.js.map +1 -0
- package/dist/lexer/helpers.d.ts +14 -0
- package/dist/lexer/helpers.d.ts.map +1 -0
- package/dist/lexer/helpers.js +30 -0
- package/dist/lexer/helpers.js.map +1 -0
- package/dist/lexer/index.d.ts +8 -0
- package/dist/lexer/index.d.ts.map +1 -0
- package/dist/lexer/index.js +8 -0
- package/dist/lexer/index.js.map +1 -0
- package/dist/lexer/operators.d.ts +11 -0
- package/dist/lexer/operators.d.ts.map +1 -0
- package/dist/lexer/operators.js +58 -0
- package/dist/lexer/operators.js.map +1 -0
- package/dist/lexer/readers.d.ts +12 -0
- package/dist/lexer/readers.d.ts.map +1 -0
- package/dist/lexer/readers.js +144 -0
- package/dist/lexer/readers.js.map +1 -0
- package/dist/lexer/state.d.ts +18 -0
- package/dist/lexer/state.d.ts.map +1 -0
- package/dist/lexer/state.js +37 -0
- package/dist/lexer/state.js.map +1 -0
- package/dist/lexer/tokenizer.d.ts +9 -0
- package/dist/lexer/tokenizer.d.ts.map +1 -0
- package/dist/lexer/tokenizer.js +100 -0
- package/dist/lexer/tokenizer.js.map +1 -0
- package/dist/lexer.d.ts +19 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +344 -0
- package/dist/lexer.js.map +1 -0
- package/dist/parser/arithmetic.d.ts +16 -0
- package/dist/parser/arithmetic.d.ts.map +1 -0
- package/dist/parser/arithmetic.js +128 -0
- package/dist/parser/arithmetic.js.map +1 -0
- package/dist/parser/boolean.d.ts +15 -0
- package/dist/parser/boolean.d.ts.map +1 -0
- package/dist/parser/boolean.js +20 -0
- package/dist/parser/boolean.js.map +1 -0
- package/dist/parser/control-flow.d.ts +56 -0
- package/dist/parser/control-flow.d.ts.map +1 -0
- package/dist/parser/control-flow.js +167 -0
- package/dist/parser/control-flow.js.map +1 -0
- package/dist/parser/expressions.d.ts +23 -0
- package/dist/parser/expressions.d.ts.map +1 -0
- package/dist/parser/expressions.js +950 -0
- package/dist/parser/expressions.js.map +1 -0
- package/dist/parser/extraction.d.ts +48 -0
- package/dist/parser/extraction.d.ts.map +1 -0
- package/dist/parser/extraction.js +279 -0
- package/dist/parser/extraction.js.map +1 -0
- package/dist/parser/functions.d.ts +20 -0
- package/dist/parser/functions.d.ts.map +1 -0
- package/dist/parser/functions.js +96 -0
- package/dist/parser/functions.js.map +1 -0
- package/dist/parser/helpers.d.ts +94 -0
- package/dist/parser/helpers.d.ts.map +1 -0
- package/dist/parser/helpers.js +225 -0
- package/dist/parser/helpers.js.map +1 -0
- package/dist/parser/index.d.ts +49 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +73 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/literals.d.ts +37 -0
- package/dist/parser/literals.d.ts.map +1 -0
- package/dist/parser/literals.js +373 -0
- package/dist/parser/literals.js.map +1 -0
- package/dist/parser/parser-collect.d.ts +16 -0
- package/dist/parser/parser-collect.d.ts.map +1 -0
- package/dist/parser/parser-collect.js +125 -0
- package/dist/parser/parser-collect.js.map +1 -0
- package/dist/parser/parser-control.d.ts +20 -0
- package/dist/parser/parser-control.d.ts.map +1 -0
- package/dist/parser/parser-control.js +120 -0
- package/dist/parser/parser-control.js.map +1 -0
- package/dist/parser/parser-expr.d.ts +37 -0
- package/dist/parser/parser-expr.d.ts.map +1 -0
- package/dist/parser/parser-expr.js +639 -0
- package/dist/parser/parser-expr.js.map +1 -0
- package/dist/parser/parser-extract.d.ts +17 -0
- package/dist/parser/parser-extract.d.ts.map +1 -0
- package/dist/parser/parser-extract.js +222 -0
- package/dist/parser/parser-extract.js.map +1 -0
- package/dist/parser/parser-functions.d.ts +21 -0
- package/dist/parser/parser-functions.d.ts.map +1 -0
- package/dist/parser/parser-functions.js +155 -0
- package/dist/parser/parser-functions.js.map +1 -0
- package/dist/parser/parser-literals.d.ts +22 -0
- package/dist/parser/parser-literals.d.ts.map +1 -0
- package/dist/parser/parser-literals.js +288 -0
- package/dist/parser/parser-literals.js.map +1 -0
- package/dist/parser/parser-script.d.ts +21 -0
- package/dist/parser/parser-script.d.ts.map +1 -0
- package/dist/parser/parser-script.js +174 -0
- package/dist/parser/parser-script.js.map +1 -0
- package/dist/parser/parser-variables.d.ts +20 -0
- package/dist/parser/parser-variables.d.ts.map +1 -0
- package/dist/parser/parser-variables.js +146 -0
- package/dist/parser/parser-variables.js.map +1 -0
- package/dist/parser/parser.d.ts +49 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +54 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/script.d.ts +14 -0
- package/dist/parser/script.d.ts.map +1 -0
- package/dist/parser/script.js +196 -0
- package/dist/parser/script.js.map +1 -0
- package/dist/parser/state.d.ts +40 -0
- package/dist/parser/state.d.ts.map +1 -0
- package/dist/parser/state.js +129 -0
- package/dist/parser/state.js.map +1 -0
- package/dist/parser/variables.d.ts +10 -0
- package/dist/parser/variables.d.ts.map +1 -0
- package/dist/parser/variables.js +215 -0
- package/dist/parser/variables.js.map +1 -0
- package/dist/runtime/ast-equals.d.ts +13 -0
- package/dist/runtime/ast-equals.d.ts.map +1 -0
- package/dist/runtime/ast-equals.js +447 -0
- package/dist/runtime/ast-equals.js.map +1 -0
- package/dist/runtime/builtins.d.ts +13 -0
- package/dist/runtime/builtins.d.ts.map +1 -0
- package/dist/runtime/builtins.js +180 -0
- package/dist/runtime/builtins.js.map +1 -0
- package/dist/runtime/callable.d.ts +88 -0
- package/dist/runtime/callable.d.ts.map +1 -0
- package/dist/runtime/callable.js +98 -0
- package/dist/runtime/callable.js.map +1 -0
- package/dist/runtime/context.d.ts +13 -0
- package/dist/runtime/context.d.ts.map +1 -0
- package/dist/runtime/context.js +73 -0
- package/dist/runtime/context.js.map +1 -0
- package/dist/runtime/core/callable.d.ts +171 -0
- package/dist/runtime/core/callable.d.ts.map +1 -0
- package/dist/runtime/core/callable.js +246 -0
- package/dist/runtime/core/callable.js.map +1 -0
- package/dist/runtime/core/context.d.ts +29 -0
- package/dist/runtime/core/context.d.ts.map +1 -0
- package/dist/runtime/core/context.js +154 -0
- package/dist/runtime/core/context.js.map +1 -0
- package/dist/runtime/core/equals.d.ts +9 -0
- package/dist/runtime/core/equals.d.ts.map +1 -0
- package/dist/runtime/core/equals.js +381 -0
- package/dist/runtime/core/equals.js.map +1 -0
- package/dist/runtime/core/eval/base.d.ts +65 -0
- package/dist/runtime/core/eval/base.d.ts.map +1 -0
- package/dist/runtime/core/eval/base.js +112 -0
- package/dist/runtime/core/eval/base.js.map +1 -0
- package/dist/runtime/core/eval/evaluator.d.ts +47 -0
- package/dist/runtime/core/eval/evaluator.d.ts.map +1 -0
- package/dist/runtime/core/eval/evaluator.js +73 -0
- package/dist/runtime/core/eval/evaluator.js.map +1 -0
- package/dist/runtime/core/eval/index.d.ts +57 -0
- package/dist/runtime/core/eval/index.d.ts.map +1 -0
- package/dist/runtime/core/eval/index.js +95 -0
- package/dist/runtime/core/eval/index.js.map +1 -0
- package/dist/runtime/core/eval/mixins/annotations.d.ts +19 -0
- package/dist/runtime/core/eval/mixins/annotations.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/annotations.js +146 -0
- package/dist/runtime/core/eval/mixins/annotations.js.map +1 -0
- package/dist/runtime/core/eval/mixins/closures.d.ts +49 -0
- package/dist/runtime/core/eval/mixins/closures.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/closures.js +479 -0
- package/dist/runtime/core/eval/mixins/closures.js.map +1 -0
- package/dist/runtime/core/eval/mixins/collections.d.ts +24 -0
- package/dist/runtime/core/eval/mixins/collections.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/collections.js +466 -0
- package/dist/runtime/core/eval/mixins/collections.js.map +1 -0
- package/dist/runtime/core/eval/mixins/control-flow.d.ts +27 -0
- package/dist/runtime/core/eval/mixins/control-flow.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/control-flow.js +369 -0
- package/dist/runtime/core/eval/mixins/control-flow.js.map +1 -0
- package/dist/runtime/core/eval/mixins/core.d.ts +24 -0
- package/dist/runtime/core/eval/mixins/core.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/core.js +335 -0
- package/dist/runtime/core/eval/mixins/core.js.map +1 -0
- package/dist/runtime/core/eval/mixins/expressions.d.ts +19 -0
- package/dist/runtime/core/eval/mixins/expressions.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/expressions.js +202 -0
- package/dist/runtime/core/eval/mixins/expressions.js.map +1 -0
- package/dist/runtime/core/eval/mixins/extraction.d.ts +10 -0
- package/dist/runtime/core/eval/mixins/extraction.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/extraction.js +250 -0
- package/dist/runtime/core/eval/mixins/extraction.js.map +1 -0
- package/dist/runtime/core/eval/mixins/literals.d.ts +23 -0
- package/dist/runtime/core/eval/mixins/literals.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/literals.js +180 -0
- package/dist/runtime/core/eval/mixins/literals.js.map +1 -0
- package/dist/runtime/core/eval/mixins/types.d.ts +20 -0
- package/dist/runtime/core/eval/mixins/types.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/types.js +109 -0
- package/dist/runtime/core/eval/mixins/types.js.map +1 -0
- package/dist/runtime/core/eval/mixins/variables.d.ts +34 -0
- package/dist/runtime/core/eval/mixins/variables.d.ts.map +1 -0
- package/dist/runtime/core/eval/mixins/variables.js +247 -0
- package/dist/runtime/core/eval/mixins/variables.js.map +1 -0
- package/dist/runtime/core/eval/types.d.ts +41 -0
- package/dist/runtime/core/eval/types.d.ts.map +1 -0
- package/dist/runtime/core/eval/types.js +10 -0
- package/dist/runtime/core/eval/types.js.map +1 -0
- package/dist/runtime/core/evaluate.d.ts +42 -0
- package/dist/runtime/core/evaluate.d.ts.map +1 -0
- package/dist/runtime/core/evaluate.debug.js +1251 -0
- package/dist/runtime/core/evaluate.js +1913 -0
- package/dist/runtime/core/evaluate.js.map +1 -0
- package/dist/runtime/core/execute.d.ts +26 -0
- package/dist/runtime/core/execute.d.ts.map +1 -0
- package/dist/runtime/core/execute.js +177 -0
- package/dist/runtime/core/execute.js.map +1 -0
- package/dist/runtime/core/signals.d.ts +19 -0
- package/dist/runtime/core/signals.d.ts.map +1 -0
- package/dist/runtime/core/signals.js +26 -0
- package/dist/runtime/core/signals.js.map +1 -0
- package/dist/runtime/core/types.d.ts +177 -0
- package/dist/runtime/core/types.d.ts.map +1 -0
- package/dist/runtime/core/types.js +50 -0
- package/dist/runtime/core/types.js.map +1 -0
- package/dist/runtime/core/values.d.ts +66 -0
- package/dist/runtime/core/values.d.ts.map +1 -0
- package/dist/runtime/core/values.js +240 -0
- package/dist/runtime/core/values.js.map +1 -0
- package/dist/runtime/evaluate.d.ts +32 -0
- package/dist/runtime/evaluate.d.ts.map +1 -0
- package/dist/runtime/evaluate.js +1111 -0
- package/dist/runtime/evaluate.js.map +1 -0
- package/dist/runtime/execute.d.ts +26 -0
- package/dist/runtime/execute.d.ts.map +1 -0
- package/dist/runtime/execute.js +121 -0
- package/dist/runtime/execute.js.map +1 -0
- package/dist/runtime/ext/builtins.d.ts +16 -0
- package/dist/runtime/ext/builtins.d.ts.map +1 -0
- package/dist/runtime/ext/builtins.js +528 -0
- package/dist/runtime/ext/builtins.js.map +1 -0
- package/dist/runtime/ext/content-parser.d.ts +83 -0
- package/dist/runtime/ext/content-parser.d.ts.map +1 -0
- package/dist/runtime/ext/content-parser.js +536 -0
- package/dist/runtime/ext/content-parser.js.map +1 -0
- package/dist/runtime/index.d.ts +28 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +34 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/signals.d.ts +19 -0
- package/dist/runtime/signals.d.ts.map +1 -0
- package/dist/runtime/signals.js +26 -0
- package/dist/runtime/signals.js.map +1 -0
- package/dist/runtime/types.d.ts +169 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +50 -0
- package/dist/runtime/types.js.map +1 -0
- package/dist/runtime/values.d.ts +50 -0
- package/dist/runtime/values.d.ts.map +1 -0
- package/dist/runtime/values.js +209 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/runtime.d.ts +254 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +2014 -0
- package/dist/runtime.js.map +1 -0
- package/dist/types.d.ts +752 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +189 -0
- package/dist/types.js.map +1 -0
- package/docs/00_INDEX.md +65 -0
- package/docs/01_guide.md +390 -0
- package/docs/02_types.md +399 -0
- package/docs/03_variables.md +314 -0
- package/docs/04_operators.md +551 -0
- package/docs/05_control-flow.md +350 -0
- package/docs/06_closures.md +353 -0
- package/docs/07_collections.md +686 -0
- package/docs/08_iterators.md +330 -0
- package/docs/09_strings.md +205 -0
- package/docs/10_parsing.md +366 -0
- package/docs/11_reference.md +350 -0
- package/docs/12_examples.md +771 -0
- package/docs/13_modules.md +519 -0
- package/docs/14_host-integration.md +826 -0
- package/docs/15_grammar.ebnf +693 -0
- package/docs/16_conventions.md +696 -0
- package/docs/99_llm-reference.txt +300 -0
- package/docs/assets/logo.png +0 -0
- package/package.json +70 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rill AST Types
|
|
3
|
+
* Based on docs/grammar.ebnf
|
|
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 codes for programmatic handling */
|
|
15
|
+
export declare const RILL_ERROR_CODES: {
|
|
16
|
+
readonly PARSE_UNEXPECTED_TOKEN: "PARSE_UNEXPECTED_TOKEN";
|
|
17
|
+
readonly PARSE_INVALID_SYNTAX: "PARSE_INVALID_SYNTAX";
|
|
18
|
+
readonly PARSE_INVALID_TYPE: "PARSE_INVALID_TYPE";
|
|
19
|
+
readonly RUNTIME_UNDEFINED_VARIABLE: "RUNTIME_UNDEFINED_VARIABLE";
|
|
20
|
+
readonly RUNTIME_UNDEFINED_FUNCTION: "RUNTIME_UNDEFINED_FUNCTION";
|
|
21
|
+
readonly RUNTIME_UNDEFINED_METHOD: "RUNTIME_UNDEFINED_METHOD";
|
|
22
|
+
readonly RUNTIME_TYPE_ERROR: "RUNTIME_TYPE_ERROR";
|
|
23
|
+
readonly RUNTIME_TIMEOUT: "RUNTIME_TIMEOUT";
|
|
24
|
+
readonly RUNTIME_INVALID_PATTERN: "RUNTIME_INVALID_PATTERN";
|
|
25
|
+
readonly RUNTIME_AUTO_EXCEPTION: "RUNTIME_AUTO_EXCEPTION";
|
|
26
|
+
readonly RUNTIME_ABORTED: "RUNTIME_ABORTED";
|
|
27
|
+
readonly RUNTIME_PROPERTY_NOT_FOUND: "RUNTIME_PROPERTY_NOT_FOUND";
|
|
28
|
+
readonly RUNTIME_LIMIT_EXCEEDED: "RUNTIME_LIMIT_EXCEEDED";
|
|
29
|
+
};
|
|
30
|
+
export type RillErrorCode = (typeof RILL_ERROR_CODES)[keyof typeof RILL_ERROR_CODES];
|
|
31
|
+
/** Structured error data for host applications */
|
|
32
|
+
export interface RillErrorData {
|
|
33
|
+
readonly code: RillErrorCode;
|
|
34
|
+
readonly message: string;
|
|
35
|
+
readonly location?: SourceLocation | undefined;
|
|
36
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Base error class for all Rill errors.
|
|
40
|
+
* Provides structured data for host applications to format as needed.
|
|
41
|
+
*/
|
|
42
|
+
export declare class RillError extends Error {
|
|
43
|
+
readonly code: RillErrorCode;
|
|
44
|
+
readonly location?: SourceLocation | undefined;
|
|
45
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
46
|
+
constructor(data: RillErrorData);
|
|
47
|
+
/** Get structured error data for custom formatting */
|
|
48
|
+
toData(): RillErrorData;
|
|
49
|
+
/** Format error for display (can be overridden by host) */
|
|
50
|
+
format(formatter?: (data: RillErrorData) => string): string;
|
|
51
|
+
}
|
|
52
|
+
/** Parse-time errors */
|
|
53
|
+
export declare class ParseError extends RillError {
|
|
54
|
+
constructor(message: string, location: SourceLocation, context?: Record<string, unknown>);
|
|
55
|
+
}
|
|
56
|
+
/** Runtime execution errors */
|
|
57
|
+
export declare class RuntimeError extends RillError {
|
|
58
|
+
constructor(code: RillErrorCode, message: string, location?: SourceLocation, context?: Record<string, unknown>);
|
|
59
|
+
/** Create from an AST node */
|
|
60
|
+
static fromNode(code: RillErrorCode, message: string, node?: {
|
|
61
|
+
span: SourceSpan;
|
|
62
|
+
}, context?: Record<string, unknown>): RuntimeError;
|
|
63
|
+
}
|
|
64
|
+
/** Timeout errors */
|
|
65
|
+
export declare class TimeoutError extends RuntimeError {
|
|
66
|
+
readonly functionName: string;
|
|
67
|
+
readonly timeoutMs: number;
|
|
68
|
+
constructor(functionName: string, timeoutMs: number, location?: SourceLocation);
|
|
69
|
+
}
|
|
70
|
+
/** Auto-exception errors (when $_ matches a pattern) */
|
|
71
|
+
export declare class AutoExceptionError extends RuntimeError {
|
|
72
|
+
readonly pattern: string;
|
|
73
|
+
readonly matchedValue: string;
|
|
74
|
+
constructor(pattern: string, matchedValue: string, location?: SourceLocation);
|
|
75
|
+
}
|
|
76
|
+
/** Abort errors (when execution is cancelled via AbortSignal) */
|
|
77
|
+
export declare class AbortError extends RuntimeError {
|
|
78
|
+
constructor(location?: SourceLocation);
|
|
79
|
+
}
|
|
80
|
+
export declare const TOKEN_TYPES: {
|
|
81
|
+
readonly STRING: "STRING";
|
|
82
|
+
readonly NUMBER: "NUMBER";
|
|
83
|
+
readonly TRUE: "TRUE";
|
|
84
|
+
readonly FALSE: "FALSE";
|
|
85
|
+
readonly IDENTIFIER: "IDENTIFIER";
|
|
86
|
+
readonly DOLLAR: "DOLLAR";
|
|
87
|
+
readonly PIPE_VAR: "PIPE_VAR";
|
|
88
|
+
readonly ARROW: "ARROW";
|
|
89
|
+
readonly CAPTURE_ARROW: "CAPTURE_ARROW";
|
|
90
|
+
readonly DOT: "DOT";
|
|
91
|
+
readonly QUESTION: "QUESTION";
|
|
92
|
+
readonly AT: "AT";
|
|
93
|
+
readonly CARET: "CARET";
|
|
94
|
+
readonly COLON: "COLON";
|
|
95
|
+
readonly DOUBLE_COLON: "DOUBLE_COLON";
|
|
96
|
+
readonly COMMA: "COMMA";
|
|
97
|
+
readonly BANG: "BANG";
|
|
98
|
+
readonly AND: "AND";
|
|
99
|
+
readonly OR: "OR";
|
|
100
|
+
readonly NULLISH_COALESCE: "NULLISH_COALESCE";
|
|
101
|
+
readonly DOT_QUESTION: "DOT_QUESTION";
|
|
102
|
+
readonly AMPERSAND: "AMPERSAND";
|
|
103
|
+
readonly ASSIGN: "ASSIGN";
|
|
104
|
+
readonly EQ: "EQ";
|
|
105
|
+
readonly NE: "NE";
|
|
106
|
+
readonly LT: "LT";
|
|
107
|
+
readonly GT: "GT";
|
|
108
|
+
readonly LE: "LE";
|
|
109
|
+
readonly GE: "GE";
|
|
110
|
+
readonly STAR_LT: "STAR_LT";
|
|
111
|
+
readonly SLASH_LT: "SLASH_LT";
|
|
112
|
+
readonly UNDERSCORE: "UNDERSCORE";
|
|
113
|
+
readonly PIPE_BAR: "PIPE_BAR";
|
|
114
|
+
readonly PLUS: "PLUS";
|
|
115
|
+
readonly MINUS: "MINUS";
|
|
116
|
+
readonly STAR: "STAR";
|
|
117
|
+
readonly SLASH: "SLASH";
|
|
118
|
+
readonly PERCENT: "PERCENT";
|
|
119
|
+
readonly LPAREN: "LPAREN";
|
|
120
|
+
readonly RPAREN: "RPAREN";
|
|
121
|
+
readonly LBRACE: "LBRACE";
|
|
122
|
+
readonly RBRACE: "RBRACE";
|
|
123
|
+
readonly LBRACKET: "LBRACKET";
|
|
124
|
+
readonly RBRACKET: "RBRACKET";
|
|
125
|
+
readonly BREAK: "BREAK";
|
|
126
|
+
readonly RETURN: "RETURN";
|
|
127
|
+
readonly EACH: "EACH";
|
|
128
|
+
readonly MAP: "MAP";
|
|
129
|
+
readonly FOLD: "FOLD";
|
|
130
|
+
readonly FILTER: "FILTER";
|
|
131
|
+
readonly FRONTMATTER_DELIM: "FRONTMATTER_DELIM";
|
|
132
|
+
readonly HEREDOC_START: "HEREDOC_START";
|
|
133
|
+
readonly HEREDOC_BODY: "HEREDOC_BODY";
|
|
134
|
+
readonly HEREDOC_END: "HEREDOC_END";
|
|
135
|
+
readonly NEWLINE: "NEWLINE";
|
|
136
|
+
readonly COMMENT: "COMMENT";
|
|
137
|
+
readonly EOF: "EOF";
|
|
138
|
+
};
|
|
139
|
+
export type TokenType = (typeof TOKEN_TYPES)[keyof typeof TOKEN_TYPES];
|
|
140
|
+
export interface Token {
|
|
141
|
+
readonly type: TokenType;
|
|
142
|
+
readonly value: string;
|
|
143
|
+
readonly span: SourceSpan;
|
|
144
|
+
}
|
|
145
|
+
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' | 'Dict' | 'DictEntry' | 'Break' | 'Return' | 'BinaryExpr' | 'UnaryExpr' | 'InnerExpr' | 'GroupedExpr' | 'ClosureChain' | 'Destructure' | 'DestructPattern' | 'Slice' | 'Enumerate' | 'Spread' | 'TypeAssertion' | 'TypeCheck' | 'AnnotatedStatement' | 'NamedArg' | 'SpreadArg' | 'EachExpr' | 'MapExpr' | 'FoldExpr' | 'FilterExpr' | 'Error';
|
|
146
|
+
interface BaseNode {
|
|
147
|
+
readonly span: SourceSpan;
|
|
148
|
+
}
|
|
149
|
+
export interface ScriptNode extends BaseNode {
|
|
150
|
+
readonly type: 'Script';
|
|
151
|
+
readonly frontmatter: FrontmatterNode | null;
|
|
152
|
+
/** Statements in the script. May include ErrorNode when parsed with recoveryMode. */
|
|
153
|
+
readonly statements: (StatementNode | AnnotatedStatementNode | ErrorNode)[];
|
|
154
|
+
}
|
|
155
|
+
export interface FrontmatterNode extends BaseNode {
|
|
156
|
+
readonly type: 'Frontmatter';
|
|
157
|
+
readonly content: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Closure: |params| body
|
|
161
|
+
* First-class closure with optional typed parameters and defaults.
|
|
162
|
+
* Scope rules: captures outer (read-only), local mutable.
|
|
163
|
+
*
|
|
164
|
+
* Body can be:
|
|
165
|
+
* - Simple: |x| $x (postfix-expr)
|
|
166
|
+
* - Grouped: |x| ($x * 2) (compound expression)
|
|
167
|
+
* - Block: |x| { $a ↵ $b } (multiple statements)
|
|
168
|
+
*/
|
|
169
|
+
export interface ClosureNode extends BaseNode {
|
|
170
|
+
readonly type: 'Closure';
|
|
171
|
+
readonly params: ClosureParamNode[];
|
|
172
|
+
readonly body: BodyNode;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Function parameter with optional type and default value.
|
|
176
|
+
* - (x) { } -- untyped
|
|
177
|
+
* - (x: string) { } -- typed
|
|
178
|
+
* - (x: string = "hi") { } -- typed with default
|
|
179
|
+
*/
|
|
180
|
+
export interface ClosureParamNode extends BaseNode {
|
|
181
|
+
readonly type: 'ClosureParam';
|
|
182
|
+
readonly name: string;
|
|
183
|
+
readonly typeName: 'string' | 'number' | 'bool' | null;
|
|
184
|
+
readonly defaultValue: LiteralNode | null;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Statement: a pipe chain expression.
|
|
188
|
+
* Termination (capture/break/return) is now part of PipeChainNode.
|
|
189
|
+
*/
|
|
190
|
+
export interface StatementNode extends BaseNode {
|
|
191
|
+
readonly type: 'Statement';
|
|
192
|
+
readonly expression: PipeChainNode;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Error node for recovery mode parsing.
|
|
196
|
+
* Represents unparseable content that was skipped during error recovery.
|
|
197
|
+
* Only appears in ASTs when parsing with `recoveryMode: true`.
|
|
198
|
+
*/
|
|
199
|
+
export interface ErrorNode extends BaseNode {
|
|
200
|
+
readonly type: 'Error';
|
|
201
|
+
/** The error message describing what went wrong */
|
|
202
|
+
readonly message: string;
|
|
203
|
+
/** The raw source text that could not be parsed */
|
|
204
|
+
readonly text: string;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Annotated statement: ^(key: value, ...) statement
|
|
208
|
+
* Annotations modify operational parameters for statements.
|
|
209
|
+
* They prefix statements and bind to the immediately following construct.
|
|
210
|
+
*
|
|
211
|
+
* Examples:
|
|
212
|
+
* ^(limit: 100) $items @ process()
|
|
213
|
+
* ^(timeout: 30) fetch($url)
|
|
214
|
+
* ^(retry: 3, backoff: 1.5) api_call()
|
|
215
|
+
*/
|
|
216
|
+
export interface AnnotatedStatementNode extends BaseNode {
|
|
217
|
+
readonly type: 'AnnotatedStatement';
|
|
218
|
+
readonly annotations: AnnotationArg[];
|
|
219
|
+
readonly statement: StatementNode;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Annotation argument: named or spread
|
|
223
|
+
* Reuses similar structure to dict entries but with spread support.
|
|
224
|
+
*/
|
|
225
|
+
export type AnnotationArg = NamedArgNode | SpreadArgNode;
|
|
226
|
+
/**
|
|
227
|
+
* Named annotation argument: key: value
|
|
228
|
+
* Example: limit: 100, timeout: 30
|
|
229
|
+
*/
|
|
230
|
+
export interface NamedArgNode extends BaseNode {
|
|
231
|
+
readonly type: 'NamedArg';
|
|
232
|
+
readonly name: string;
|
|
233
|
+
readonly value: ExpressionNode;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Spread annotation argument: *expr
|
|
237
|
+
* Example: *$opts spreads tuple keys as annotations
|
|
238
|
+
*/
|
|
239
|
+
export interface SpreadArgNode extends BaseNode {
|
|
240
|
+
readonly type: 'SpreadArg';
|
|
241
|
+
readonly expression: ExpressionNode;
|
|
242
|
+
}
|
|
243
|
+
/** Rill type names for type annotations */
|
|
244
|
+
export type RillTypeName = 'string' | 'number' | 'bool' | 'closure' | 'list' | 'dict' | 'tuple';
|
|
245
|
+
export interface CaptureNode extends BaseNode {
|
|
246
|
+
readonly type: 'Capture';
|
|
247
|
+
readonly name: string;
|
|
248
|
+
/** Optional explicit type annotation: $name:string */
|
|
249
|
+
readonly typeName: RillTypeName | null;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Break: exit loop with current pipe value.
|
|
253
|
+
* Used as chain terminator: $x -> break
|
|
254
|
+
* Or bare: break (implicit $ -> break)
|
|
255
|
+
*/
|
|
256
|
+
export interface BreakNode extends BaseNode {
|
|
257
|
+
readonly type: 'Break';
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Return: exit closure with current pipe value.
|
|
261
|
+
* Used as chain terminator: $x -> return
|
|
262
|
+
* Or bare: return (implicit $ -> return)
|
|
263
|
+
*/
|
|
264
|
+
export interface ReturnNode extends BaseNode {
|
|
265
|
+
readonly type: 'Return';
|
|
266
|
+
}
|
|
267
|
+
export type ExpressionNode = PipeChainNode;
|
|
268
|
+
/** Chain terminator: capture, break, or return */
|
|
269
|
+
export type ChainTerminator = CaptureNode | BreakNode | ReturnNode;
|
|
270
|
+
export interface PipeChainNode extends BaseNode {
|
|
271
|
+
readonly type: 'PipeChain';
|
|
272
|
+
readonly head: ArithHead;
|
|
273
|
+
/**
|
|
274
|
+
* Pipe targets and inline captures.
|
|
275
|
+
* Inline captures act as implicit .set() — store value and return unchanged.
|
|
276
|
+
* Semantically: "-> $a ->" ≡ "-> $a.set($) ->"
|
|
277
|
+
*/
|
|
278
|
+
readonly pipes: (PipeTargetNode | CaptureNode)[];
|
|
279
|
+
/**
|
|
280
|
+
* Chain terminator: final capture, break, or return.
|
|
281
|
+
* Examples:
|
|
282
|
+
* $x -> $y terminator = Capture($y)
|
|
283
|
+
* $x -> break terminator = Break
|
|
284
|
+
* $x -> return terminator = Return
|
|
285
|
+
* $x -> .method terminator = null
|
|
286
|
+
*/
|
|
287
|
+
readonly terminator: ChainTerminator | null;
|
|
288
|
+
}
|
|
289
|
+
export interface PostfixExprNode extends BaseNode {
|
|
290
|
+
readonly type: 'PostfixExpr';
|
|
291
|
+
readonly primary: PrimaryNode;
|
|
292
|
+
readonly methods: (MethodCallNode | InvokeNode)[];
|
|
293
|
+
}
|
|
294
|
+
export type PrimaryNode = LiteralNode | VariableNode | HostCallNode | ClosureCallNode | MethodCallNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | GroupedExprNode | SpreadNode | TypeAssertionNode | TypeCheckNode;
|
|
295
|
+
export type PipeTargetNode = HostCallNode | ClosureCallNode | MethodCallNode | PipeInvokeNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | StringLiteralNode | GroupedExprNode | ClosureChainNode | DestructureNode | SliceNode | SpreadNode | TypeAssertionNode | TypeCheckNode | EachExprNode | MapExprNode | FoldExprNode | FilterExprNode | PostfixExprNode | VariableNode;
|
|
296
|
+
/** Invoke pipe value as a closure: -> $() or -> $(arg1, arg2) */
|
|
297
|
+
export interface PipeInvokeNode extends BaseNode {
|
|
298
|
+
readonly type: 'PipeInvoke';
|
|
299
|
+
readonly args: ExpressionNode[];
|
|
300
|
+
}
|
|
301
|
+
export type LiteralNode = StringLiteralNode | NumberLiteralNode | BoolLiteralNode | TupleNode | DictNode | ClosureNode;
|
|
302
|
+
export interface StringLiteralNode extends BaseNode {
|
|
303
|
+
readonly type: 'StringLiteral';
|
|
304
|
+
readonly parts: (string | InterpolationNode)[];
|
|
305
|
+
readonly isHeredoc: boolean;
|
|
306
|
+
}
|
|
307
|
+
export interface InterpolationNode extends BaseNode {
|
|
308
|
+
readonly type: 'Interpolation';
|
|
309
|
+
readonly expression: ExpressionNode;
|
|
310
|
+
}
|
|
311
|
+
export interface NumberLiteralNode extends BaseNode {
|
|
312
|
+
readonly type: 'NumberLiteral';
|
|
313
|
+
readonly value: number;
|
|
314
|
+
}
|
|
315
|
+
export interface BoolLiteralNode extends BaseNode {
|
|
316
|
+
readonly type: 'BoolLiteral';
|
|
317
|
+
readonly value: boolean;
|
|
318
|
+
}
|
|
319
|
+
export interface TupleNode extends BaseNode {
|
|
320
|
+
readonly type: 'Tuple';
|
|
321
|
+
readonly elements: ExpressionNode[];
|
|
322
|
+
}
|
|
323
|
+
export interface DictNode extends BaseNode {
|
|
324
|
+
readonly type: 'Dict';
|
|
325
|
+
readonly entries: DictEntryNode[];
|
|
326
|
+
}
|
|
327
|
+
export interface DictEntryNode extends BaseNode {
|
|
328
|
+
readonly type: 'DictEntry';
|
|
329
|
+
readonly key: string;
|
|
330
|
+
readonly value: ExpressionNode;
|
|
331
|
+
}
|
|
332
|
+
export type BinaryOp = '+' | '-' | '*' | '/' | '%' | '&&' | '||' | '==' | '!=' | '<' | '>' | '<=' | '>=';
|
|
333
|
+
/**
|
|
334
|
+
* Expression head types for binary/unary expressions.
|
|
335
|
+
* Includes arithmetic (+, -, *, /, %) and logical (&&, ||, !) operators.
|
|
336
|
+
*/
|
|
337
|
+
export type ArithHead = BinaryExprNode | UnaryExprNode | PostfixExprNode;
|
|
338
|
+
/**
|
|
339
|
+
* Binary expression: left op right
|
|
340
|
+
* Arithmetic: ($x + 5), ($a * $b), (2 + 3 * 4)
|
|
341
|
+
* Logical: ($a && $b), ($x || $y)
|
|
342
|
+
*/
|
|
343
|
+
export interface BinaryExprNode extends BaseNode {
|
|
344
|
+
readonly type: 'BinaryExpr';
|
|
345
|
+
readonly op: BinaryOp;
|
|
346
|
+
readonly left: ArithHead;
|
|
347
|
+
readonly right: ArithHead;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Unary expression: -operand or !operand
|
|
351
|
+
* Examples: (-5), (-$x), (!$ready)
|
|
352
|
+
*/
|
|
353
|
+
export interface UnaryExprNode extends BaseNode {
|
|
354
|
+
readonly type: 'UnaryExpr';
|
|
355
|
+
readonly op: '-' | '!';
|
|
356
|
+
readonly operand: UnaryExprNode | PostfixExprNode;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Grouped expression: ( expression )
|
|
360
|
+
* Single-expression block with () delimiters.
|
|
361
|
+
* Provides scoping — captures inside are local and not visible outside.
|
|
362
|
+
*
|
|
363
|
+
* Scoping rules identical to blocks:
|
|
364
|
+
* ("hello" -> $local) — $local is scoped to group, returns "hello"
|
|
365
|
+
*/
|
|
366
|
+
export interface GroupedExprNode extends BaseNode {
|
|
367
|
+
readonly type: 'GroupedExpr';
|
|
368
|
+
readonly expression: PipeChainNode;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Simple body: expression that can follow closure params, conditionals, or loops.
|
|
372
|
+
* No naked compound expressions — arithmetic/pipes/booleans must be grouped.
|
|
373
|
+
*
|
|
374
|
+
* Valid: block, grouped, or postfix-expr (variable, literal, method, function call)
|
|
375
|
+
* Examples:
|
|
376
|
+
* |x| $x — postfix-expr
|
|
377
|
+
* |x| ($x * 2) — grouped (compound)
|
|
378
|
+
* |x| { $a ↵ $b } — block (multiple statements)
|
|
379
|
+
*/
|
|
380
|
+
export type BodyNode = BlockNode | GroupedExprNode | PostfixExprNode | PipeChainNode;
|
|
381
|
+
export interface VariableNode extends BaseNode {
|
|
382
|
+
readonly type: 'Variable';
|
|
383
|
+
readonly name: string | null;
|
|
384
|
+
readonly isPipeVar: boolean;
|
|
385
|
+
/** Ordered chain of property accesses: .name, [0], .$var, etc. */
|
|
386
|
+
readonly accessChain: PropertyAccess[];
|
|
387
|
+
/**
|
|
388
|
+
* Default value for null-coalescing: $data.path ?? default
|
|
389
|
+
* If property access returns null/missing, use this value instead.
|
|
390
|
+
*/
|
|
391
|
+
readonly defaultValue: BodyNode | null;
|
|
392
|
+
/**
|
|
393
|
+
* Existence check on final path element: $data.?path
|
|
394
|
+
* Returns boolean (true if path exists).
|
|
395
|
+
* When set, implies safe traversal (no error on missing intermediate paths).
|
|
396
|
+
*/
|
|
397
|
+
readonly existenceCheck: ExistenceCheck | null;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Existence check configuration.
|
|
401
|
+
* For .?path (just exists) or .?path&type (exists AND type matches).
|
|
402
|
+
*/
|
|
403
|
+
export interface ExistenceCheck {
|
|
404
|
+
/** The final field/index being checked for existence */
|
|
405
|
+
readonly finalAccess: FieldAccess;
|
|
406
|
+
/** Optional type check: returns true only if exists AND matches type */
|
|
407
|
+
readonly typeName: RillTypeName | null;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Field access element in a property access chain (dot-based).
|
|
411
|
+
*
|
|
412
|
+
* Access forms:
|
|
413
|
+
* - literal: .identifier (string key)
|
|
414
|
+
* - variable: .$var (variable as key)
|
|
415
|
+
* - computed: .(expr) (computed expression)
|
|
416
|
+
* - block: .{block} (block returning key)
|
|
417
|
+
* - alternatives: .(a || b) (try keys left-to-right)
|
|
418
|
+
*
|
|
419
|
+
* Note: Numeric indices use bracket syntax [0], [-1] instead of dot.
|
|
420
|
+
*/
|
|
421
|
+
export type FieldAccess = FieldAccessLiteral | FieldAccessVariable | FieldAccessComputed | FieldAccessBlock | FieldAccessAlternatives;
|
|
422
|
+
/** Literal field access: .identifier */
|
|
423
|
+
export interface FieldAccessLiteral {
|
|
424
|
+
readonly kind: 'literal';
|
|
425
|
+
readonly field: string;
|
|
426
|
+
}
|
|
427
|
+
/** Variable as key: .$var */
|
|
428
|
+
export interface FieldAccessVariable {
|
|
429
|
+
readonly kind: 'variable';
|
|
430
|
+
readonly variableName: string;
|
|
431
|
+
}
|
|
432
|
+
/** Computed expression: .(expr) */
|
|
433
|
+
export interface FieldAccessComputed {
|
|
434
|
+
readonly kind: 'computed';
|
|
435
|
+
readonly expression: ExpressionNode;
|
|
436
|
+
}
|
|
437
|
+
/** Block returning key: .{block} */
|
|
438
|
+
export interface FieldAccessBlock {
|
|
439
|
+
readonly kind: 'block';
|
|
440
|
+
readonly block: BlockNode;
|
|
441
|
+
}
|
|
442
|
+
/** Alternatives (try keys left-to-right): .(a || b) */
|
|
443
|
+
export interface FieldAccessAlternatives {
|
|
444
|
+
readonly kind: 'alternatives';
|
|
445
|
+
readonly alternatives: string[];
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Bracket index access: [expr]
|
|
449
|
+
* Used for numeric indexing into lists/strings.
|
|
450
|
+
* Expression can be positive (from start) or negative (from end).
|
|
451
|
+
*/
|
|
452
|
+
export interface BracketAccess {
|
|
453
|
+
/** Discriminator for the unified PropertyAccess type */
|
|
454
|
+
readonly accessKind: 'bracket';
|
|
455
|
+
/** The index expression (evaluates to number) */
|
|
456
|
+
readonly expression: ExpressionNode;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Unified property access type.
|
|
460
|
+
* Used to maintain order of mixed dot and bracket accesses.
|
|
461
|
+
* e.g., $data[0].name[1] has accesses: [bracket(0), field(name), bracket(1)]
|
|
462
|
+
*/
|
|
463
|
+
export type PropertyAccess = FieldAccess | BracketAccess;
|
|
464
|
+
export interface HostCallNode extends BaseNode {
|
|
465
|
+
readonly type: 'HostCall';
|
|
466
|
+
readonly name: string;
|
|
467
|
+
readonly args: ExpressionNode[];
|
|
468
|
+
}
|
|
469
|
+
export interface MethodCallNode extends BaseNode {
|
|
470
|
+
readonly type: 'MethodCall';
|
|
471
|
+
readonly name: string;
|
|
472
|
+
readonly args: ExpressionNode[];
|
|
473
|
+
}
|
|
474
|
+
/** Postfix invocation: expr(args) - calls the result of expr as a closure */
|
|
475
|
+
export interface InvokeNode extends BaseNode {
|
|
476
|
+
readonly type: 'Invoke';
|
|
477
|
+
readonly args: ExpressionNode[];
|
|
478
|
+
}
|
|
479
|
+
/** Call a closure stored in a variable: $fn(args) or $obj.method(args) */
|
|
480
|
+
export interface ClosureCallNode extends BaseNode {
|
|
481
|
+
readonly type: 'ClosureCall';
|
|
482
|
+
readonly name: string;
|
|
483
|
+
readonly accessChain: string[];
|
|
484
|
+
readonly args: ExpressionNode[];
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Conditional: ?($cond) body : else
|
|
488
|
+
* Body can be any simple-body (block, grouped, or postfix-expr).
|
|
489
|
+
*
|
|
490
|
+
* Examples:
|
|
491
|
+
* ?($x > 0) "positive" : "negative" — literals
|
|
492
|
+
* ?($x > 0) ($x * 2) : ($x / 2) — grouped
|
|
493
|
+
* ?($x > 0) { complex } : { other } — blocks
|
|
494
|
+
*/
|
|
495
|
+
export interface ConditionalNode extends BaseNode {
|
|
496
|
+
readonly type: 'Conditional';
|
|
497
|
+
readonly input: ExpressionNode | null;
|
|
498
|
+
readonly condition: BodyNode | null;
|
|
499
|
+
readonly thenBranch: BodyNode;
|
|
500
|
+
readonly elseBranch: BodyNode | ConditionalNode | null;
|
|
501
|
+
}
|
|
502
|
+
export interface WhileLoopNode extends BaseNode {
|
|
503
|
+
readonly type: 'WhileLoop';
|
|
504
|
+
readonly condition: ExpressionNode;
|
|
505
|
+
readonly body: BodyNode;
|
|
506
|
+
}
|
|
507
|
+
export interface DoWhileLoopNode extends BaseNode {
|
|
508
|
+
readonly type: 'DoWhileLoop';
|
|
509
|
+
readonly input: ExpressionNode | null;
|
|
510
|
+
readonly body: BodyNode;
|
|
511
|
+
readonly condition: BodyNode;
|
|
512
|
+
}
|
|
513
|
+
export interface BlockNode extends BaseNode {
|
|
514
|
+
readonly type: 'Block';
|
|
515
|
+
readonly statements: (StatementNode | AnnotatedStatementNode)[];
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Collection operator body types.
|
|
519
|
+
* These are the valid forms for the body of each/map/fold operators.
|
|
520
|
+
*/
|
|
521
|
+
export type IteratorBody = ClosureNode | BlockNode | GroupedExprNode | VariableNode | PostfixExprNode | SpreadNode | HostCallNode;
|
|
522
|
+
/**
|
|
523
|
+
* Each expression: sequential iteration returning list of all results.
|
|
524
|
+
*
|
|
525
|
+
* Syntax forms:
|
|
526
|
+
* collection -> each |x| body
|
|
527
|
+
* collection -> each { body }
|
|
528
|
+
* collection -> each (expr)
|
|
529
|
+
* collection -> each $fn
|
|
530
|
+
* collection -> each $
|
|
531
|
+
*
|
|
532
|
+
* With accumulator:
|
|
533
|
+
* collection -> each(init) { body } -- $@ is accumulator
|
|
534
|
+
* collection -> each |x, acc = init| body -- $acc is accumulator
|
|
535
|
+
*
|
|
536
|
+
* Returns: list of all body results (or scan results if accumulator)
|
|
537
|
+
*/
|
|
538
|
+
export interface EachExprNode extends BaseNode {
|
|
539
|
+
readonly type: 'EachExpr';
|
|
540
|
+
/** The body to execute for each element */
|
|
541
|
+
readonly body: IteratorBody;
|
|
542
|
+
/**
|
|
543
|
+
* Optional accumulator initial value (for block form with $@ access).
|
|
544
|
+
* null when using inline closure with accumulator (it's in the closure params)
|
|
545
|
+
* or when no accumulator is used.
|
|
546
|
+
*/
|
|
547
|
+
readonly accumulator: ExpressionNode | null;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Map expression: parallel iteration returning list of all results.
|
|
551
|
+
*
|
|
552
|
+
* Syntax forms:
|
|
553
|
+
* collection -> map |x| body
|
|
554
|
+
* collection -> map { body }
|
|
555
|
+
* collection -> map (expr)
|
|
556
|
+
* collection -> map $fn
|
|
557
|
+
* collection -> map $
|
|
558
|
+
*
|
|
559
|
+
* No accumulator (parallel execution has no "previous").
|
|
560
|
+
* Concurrency limit via ^(limit: N) annotation.
|
|
561
|
+
*
|
|
562
|
+
* Returns: list of all body results (order preserved)
|
|
563
|
+
*/
|
|
564
|
+
export interface MapExprNode extends BaseNode {
|
|
565
|
+
readonly type: 'MapExpr';
|
|
566
|
+
/** The body to execute for each element (in parallel) */
|
|
567
|
+
readonly body: IteratorBody;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Fold expression: sequential reduction returning final result only.
|
|
571
|
+
*
|
|
572
|
+
* Syntax forms:
|
|
573
|
+
* collection -> fold |x, acc = init| body -- $acc is accumulator
|
|
574
|
+
* collection -> fold(init) { body } -- $@ is accumulator
|
|
575
|
+
* collection -> fold $fn -- fn must have accumulator param
|
|
576
|
+
*
|
|
577
|
+
* Accumulator is required.
|
|
578
|
+
*
|
|
579
|
+
* Returns: final accumulated value only
|
|
580
|
+
*/
|
|
581
|
+
export interface FoldExprNode extends BaseNode {
|
|
582
|
+
readonly type: 'FoldExpr';
|
|
583
|
+
/** The body to execute for each element */
|
|
584
|
+
readonly body: IteratorBody;
|
|
585
|
+
/**
|
|
586
|
+
* Accumulator initial value (for block form with $@ access).
|
|
587
|
+
* null when using inline closure (accumulator is in closure params).
|
|
588
|
+
*/
|
|
589
|
+
readonly accumulator: ExpressionNode | null;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Filter expression: parallel filtering returning elements where predicate is truthy.
|
|
593
|
+
*
|
|
594
|
+
* Syntax forms:
|
|
595
|
+
* collection -> filter |x| body
|
|
596
|
+
* collection -> filter { body }
|
|
597
|
+
* collection -> filter (expr)
|
|
598
|
+
* collection -> filter $fn
|
|
599
|
+
*
|
|
600
|
+
* Predicate returns truthy/falsy. Elements where predicate is truthy are kept.
|
|
601
|
+
*
|
|
602
|
+
* Returns: list of elements where body was truthy
|
|
603
|
+
*/
|
|
604
|
+
export interface FilterExprNode extends BaseNode {
|
|
605
|
+
readonly type: 'FilterExpr';
|
|
606
|
+
/** The predicate body to evaluate for each element */
|
|
607
|
+
readonly body: IteratorBody;
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Sequential spread: $input -> @$closures
|
|
611
|
+
* Chains closures where each receives the previous result.
|
|
612
|
+
*
|
|
613
|
+
* Equivalent to a fold: $input -> [$f, $g, $h] -> @ { $() }
|
|
614
|
+
* - With stored closures: the $ is the current closure, $() invokes it
|
|
615
|
+
* - With inline blocks: $ is the accumulated value directly
|
|
616
|
+
*/
|
|
617
|
+
export interface ClosureChainNode extends BaseNode {
|
|
618
|
+
readonly type: 'ClosureChain';
|
|
619
|
+
readonly target: ExpressionNode;
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Destructure operator: *<...>
|
|
623
|
+
* Extracts elements from tuples/dicts into variables.
|
|
624
|
+
*
|
|
625
|
+
* Tuple: [1, 2, 3] -> *<$a, $b, $c>
|
|
626
|
+
* Dict: [name: "x"] -> *<name: $n>
|
|
627
|
+
* Nested: [[1, 2], 3] -> *<*<$a, $b>, $c>
|
|
628
|
+
*/
|
|
629
|
+
export interface DestructureNode extends BaseNode {
|
|
630
|
+
readonly type: 'Destructure';
|
|
631
|
+
readonly elements: DestructPatternNode[];
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Element in a destructure pattern.
|
|
635
|
+
* Can be: typed variable, key-variable pair, skip placeholder, or nested destructure.
|
|
636
|
+
*/
|
|
637
|
+
export interface DestructPatternNode extends BaseNode {
|
|
638
|
+
readonly type: 'DestructPattern';
|
|
639
|
+
readonly kind: 'variable' | 'keyValue' | 'skip' | 'nested';
|
|
640
|
+
/** Variable name (for 'variable' and 'keyValue' kinds) */
|
|
641
|
+
readonly name: string | null;
|
|
642
|
+
/** Key name (for 'keyValue' kind - dict destructuring) */
|
|
643
|
+
readonly key: string | null;
|
|
644
|
+
/** Type annotation (for 'variable' and 'keyValue' kinds) */
|
|
645
|
+
readonly typeName: RillTypeName | null;
|
|
646
|
+
/** Nested destructure pattern (for 'nested' kind) */
|
|
647
|
+
readonly nested: DestructureNode | null;
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Slice operator: /<start:stop:step>
|
|
651
|
+
* Extracts a portion of a tuple or string using Python-style slicing.
|
|
652
|
+
*
|
|
653
|
+
* Examples:
|
|
654
|
+
* $tuple -> /<0:3> # elements 0, 1, 2
|
|
655
|
+
* $tuple -> /<::-1> # reversed
|
|
656
|
+
* "hello" -> /<1:4> # "ell"
|
|
657
|
+
*/
|
|
658
|
+
export interface SliceNode extends BaseNode {
|
|
659
|
+
readonly type: 'Slice';
|
|
660
|
+
/** Start index (null = from beginning) */
|
|
661
|
+
readonly start: SliceBoundNode | null;
|
|
662
|
+
/** Stop index (null = to end) */
|
|
663
|
+
readonly stop: SliceBoundNode | null;
|
|
664
|
+
/** Step (null = 1) */
|
|
665
|
+
readonly step: SliceBoundNode | null;
|
|
666
|
+
}
|
|
667
|
+
/** A slice bound: number, variable, or grouped expression */
|
|
668
|
+
export type SliceBoundNode = NumberLiteralNode | VariableNode | GroupedExprNode;
|
|
669
|
+
/**
|
|
670
|
+
* Spread operator: *expr or -> *
|
|
671
|
+
* Converts tuple or dict to args type for unpacking at closure invocation.
|
|
672
|
+
*
|
|
673
|
+
* Prefix form: *[1, 2, 3], *$tuple, *[x: 1, y: 2]
|
|
674
|
+
* Pipe target form: [1, 2, 3] -> *
|
|
675
|
+
*
|
|
676
|
+
* Creates an args value that unpacks into separate arguments when passed to a closure.
|
|
677
|
+
*/
|
|
678
|
+
export interface SpreadNode extends BaseNode {
|
|
679
|
+
readonly type: 'Spread';
|
|
680
|
+
/** The expression to spread (null when used as pipe target: -> *) */
|
|
681
|
+
readonly operand: ExpressionNode | null;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Type assertion: expr:type
|
|
685
|
+
* Asserts that the expression evaluates to the specified type.
|
|
686
|
+
* Returns the value unchanged if assertion passes, errors on mismatch.
|
|
687
|
+
*
|
|
688
|
+
* Examples:
|
|
689
|
+
* fetchData():string # assert result is string
|
|
690
|
+
* $val -> :number -> process() # assert pipe value is number
|
|
691
|
+
* "hello":string # "hello" (pass)
|
|
692
|
+
* "hello":number # Error: expected number, got string
|
|
693
|
+
*
|
|
694
|
+
* When operand is null, it acts on the implicit $:
|
|
695
|
+
* :string ≡ $:string
|
|
696
|
+
*/
|
|
697
|
+
export interface TypeAssertionNode extends BaseNode {
|
|
698
|
+
readonly type: 'TypeAssertion';
|
|
699
|
+
/** The expression to assert (null for bare :type which uses $) */
|
|
700
|
+
readonly operand: PostfixExprNode | null;
|
|
701
|
+
/** The expected type */
|
|
702
|
+
readonly typeName: RillTypeName;
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Type check: expr:?type
|
|
706
|
+
* Checks if the expression evaluates to the specified type.
|
|
707
|
+
* Returns true if types match, false otherwise.
|
|
708
|
+
*
|
|
709
|
+
* Examples:
|
|
710
|
+
* fetchData():?string # is result a string?
|
|
711
|
+
* $val -> :?number -> process() # is pipe value a number?
|
|
712
|
+
* "hello":?string # true
|
|
713
|
+
* "hello":?number # false
|
|
714
|
+
*
|
|
715
|
+
* When operand is null, it checks the implicit $:
|
|
716
|
+
* :?string ≡ $:?string
|
|
717
|
+
*/
|
|
718
|
+
export interface TypeCheckNode extends BaseNode {
|
|
719
|
+
readonly type: 'TypeCheck';
|
|
720
|
+
/** The expression to check (null for bare :?type which uses $) */
|
|
721
|
+
readonly operand: PostfixExprNode | null;
|
|
722
|
+
/** The type to check for */
|
|
723
|
+
readonly typeName: RillTypeName;
|
|
724
|
+
}
|
|
725
|
+
export type SimplePrimaryNode = LiteralNode | VariableNode | HostCallNode | MethodCallNode | BlockNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | PostfixExprNode | TypeAssertionNode | TypeCheckNode;
|
|
726
|
+
export type ASTNode = ScriptNode | FrontmatterNode | ClosureNode | ClosureParamNode | StatementNode | CaptureNode | BreakNode | ReturnNode | PipeChainNode | PostfixExprNode | MethodCallNode | InvokeNode | HostCallNode | ClosureCallNode | PipeInvokeNode | VariableNode | ConditionalNode | WhileLoopNode | DoWhileLoopNode | BlockNode | StringLiteralNode | InterpolationNode | NumberLiteralNode | BoolLiteralNode | TupleNode | DictNode | DictEntryNode | BinaryExprNode | UnaryExprNode | GroupedExprNode | ClosureChainNode | DestructureNode | DestructPatternNode | SliceNode | SpreadNode | TypeAssertionNode | TypeCheckNode | AnnotatedStatementNode | NamedArgNode | SpreadArgNode | EachExprNode | MapExprNode | FoldExprNode | FilterExprNode | ErrorNode;
|
|
727
|
+
/**
|
|
728
|
+
* Options for the parser.
|
|
729
|
+
*/
|
|
730
|
+
export interface ParseOptions {
|
|
731
|
+
/**
|
|
732
|
+
* Enable recovery mode for IDE/tooling scenarios.
|
|
733
|
+
* When true, the parser attempts to recover from errors and
|
|
734
|
+
* returns a partial AST with ErrorNode entries instead of throwing.
|
|
735
|
+
* Default: false (throws on first error).
|
|
736
|
+
*/
|
|
737
|
+
readonly recoveryMode?: boolean;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Result of parsing with recovery mode enabled.
|
|
741
|
+
* Contains the AST (which may include ErrorNode entries) and collected errors.
|
|
742
|
+
*/
|
|
743
|
+
export interface ParseResult {
|
|
744
|
+
/** The parsed AST (may contain ErrorNode entries in statements) */
|
|
745
|
+
readonly ast: ScriptNode;
|
|
746
|
+
/** Parse errors collected during recovery (empty if no errors) */
|
|
747
|
+
readonly errors: ParseError[];
|
|
748
|
+
/** True if parsing completed without errors */
|
|
749
|
+
readonly success: boolean;
|
|
750
|
+
}
|
|
751
|
+
export {};
|
|
752
|
+
//# sourceMappingURL=types.d.ts.map
|