@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
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExtractionMixin - Extraction Operators
|
|
3
|
+
*
|
|
4
|
+
* Handles destructure, slice, and spread operations for extracting
|
|
5
|
+
* values from lists and dicts.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import { RILL_ERROR_CODES, RuntimeError } from '../../../../types.js';
|
|
10
|
+
import { createTupleFromDict, createTupleFromList, inferType, } from '../../values.js';
|
|
11
|
+
import { isDict } from '../../callable.js';
|
|
12
|
+
/**
|
|
13
|
+
* ExtractionMixin implementation.
|
|
14
|
+
*
|
|
15
|
+
* Provides extraction operator functionality for destructuring lists/dicts,
|
|
16
|
+
* slicing sequences, and spreading values for argument unpacking.
|
|
17
|
+
*
|
|
18
|
+
* Depends on:
|
|
19
|
+
* - EvaluatorBase: ctx, checkAborted(), getNodeLocation()
|
|
20
|
+
* - evaluateExpression() (from CoreMixin composition)
|
|
21
|
+
* - evaluateVariable() (from VariablesMixin composition)
|
|
22
|
+
* - setVariable() (from VariablesMixin composition)
|
|
23
|
+
*
|
|
24
|
+
* Methods added:
|
|
25
|
+
* - evaluateDestructure(node, input) -> RillValue
|
|
26
|
+
* - evaluateSlice(node, input) -> Promise<RillValue>
|
|
27
|
+
* - evaluateSpread(node) -> Promise<RillTuple>
|
|
28
|
+
*
|
|
29
|
+
* Covers:
|
|
30
|
+
* - IR-26: evaluateDestructure(node, input) -> RillValue
|
|
31
|
+
* - IR-27: evaluateSlice(node, input) -> Promise<RillValue>
|
|
32
|
+
* - IR-28: evaluateSpread(node) -> Promise<RillTuple>
|
|
33
|
+
*
|
|
34
|
+
* Error handling:
|
|
35
|
+
* - EC-13: Destructure/slice on wrong types -> RuntimeError(RUNTIME_TYPE_ERROR)
|
|
36
|
+
* - EC-14: List destructure size mismatch -> RuntimeError
|
|
37
|
+
*/
|
|
38
|
+
function createExtractionMixin(Base) {
|
|
39
|
+
return class ExtractionEvaluator extends Base {
|
|
40
|
+
/**
|
|
41
|
+
* Evaluate destructure operator: *<$a, $b, $c>
|
|
42
|
+
* Extracts values from list or dict into variables.
|
|
43
|
+
*
|
|
44
|
+
* List destructure: [1, 2, 3] -> *<$a, $b, $c> # $a=1, $b=2, $c=3
|
|
45
|
+
* Dict destructure: [x: 1, y: 2] -> *<x: $a, y: $b> # $a=1, $b=2
|
|
46
|
+
*/
|
|
47
|
+
evaluateDestructure(node, input) {
|
|
48
|
+
const isList = Array.isArray(input);
|
|
49
|
+
const isDictInput = isDict(input);
|
|
50
|
+
const firstNonSkip = node.elements.find((e) => e.kind !== 'skip');
|
|
51
|
+
const isKeyPattern = firstNonSkip?.kind === 'keyValue';
|
|
52
|
+
if (isKeyPattern) {
|
|
53
|
+
// Dict destructure pattern
|
|
54
|
+
if (!isDictInput) {
|
|
55
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Key destructure requires dict, got ${isList ? 'list' : typeof input}`, node.span.start);
|
|
56
|
+
}
|
|
57
|
+
for (const elem of node.elements) {
|
|
58
|
+
if (elem.kind === 'skip')
|
|
59
|
+
continue;
|
|
60
|
+
if (elem.kind === 'nested') {
|
|
61
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Nested destructure not supported in dict patterns', elem.span.start);
|
|
62
|
+
}
|
|
63
|
+
if (elem.kind !== 'keyValue' ||
|
|
64
|
+
elem.key === null ||
|
|
65
|
+
elem.name === null) {
|
|
66
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Dict destructure requires key: $var patterns', elem.span.start);
|
|
67
|
+
}
|
|
68
|
+
const dictInput = input;
|
|
69
|
+
if (!(elem.key in dictInput)) {
|
|
70
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Key '${elem.key}' not found in dict`, elem.span.start, { key: elem.key, availableKeys: Object.keys(dictInput) });
|
|
71
|
+
}
|
|
72
|
+
const dictValue = dictInput[elem.key];
|
|
73
|
+
if (dictValue === undefined) {
|
|
74
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Key '${elem.key}' has undefined value`, elem.span.start);
|
|
75
|
+
}
|
|
76
|
+
// Note: setVariable will be available from VariablesMixin
|
|
77
|
+
// which is applied before ExtractionMixin in the composition order
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
|
+
this.setVariable(elem.name, dictValue, elem.typeName ?? undefined, elem.span.start);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// List destructure pattern
|
|
84
|
+
if (!isList) {
|
|
85
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Positional destructure requires list, got ${isDictInput ? 'dict' : typeof input}`, node.span.start);
|
|
86
|
+
}
|
|
87
|
+
const listInput = input;
|
|
88
|
+
if (node.elements.length !== listInput.length) {
|
|
89
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Destructure pattern has ${node.elements.length} elements, list has ${listInput.length}`, node.span.start);
|
|
90
|
+
}
|
|
91
|
+
for (let i = 0; i < node.elements.length; i++) {
|
|
92
|
+
const elem = node.elements[i];
|
|
93
|
+
const value = listInput[i];
|
|
94
|
+
if (elem === undefined || value === undefined) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (elem.kind === 'skip')
|
|
98
|
+
continue;
|
|
99
|
+
if (elem.kind === 'nested' && elem.nested) {
|
|
100
|
+
this.evaluateDestructure(elem.nested, value);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (elem.name === null) {
|
|
104
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Invalid destructure element', elem.span.start);
|
|
105
|
+
}
|
|
106
|
+
// Note: setVariable will be available from VariablesMixin
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
this.setVariable(elem.name, value, elem.typeName ?? undefined, elem.span.start);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return input;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Evaluate slice operator: /<start:stop:step>
|
|
115
|
+
* Extracts a portion of a list or string using Python-style slicing.
|
|
116
|
+
*
|
|
117
|
+
* Examples:
|
|
118
|
+
* [0, 1, 2, 3, 4] -> /<0:3> # [0, 1, 2]
|
|
119
|
+
* [0, 1, 2, 3, 4] -> /<-2:> # [3, 4]
|
|
120
|
+
* [0, 1, 2, 3, 4] -> /<::-1> # [4, 3, 2, 1, 0]
|
|
121
|
+
* "hello" -> /<1:4> # "ell"
|
|
122
|
+
*/
|
|
123
|
+
async evaluateSlice(node, input) {
|
|
124
|
+
const isList = Array.isArray(input);
|
|
125
|
+
const isString = typeof input === 'string';
|
|
126
|
+
if (!isList && !isString) {
|
|
127
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Slice requires list or string, got ${isDict(input) ? 'dict' : typeof input}`, node.span.start);
|
|
128
|
+
}
|
|
129
|
+
const startBound = node.start
|
|
130
|
+
? await this.evaluateSliceBound(node.start)
|
|
131
|
+
: null;
|
|
132
|
+
const stopBound = node.stop
|
|
133
|
+
? await this.evaluateSliceBound(node.stop)
|
|
134
|
+
: null;
|
|
135
|
+
const stepBound = node.step
|
|
136
|
+
? await this.evaluateSliceBound(node.step)
|
|
137
|
+
: null;
|
|
138
|
+
if (isList) {
|
|
139
|
+
return this.applySlice(input, input.length, startBound, stopBound, stepBound);
|
|
140
|
+
}
|
|
141
|
+
return this.applySlice(input, input.length, startBound, stopBound, stepBound);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Evaluate spread operator: *[...] or *[key: value, ...]
|
|
145
|
+
* Creates a tuple from a list or dict for argument unpacking.
|
|
146
|
+
*
|
|
147
|
+
* Examples:
|
|
148
|
+
* *[1, 2, 3] -> $fn() # Calls $fn(1, 2, 3)
|
|
149
|
+
* *[a: 1, b: 2] -> $fn() # Calls $fn with named args
|
|
150
|
+
*/
|
|
151
|
+
async evaluateSpread(node) {
|
|
152
|
+
let value;
|
|
153
|
+
if (node.operand === null) {
|
|
154
|
+
value = this.ctx.pipeValue;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// Note: evaluateExpression will be available from CoreMixin
|
|
158
|
+
// which is applied before ExtractionMixin in the composition order
|
|
159
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
160
|
+
value = await this.evaluateExpression(node.operand);
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(value)) {
|
|
163
|
+
return createTupleFromList(value);
|
|
164
|
+
}
|
|
165
|
+
if (isDict(value)) {
|
|
166
|
+
return createTupleFromDict(value);
|
|
167
|
+
}
|
|
168
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Spread requires list or dict, got ${inferType(value)}`, node.span.start);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Evaluate a slice bound expression (start, stop, or step).
|
|
172
|
+
* Returns the numeric value of the bound.
|
|
173
|
+
*/
|
|
174
|
+
async evaluateSliceBound(bound) {
|
|
175
|
+
if (bound === null) {
|
|
176
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Slice bound is null', undefined);
|
|
177
|
+
}
|
|
178
|
+
switch (bound.type) {
|
|
179
|
+
case 'NumberLiteral':
|
|
180
|
+
return bound.value;
|
|
181
|
+
case 'Variable': {
|
|
182
|
+
// Note: evaluateVariable will be available from VariablesMixin
|
|
183
|
+
// which is applied before ExtractionMixin in the composition order
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
|
+
const value = this.evaluateVariable(bound);
|
|
186
|
+
if (typeof value !== 'number') {
|
|
187
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Slice bound must be number, got ${typeof value}`, bound.span.start);
|
|
188
|
+
}
|
|
189
|
+
return value;
|
|
190
|
+
}
|
|
191
|
+
case 'GroupedExpr': {
|
|
192
|
+
// Note: evaluateGroupedExpr will be available from ExpressionsMixin
|
|
193
|
+
// which is applied after ExtractionMixin, so we need to call evaluateExpression
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
195
|
+
const value = await this.evaluateExpression(bound.expression);
|
|
196
|
+
if (typeof value !== 'number') {
|
|
197
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Slice bound must be number, got ${typeof value}`, bound.span.start);
|
|
198
|
+
}
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Apply Python-style slice to a list or string.
|
|
205
|
+
* Handles negative indices, step values, and edge cases.
|
|
206
|
+
*/
|
|
207
|
+
applySlice(input, len, start, stop, step) {
|
|
208
|
+
const actualStep = step ?? 1;
|
|
209
|
+
if (actualStep === 0) {
|
|
210
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Slice step cannot be zero', undefined);
|
|
211
|
+
}
|
|
212
|
+
const normalizeIndex = (idx, defaultVal, forStep) => {
|
|
213
|
+
if (idx === null)
|
|
214
|
+
return defaultVal;
|
|
215
|
+
let normalized = idx < 0 ? len + idx : idx;
|
|
216
|
+
if (forStep > 0) {
|
|
217
|
+
normalized = Math.max(0, Math.min(len, normalized));
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
normalized = Math.max(-1, Math.min(len - 1, normalized));
|
|
221
|
+
}
|
|
222
|
+
return normalized;
|
|
223
|
+
};
|
|
224
|
+
const actualStart = normalizeIndex(start, actualStep > 0 ? 0 : len - 1, actualStep);
|
|
225
|
+
const actualStop = normalizeIndex(stop, actualStep > 0 ? len : -1, actualStep);
|
|
226
|
+
const indices = [];
|
|
227
|
+
if (actualStep > 0) {
|
|
228
|
+
for (let i = actualStart; i < actualStop; i += actualStep) {
|
|
229
|
+
indices.push(i);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
for (let i = actualStart; i > actualStop; i += actualStep) {
|
|
234
|
+
indices.push(i);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (Array.isArray(input)) {
|
|
238
|
+
return indices.map((i) => input[i]);
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
return indices.map((i) => input[i]).join('');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
// Export with type assertion to work around TS4094 limitation
|
|
247
|
+
// TypeScript can't generate declarations for functions returning classes with protected members
|
|
248
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
249
|
+
export const ExtractionMixin = createExtractionMixin;
|
|
250
|
+
//# sourceMappingURL=extraction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extraction.js","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/extraction.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGtE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,GACV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAS,qBAAqB,CAAC,IAAyC;IACtE,OAAO,MAAM,mBAAoB,SAAQ,IAAI;QAC3C;;;;;;WAMG;QACO,mBAAmB,CAC3B,IAAqB,EACrB,KAAgB;YAEhB,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAElC,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAA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Handles evaluation of literal values including:
|
|
5
|
+
* - String literals with interpolation
|
|
6
|
+
* - Tuple literals
|
|
7
|
+
* - Dict literals with callable binding
|
|
8
|
+
* - Closure creation with late binding
|
|
9
|
+
*
|
|
10
|
+
* Interface requirements (from spec):
|
|
11
|
+
* - evaluateString(node) -> Promise<string>
|
|
12
|
+
* - evaluateTuple(node) -> Promise<RillValue[]>
|
|
13
|
+
* - evaluateDict(node) -> Promise<Record<string, RillValue>>
|
|
14
|
+
* - createClosure(node) -> Promise<ScriptCallable>
|
|
15
|
+
*
|
|
16
|
+
* Error Handling:
|
|
17
|
+
* - String interpolation errors propagate from evaluateExpression() [EC-6]
|
|
18
|
+
* - Dict/tuple evaluation errors propagate from nested expressions [EC-7]
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare const LiteralsMixin: any;
|
|
23
|
+
//# sourceMappingURL=literals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literals.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/literals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAgMH,eAAO,MAAM,aAAa,EAA0B,GAAG,CAAC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiteralsMixin: String, Tuple, Dict, and Closure Evaluation
|
|
3
|
+
*
|
|
4
|
+
* Handles evaluation of literal values including:
|
|
5
|
+
* - String literals with interpolation
|
|
6
|
+
* - Tuple literals
|
|
7
|
+
* - Dict literals with callable binding
|
|
8
|
+
* - Closure creation with late binding
|
|
9
|
+
*
|
|
10
|
+
* Interface requirements (from spec):
|
|
11
|
+
* - evaluateString(node) -> Promise<string>
|
|
12
|
+
* - evaluateTuple(node) -> Promise<RillValue[]>
|
|
13
|
+
* - evaluateDict(node) -> Promise<Record<string, RillValue>>
|
|
14
|
+
* - createClosure(node) -> Promise<ScriptCallable>
|
|
15
|
+
*
|
|
16
|
+
* Error Handling:
|
|
17
|
+
* - String interpolation errors propagate from evaluateExpression() [EC-6]
|
|
18
|
+
* - Dict/tuple evaluation errors propagate from nested expressions [EC-7]
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
import { RuntimeError, RILL_ERROR_CODES } from '../../../../types.js';
|
|
23
|
+
import { formatValue, isReservedMethod } from '../../values.js';
|
|
24
|
+
import { isCallable, } from '../../callable.js';
|
|
25
|
+
/**
|
|
26
|
+
* LiteralsMixin implementation.
|
|
27
|
+
*
|
|
28
|
+
* Provides evaluation of literal values. String literals support interpolation,
|
|
29
|
+
* closures are created with late binding, and dict callables are automatically
|
|
30
|
+
* bound to their containing dict.
|
|
31
|
+
*
|
|
32
|
+
* Depends on:
|
|
33
|
+
* - EvaluatorBase: ctx, checkAborted(), getNodeLocation()
|
|
34
|
+
* - evaluateExpression() (from future CoreMixin composition)
|
|
35
|
+
* - evaluatePrimary() (from future CoreMixin composition)
|
|
36
|
+
*
|
|
37
|
+
* Methods added:
|
|
38
|
+
* - evaluateString(node) -> Promise<string>
|
|
39
|
+
* - evaluateTuple(node) -> Promise<RillValue[]>
|
|
40
|
+
* - evaluateDict(node) -> Promise<Record<string, RillValue>>
|
|
41
|
+
* - createClosure(node) -> Promise<ScriptCallable>
|
|
42
|
+
*/
|
|
43
|
+
function createLiteralsMixin(Base) {
|
|
44
|
+
return class LiteralsEvaluator extends Base {
|
|
45
|
+
/**
|
|
46
|
+
* Evaluate string literal with interpolation.
|
|
47
|
+
* Interpolation expressions are evaluated with the current pipe value preserved.
|
|
48
|
+
*
|
|
49
|
+
* String parts are concatenated with interpolated values formatted via formatValue().
|
|
50
|
+
* Errors from interpolation expression evaluation propagate to caller.
|
|
51
|
+
*/
|
|
52
|
+
async evaluateString(node) {
|
|
53
|
+
let result = '';
|
|
54
|
+
// Save pipeValue since interpolation expressions can modify it
|
|
55
|
+
const savedPipeValue = this.ctx.pipeValue;
|
|
56
|
+
for (const part of node.parts) {
|
|
57
|
+
if (typeof part === 'string') {
|
|
58
|
+
result += part;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// InterpolationNode: evaluate the expression
|
|
62
|
+
// Restore pipeValue before each interpolation so they all see the same value
|
|
63
|
+
this.ctx.pipeValue = savedPipeValue;
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
const value = await this.evaluateExpression(part.expression);
|
|
66
|
+
result += formatValue(value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Restore pipeValue after string evaluation
|
|
70
|
+
this.ctx.pipeValue = savedPipeValue;
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Evaluate tuple literal.
|
|
75
|
+
* Elements are evaluated in order and collected into an array.
|
|
76
|
+
*
|
|
77
|
+
* Errors from element evaluation propagate to caller.
|
|
78
|
+
*/
|
|
79
|
+
async evaluateTuple(node) {
|
|
80
|
+
const elements = [];
|
|
81
|
+
for (const elem of node.elements) {
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
elements.push(await this.evaluateExpression(elem));
|
|
84
|
+
}
|
|
85
|
+
return elements;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Evaluate dict literal.
|
|
89
|
+
* All callables in the dict are bound to the containing dict via boundDict property.
|
|
90
|
+
*
|
|
91
|
+
* Reserved method names (keys, values, entries) cannot be used as dict keys.
|
|
92
|
+
* Errors from value evaluation propagate to caller.
|
|
93
|
+
*/
|
|
94
|
+
async evaluateDict(node) {
|
|
95
|
+
const result = {};
|
|
96
|
+
for (const entry of node.entries) {
|
|
97
|
+
if (isReservedMethod(entry.key)) {
|
|
98
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Cannot use reserved method name '${entry.key}' as dict key`, entry.span.start, { key: entry.key, reservedMethods: ['keys', 'values', 'entries'] });
|
|
99
|
+
}
|
|
100
|
+
if (this.isClosureExpr(entry.value)) {
|
|
101
|
+
// Safe cast: isClosureExpr ensures head is PostfixExpr with Closure primary
|
|
102
|
+
const head = entry.value.head;
|
|
103
|
+
const fnLit = head.primary;
|
|
104
|
+
const closure = await this.createClosure(fnLit);
|
|
105
|
+
result[entry.key] = closure;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
109
|
+
result[entry.key] = await this.evaluateExpression(entry.value);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Bind all callables to the containing dict
|
|
113
|
+
for (const key of Object.keys(result)) {
|
|
114
|
+
const value = result[key];
|
|
115
|
+
if (value !== undefined && isCallable(value)) {
|
|
116
|
+
result[key] = {
|
|
117
|
+
...value,
|
|
118
|
+
boundDict: result,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Create a script callable from a closure node.
|
|
126
|
+
* Closures use late binding - variables are resolved in definingScope when invoked.
|
|
127
|
+
*
|
|
128
|
+
* Default parameter values are evaluated immediately in the current context.
|
|
129
|
+
* Property-style callables (zero params) are auto-invoked on dict access.
|
|
130
|
+
*/
|
|
131
|
+
async createClosure(node) {
|
|
132
|
+
// Store reference to the defining scope for late-bound variable resolution
|
|
133
|
+
const definingScope = this.ctx;
|
|
134
|
+
const params = [];
|
|
135
|
+
for (const param of node.params) {
|
|
136
|
+
let defaultValue = null;
|
|
137
|
+
if (param.defaultValue) {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
+
defaultValue = await this.evaluatePrimary(param.defaultValue);
|
|
140
|
+
}
|
|
141
|
+
params.push({
|
|
142
|
+
name: param.name,
|
|
143
|
+
typeName: param.typeName,
|
|
144
|
+
defaultValue,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
const isProperty = params.length === 0;
|
|
148
|
+
return {
|
|
149
|
+
__type: 'callable',
|
|
150
|
+
kind: 'script',
|
|
151
|
+
params,
|
|
152
|
+
body: node.body,
|
|
153
|
+
definingScope,
|
|
154
|
+
isProperty,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Helper: Check if expression is a bare closure (no pipes, no methods).
|
|
159
|
+
* Used to detect dict entries that should be treated as closures.
|
|
160
|
+
*/
|
|
161
|
+
isClosureExpr(expr) {
|
|
162
|
+
if (expr.type !== 'PipeChain')
|
|
163
|
+
return false;
|
|
164
|
+
const chain = expr;
|
|
165
|
+
if (chain.pipes.length > 0)
|
|
166
|
+
return false;
|
|
167
|
+
if (chain.head.type !== 'PostfixExpr')
|
|
168
|
+
return false;
|
|
169
|
+
const head = chain.head;
|
|
170
|
+
if (head.methods.length > 0)
|
|
171
|
+
return false;
|
|
172
|
+
return head.primary.type === 'Closure';
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
// Export with type assertion to work around TS4094 limitation
|
|
177
|
+
// TypeScript can't generate declarations for functions returning classes with protected members
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
179
|
+
export const LiteralsMixin = createLiteralsMixin;
|
|
180
|
+
//# sourceMappingURL=literals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literals.js","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/literals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAWH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,UAAU,GAGX,MAAM,mBAAmB,CAAC;AAI3B;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,mBAAmB,CAAC,IAAyC;IACpE,OAAO,MAAM,iB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AAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,gGAAgG;AAChG,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAG,mBAA0B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypesMixin: Type Assertions and Checks
|
|
3
|
+
*
|
|
4
|
+
* Handles type assertion (:type) and type check (:?type) operations.
|
|
5
|
+
* Provides runtime type validation with error reporting.
|
|
6
|
+
*
|
|
7
|
+
* Interface requirements (from spec):
|
|
8
|
+
* - assertType(value, expected, location?) -> RillValue
|
|
9
|
+
* - evaluateTypeAssertion(node, input) -> Promise<RillValue>
|
|
10
|
+
* - evaluateTypeCheck(node, input) -> Promise<boolean>
|
|
11
|
+
* - evaluateTypeAssertionPrimary(node) -> Promise<RillValue>
|
|
12
|
+
* - evaluateTypeCheckPrimary(node) -> Promise<boolean>
|
|
13
|
+
*
|
|
14
|
+
* Error Handling:
|
|
15
|
+
* - Type assertion failures throw RuntimeError(RUNTIME_TYPE_ERROR) [EC-24]
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const TypesMixin: any;
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAqIH,eAAO,MAAM,UAAU,EAAuB,GAAG,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypesMixin: Type Assertions and Checks
|
|
3
|
+
*
|
|
4
|
+
* Handles type assertion (:type) and type check (:?type) operations.
|
|
5
|
+
* Provides runtime type validation with error reporting.
|
|
6
|
+
*
|
|
7
|
+
* Interface requirements (from spec):
|
|
8
|
+
* - assertType(value, expected, location?) -> RillValue
|
|
9
|
+
* - evaluateTypeAssertion(node, input) -> Promise<RillValue>
|
|
10
|
+
* - evaluateTypeCheck(node, input) -> Promise<boolean>
|
|
11
|
+
* - evaluateTypeAssertionPrimary(node) -> Promise<RillValue>
|
|
12
|
+
* - evaluateTypeCheckPrimary(node) -> Promise<boolean>
|
|
13
|
+
*
|
|
14
|
+
* Error Handling:
|
|
15
|
+
* - Type assertion failures throw RuntimeError(RUNTIME_TYPE_ERROR) [EC-24]
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
import { RuntimeError, RILL_ERROR_CODES } from '../../../../types.js';
|
|
20
|
+
import { inferType, checkType } from '../../values.js';
|
|
21
|
+
/**
|
|
22
|
+
* TypesMixin implementation.
|
|
23
|
+
*
|
|
24
|
+
* Provides type assertion and type check functionality. Type assertions
|
|
25
|
+
* validate that a value is of the expected type and throw on mismatch.
|
|
26
|
+
* Type checks return boolean results without throwing.
|
|
27
|
+
*
|
|
28
|
+
* Depends on:
|
|
29
|
+
* - EvaluatorBase: ctx, checkAborted(), getNodeLocation()
|
|
30
|
+
* - evaluatePostfixExpr() (from future CoreMixin composition)
|
|
31
|
+
*
|
|
32
|
+
* Methods added:
|
|
33
|
+
* - assertType(value, expected, location?) -> RillValue
|
|
34
|
+
* - evaluateTypeAssertion(node, input) -> Promise<RillValue>
|
|
35
|
+
* - evaluateTypeCheck(node, input) -> Promise<boolean>
|
|
36
|
+
* - evaluateTypeAssertionPrimary(node) -> Promise<RillValue>
|
|
37
|
+
* - evaluateTypeCheckPrimary(node) -> Promise<boolean>
|
|
38
|
+
*/
|
|
39
|
+
function createTypesMixin(Base) {
|
|
40
|
+
return class TypesEvaluator extends Base {
|
|
41
|
+
/**
|
|
42
|
+
* Assert that a value is of the expected type.
|
|
43
|
+
* Returns the value unchanged if assertion passes, throws on mismatch.
|
|
44
|
+
* Exported for use by type assertion evaluation.
|
|
45
|
+
*/
|
|
46
|
+
assertType(value, expected, location) {
|
|
47
|
+
const actual = inferType(value);
|
|
48
|
+
if (actual !== expected) {
|
|
49
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, `Type assertion failed: expected ${expected}, got ${actual}`, location, { expectedType: expected, actualType: actual });
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Evaluate type assertion: expr:type or :type (shorthand for $:type).
|
|
55
|
+
* Returns the value if type matches, throws on mismatch.
|
|
56
|
+
*/
|
|
57
|
+
async evaluateTypeAssertion(node, input) {
|
|
58
|
+
// If operand is null, use the input (pipe value)
|
|
59
|
+
// Otherwise, evaluate the operand
|
|
60
|
+
const value = node.operand
|
|
61
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
await this.evaluatePostfixExpr(node.operand)
|
|
63
|
+
: input;
|
|
64
|
+
return this.assertType(value, node.typeName, node.span.start);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Evaluate type check: expr:?type or :?type (shorthand for $:?type).
|
|
68
|
+
* Returns true if type matches, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
async evaluateTypeCheck(node, input) {
|
|
71
|
+
// If operand is null, use the input (pipe value)
|
|
72
|
+
// Otherwise, evaluate the operand
|
|
73
|
+
const value = node.operand
|
|
74
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
75
|
+
await this.evaluatePostfixExpr(node.operand)
|
|
76
|
+
: input;
|
|
77
|
+
return checkType(value, node.typeName);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Evaluate postfix type assertion: expr:type.
|
|
81
|
+
* The operand is always present (not null) for postfix form.
|
|
82
|
+
*/
|
|
83
|
+
async evaluateTypeAssertionPrimary(node) {
|
|
84
|
+
if (!node.operand) {
|
|
85
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Postfix type assertion requires operand', node.span.start);
|
|
86
|
+
}
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
const value = await this.evaluatePostfixExpr(node.operand);
|
|
89
|
+
return this.evaluateTypeAssertion(node, value);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Evaluate postfix type check: expr:?type.
|
|
93
|
+
* The operand is always present (not null) for postfix form.
|
|
94
|
+
*/
|
|
95
|
+
async evaluateTypeCheckPrimary(node) {
|
|
96
|
+
if (!node.operand) {
|
|
97
|
+
throw new RuntimeError(RILL_ERROR_CODES.RUNTIME_TYPE_ERROR, 'Postfix type check requires operand', node.span.start);
|
|
98
|
+
}
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
+
const value = await this.evaluatePostfixExpr(node.operand);
|
|
101
|
+
return this.evaluateTypeCheck(node, value);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
// Export with type assertion to work around TS4094 limitation
|
|
106
|
+
// TypeScript can't generate declarations for functions returning classes with protected members
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
export const TypesMixin = createTypesMixin;
|
|
109
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAQH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIvD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,gBAAgB,CAAC,IAAyC;IACjE,OAAO,MAAM,cAAe,SAAQ,IAAI;QACtC;;;;WAIG;QACH,UAAU,CACR,KAAgB,EAChB,QAAsB,EACtB,QAAyB;YAEzB,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,MAAM,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MAAM,KAAK,GAAG,MAAO,IAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpE,OAAO,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACjD,CAAC;QAED;;;WAGG;QACH,KAAK,CAAC,wBAAwB,CAAC,IAAmB;YAChD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,MAAM,IAAI,YAAY,CACpB,gBAAgB,CAAC,kBAAkB,EACnC,qCAAqC,EACrC,IAAI,CAAC,IAAI,CAAC,KAAK,CAChB,CAAC;YACJ,CAAC;YACD,8DAA8D;YAC9D,MAAM,KAAK,GAAG,MAAO,IAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpE,OAAO,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC;AAED,8DAA8D;AAC9D,gGAAgG;AAChG,8DAA8D;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAuB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VariablesMixin: Variable Access and Mutation
|
|
3
|
+
*
|
|
4
|
+
* Handles variable access, mutation, and capture operations:
|
|
5
|
+
* - Variable lookup with scope chain traversal
|
|
6
|
+
* - Variable assignment with type checking
|
|
7
|
+
* - Capture syntax (:> $name)
|
|
8
|
+
*
|
|
9
|
+
* LIMITATIONS:
|
|
10
|
+
* - Property access chains ($data.field[0]) require AccessMixin
|
|
11
|
+
* - Existence checks (.?field) require AccessMixin
|
|
12
|
+
* - Default values ($data ?? default) require AccessMixin or ControlFlowMixin
|
|
13
|
+
*
|
|
14
|
+
* Interface requirements (from spec):
|
|
15
|
+
* - setVariable(name, value, explicitType?, location?) -> void
|
|
16
|
+
* - evaluateVariable(node) -> RillValue
|
|
17
|
+
* - evaluateVariableAsync(node) -> Promise<RillValue>
|
|
18
|
+
* - evaluateCapture(node, input) -> RillValue
|
|
19
|
+
*
|
|
20
|
+
* Depends on:
|
|
21
|
+
* - EvaluatorBase: ctx, checkAborted(), getNodeLocation()
|
|
22
|
+
* - context utilities: getVariable, hasVariable
|
|
23
|
+
*
|
|
24
|
+
* Extended by:
|
|
25
|
+
* - AccessMixin: Will add property chain evaluation to evaluateVariableAsync
|
|
26
|
+
*
|
|
27
|
+
* Error Handling:
|
|
28
|
+
* - Undefined variables throw RuntimeError(RUNTIME_UNDEFINED_VARIABLE) [EC-8]
|
|
29
|
+
* - Type mismatches throw RuntimeError(RUNTIME_TYPE_ERROR) [EC-9]
|
|
30
|
+
*
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare const VariablesMixin: any;
|
|
34
|
+
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/core/eval/mixins/variables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AA4UH,eAAO,MAAM,cAAc,EAA2B,GAAG,CAAC"}
|