@rcrsr/rill 0.15.0 → 0.16.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/dist/ast-nodes.d.ts +2 -13
- package/dist/ast-nodes.js +0 -1
- package/dist/ast-unions.d.ts +0 -1
- package/dist/ast-unions.js +0 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -1
- package/dist/error-classes.d.ts +0 -1
- package/dist/error-classes.js +0 -1
- package/dist/error-formatter.d.ts +0 -1
- package/dist/error-formatter.js +0 -1
- package/dist/error-registry.d.ts +0 -1
- package/dist/error-registry.js +32 -1
- package/dist/ext/crypto/index.d.ts +0 -1
- package/dist/ext/crypto/index.js +5 -6
- package/dist/ext/exec/index.d.ts +0 -1
- package/dist/ext/exec/index.js +3 -4
- package/dist/ext/exec/runner.d.ts +0 -1
- package/dist/ext/exec/runner.js +0 -1
- package/dist/ext/fetch/index.d.ts +0 -1
- package/dist/ext/fetch/index.js +8 -39
- package/dist/ext/fetch/request.d.ts +0 -1
- package/dist/ext/fetch/request.js +0 -1
- package/dist/ext/fs/index.d.ts +0 -1
- package/dist/ext/fs/index.js +26 -27
- package/dist/ext/fs/sandbox.d.ts +0 -1
- package/dist/ext/fs/sandbox.js +0 -1
- package/dist/ext/kv/index.d.ts +0 -1
- package/dist/ext/kv/index.js +19 -20
- package/dist/ext/kv/store.d.ts +0 -1
- package/dist/ext/kv/store.js +0 -1
- package/dist/generated/introspection-data.d.ts +0 -1
- package/dist/generated/introspection-data.js +0 -1
- package/dist/generated/version-data.d.ts +1 -2
- package/dist/generated/version-data.js +2 -3
- package/dist/highlight-map.d.ts +0 -1
- package/dist/highlight-map.js +0 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/lexer/errors.d.ts +0 -1
- package/dist/lexer/errors.js +0 -1
- package/dist/lexer/helpers.d.ts +0 -1
- package/dist/lexer/helpers.js +0 -1
- package/dist/lexer/index.d.ts +0 -1
- package/dist/lexer/index.js +0 -1
- package/dist/lexer/operators.d.ts +0 -1
- package/dist/lexer/operators.js +0 -1
- package/dist/lexer/readers.d.ts +0 -1
- package/dist/lexer/readers.js +0 -1
- package/dist/lexer/state.d.ts +0 -1
- package/dist/lexer/state.js +0 -1
- package/dist/lexer/tokenizer.d.ts +0 -1
- package/dist/lexer/tokenizer.js +0 -1
- package/dist/parser/helpers.d.ts +0 -1
- package/dist/parser/helpers.js +0 -1
- package/dist/parser/index.d.ts +0 -1
- package/dist/parser/index.js +0 -1
- package/dist/parser/parser-collect.d.ts +0 -1
- package/dist/parser/parser-collect.js +0 -1
- package/dist/parser/parser-control.d.ts +0 -1
- package/dist/parser/parser-control.js +0 -1
- package/dist/parser/parser-expr.d.ts +0 -1
- package/dist/parser/parser-expr.js +0 -1
- package/dist/parser/parser-extract.d.ts +0 -1
- package/dist/parser/parser-extract.js +0 -1
- package/dist/parser/parser-functions.d.ts +0 -1
- package/dist/parser/parser-functions.js +0 -1
- package/dist/parser/parser-literals.d.ts +0 -1
- package/dist/parser/parser-literals.js +4 -2
- package/dist/parser/parser-script.d.ts +0 -1
- package/dist/parser/parser-script.js +0 -1
- package/dist/parser/parser-shape.d.ts +2 -3
- package/dist/parser/parser-shape.js +8 -52
- package/dist/parser/parser-types.d.ts +28 -2
- package/dist/parser/parser-types.js +64 -13
- package/dist/parser/parser-use.d.ts +0 -1
- package/dist/parser/parser-use.js +0 -1
- package/dist/parser/parser-variables.d.ts +0 -1
- package/dist/parser/parser-variables.js +0 -1
- package/dist/parser/parser.d.ts +0 -1
- package/dist/parser/parser.js +0 -1
- package/dist/parser/state.d.ts +0 -1
- package/dist/parser/state.js +0 -1
- package/dist/runtime/core/callable.d.ts +40 -13
- package/dist/runtime/core/callable.js +137 -28
- package/dist/runtime/core/context.d.ts +0 -1
- package/dist/runtime/core/context.js +1 -2
- package/dist/runtime/core/equals.d.ts +0 -1
- package/dist/runtime/core/equals.js +35 -3
- package/dist/runtime/core/eval/base.d.ts +0 -1
- package/dist/runtime/core/eval/base.js +0 -1
- package/dist/runtime/core/eval/evaluator.d.ts +0 -1
- package/dist/runtime/core/eval/evaluator.js +0 -1
- package/dist/runtime/core/eval/index.d.ts +0 -1
- package/dist/runtime/core/eval/index.js +0 -1
- package/dist/runtime/core/eval/mixins/annotations.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/annotations.js +0 -1
- package/dist/runtime/core/eval/mixins/closures.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/closures.js +82 -60
- package/dist/runtime/core/eval/mixins/collections.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/collections.js +9 -4
- package/dist/runtime/core/eval/mixins/control-flow.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/control-flow.js +0 -1
- package/dist/runtime/core/eval/mixins/conversion.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/conversion.js +153 -86
- package/dist/runtime/core/eval/mixins/core.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/core.js +0 -1
- package/dist/runtime/core/eval/mixins/expressions.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/expressions.js +0 -1
- package/dist/runtime/core/eval/mixins/extraction.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/extraction.js +8 -9
- package/dist/runtime/core/eval/mixins/list-dispatch.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/list-dispatch.js +0 -1
- package/dist/runtime/core/eval/mixins/literals.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/literals.js +3 -7
- package/dist/runtime/core/eval/mixins/types.d.ts +2 -1
- package/dist/runtime/core/eval/mixins/types.js +222 -242
- package/dist/runtime/core/eval/mixins/use.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/use.js +0 -1
- package/dist/runtime/core/eval/mixins/variables.d.ts +0 -1
- package/dist/runtime/core/eval/mixins/variables.js +6 -7
- package/dist/runtime/core/eval/types.d.ts +0 -1
- package/dist/runtime/core/eval/types.js +0 -1
- package/dist/runtime/core/execute.d.ts +0 -1
- package/dist/runtime/core/execute.js +0 -1
- package/dist/runtime/core/field-descriptor.d.ts +2 -3
- package/dist/runtime/core/field-descriptor.js +0 -1
- package/dist/runtime/core/introspection.d.ts +0 -1
- package/dist/runtime/core/introspection.js +0 -1
- package/dist/runtime/core/resolvers.d.ts +0 -1
- package/dist/runtime/core/resolvers.js +0 -1
- package/dist/runtime/core/signals.d.ts +0 -1
- package/dist/runtime/core/signals.js +0 -1
- package/dist/runtime/core/types.d.ts +0 -1
- package/dist/runtime/core/types.js +0 -1
- package/dist/runtime/core/values.d.ts +59 -26
- package/dist/runtime/core/values.js +289 -77
- package/dist/runtime/ext/builtins.d.ts +0 -1
- package/dist/runtime/ext/builtins.js +43 -17
- package/dist/runtime/ext/extensions.d.ts +0 -1
- package/dist/runtime/ext/extensions.js +0 -1
- package/dist/runtime/index.d.ts +2 -3
- package/dist/runtime/index.js +1 -2
- package/dist/signature-parser.d.ts +0 -1
- package/dist/signature-parser.js +8 -6
- package/dist/source-location.d.ts +0 -1
- package/dist/source-location.js +0 -1
- package/dist/token-types.d.ts +0 -1
- package/dist/token-types.js +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -1
- package/dist/value-types.d.ts +15 -12
- package/dist/value-types.js +0 -1
- package/package.json +2 -1
- package/dist/ast-nodes.d.ts.map +0 -1
- package/dist/ast-nodes.js.map +0 -1
- package/dist/ast-unions.d.ts.map +0 -1
- package/dist/ast-unions.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/error-classes.d.ts.map +0 -1
- package/dist/error-classes.js.map +0 -1
- package/dist/error-formatter.d.ts.map +0 -1
- package/dist/error-formatter.js.map +0 -1
- package/dist/error-registry.d.ts.map +0 -1
- package/dist/error-registry.js.map +0 -1
- package/dist/ext/crypto/index.d.ts.map +0 -1
- package/dist/ext/crypto/index.js.map +0 -1
- package/dist/ext/exec/index.d.ts.map +0 -1
- package/dist/ext/exec/index.js.map +0 -1
- package/dist/ext/exec/runner.d.ts.map +0 -1
- package/dist/ext/exec/runner.js.map +0 -1
- package/dist/ext/fetch/index.d.ts.map +0 -1
- package/dist/ext/fetch/index.js.map +0 -1
- package/dist/ext/fetch/request.d.ts.map +0 -1
- package/dist/ext/fetch/request.js.map +0 -1
- package/dist/ext/fs/index.d.ts.map +0 -1
- package/dist/ext/fs/index.js.map +0 -1
- package/dist/ext/fs/sandbox.d.ts.map +0 -1
- package/dist/ext/fs/sandbox.js.map +0 -1
- package/dist/ext/kv/index.d.ts.map +0 -1
- package/dist/ext/kv/index.js.map +0 -1
- package/dist/ext/kv/store.d.ts.map +0 -1
- package/dist/ext/kv/store.js.map +0 -1
- package/dist/generated/introspection-data.d.ts.map +0 -1
- package/dist/generated/introspection-data.js.map +0 -1
- package/dist/generated/version-data.d.ts.map +0 -1
- package/dist/generated/version-data.js.map +0 -1
- package/dist/highlight-map.d.ts.map +0 -1
- package/dist/highlight-map.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lexer/errors.d.ts.map +0 -1
- package/dist/lexer/errors.js.map +0 -1
- package/dist/lexer/helpers.d.ts.map +0 -1
- package/dist/lexer/helpers.js.map +0 -1
- package/dist/lexer/index.d.ts.map +0 -1
- package/dist/lexer/index.js.map +0 -1
- package/dist/lexer/operators.d.ts.map +0 -1
- package/dist/lexer/operators.js.map +0 -1
- package/dist/lexer/readers.d.ts.map +0 -1
- package/dist/lexer/readers.js.map +0 -1
- package/dist/lexer/state.d.ts.map +0 -1
- package/dist/lexer/state.js.map +0 -1
- package/dist/lexer/tokenizer.d.ts.map +0 -1
- package/dist/lexer/tokenizer.js.map +0 -1
- package/dist/parser/helpers.d.ts.map +0 -1
- package/dist/parser/helpers.js.map +0 -1
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/parser/index.js.map +0 -1
- package/dist/parser/parser-collect.d.ts.map +0 -1
- package/dist/parser/parser-collect.js.map +0 -1
- package/dist/parser/parser-control.d.ts.map +0 -1
- package/dist/parser/parser-control.js.map +0 -1
- package/dist/parser/parser-expr.d.ts.map +0 -1
- package/dist/parser/parser-expr.js.map +0 -1
- package/dist/parser/parser-extract.d.ts.map +0 -1
- package/dist/parser/parser-extract.js.map +0 -1
- package/dist/parser/parser-functions.d.ts.map +0 -1
- package/dist/parser/parser-functions.js.map +0 -1
- package/dist/parser/parser-literals.d.ts.map +0 -1
- package/dist/parser/parser-literals.js.map +0 -1
- package/dist/parser/parser-script.d.ts.map +0 -1
- package/dist/parser/parser-script.js.map +0 -1
- package/dist/parser/parser-shape.d.ts.map +0 -1
- package/dist/parser/parser-shape.js.map +0 -1
- package/dist/parser/parser-types.d.ts.map +0 -1
- package/dist/parser/parser-types.js.map +0 -1
- package/dist/parser/parser-use.d.ts.map +0 -1
- package/dist/parser/parser-use.js.map +0 -1
- package/dist/parser/parser-variables.d.ts.map +0 -1
- package/dist/parser/parser-variables.js.map +0 -1
- package/dist/parser/parser.d.ts.map +0 -1
- package/dist/parser/parser.js.map +0 -1
- package/dist/parser/state.d.ts.map +0 -1
- package/dist/parser/state.js.map +0 -1
- package/dist/runtime/core/callable.d.ts.map +0 -1
- package/dist/runtime/core/callable.js.map +0 -1
- package/dist/runtime/core/context.d.ts.map +0 -1
- package/dist/runtime/core/context.js.map +0 -1
- package/dist/runtime/core/equals.d.ts.map +0 -1
- package/dist/runtime/core/equals.js.map +0 -1
- package/dist/runtime/core/eval/base.d.ts.map +0 -1
- package/dist/runtime/core/eval/base.js.map +0 -1
- package/dist/runtime/core/eval/evaluator.d.ts.map +0 -1
- package/dist/runtime/core/eval/evaluator.js.map +0 -1
- package/dist/runtime/core/eval/index.d.ts.map +0 -1
- package/dist/runtime/core/eval/index.js.map +0 -1
- package/dist/runtime/core/eval/mixins/annotations.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/annotations.js.map +0 -1
- package/dist/runtime/core/eval/mixins/closures.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/closures.js.map +0 -1
- package/dist/runtime/core/eval/mixins/collections.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/collections.js.map +0 -1
- package/dist/runtime/core/eval/mixins/control-flow.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/control-flow.js.map +0 -1
- package/dist/runtime/core/eval/mixins/conversion.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/conversion.js.map +0 -1
- package/dist/runtime/core/eval/mixins/core.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/core.js.map +0 -1
- package/dist/runtime/core/eval/mixins/expressions.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/expressions.js.map +0 -1
- package/dist/runtime/core/eval/mixins/extraction.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/extraction.js.map +0 -1
- package/dist/runtime/core/eval/mixins/list-dispatch.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/list-dispatch.js.map +0 -1
- package/dist/runtime/core/eval/mixins/literals.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/literals.js.map +0 -1
- package/dist/runtime/core/eval/mixins/types.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/types.js.map +0 -1
- package/dist/runtime/core/eval/mixins/use.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/use.js.map +0 -1
- package/dist/runtime/core/eval/mixins/variables.d.ts.map +0 -1
- package/dist/runtime/core/eval/mixins/variables.js.map +0 -1
- package/dist/runtime/core/eval/types.d.ts.map +0 -1
- package/dist/runtime/core/eval/types.js.map +0 -1
- package/dist/runtime/core/execute.d.ts.map +0 -1
- package/dist/runtime/core/execute.js.map +0 -1
- package/dist/runtime/core/field-descriptor.d.ts.map +0 -1
- package/dist/runtime/core/field-descriptor.js.map +0 -1
- package/dist/runtime/core/introspection.d.ts.map +0 -1
- package/dist/runtime/core/introspection.js.map +0 -1
- package/dist/runtime/core/resolvers.d.ts.map +0 -1
- package/dist/runtime/core/resolvers.js.map +0 -1
- package/dist/runtime/core/signals.d.ts.map +0 -1
- package/dist/runtime/core/signals.js.map +0 -1
- package/dist/runtime/core/types.d.ts.map +0 -1
- package/dist/runtime/core/types.js.map +0 -1
- package/dist/runtime/core/values.d.ts.map +0 -1
- package/dist/runtime/core/values.js.map +0 -1
- package/dist/runtime/ext/builtins.d.ts.map +0 -1
- package/dist/runtime/ext/builtins.js.map +0 -1
- package/dist/runtime/ext/extensions.d.ts.map +0 -1
- package/dist/runtime/ext/extensions.js.map +0 -1
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js.map +0 -1
- package/dist/signature-parser.d.ts.map +0 -1
- package/dist/signature-parser.js.map +0 -1
- package/dist/source-location.d.ts.map +0 -1
- package/dist/source-location.js.map +0 -1
- package/dist/token-types.d.ts.map +0 -1
- package/dist/token-types.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/value-types.d.ts.map +0 -1
- package/dist/value-types.js.map +0 -1
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
import { TOKEN_TYPES, ParseError, } from '../types.js';
|
|
8
|
-
import { check, advance, expect, current, peek, } from './state.js';
|
|
8
|
+
import { check, advance, expect, current, peek, skipNewlines, } from './state.js';
|
|
9
9
|
import { VALID_TYPE_NAMES, parseTypeName } from './helpers.js';
|
|
10
10
|
/**
|
|
11
11
|
* Parse a type reference from the current position in the token stream.
|
|
@@ -33,7 +33,7 @@ import { VALID_TYPE_NAMES, parseTypeName } from './helpers.js';
|
|
|
33
33
|
* @internal
|
|
34
34
|
*/
|
|
35
35
|
export function parseTypeRef(state, opts) {
|
|
36
|
-
const first = parseSingleType(state);
|
|
36
|
+
const first = parseSingleType(state, opts);
|
|
37
37
|
// Union accumulation: collect additional members after each "|"
|
|
38
38
|
if (!check(state, TOKEN_TYPES.PIPE_BAR)) {
|
|
39
39
|
return first;
|
|
@@ -75,7 +75,7 @@ export function parseTypeRef(state, opts) {
|
|
|
75
75
|
throw new ParseError('RILL-P011', "Expected type name after '|'", current(state).span.start);
|
|
76
76
|
}
|
|
77
77
|
advance(state); // consume "|"
|
|
78
|
-
const next = parseSingleType(state);
|
|
78
|
+
const next = parseSingleType(state, opts);
|
|
79
79
|
// Flatten nested unions
|
|
80
80
|
if (next.kind === 'union') {
|
|
81
81
|
members.push(...next.members);
|
|
@@ -97,7 +97,7 @@ export function parseTypeRef(state, opts) {
|
|
|
97
97
|
* Grammar: `single-type = "$" identifier | type-name [ "(" type-ref-arg-list ")" ]`
|
|
98
98
|
* @internal
|
|
99
99
|
*/
|
|
100
|
-
function parseSingleType(state) {
|
|
100
|
+
function parseSingleType(state, opts) {
|
|
101
101
|
if (check(state, TOKEN_TYPES.DOLLAR)) {
|
|
102
102
|
advance(state); // consume $
|
|
103
103
|
const nameToken = expect(state, TOKEN_TYPES.IDENTIFIER, 'Expected variable name after $');
|
|
@@ -109,7 +109,39 @@ function parseSingleType(state) {
|
|
|
109
109
|
return { kind: 'static', typeName };
|
|
110
110
|
}
|
|
111
111
|
advance(state); // consume "("
|
|
112
|
+
const args = parseFieldArgList(state, opts?.parseLiteral ? { parseLiteral: opts.parseLiteral } : undefined);
|
|
113
|
+
advance(state); // consume ")"
|
|
114
|
+
return { kind: 'static', typeName, args };
|
|
115
|
+
}
|
|
116
|
+
// ============================================================
|
|
117
|
+
// FIELD ARG LIST PARSING
|
|
118
|
+
// ============================================================
|
|
119
|
+
/**
|
|
120
|
+
* Parse a comma-separated list of field arguments between `(` and `)`.
|
|
121
|
+
*
|
|
122
|
+
* Caller has already consumed the opening `(`. This function parses zero
|
|
123
|
+
* or more arguments up to the closing `)` but does NOT consume it.
|
|
124
|
+
*
|
|
125
|
+
* Supports:
|
|
126
|
+
* - Named args: `name: type` → `{ name, value }`
|
|
127
|
+
* - Positional args: `type` → `{ value }`
|
|
128
|
+
* - Default values: `= literal` → `{ ..., defaultValue }` (when parseLiteral provided)
|
|
129
|
+
* - Union types in value position via `parseTypeRef`
|
|
130
|
+
* - Trailing commas before `)`
|
|
131
|
+
*
|
|
132
|
+
* Named arg detection: IDENTIFIER followed by COLON lookahead.
|
|
133
|
+
*
|
|
134
|
+
* @param state - Parser state (positioned after opening paren)
|
|
135
|
+
* @param opts - Optional parseLiteral callback for default value support
|
|
136
|
+
*
|
|
137
|
+
* @throws ParseError RILL-P014 if token after arg is not `,` or `)` (EC-1)
|
|
138
|
+
* @throws ParseError RILL-P014 if missing closing `)` (EC-2)
|
|
139
|
+
*
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export function parseFieldArgList(state, opts) {
|
|
112
143
|
const args = [];
|
|
144
|
+
skipNewlines(state);
|
|
113
145
|
// Parse arg list: allow empty "()" and trailing commas
|
|
114
146
|
while (!check(state, TOKEN_TYPES.RPAREN)) {
|
|
115
147
|
// Check for named arg: identifier ":" type-ref
|
|
@@ -120,28 +152,47 @@ function parseSingleType(state) {
|
|
|
120
152
|
const name = tok.value;
|
|
121
153
|
advance(state); // consume identifier
|
|
122
154
|
advance(state); // consume ":"
|
|
123
|
-
|
|
124
|
-
|
|
155
|
+
skipNewlines(state);
|
|
156
|
+
const typeRefOpts = opts?.parseLiteral
|
|
157
|
+
? { parseLiteral: opts.parseLiteral }
|
|
158
|
+
: undefined;
|
|
159
|
+
const value = parseTypeRef(state, typeRefOpts);
|
|
160
|
+
const arg = { name, value };
|
|
161
|
+
if (opts?.parseLiteral && check(state, TOKEN_TYPES.ASSIGN)) {
|
|
162
|
+
advance(state); // consume =
|
|
163
|
+
skipNewlines(state);
|
|
164
|
+
arg.defaultValue = opts.parseLiteral();
|
|
165
|
+
}
|
|
166
|
+
args.push(arg);
|
|
125
167
|
}
|
|
126
168
|
else {
|
|
127
169
|
// Positional arg: type-ref
|
|
128
|
-
const
|
|
129
|
-
|
|
170
|
+
const typeRefOpts = opts?.parseLiteral
|
|
171
|
+
? { parseLiteral: opts.parseLiteral }
|
|
172
|
+
: undefined;
|
|
173
|
+
const value = parseTypeRef(state, typeRefOpts);
|
|
174
|
+
const arg = { value };
|
|
175
|
+
if (opts?.parseLiteral && check(state, TOKEN_TYPES.ASSIGN)) {
|
|
176
|
+
advance(state); // consume =
|
|
177
|
+
skipNewlines(state);
|
|
178
|
+
arg.defaultValue = opts.parseLiteral();
|
|
179
|
+
}
|
|
180
|
+
args.push(arg);
|
|
130
181
|
}
|
|
182
|
+
skipNewlines(state);
|
|
131
183
|
// Consume trailing or separating comma
|
|
132
184
|
if (check(state, TOKEN_TYPES.COMMA)) {
|
|
133
185
|
advance(state);
|
|
186
|
+
skipNewlines(state);
|
|
134
187
|
}
|
|
135
188
|
else if (!check(state, TOKEN_TYPES.RPAREN)) {
|
|
136
|
-
// Neither comma nor closing paren — malformed arg list (EC-
|
|
189
|
+
// Neither comma nor closing paren — malformed arg list (EC-1)
|
|
137
190
|
throw new ParseError('RILL-P014', "Expected ',' or ')' in type argument list", current(state).span.start);
|
|
138
191
|
}
|
|
139
192
|
}
|
|
140
|
-
//
|
|
193
|
+
// Verify closing ")" is present (EC-2)
|
|
141
194
|
if (!check(state, TOKEN_TYPES.RPAREN)) {
|
|
142
195
|
throw new ParseError('RILL-P014', "Expected ')' to close type argument list", current(state).span.start);
|
|
143
196
|
}
|
|
144
|
-
|
|
145
|
-
return { kind: 'static', typeName, args };
|
|
197
|
+
return args;
|
|
146
198
|
}
|
|
147
|
-
//# sourceMappingURL=parser-types.js.map
|
package/dist/parser/parser.d.ts
CHANGED
package/dist/parser/parser.js
CHANGED
package/dist/parser/state.d.ts
CHANGED
|
@@ -43,4 +43,3 @@ export declare function skipNewlines(state: ParserState): void;
|
|
|
43
43
|
export declare function skipNewlinesIfFollowedBy(state: ParserState, tokenType: string): boolean;
|
|
44
44
|
/** @internal */
|
|
45
45
|
export declare function makeSpan(start: SourceLocation, end: SourceLocation): SourceSpan;
|
|
46
|
-
//# sourceMappingURL=state.d.ts.map
|
package/dist/parser/state.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* [ASSUMPTION] validateDefaultValueType _functionName Parameter
|
|
19
19
|
* - Parameter accepted but unused (prefixed with _ to satisfy eslint)
|
|
20
|
-
* - Kept for API consistency with
|
|
20
|
+
* - Kept for API consistency with marshalArgs signature
|
|
21
21
|
*/
|
|
22
22
|
import type { BodyNode, SourceLocation } from '../../types.js';
|
|
23
23
|
import type { RillType, RillTypeValue, RillValue } from './values.js';
|
|
@@ -31,7 +31,7 @@ interface RuntimeContextLike {
|
|
|
31
31
|
* Callable function signature.
|
|
32
32
|
* Used for both host-provided functions and runtime callables.
|
|
33
33
|
*/
|
|
34
|
-
export type CallableFn = (args:
|
|
34
|
+
export type CallableFn = (args: Record<string, RillValue>, ctx: RuntimeContextLike, location?: SourceLocation) => RillValue | Promise<RillValue>;
|
|
35
35
|
/**
|
|
36
36
|
* Unified parameter definition for all callable types (script closures and host functions).
|
|
37
37
|
*
|
|
@@ -154,19 +154,46 @@ export declare function paramsToStructuralType(params: readonly RillParam[]): Ri
|
|
|
154
154
|
*/
|
|
155
155
|
export declare function validateDefaultValueType(param: RillParam, _functionName: string): void;
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* Options for marshalArgs error reporting.
|
|
158
|
+
*/
|
|
159
|
+
export interface MarshalOptions {
|
|
160
|
+
/** Function name included in error messages */
|
|
161
|
+
readonly functionName: string;
|
|
162
|
+
/** Source location for error reporting */
|
|
163
|
+
readonly location: SourceLocation | undefined;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Hydrate missing dict/ordered field-level defaults into a value.
|
|
167
|
+
*
|
|
168
|
+
* When a param has type `dict(a: string = "x", b: number)` and the caller
|
|
169
|
+
* passes `[b: 2]`, this fills in `a` with its default `"x"`. Fields without
|
|
170
|
+
* defaults are left absent so Stage 3 catches them with RILL-R001.
|
|
171
|
+
*
|
|
172
|
+
* Pure function: no class context, no evaluator, no side effects.
|
|
173
|
+
*/
|
|
174
|
+
export declare function hydrateFieldDefaults(value: RillValue, type: RillType): RillValue;
|
|
175
|
+
/**
|
|
176
|
+
* Unified marshaling entry point for all 3 invocation paths.
|
|
177
|
+
*
|
|
178
|
+
* Builds a named argument map from positional args, hydrates defaults,
|
|
179
|
+
* type-checks each field, and returns a Record<string, RillValue>.
|
|
180
|
+
*
|
|
181
|
+
* Stages:
|
|
182
|
+
* 1. Excess args check (RILL-R045)
|
|
183
|
+
* 2. Default hydration + missing required check (RILL-R044)
|
|
184
|
+
* 2.5. Dict/ordered field-level default hydration
|
|
185
|
+
* 3. Type check per field (RILL-R001)
|
|
158
186
|
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
187
|
+
* Preconditions (enforced by caller):
|
|
188
|
+
* - args contains already-evaluated RillValue[]
|
|
189
|
+
* - pipe value already inserted as first element by caller
|
|
190
|
+
* - boundDict already prepended as first element by caller
|
|
191
|
+
* - params is defined (caller skips marshalArgs for untyped callables)
|
|
163
192
|
*
|
|
164
|
-
* @param args -
|
|
193
|
+
* @param args - Positional arguments (already evaluated)
|
|
165
194
|
* @param params - Parameter definitions
|
|
166
|
-
* @param
|
|
167
|
-
* @
|
|
168
|
-
* @throws RuntimeError with RILL-R001 on validation failure
|
|
195
|
+
* @param options - Error context: functionName and location
|
|
196
|
+
* @returns Named argument map keyed by param name
|
|
169
197
|
*/
|
|
170
|
-
export declare function
|
|
198
|
+
export declare function marshalArgs(args: RillValue[], params: readonly RillParam[], options?: MarshalOptions): Record<string, RillValue>;
|
|
171
199
|
export {};
|
|
172
|
-
//# sourceMappingURL=callable.d.ts.map
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
*
|
|
18
18
|
* [ASSUMPTION] validateDefaultValueType _functionName Parameter
|
|
19
19
|
* - Parameter accepted but unused (prefixed with _ to satisfy eslint)
|
|
20
|
-
* - Kept for API consistency with
|
|
20
|
+
* - Kept for API consistency with marshalArgs signature
|
|
21
21
|
*/
|
|
22
22
|
import { RuntimeError } from '../../types.js';
|
|
23
23
|
import { astEquals } from './equals.js';
|
|
24
|
-
import { formatValue, formatStructuralType, inferType, isTuple,
|
|
24
|
+
import { formatValue, formatStructuralType, inferType, isOrdered, createOrdered, deepCopyRillValue, isTuple, paramToFieldDef, structuralTypeEquals, structuralTypeMatches, anyTypeValue, hasCollectionFields, emptyForType, } from './values.js';
|
|
25
25
|
/** Type guard for any callable */
|
|
26
26
|
export function isCallable(value) {
|
|
27
27
|
return (typeof value === 'object' &&
|
|
@@ -159,7 +159,7 @@ export function callableEquals(a, b, valueEquals = (x, y) => formatValue(x) ===
|
|
|
159
159
|
* @returns Frozen RillType with closure variant
|
|
160
160
|
*/
|
|
161
161
|
export function paramsToStructuralType(params) {
|
|
162
|
-
const closureParams = params.map((param) =>
|
|
162
|
+
const closureParams = params.map((param) => paramToFieldDef(param.name, param.type ?? { type: 'any' }, param.defaultValue));
|
|
163
163
|
return Object.freeze({
|
|
164
164
|
type: 'closure',
|
|
165
165
|
params: closureParams,
|
|
@@ -189,54 +189,162 @@ export function validateDefaultValueType(param, _functionName) {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
/**
|
|
192
|
-
*
|
|
192
|
+
* Hydrate missing dict/ordered field-level defaults into a value.
|
|
193
193
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* Applies defaultValue in-place on the args array before validation.
|
|
194
|
+
* When a param has type `dict(a: string = "x", b: number)` and the caller
|
|
195
|
+
* passes `[b: 2]`, this fills in `a` with its default `"x"`. Fields without
|
|
196
|
+
* defaults are left absent so Stage 3 catches them with RILL-R001.
|
|
198
197
|
*
|
|
199
|
-
*
|
|
198
|
+
* Pure function: no class context, no evaluator, no side effects.
|
|
199
|
+
*/
|
|
200
|
+
export function hydrateFieldDefaults(value, type) {
|
|
201
|
+
if (type.type === 'dict' && type.fields && isDict(value)) {
|
|
202
|
+
const dictValue = value;
|
|
203
|
+
// Seed with all input entries so extra keys survive (structural match allows extras)
|
|
204
|
+
const result = { ...dictValue };
|
|
205
|
+
for (const [fieldName, fieldDef] of Object.entries(type.fields)) {
|
|
206
|
+
if (fieldName in dictValue) {
|
|
207
|
+
result[fieldName] = hydrateFieldDefaults(dictValue[fieldName], fieldDef.type);
|
|
208
|
+
}
|
|
209
|
+
else if (fieldDef.defaultValue !== undefined) {
|
|
210
|
+
result[fieldName] = hydrateFieldDefaults(deepCopyRillValue(fieldDef.defaultValue), fieldDef.type);
|
|
211
|
+
}
|
|
212
|
+
else if (hasCollectionFields(fieldDef.type)) {
|
|
213
|
+
result[fieldName] = hydrateFieldDefaults(emptyForType(fieldDef.type), fieldDef.type);
|
|
214
|
+
}
|
|
215
|
+
// Missing without default and not collection: leave absent for Stage 3
|
|
216
|
+
}
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
if (type.type === 'ordered' && type.fields && isOrdered(value)) {
|
|
220
|
+
const lookup = new Map(value.entries.map(([k, v]) => [k, v]));
|
|
221
|
+
const fieldNames = new Set(type.fields.map((f) => f.name ?? ''));
|
|
222
|
+
const resultEntries = [];
|
|
223
|
+
for (const field of type.fields) {
|
|
224
|
+
const name = field.name ?? '';
|
|
225
|
+
if (lookup.has(name)) {
|
|
226
|
+
resultEntries.push([
|
|
227
|
+
name,
|
|
228
|
+
hydrateFieldDefaults(lookup.get(name), field.type),
|
|
229
|
+
]);
|
|
230
|
+
}
|
|
231
|
+
else if (field.defaultValue !== undefined) {
|
|
232
|
+
resultEntries.push([
|
|
233
|
+
name,
|
|
234
|
+
hydrateFieldDefaults(deepCopyRillValue(field.defaultValue), field.type),
|
|
235
|
+
]);
|
|
236
|
+
}
|
|
237
|
+
else if (hasCollectionFields(field.type)) {
|
|
238
|
+
resultEntries.push([
|
|
239
|
+
name,
|
|
240
|
+
hydrateFieldDefaults(emptyForType(field.type), field.type),
|
|
241
|
+
]);
|
|
242
|
+
}
|
|
243
|
+
// Missing without default and not collection: leave absent for Stage 3
|
|
244
|
+
}
|
|
245
|
+
// Append extra entries not declared in type.fields (structural match allows extras)
|
|
246
|
+
for (const [k, v] of value.entries) {
|
|
247
|
+
if (!fieldNames.has(k)) {
|
|
248
|
+
resultEntries.push([k, v]);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return createOrdered(resultEntries);
|
|
252
|
+
}
|
|
253
|
+
if (type.type === 'tuple' && type.elements && isTuple(value)) {
|
|
254
|
+
const elements = type.elements;
|
|
255
|
+
const entries = value.entries;
|
|
256
|
+
// All fields present: recurse into nested types for present positions
|
|
257
|
+
if (entries.length >= elements.length) {
|
|
258
|
+
const resultEntries = elements.map((el, i) => hydrateFieldDefaults(entries[i], el.type));
|
|
259
|
+
// Preserve any extra trailing entries beyond the type definition
|
|
260
|
+
for (let i = elements.length; i < entries.length; i++) {
|
|
261
|
+
resultEntries.push(entries[i]);
|
|
262
|
+
}
|
|
263
|
+
return { __rill_tuple: true, entries: resultEntries };
|
|
264
|
+
}
|
|
265
|
+
// Value shorter: fill missing trailing positions with defaults
|
|
266
|
+
const resultEntries = [];
|
|
267
|
+
for (let i = 0; i < elements.length; i++) {
|
|
268
|
+
const el = elements[i];
|
|
269
|
+
if (i < entries.length) {
|
|
270
|
+
resultEntries.push(hydrateFieldDefaults(entries[i], el.type));
|
|
271
|
+
}
|
|
272
|
+
else if (el.defaultValue !== undefined) {
|
|
273
|
+
resultEntries.push(hydrateFieldDefaults(deepCopyRillValue(el.defaultValue), el.type));
|
|
274
|
+
}
|
|
275
|
+
else if (hasCollectionFields(el.type)) {
|
|
276
|
+
resultEntries.push(hydrateFieldDefaults(emptyForType(el.type), el.type));
|
|
277
|
+
}
|
|
278
|
+
// Missing without default and not collection: leave absent (shorter tuple) for Stage 3
|
|
279
|
+
}
|
|
280
|
+
return { __rill_tuple: true, entries: resultEntries };
|
|
281
|
+
}
|
|
282
|
+
return value;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Unified marshaling entry point for all 3 invocation paths.
|
|
286
|
+
*
|
|
287
|
+
* Builds a named argument map from positional args, hydrates defaults,
|
|
288
|
+
* type-checks each field, and returns a Record<string, RillValue>.
|
|
289
|
+
*
|
|
290
|
+
* Stages:
|
|
291
|
+
* 1. Excess args check (RILL-R045)
|
|
292
|
+
* 2. Default hydration + missing required check (RILL-R044)
|
|
293
|
+
* 2.5. Dict/ordered field-level default hydration
|
|
294
|
+
* 3. Type check per field (RILL-R001)
|
|
295
|
+
*
|
|
296
|
+
* Preconditions (enforced by caller):
|
|
297
|
+
* - args contains already-evaluated RillValue[]
|
|
298
|
+
* - pipe value already inserted as first element by caller
|
|
299
|
+
* - boundDict already prepended as first element by caller
|
|
300
|
+
* - params is defined (caller skips marshalArgs for untyped callables)
|
|
301
|
+
*
|
|
302
|
+
* @param args - Positional arguments (already evaluated)
|
|
200
303
|
* @param params - Parameter definitions
|
|
201
|
-
* @param
|
|
202
|
-
* @
|
|
203
|
-
* @throws RuntimeError with RILL-R001 on validation failure
|
|
304
|
+
* @param options - Error context: functionName and location
|
|
305
|
+
* @returns Named argument map keyed by param name
|
|
204
306
|
*/
|
|
205
|
-
export function
|
|
206
|
-
|
|
307
|
+
export function marshalArgs(args, params, options) {
|
|
308
|
+
const functionName = options?.functionName ?? '<anonymous>';
|
|
309
|
+
const location = options?.location;
|
|
310
|
+
// Stage 1: Excess args check
|
|
207
311
|
if (args.length > params.length) {
|
|
208
|
-
throw new RuntimeError('RILL-
|
|
312
|
+
throw new RuntimeError('RILL-R045', `Function expects ${params.length} arguments, got ${args.length}`, location, {
|
|
209
313
|
functionName,
|
|
210
314
|
expectedCount: params.length,
|
|
211
315
|
actualCount: args.length,
|
|
212
316
|
});
|
|
213
317
|
}
|
|
214
|
-
|
|
318
|
+
const result = {};
|
|
319
|
+
// Stage 2 + 3: Hydrate defaults, check required, type-check
|
|
215
320
|
for (let i = 0; i < params.length; i++) {
|
|
216
321
|
const param = params[i];
|
|
217
322
|
if (param === undefined)
|
|
218
323
|
continue;
|
|
219
|
-
let
|
|
220
|
-
//
|
|
221
|
-
if (
|
|
324
|
+
let value = args[i];
|
|
325
|
+
// Hydrate default when no positional arg was supplied
|
|
326
|
+
if (value === undefined) {
|
|
222
327
|
if (param.defaultValue !== undefined) {
|
|
223
|
-
|
|
224
|
-
args[i] = arg;
|
|
328
|
+
value = param.defaultValue;
|
|
225
329
|
}
|
|
226
330
|
else {
|
|
227
|
-
// Missing required
|
|
228
|
-
throw new RuntimeError('RILL-
|
|
331
|
+
// Stage 2: Missing required parameter
|
|
332
|
+
throw new RuntimeError('RILL-R044', `Missing argument for parameter '${param.name}'`, location, {
|
|
229
333
|
functionName,
|
|
230
334
|
paramName: param.name,
|
|
231
335
|
});
|
|
232
336
|
}
|
|
233
337
|
}
|
|
234
|
-
//
|
|
338
|
+
// Stage 2.5: Hydrate dict/ordered field-level defaults
|
|
339
|
+
if (param.type !== undefined) {
|
|
340
|
+
value = hydrateFieldDefaults(value, param.type);
|
|
341
|
+
}
|
|
342
|
+
// Stage 3: Type check when param.type is defined
|
|
235
343
|
if (param.type !== undefined) {
|
|
236
|
-
if (!structuralTypeMatches(
|
|
344
|
+
if (!structuralTypeMatches(value, param.type)) {
|
|
237
345
|
const expectedType = formatStructuralType(param.type);
|
|
238
|
-
const actualType = inferType(
|
|
239
|
-
throw new RuntimeError('RILL-R001', `
|
|
346
|
+
const actualType = inferType(value);
|
|
347
|
+
throw new RuntimeError('RILL-R001', `Parameter type mismatch: ${param.name} expects ${expectedType}, got ${actualType}`, location, {
|
|
240
348
|
functionName,
|
|
241
349
|
paramName: param.name,
|
|
242
350
|
expectedType,
|
|
@@ -244,6 +352,7 @@ export function validateCallableArgs(args, params, functionName, location) {
|
|
|
244
352
|
});
|
|
245
353
|
}
|
|
246
354
|
}
|
|
355
|
+
result[param.name] = value;
|
|
247
356
|
}
|
|
357
|
+
return result;
|
|
248
358
|
}
|
|
249
|
-
//# sourceMappingURL=callable.js.map
|
|
@@ -14,7 +14,7 @@ import { callable, validateDefaultValueType, } from './callable.js';
|
|
|
14
14
|
// chain: pipe form sends 1 arg when signature declares 2 (pipeValue is the first).
|
|
15
15
|
const UNTYPED_BUILTINS = new Set(['log', 'chain']);
|
|
16
16
|
// Built-in methods that do their own internal arg validation with specific error
|
|
17
|
-
// messages expected by protected language tests. Generic
|
|
17
|
+
// messages expected by protected language tests. Generic marshalArgs
|
|
18
18
|
// must not fire before the method body's own check.
|
|
19
19
|
export const UNVALIDATED_METHOD_PARAMS = new Set(['has', 'has_any', 'has_all']);
|
|
20
20
|
// Built-in methods that perform their own receiver type checking with specific
|
|
@@ -319,4 +319,3 @@ export function popCallFrame(ctx) {
|
|
|
319
319
|
ctx.callStack.pop();
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -544,7 +544,7 @@ function typeRefStaticEquals(a, b) {
|
|
|
544
544
|
return typeRefArgListEquals(a.args, b.args);
|
|
545
545
|
}
|
|
546
546
|
/**
|
|
547
|
-
* Compare two optional
|
|
547
|
+
* Compare two optional FieldArg arrays for structural equality.
|
|
548
548
|
*/
|
|
549
549
|
function typeRefArgListEquals(a, b) {
|
|
550
550
|
const aArgs = a ?? [];
|
|
@@ -556,7 +556,9 @@ function typeRefArgListEquals(a, b) {
|
|
|
556
556
|
const bArg = bArgs[i];
|
|
557
557
|
if (aArg.name !== bArg.name)
|
|
558
558
|
return false;
|
|
559
|
-
if (!typeRefEquals(aArg.
|
|
559
|
+
if (!typeRefEquals(aArg.value, bArg.value))
|
|
560
|
+
return false;
|
|
561
|
+
if (!literalNodeEquals(aArg.defaultValue, bArg.defaultValue))
|
|
560
562
|
return false;
|
|
561
563
|
}
|
|
562
564
|
return true;
|
|
@@ -578,4 +580,34 @@ function typeRefEquals(a, b) {
|
|
|
578
580
|
}
|
|
579
581
|
return false;
|
|
580
582
|
}
|
|
581
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Compare two optional LiteralNode values for structural equality.
|
|
585
|
+
* Both-undefined returns true. One-undefined returns false.
|
|
586
|
+
* Complex nodes (ListLiteral, Dict, Closure) return false defensively.
|
|
587
|
+
*/
|
|
588
|
+
function literalNodeEquals(a, b) {
|
|
589
|
+
if (a === undefined && b === undefined)
|
|
590
|
+
return true;
|
|
591
|
+
if (a === undefined || b === undefined)
|
|
592
|
+
return false;
|
|
593
|
+
if (a.type !== b.type)
|
|
594
|
+
return false;
|
|
595
|
+
switch (a.type) {
|
|
596
|
+
case 'NumberLiteral':
|
|
597
|
+
return a.value === b.value;
|
|
598
|
+
case 'BoolLiteral':
|
|
599
|
+
return a.value === b.value;
|
|
600
|
+
case 'StringLiteral': {
|
|
601
|
+
const bStr = b;
|
|
602
|
+
if (a.parts.length !== 1 || bStr.parts.length !== 1)
|
|
603
|
+
return false;
|
|
604
|
+
return a.parts[0] === bStr.parts[0];
|
|
605
|
+
}
|
|
606
|
+
case 'ListLiteral':
|
|
607
|
+
case 'Dict':
|
|
608
|
+
case 'Closure':
|
|
609
|
+
return false;
|
|
610
|
+
default:
|
|
611
|
+
return false;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
@@ -69,4 +69,3 @@ export declare function getAnnotation(ctx: RuntimeContext, key: string): RillVal
|
|
|
69
69
|
* @param location - Optional call site location for error reporting
|
|
70
70
|
*/
|
|
71
71
|
export declare function invokeCallable(callable: RillCallable, args: RillValue[], ctx: RuntimeContext, location?: SourceLocation): Promise<RillValue>;
|
|
72
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -149,4 +149,3 @@ function createAnnotationsMixin(Base) {
|
|
|
149
149
|
// TypeScript can't generate declarations for functions returning classes with protected members
|
|
150
150
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
151
|
export const AnnotationsMixin = createAnnotationsMixin;
|
|
152
|
-
//# sourceMappingURL=annotations.js.map
|