@rcrsr/rill 0.16.0 → 0.18.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/README.md +37 -21
- package/dist/ast-nodes.d.ts +14 -4
- package/dist/ast-unions.d.ts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -0
- package/dist/error-registry.js +228 -0
- package/dist/ext/crypto/index.d.ts +3 -3
- package/dist/ext/crypto/index.js +62 -59
- package/dist/ext/exec/index.d.ts +3 -3
- package/dist/ext/exec/index.js +15 -9
- package/dist/ext/fetch/index.d.ts +3 -3
- package/dist/ext/fetch/index.js +17 -12
- package/dist/ext/fetch/request.js +1 -1
- package/dist/ext/fs/index.d.ts +3 -3
- package/dist/ext/fs/index.js +256 -266
- package/dist/ext/fs/sandbox.d.ts +18 -0
- package/dist/ext/fs/sandbox.js +33 -0
- package/dist/ext/kv/index.d.ts +3 -3
- package/dist/ext/kv/index.js +198 -196
- package/dist/ext/kv/store.d.ts +1 -1
- package/dist/ext/kv/store.js +2 -1
- package/dist/ext-parse-bridge.d.ts +10 -0
- package/dist/ext-parse-bridge.js +10 -0
- package/dist/generated/introspection-data.d.ts +1 -1
- package/dist/generated/introspection-data.js +385 -296
- package/dist/generated/version-data.d.ts +1 -1
- package/dist/generated/version-data.js +2 -2
- package/dist/highlight-map.js +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -5
- package/dist/lexer/operators.js +1 -0
- package/dist/parser/helpers.js +1 -0
- package/dist/parser/parser-expr.js +44 -5
- package/dist/parser/parser-literals.js +111 -4
- package/dist/parser/parser-shape.js +2 -2
- package/dist/parser/parser-types.js +12 -0
- package/dist/parser/parser-use.js +26 -3
- package/dist/parser/parser.d.ts +2 -0
- package/dist/parser/parser.js +2 -0
- package/dist/runtime/core/callable.d.ts +24 -13
- package/dist/runtime/core/callable.js +71 -38
- package/dist/runtime/core/context.d.ts +2 -13
- package/dist/runtime/core/context.js +80 -79
- package/dist/runtime/core/eval/base.d.ts +2 -2
- package/dist/runtime/core/eval/base.js +2 -0
- package/dist/runtime/core/eval/evaluator.d.ts +1 -1
- package/dist/runtime/core/eval/index.d.ts +3 -3
- package/dist/runtime/core/eval/index.js +11 -0
- package/dist/runtime/core/eval/mixins/closures.js +381 -41
- package/dist/runtime/core/eval/mixins/collections.js +81 -6
- package/dist/runtime/core/eval/mixins/control-flow.js +1 -1
- package/dist/runtime/core/eval/mixins/conversion.js +61 -115
- package/dist/runtime/core/eval/mixins/core.js +17 -4
- package/dist/runtime/core/eval/mixins/expressions.js +36 -27
- package/dist/runtime/core/eval/mixins/extraction.js +2 -3
- package/dist/runtime/core/eval/mixins/list-dispatch.js +1 -1
- package/dist/runtime/core/eval/mixins/literals.js +17 -6
- package/dist/runtime/core/eval/mixins/types.js +73 -54
- package/dist/runtime/core/eval/mixins/variables.js +12 -8
- package/dist/runtime/core/execute.d.ts +1 -1
- package/dist/runtime/core/field-descriptor.d.ts +3 -3
- package/dist/runtime/core/field-descriptor.js +2 -1
- package/dist/runtime/core/introspection.d.ts +2 -2
- package/dist/runtime/core/introspection.js +7 -6
- package/dist/runtime/core/resolvers.d.ts +1 -1
- package/dist/runtime/core/signals.d.ts +6 -1
- package/dist/runtime/core/signals.js +9 -0
- package/dist/runtime/core/types/constructors.d.ts +54 -0
- package/dist/runtime/core/types/constructors.js +201 -0
- package/dist/runtime/core/types/guards.d.ts +42 -0
- package/dist/runtime/core/types/guards.js +88 -0
- package/dist/runtime/core/types/index.d.ts +18 -0
- package/dist/runtime/core/types/index.js +19 -0
- package/dist/runtime/core/types/markers.d.ts +12 -0
- package/dist/runtime/core/types/markers.js +7 -0
- package/dist/runtime/core/types/operations.d.ts +98 -0
- package/dist/runtime/core/types/operations.js +804 -0
- package/dist/runtime/core/types/registrations.d.ts +126 -0
- package/dist/runtime/core/types/registrations.js +751 -0
- package/dist/runtime/core/{types.d.ts → types/runtime.d.ts} +22 -10
- package/dist/runtime/core/types/structures.d.ts +146 -0
- package/dist/runtime/core/types/structures.js +12 -0
- package/dist/runtime/core/values.d.ts +29 -209
- package/dist/runtime/core/values.js +56 -968
- package/dist/runtime/ext/builtins.js +88 -68
- package/dist/runtime/ext/extensions.d.ts +31 -125
- package/dist/runtime/ext/extensions.js +2 -94
- package/dist/runtime/ext/test-context.d.ts +28 -0
- package/dist/runtime/ext/test-context.js +155 -0
- package/dist/runtime/index.d.ts +12 -12
- package/dist/runtime/index.js +13 -5
- package/dist/signature-parser.d.ts +2 -2
- package/dist/signature-parser.js +14 -14
- package/dist/token-types.d.ts +1 -0
- package/dist/token-types.js +1 -0
- package/package.json +1 -1
- /package/dist/runtime/core/{types.js → types/runtime.js} +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test Context Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates a pre-wired RuntimeContext from extension value maps.
|
|
5
|
+
* Designed for testing and lightweight embedding without rill-config.
|
|
6
|
+
*/
|
|
7
|
+
import { parseSource } from '../../ext-parse-bridge.js';
|
|
8
|
+
import { createRuntimeContext } from '../core/context.js';
|
|
9
|
+
import { extResolver } from '../core/resolvers.js';
|
|
10
|
+
import { isCallable } from '../core/callable.js';
|
|
11
|
+
import { formatStructure } from '../core/types/operations.js';
|
|
12
|
+
import { RuntimeError } from '../../types.js';
|
|
13
|
+
// ============================================================
|
|
14
|
+
// ERROR CLASS
|
|
15
|
+
// ============================================================
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when extension binding generation fails.
|
|
18
|
+
* Mirrors the ExtensionBindingError in rill-config for core-only usage.
|
|
19
|
+
*/
|
|
20
|
+
export class ExtensionBindingError extends Error {
|
|
21
|
+
code = 'EXTENSION_BINDING';
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'ExtensionBindingError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// ============================================================
|
|
28
|
+
// BINDING GENERATOR
|
|
29
|
+
// ============================================================
|
|
30
|
+
/**
|
|
31
|
+
* Format a RillParam as a rill source parameter declaration.
|
|
32
|
+
* Produces `name: type` syntax matching the parser's closure annotation grammar.
|
|
33
|
+
*/
|
|
34
|
+
function formatParam(param) {
|
|
35
|
+
const typeName = param.type !== undefined ? formatStructure(param.type) : 'any';
|
|
36
|
+
return `${param.name}: ${typeName}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a RillValue is a plain dict (not a callable, tuple, vector, etc.).
|
|
40
|
+
*/
|
|
41
|
+
function isPlainDict(value) {
|
|
42
|
+
return (typeof value === 'object' &&
|
|
43
|
+
value !== null &&
|
|
44
|
+
!Array.isArray(value) &&
|
|
45
|
+
!isCallable(value) &&
|
|
46
|
+
!('__rill_tuple' in value) &&
|
|
47
|
+
!('__rill_vector' in value) &&
|
|
48
|
+
!('__rill_ordered' in value) &&
|
|
49
|
+
!('__rill_type' in value) &&
|
|
50
|
+
!('__rill_field_descriptor' in value));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate rill source for a nested value tree.
|
|
54
|
+
* Callable leaves produce `use<ext:path>:|params| :returnType`.
|
|
55
|
+
* Dict nodes recurse. All other values produce `use<ext:path>`.
|
|
56
|
+
*/
|
|
57
|
+
function buildNestedSource(value, path, indent) {
|
|
58
|
+
if (isCallable(value)) {
|
|
59
|
+
const c = value;
|
|
60
|
+
const paramStr = c.params.map(formatParam).join(', ');
|
|
61
|
+
const returnSuffix = ` :${formatStructure(c.returnType.structure)}`;
|
|
62
|
+
return `use<ext:${path}>:|${paramStr}|${returnSuffix}`;
|
|
63
|
+
}
|
|
64
|
+
if (isPlainDict(value)) {
|
|
65
|
+
const entries = Object.entries(value);
|
|
66
|
+
if (entries.length === 0)
|
|
67
|
+
return '[:]';
|
|
68
|
+
const childIndent = indent + ' ';
|
|
69
|
+
const parts = entries.map(([key, child]) => {
|
|
70
|
+
const childPath = path.length > 0 ? `${path}.${key}` : key;
|
|
71
|
+
const childSource = buildNestedSource(child, childPath, childIndent);
|
|
72
|
+
return `${childIndent}${key}: ${childSource}`;
|
|
73
|
+
});
|
|
74
|
+
return `[\n${parts.join(',\n')}\n${indent}]`;
|
|
75
|
+
}
|
|
76
|
+
// Scalar, list, tuple, vector: resolve directly via ext resolver
|
|
77
|
+
return `use<ext:${path}>`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Generate rill source bindings from an extension value map.
|
|
81
|
+
* Returns a rill dict literal suitable for use as module:ext source.
|
|
82
|
+
*
|
|
83
|
+
* @throws {ExtensionBindingError} when binding generation fails
|
|
84
|
+
*/
|
|
85
|
+
function buildExtensionBindings(extensions) {
|
|
86
|
+
try {
|
|
87
|
+
const entries = Object.entries(extensions);
|
|
88
|
+
if (entries.length === 0)
|
|
89
|
+
return '[:]';
|
|
90
|
+
const parts = entries.map(([name, value]) => {
|
|
91
|
+
const source = buildNestedSource(value, name, '');
|
|
92
|
+
return ` ${name}: ${source}`;
|
|
93
|
+
});
|
|
94
|
+
return `[\n${parts.join(',\n')}\n]`;
|
|
95
|
+
}
|
|
96
|
+
catch (err) {
|
|
97
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
98
|
+
throw new ExtensionBindingError(`Failed to generate extension bindings: ${reason}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// ============================================================
|
|
102
|
+
// MODULE RESOLVER FOR EXT BINDINGS
|
|
103
|
+
// ============================================================
|
|
104
|
+
/**
|
|
105
|
+
* Create a module resolver that serves generated extension binding source.
|
|
106
|
+
* Handles only the `ext` resource; rejects all other module IDs.
|
|
107
|
+
*/
|
|
108
|
+
function createExtModuleResolver(bindingSource) {
|
|
109
|
+
return (resource) => {
|
|
110
|
+
if (resource === 'ext') {
|
|
111
|
+
return { kind: 'source', text: bindingSource, sourceId: 'module:ext' };
|
|
112
|
+
}
|
|
113
|
+
throw new RuntimeError('RILL-R076', `Unknown module '${resource}'`);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// ============================================================
|
|
117
|
+
// PUBLIC API
|
|
118
|
+
// ============================================================
|
|
119
|
+
/**
|
|
120
|
+
* Create a RuntimeContext pre-wired with extension values.
|
|
121
|
+
* Builds extension bindings, registers ext and module resolvers,
|
|
122
|
+
* and returns a context ready for execute().
|
|
123
|
+
*
|
|
124
|
+
* @throws {TypeError} when an extension value is undefined (EC-9)
|
|
125
|
+
* @throws {ExtensionBindingError} when binding generation fails (EC-10)
|
|
126
|
+
*/
|
|
127
|
+
export function createTestContext(extensions) {
|
|
128
|
+
// EC-9: Validate no undefined extension values
|
|
129
|
+
for (const [name, entry] of Object.entries(extensions)) {
|
|
130
|
+
if (entry.value === undefined) {
|
|
131
|
+
throw new TypeError(`Extension '${name}' has undefined value`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Build ext resolver config: maps extension names to their RillValues
|
|
135
|
+
const extConfig = {};
|
|
136
|
+
for (const [name, entry] of Object.entries(extensions)) {
|
|
137
|
+
extConfig[name] = entry.value;
|
|
138
|
+
}
|
|
139
|
+
// Generate rill source bindings (EC-10: propagates ExtensionBindingError)
|
|
140
|
+
const bindingSource = buildExtensionBindings(extConfig);
|
|
141
|
+
// Create module resolver for ext bindings
|
|
142
|
+
const extModuleResolver = createExtModuleResolver(bindingSource);
|
|
143
|
+
return createRuntimeContext({
|
|
144
|
+
resolvers: {
|
|
145
|
+
ext: extResolver,
|
|
146
|
+
module: extModuleResolver,
|
|
147
|
+
},
|
|
148
|
+
configurations: {
|
|
149
|
+
resolvers: {
|
|
150
|
+
ext: extConfig,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
parseSource,
|
|
154
|
+
});
|
|
155
|
+
}
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -16,25 +16,25 @@
|
|
|
16
16
|
* - ext/: Self-contained extensions
|
|
17
17
|
* - builtins.ts: Built-in functions and methods
|
|
18
18
|
*/
|
|
19
|
-
export type { CaptureEvent, ErrorEvent, ExecutionResult, ExecutionStepper,
|
|
20
|
-
export type { ApplicationCallable, CallableFn, RillCallable, RillFunction, RillParam, RuntimeCallable, ScriptCallable, } from './core/callable.js';
|
|
21
|
-
export { callable, isApplicationCallable, isCallable, isDict, isRuntimeCallable, isScriptCallable, } from './core/callable.js';
|
|
22
|
-
export type {
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
export { anyTypeValue, commonType, createTuple, createVector, formatStructuralType, inferElementType, inferStructuralType, inferType, isRillIterator, isTuple, isTypeValue, isVector, isReservedMethod, paramToFieldDef, rillTypeToTypeValue, RESERVED_DICT_METHODS, structuralTypeEquals, structuralTypeMatches, toNative, } from './core/values.js';
|
|
19
|
+
export type { CaptureEvent, ErrorEvent, ExecutionResult, ExecutionStepper, ExtensionEvent, FieldComparisonCallbacks, FunctionReturnEvent, HostCallEvent, NativeArray, NativePlainObject, NativeValue, ObservabilityCallbacks, ResolverResult, RillFieldDef, RillIterator, RillStream, RillTuple, RillTypeValue, RillValue, RillVector, RuntimeCallbacks, RuntimeContext, RuntimeOptions, SchemeResolver, StepEndEvent, StepResult, StepStartEvent, TypeDefinition, TypeProtocol, TypeStructure, } from './core/types/index.js';
|
|
20
|
+
export type { ApplicationCallable, CallableFn, MarshalOptions, RillCallable, RillFunction, RillParam, RuntimeCallable, ScriptCallable, } from './core/callable.js';
|
|
21
|
+
export { callable, hydrateFieldDefaults, isApplicationCallable, isCallable, isDict, isRuntimeCallable, isScriptCallable, marshalArgs, toCallable, } from './core/callable.js';
|
|
22
|
+
export type { NativeResult } from './core/values.js';
|
|
23
|
+
export { BUILT_IN_TYPES, commonType, compareStructuredFields, copyValue, createOrdered, createRillStream, createTuple, createVector, deepEquals, deserializeValue, formatRillLiteral, formatStructure, formatValue, inferElementType, inferStructure, inferType, isIterator, isRillStream, isStream, isTuple, isTypeValue, isVector, paramToFieldDef, serializeValue, structureEquals, structureMatches, } from './core/types/index.js';
|
|
24
|
+
export { anyTypeValue, isEmpty, isReservedMethod, isTruthy, RESERVED_DICT_METHODS, structureToTypeValue, toNative, } from './core/values.js';
|
|
26
25
|
export { buildFieldDescriptor } from './core/field-descriptor.js';
|
|
27
|
-
export { BreakSignal, ReturnSignal } from './core/signals.js';
|
|
28
|
-
export type {
|
|
29
|
-
export type { ConfigFieldDescriptor, ExtensionConfigSchema, ExtensionFactory, ExtensionManifest, ExtensionResult, FsExtensionContract, HoistedExtension, KvExtensionContract, LlmExtensionContract, VectorExtensionContract, } from './ext/extensions.js';
|
|
26
|
+
export { BreakSignal, ReturnSignal, YieldSignal } from './core/signals.js';
|
|
27
|
+
export type { ConfigFieldDescriptor, ExtensionConfigSchema, ExtensionFactory, ExtensionFactoryResult, ExtensionManifest, FsExtensionContract, KvExtensionContract, } from './ext/extensions.js';
|
|
30
28
|
export type { SchemaEntry } from '../ext/kv/index.js';
|
|
31
|
-
export {
|
|
29
|
+
export { emitExtensionEvent } from './ext/extensions.js';
|
|
32
30
|
export { contextResolver, extResolver, moduleResolver, } from './core/resolvers.js';
|
|
33
|
-
export {
|
|
31
|
+
export { createRuntimeContext } from './core/context.js';
|
|
32
|
+
export { createTestContext, ExtensionBindingError, } from './ext/test-context.js';
|
|
34
33
|
export type { CallFrame } from '../types.js';
|
|
35
34
|
export { getCallStack, pushCallFrame, popCallFrame } from './core/context.js';
|
|
36
35
|
export { createStepper, execute } from './core/execute.js';
|
|
37
36
|
export { invokeCallable } from './core/eval/index.js';
|
|
37
|
+
export { BUILTIN_METHODS } from './ext/builtins.js';
|
|
38
38
|
export type { DocumentationCoverageResult, FunctionMetadata, ParamMetadata, } from './core/introspection.js';
|
|
39
39
|
export { generateManifest, getDocumentationCoverage, getFunctions, getLanguageReference, } from './core/introspection.js';
|
|
40
40
|
export type { VersionInfo } from '../generated/version-data.js';
|
package/dist/runtime/index.js
CHANGED
|
@@ -16,14 +16,17 @@
|
|
|
16
16
|
* - ext/: Self-contained extensions
|
|
17
17
|
* - builtins.ts: Built-in functions and methods
|
|
18
18
|
*/
|
|
19
|
-
export { callable, isApplicationCallable, isCallable, isDict, isRuntimeCallable, isScriptCallable, } from './core/callable.js';
|
|
20
|
-
|
|
19
|
+
export { callable, hydrateFieldDefaults, isApplicationCallable, isCallable, isDict, isRuntimeCallable, isScriptCallable, marshalArgs, toCallable, } from './core/callable.js';
|
|
20
|
+
// Extracted to types/ sub-modules (via barrel)
|
|
21
|
+
export { BUILT_IN_TYPES, commonType, compareStructuredFields, copyValue, createOrdered, createRillStream, createTuple, createVector, deepEquals, deserializeValue, formatRillLiteral, formatStructure, formatValue, inferElementType, inferStructure, inferType, isIterator, isRillStream, isStream, isTuple, isTypeValue, isVector, paramToFieldDef, serializeValue, structureEquals, structureMatches, } from './core/types/index.js';
|
|
22
|
+
// Remain in values.ts
|
|
23
|
+
export { anyTypeValue, isEmpty, isReservedMethod, isTruthy, RESERVED_DICT_METHODS, structureToTypeValue, toNative, } from './core/values.js';
|
|
21
24
|
export { buildFieldDescriptor } from './core/field-descriptor.js';
|
|
22
25
|
// ============================================================
|
|
23
26
|
// CONTROL FLOW SIGNALS
|
|
24
27
|
// ============================================================
|
|
25
|
-
export { BreakSignal, ReturnSignal } from './core/signals.js';
|
|
26
|
-
export {
|
|
28
|
+
export { BreakSignal, ReturnSignal, YieldSignal } from './core/signals.js';
|
|
29
|
+
export { emitExtensionEvent } from './ext/extensions.js';
|
|
27
30
|
// ============================================================
|
|
28
31
|
// BUILT-IN RESOLVERS
|
|
29
32
|
// ============================================================
|
|
@@ -31,7 +34,8 @@ export { contextResolver, extResolver, moduleResolver, } from './core/resolvers.
|
|
|
31
34
|
// ============================================================
|
|
32
35
|
// CONTEXT FACTORY
|
|
33
36
|
// ============================================================
|
|
34
|
-
export {
|
|
37
|
+
export { createRuntimeContext } from './core/context.js';
|
|
38
|
+
export { createTestContext, ExtensionBindingError, } from './ext/test-context.js';
|
|
35
39
|
export { getCallStack, pushCallFrame, popCallFrame } from './core/context.js';
|
|
36
40
|
// ============================================================
|
|
37
41
|
// SCRIPT EXECUTION
|
|
@@ -41,5 +45,9 @@ export { createStepper, execute } from './core/execute.js';
|
|
|
41
45
|
// CALLABLE INVOCATION
|
|
42
46
|
// ============================================================
|
|
43
47
|
export { invokeCallable } from './core/eval/index.js';
|
|
48
|
+
// ============================================================
|
|
49
|
+
// BUILT-IN METHODS
|
|
50
|
+
// ============================================================
|
|
51
|
+
export { BUILTIN_METHODS } from './ext/builtins.js';
|
|
44
52
|
export { generateManifest, getDocumentationCoverage, getFunctions, getLanguageReference, } from './core/introspection.js';
|
|
45
53
|
export { VERSION, VERSION_INFO } from '../generated/version-data.js';
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
* which is NOT in parser/* or lexer/* — boundary preserved.
|
|
13
13
|
*/
|
|
14
14
|
import type { RillParam } from './runtime/core/callable.js';
|
|
15
|
-
import type {
|
|
15
|
+
import type { TypeStructure } from './runtime/core/types/structures.js';
|
|
16
16
|
/**
|
|
17
17
|
* Result of parsing a signature string at registration time.
|
|
18
18
|
*/
|
|
19
19
|
export interface ParsedSignature {
|
|
20
20
|
readonly params: RillParam[];
|
|
21
|
-
readonly returnType:
|
|
21
|
+
readonly returnType: TypeStructure | undefined;
|
|
22
22
|
readonly description: string | undefined;
|
|
23
23
|
}
|
|
24
24
|
/**
|
package/dist/signature-parser.js
CHANGED
|
@@ -15,38 +15,38 @@ import { tokenize } from './lexer/index.js';
|
|
|
15
15
|
import { ParseError, TOKEN_TYPES } from './types.js';
|
|
16
16
|
import { createParserState, advance, check, current, expect, skipNewlines, isAtEnd, parseTypeRef, } from './parser/index.js';
|
|
17
17
|
// ============================================================
|
|
18
|
-
// TypeRef →
|
|
18
|
+
// TypeRef → TypeStructure static conversion
|
|
19
19
|
// ============================================================
|
|
20
20
|
/**
|
|
21
|
-
* Convert a static TypeRef to a
|
|
21
|
+
* Convert a static TypeRef to a TypeStructure.
|
|
22
22
|
*
|
|
23
23
|
* Only handles static refs (type names and unions). Dynamic refs ($var)
|
|
24
24
|
* are not valid in registration-time signatures — they throw Error.
|
|
25
25
|
*
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
|
-
function
|
|
28
|
+
function staticTypeRefToTypeStructure(typeRef, functionName) {
|
|
29
29
|
if (typeRef.kind === 'dynamic') {
|
|
30
30
|
throw new Error(`Invalid signature for function '${functionName}': dynamic type references ($variable) are not allowed in signatures`);
|
|
31
31
|
}
|
|
32
32
|
if (typeRef.kind === 'union') {
|
|
33
33
|
return {
|
|
34
|
-
|
|
35
|
-
members: typeRef.members.map((m) =>
|
|
34
|
+
kind: 'union',
|
|
35
|
+
members: typeRef.members.map((m) => staticTypeRefToTypeStructure(m, functionName)),
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
// static kind
|
|
39
39
|
const { typeName, args } = typeRef;
|
|
40
40
|
if (!args || args.length === 0) {
|
|
41
|
-
return {
|
|
41
|
+
return { kind: typeName };
|
|
42
42
|
}
|
|
43
43
|
// Parameterized types
|
|
44
44
|
if (typeName === 'list') {
|
|
45
45
|
if (args.length === 1 &&
|
|
46
46
|
args[0] !== undefined &&
|
|
47
47
|
args[0].name === undefined) {
|
|
48
|
-
const element =
|
|
49
|
-
return {
|
|
48
|
+
const element = staticTypeRefToTypeStructure(args[0].value, functionName);
|
|
49
|
+
return { kind: 'list', element };
|
|
50
50
|
}
|
|
51
51
|
throw new Error(`Invalid signature for function '${functionName}': list requires exactly one positional type argument`);
|
|
52
52
|
}
|
|
@@ -57,17 +57,17 @@ function staticTypeRefToRillType(typeRef, functionName) {
|
|
|
57
57
|
throw new Error(`Invalid signature for function '${functionName}': dict type arguments must be named (e.g. dict(key: string))`);
|
|
58
58
|
}
|
|
59
59
|
fields[arg.name] = {
|
|
60
|
-
type:
|
|
60
|
+
type: staticTypeRefToTypeStructure(arg.value, functionName),
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
return {
|
|
63
|
+
return { kind: 'dict', fields };
|
|
64
64
|
}
|
|
65
65
|
if (typeName === 'tuple') {
|
|
66
66
|
const elements = args.map((arg) => ({
|
|
67
67
|
...(arg.name !== undefined ? { name: arg.name } : {}),
|
|
68
|
-
type:
|
|
68
|
+
type: staticTypeRefToTypeStructure(arg.value, functionName),
|
|
69
69
|
}));
|
|
70
|
-
return {
|
|
70
|
+
return { kind: 'tuple', elements };
|
|
71
71
|
}
|
|
72
72
|
throw new Error(`Invalid signature for function '${functionName}': type '${typeName}' does not accept type arguments`);
|
|
73
73
|
}
|
|
@@ -205,7 +205,7 @@ function parseSignatureBody(state, functionName) {
|
|
|
205
205
|
advance(state); // consume :
|
|
206
206
|
skipNewlines(state);
|
|
207
207
|
const typeRef = parseTypeRef(state);
|
|
208
|
-
returnType =
|
|
208
|
+
returnType = staticTypeRefToTypeStructure(typeRef, functionName);
|
|
209
209
|
}
|
|
210
210
|
// Step 5: Verify no trailing tokens
|
|
211
211
|
if (!isAtEnd(state)) {
|
|
@@ -244,7 +244,7 @@ function parseSignatureParam(state, functionName) {
|
|
|
244
244
|
advance(state); // consume :
|
|
245
245
|
skipNewlines(state);
|
|
246
246
|
const typeRef = parseTypeRef(state, { allowTrailingPipe: true });
|
|
247
|
-
type =
|
|
247
|
+
type = staticTypeRefToTypeStructure(typeRef, functionName);
|
|
248
248
|
}
|
|
249
249
|
// Optional default value = literal
|
|
250
250
|
let defaultValue = undefined;
|
package/dist/token-types.d.ts
CHANGED
package/dist/token-types.js
CHANGED
package/package.json
CHANGED
|
File without changes
|