@rcrsr/rill 0.14.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.
Files changed (305) hide show
  1. package/dist/ast-nodes.d.ts +2 -11
  2. package/dist/ast-nodes.js +0 -1
  3. package/dist/ast-unions.d.ts +0 -1
  4. package/dist/ast-unions.js +0 -1
  5. package/dist/constants.d.ts +0 -1
  6. package/dist/constants.js +0 -1
  7. package/dist/error-classes.d.ts +0 -1
  8. package/dist/error-classes.js +0 -1
  9. package/dist/error-formatter.d.ts +0 -1
  10. package/dist/error-formatter.js +0 -1
  11. package/dist/error-registry.d.ts +0 -1
  12. package/dist/error-registry.js +50 -1
  13. package/dist/ext/crypto/index.d.ts +0 -1
  14. package/dist/ext/crypto/index.js +5 -6
  15. package/dist/ext/exec/index.d.ts +0 -1
  16. package/dist/ext/exec/index.js +3 -4
  17. package/dist/ext/exec/runner.d.ts +0 -1
  18. package/dist/ext/exec/runner.js +0 -1
  19. package/dist/ext/fetch/index.d.ts +0 -1
  20. package/dist/ext/fetch/index.js +8 -39
  21. package/dist/ext/fetch/request.d.ts +0 -1
  22. package/dist/ext/fetch/request.js +0 -1
  23. package/dist/ext/fs/index.d.ts +0 -1
  24. package/dist/ext/fs/index.js +26 -27
  25. package/dist/ext/fs/sandbox.d.ts +0 -1
  26. package/dist/ext/fs/sandbox.js +0 -1
  27. package/dist/ext/kv/index.d.ts +0 -1
  28. package/dist/ext/kv/index.js +19 -20
  29. package/dist/ext/kv/store.d.ts +0 -1
  30. package/dist/ext/kv/store.js +0 -1
  31. package/dist/generated/introspection-data.d.ts +0 -1
  32. package/dist/generated/introspection-data.js +0 -1
  33. package/dist/generated/version-data.d.ts +1 -2
  34. package/dist/generated/version-data.js +2 -3
  35. package/dist/highlight-map.d.ts +0 -1
  36. package/dist/highlight-map.js +0 -1
  37. package/dist/index.d.ts +1 -2
  38. package/dist/index.js +1 -2
  39. package/dist/lexer/errors.d.ts +0 -1
  40. package/dist/lexer/errors.js +0 -1
  41. package/dist/lexer/helpers.d.ts +0 -1
  42. package/dist/lexer/helpers.js +0 -1
  43. package/dist/lexer/index.d.ts +0 -1
  44. package/dist/lexer/index.js +0 -1
  45. package/dist/lexer/operators.d.ts +0 -1
  46. package/dist/lexer/operators.js +0 -1
  47. package/dist/lexer/readers.d.ts +0 -1
  48. package/dist/lexer/readers.js +0 -1
  49. package/dist/lexer/state.d.ts +0 -1
  50. package/dist/lexer/state.js +0 -1
  51. package/dist/lexer/tokenizer.d.ts +0 -1
  52. package/dist/lexer/tokenizer.js +0 -1
  53. package/dist/parser/helpers.d.ts +0 -1
  54. package/dist/parser/helpers.js +0 -1
  55. package/dist/parser/index.d.ts +0 -1
  56. package/dist/parser/index.js +0 -1
  57. package/dist/parser/parser-collect.d.ts +0 -1
  58. package/dist/parser/parser-collect.js +0 -1
  59. package/dist/parser/parser-control.d.ts +0 -1
  60. package/dist/parser/parser-control.js +0 -1
  61. package/dist/parser/parser-expr.d.ts +0 -1
  62. package/dist/parser/parser-expr.js +0 -1
  63. package/dist/parser/parser-extract.d.ts +0 -1
  64. package/dist/parser/parser-extract.js +0 -1
  65. package/dist/parser/parser-functions.d.ts +0 -1
  66. package/dist/parser/parser-functions.js +0 -1
  67. package/dist/parser/parser-literals.d.ts +0 -1
  68. package/dist/parser/parser-literals.js +4 -2
  69. package/dist/parser/parser-script.d.ts +0 -1
  70. package/dist/parser/parser-script.js +0 -1
  71. package/dist/parser/parser-shape.d.ts +2 -3
  72. package/dist/parser/parser-shape.js +8 -40
  73. package/dist/parser/parser-types.d.ts +28 -2
  74. package/dist/parser/parser-types.js +64 -13
  75. package/dist/parser/parser-use.d.ts +0 -1
  76. package/dist/parser/parser-use.js +0 -1
  77. package/dist/parser/parser-variables.d.ts +0 -1
  78. package/dist/parser/parser-variables.js +0 -1
  79. package/dist/parser/parser.d.ts +0 -1
  80. package/dist/parser/parser.js +0 -1
  81. package/dist/parser/state.d.ts +0 -1
  82. package/dist/parser/state.js +0 -1
  83. package/dist/runtime/core/callable.d.ts +40 -13
  84. package/dist/runtime/core/callable.js +137 -31
  85. package/dist/runtime/core/context.d.ts +0 -1
  86. package/dist/runtime/core/context.js +1 -2
  87. package/dist/runtime/core/equals.d.ts +0 -1
  88. package/dist/runtime/core/equals.js +35 -3
  89. package/dist/runtime/core/eval/base.d.ts +0 -1
  90. package/dist/runtime/core/eval/base.js +0 -1
  91. package/dist/runtime/core/eval/evaluator.d.ts +0 -1
  92. package/dist/runtime/core/eval/evaluator.js +0 -1
  93. package/dist/runtime/core/eval/index.d.ts +0 -1
  94. package/dist/runtime/core/eval/index.js +0 -1
  95. package/dist/runtime/core/eval/mixins/annotations.d.ts +0 -1
  96. package/dist/runtime/core/eval/mixins/annotations.js +0 -1
  97. package/dist/runtime/core/eval/mixins/closures.d.ts +0 -1
  98. package/dist/runtime/core/eval/mixins/closures.js +82 -69
  99. package/dist/runtime/core/eval/mixins/collections.d.ts +0 -1
  100. package/dist/runtime/core/eval/mixins/collections.js +9 -4
  101. package/dist/runtime/core/eval/mixins/control-flow.d.ts +0 -1
  102. package/dist/runtime/core/eval/mixins/control-flow.js +0 -1
  103. package/dist/runtime/core/eval/mixins/conversion.d.ts +0 -1
  104. package/dist/runtime/core/eval/mixins/conversion.js +263 -16
  105. package/dist/runtime/core/eval/mixins/core.d.ts +0 -1
  106. package/dist/runtime/core/eval/mixins/core.js +0 -1
  107. package/dist/runtime/core/eval/mixins/expressions.d.ts +0 -1
  108. package/dist/runtime/core/eval/mixins/expressions.js +0 -1
  109. package/dist/runtime/core/eval/mixins/extraction.d.ts +0 -1
  110. package/dist/runtime/core/eval/mixins/extraction.js +8 -9
  111. package/dist/runtime/core/eval/mixins/list-dispatch.d.ts +0 -1
  112. package/dist/runtime/core/eval/mixins/list-dispatch.js +0 -1
  113. package/dist/runtime/core/eval/mixins/literals.d.ts +0 -1
  114. package/dist/runtime/core/eval/mixins/literals.js +3 -7
  115. package/dist/runtime/core/eval/mixins/types.d.ts +2 -1
  116. package/dist/runtime/core/eval/mixins/types.js +222 -200
  117. package/dist/runtime/core/eval/mixins/use.d.ts +0 -1
  118. package/dist/runtime/core/eval/mixins/use.js +0 -1
  119. package/dist/runtime/core/eval/mixins/variables.d.ts +0 -1
  120. package/dist/runtime/core/eval/mixins/variables.js +6 -7
  121. package/dist/runtime/core/eval/types.d.ts +0 -1
  122. package/dist/runtime/core/eval/types.js +0 -1
  123. package/dist/runtime/core/execute.d.ts +0 -1
  124. package/dist/runtime/core/execute.js +0 -1
  125. package/dist/runtime/core/field-descriptor.d.ts +2 -3
  126. package/dist/runtime/core/field-descriptor.js +0 -1
  127. package/dist/runtime/core/introspection.d.ts +0 -1
  128. package/dist/runtime/core/introspection.js +0 -1
  129. package/dist/runtime/core/resolvers.d.ts +0 -1
  130. package/dist/runtime/core/resolvers.js +0 -1
  131. package/dist/runtime/core/signals.d.ts +0 -1
  132. package/dist/runtime/core/signals.js +0 -1
  133. package/dist/runtime/core/types.d.ts +0 -1
  134. package/dist/runtime/core/types.js +0 -1
  135. package/dist/runtime/core/values.d.ts +59 -8
  136. package/dist/runtime/core/values.js +338 -36
  137. package/dist/runtime/ext/builtins.d.ts +0 -1
  138. package/dist/runtime/ext/builtins.js +43 -17
  139. package/dist/runtime/ext/extensions.d.ts +0 -1
  140. package/dist/runtime/ext/extensions.js +0 -1
  141. package/dist/runtime/index.d.ts +2 -3
  142. package/dist/runtime/index.js +1 -2
  143. package/dist/signature-parser.d.ts +0 -1
  144. package/dist/signature-parser.js +8 -4
  145. package/dist/source-location.d.ts +0 -1
  146. package/dist/source-location.js +0 -1
  147. package/dist/token-types.d.ts +0 -1
  148. package/dist/token-types.js +0 -1
  149. package/dist/types.d.ts +0 -1
  150. package/dist/types.js +0 -1
  151. package/dist/value-types.d.ts +15 -12
  152. package/dist/value-types.js +0 -1
  153. package/package.json +2 -1
  154. package/dist/ast-nodes.d.ts.map +0 -1
  155. package/dist/ast-nodes.js.map +0 -1
  156. package/dist/ast-unions.d.ts.map +0 -1
  157. package/dist/ast-unions.js.map +0 -1
  158. package/dist/constants.d.ts.map +0 -1
  159. package/dist/constants.js.map +0 -1
  160. package/dist/error-classes.d.ts.map +0 -1
  161. package/dist/error-classes.js.map +0 -1
  162. package/dist/error-formatter.d.ts.map +0 -1
  163. package/dist/error-formatter.js.map +0 -1
  164. package/dist/error-registry.d.ts.map +0 -1
  165. package/dist/error-registry.js.map +0 -1
  166. package/dist/ext/crypto/index.d.ts.map +0 -1
  167. package/dist/ext/crypto/index.js.map +0 -1
  168. package/dist/ext/exec/index.d.ts.map +0 -1
  169. package/dist/ext/exec/index.js.map +0 -1
  170. package/dist/ext/exec/runner.d.ts.map +0 -1
  171. package/dist/ext/exec/runner.js.map +0 -1
  172. package/dist/ext/fetch/index.d.ts.map +0 -1
  173. package/dist/ext/fetch/index.js.map +0 -1
  174. package/dist/ext/fetch/request.d.ts.map +0 -1
  175. package/dist/ext/fetch/request.js.map +0 -1
  176. package/dist/ext/fs/index.d.ts.map +0 -1
  177. package/dist/ext/fs/index.js.map +0 -1
  178. package/dist/ext/fs/sandbox.d.ts.map +0 -1
  179. package/dist/ext/fs/sandbox.js.map +0 -1
  180. package/dist/ext/kv/index.d.ts.map +0 -1
  181. package/dist/ext/kv/index.js.map +0 -1
  182. package/dist/ext/kv/store.d.ts.map +0 -1
  183. package/dist/ext/kv/store.js.map +0 -1
  184. package/dist/generated/introspection-data.d.ts.map +0 -1
  185. package/dist/generated/introspection-data.js.map +0 -1
  186. package/dist/generated/version-data.d.ts.map +0 -1
  187. package/dist/generated/version-data.js.map +0 -1
  188. package/dist/highlight-map.d.ts.map +0 -1
  189. package/dist/highlight-map.js.map +0 -1
  190. package/dist/index.d.ts.map +0 -1
  191. package/dist/index.js.map +0 -1
  192. package/dist/lexer/errors.d.ts.map +0 -1
  193. package/dist/lexer/errors.js.map +0 -1
  194. package/dist/lexer/helpers.d.ts.map +0 -1
  195. package/dist/lexer/helpers.js.map +0 -1
  196. package/dist/lexer/index.d.ts.map +0 -1
  197. package/dist/lexer/index.js.map +0 -1
  198. package/dist/lexer/operators.d.ts.map +0 -1
  199. package/dist/lexer/operators.js.map +0 -1
  200. package/dist/lexer/readers.d.ts.map +0 -1
  201. package/dist/lexer/readers.js.map +0 -1
  202. package/dist/lexer/state.d.ts.map +0 -1
  203. package/dist/lexer/state.js.map +0 -1
  204. package/dist/lexer/tokenizer.d.ts.map +0 -1
  205. package/dist/lexer/tokenizer.js.map +0 -1
  206. package/dist/parser/helpers.d.ts.map +0 -1
  207. package/dist/parser/helpers.js.map +0 -1
  208. package/dist/parser/index.d.ts.map +0 -1
  209. package/dist/parser/index.js.map +0 -1
  210. package/dist/parser/parser-collect.d.ts.map +0 -1
  211. package/dist/parser/parser-collect.js.map +0 -1
  212. package/dist/parser/parser-control.d.ts.map +0 -1
  213. package/dist/parser/parser-control.js.map +0 -1
  214. package/dist/parser/parser-expr.d.ts.map +0 -1
  215. package/dist/parser/parser-expr.js.map +0 -1
  216. package/dist/parser/parser-extract.d.ts.map +0 -1
  217. package/dist/parser/parser-extract.js.map +0 -1
  218. package/dist/parser/parser-functions.d.ts.map +0 -1
  219. package/dist/parser/parser-functions.js.map +0 -1
  220. package/dist/parser/parser-literals.d.ts.map +0 -1
  221. package/dist/parser/parser-literals.js.map +0 -1
  222. package/dist/parser/parser-script.d.ts.map +0 -1
  223. package/dist/parser/parser-script.js.map +0 -1
  224. package/dist/parser/parser-shape.d.ts.map +0 -1
  225. package/dist/parser/parser-shape.js.map +0 -1
  226. package/dist/parser/parser-types.d.ts.map +0 -1
  227. package/dist/parser/parser-types.js.map +0 -1
  228. package/dist/parser/parser-use.d.ts.map +0 -1
  229. package/dist/parser/parser-use.js.map +0 -1
  230. package/dist/parser/parser-variables.d.ts.map +0 -1
  231. package/dist/parser/parser-variables.js.map +0 -1
  232. package/dist/parser/parser.d.ts.map +0 -1
  233. package/dist/parser/parser.js.map +0 -1
  234. package/dist/parser/state.d.ts.map +0 -1
  235. package/dist/parser/state.js.map +0 -1
  236. package/dist/runtime/core/callable.d.ts.map +0 -1
  237. package/dist/runtime/core/callable.js.map +0 -1
  238. package/dist/runtime/core/context.d.ts.map +0 -1
  239. package/dist/runtime/core/context.js.map +0 -1
  240. package/dist/runtime/core/equals.d.ts.map +0 -1
  241. package/dist/runtime/core/equals.js.map +0 -1
  242. package/dist/runtime/core/eval/base.d.ts.map +0 -1
  243. package/dist/runtime/core/eval/base.js.map +0 -1
  244. package/dist/runtime/core/eval/evaluator.d.ts.map +0 -1
  245. package/dist/runtime/core/eval/evaluator.js.map +0 -1
  246. package/dist/runtime/core/eval/index.d.ts.map +0 -1
  247. package/dist/runtime/core/eval/index.js.map +0 -1
  248. package/dist/runtime/core/eval/mixins/annotations.d.ts.map +0 -1
  249. package/dist/runtime/core/eval/mixins/annotations.js.map +0 -1
  250. package/dist/runtime/core/eval/mixins/closures.d.ts.map +0 -1
  251. package/dist/runtime/core/eval/mixins/closures.js.map +0 -1
  252. package/dist/runtime/core/eval/mixins/collections.d.ts.map +0 -1
  253. package/dist/runtime/core/eval/mixins/collections.js.map +0 -1
  254. package/dist/runtime/core/eval/mixins/control-flow.d.ts.map +0 -1
  255. package/dist/runtime/core/eval/mixins/control-flow.js.map +0 -1
  256. package/dist/runtime/core/eval/mixins/conversion.d.ts.map +0 -1
  257. package/dist/runtime/core/eval/mixins/conversion.js.map +0 -1
  258. package/dist/runtime/core/eval/mixins/core.d.ts.map +0 -1
  259. package/dist/runtime/core/eval/mixins/core.js.map +0 -1
  260. package/dist/runtime/core/eval/mixins/expressions.d.ts.map +0 -1
  261. package/dist/runtime/core/eval/mixins/expressions.js.map +0 -1
  262. package/dist/runtime/core/eval/mixins/extraction.d.ts.map +0 -1
  263. package/dist/runtime/core/eval/mixins/extraction.js.map +0 -1
  264. package/dist/runtime/core/eval/mixins/list-dispatch.d.ts.map +0 -1
  265. package/dist/runtime/core/eval/mixins/list-dispatch.js.map +0 -1
  266. package/dist/runtime/core/eval/mixins/literals.d.ts.map +0 -1
  267. package/dist/runtime/core/eval/mixins/literals.js.map +0 -1
  268. package/dist/runtime/core/eval/mixins/types.d.ts.map +0 -1
  269. package/dist/runtime/core/eval/mixins/types.js.map +0 -1
  270. package/dist/runtime/core/eval/mixins/use.d.ts.map +0 -1
  271. package/dist/runtime/core/eval/mixins/use.js.map +0 -1
  272. package/dist/runtime/core/eval/mixins/variables.d.ts.map +0 -1
  273. package/dist/runtime/core/eval/mixins/variables.js.map +0 -1
  274. package/dist/runtime/core/eval/types.d.ts.map +0 -1
  275. package/dist/runtime/core/eval/types.js.map +0 -1
  276. package/dist/runtime/core/execute.d.ts.map +0 -1
  277. package/dist/runtime/core/execute.js.map +0 -1
  278. package/dist/runtime/core/field-descriptor.d.ts.map +0 -1
  279. package/dist/runtime/core/field-descriptor.js.map +0 -1
  280. package/dist/runtime/core/introspection.d.ts.map +0 -1
  281. package/dist/runtime/core/introspection.js.map +0 -1
  282. package/dist/runtime/core/resolvers.d.ts.map +0 -1
  283. package/dist/runtime/core/resolvers.js.map +0 -1
  284. package/dist/runtime/core/signals.d.ts.map +0 -1
  285. package/dist/runtime/core/signals.js.map +0 -1
  286. package/dist/runtime/core/types.d.ts.map +0 -1
  287. package/dist/runtime/core/types.js.map +0 -1
  288. package/dist/runtime/core/values.d.ts.map +0 -1
  289. package/dist/runtime/core/values.js.map +0 -1
  290. package/dist/runtime/ext/builtins.d.ts.map +0 -1
  291. package/dist/runtime/ext/builtins.js.map +0 -1
  292. package/dist/runtime/ext/extensions.d.ts.map +0 -1
  293. package/dist/runtime/ext/extensions.js.map +0 -1
  294. package/dist/runtime/index.d.ts.map +0 -1
  295. package/dist/runtime/index.js.map +0 -1
  296. package/dist/signature-parser.d.ts.map +0 -1
  297. package/dist/signature-parser.js.map +0 -1
  298. package/dist/source-location.d.ts.map +0 -1
  299. package/dist/source-location.js.map +0 -1
  300. package/dist/token-types.d.ts.map +0 -1
  301. package/dist/token-types.js.map +0 -1
  302. package/dist/types.d.ts.map +0 -1
  303. package/dist/types.js.map +0 -1
  304. package/dist/value-types.d.ts.map +0 -1
  305. 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
- const ref = parseTypeRef(state);
124
- args.push({ name, ref });
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 ref = parseTypeRef(state);
129
- args.push({ ref });
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-14)
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
- // Consume ")"
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
- advance(state); // consume ")"
145
- return { kind: 'static', typeName, args };
197
+ return args;
146
198
  }
147
- //# sourceMappingURL=parser-types.js.map
@@ -8,4 +8,3 @@ declare module './parser.js' {
8
8
  parseUseExpr(): UseExprNode;
9
9
  }
10
10
  }
11
- //# sourceMappingURL=parser-use.d.ts.map
@@ -93,4 +93,3 @@ Parser.prototype.parseUseExpr = function () {
93
93
  span: makeSpan(start, current(this.state).span.end),
94
94
  };
95
95
  };
96
- //# sourceMappingURL=parser-use.js.map
@@ -17,4 +17,3 @@ declare module './parser.js' {
17
17
  parseDefaultValue(): BodyNode;
18
18
  }
19
19
  }
20
- //# sourceMappingURL=parser-variables.d.ts.map
@@ -175,4 +175,3 @@ Parser.prototype.parseDefaultValue = function () {
175
175
  }
176
176
  return this.parsePipeChain();
177
177
  };
178
- //# sourceMappingURL=parser-variables.js.map
@@ -46,4 +46,3 @@ export declare class Parser {
46
46
  */
47
47
  get errors(): ParseError[];
48
48
  }
49
- //# sourceMappingURL=parser.d.ts.map
@@ -51,4 +51,3 @@ export class Parser {
51
51
  return this.state.errors;
52
52
  }
53
53
  }
54
- //# sourceMappingURL=parser.js.map
@@ -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
@@ -150,4 +150,3 @@ function generateHint(expectedType, actualToken) {
150
150
  export function makeSpan(start, end) {
151
151
  return { start, end };
152
152
  }
153
- //# sourceMappingURL=state.js.map
@@ -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 validateCallableArgs signature
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: RillValue[], ctx: RuntimeContextLike, location?: SourceLocation) => RillValue | Promise<RillValue>;
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
- * Validate arguments against RillParam[] using structural type matching.
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
- * Single validation path for all callable kinds (host, built-in, script).
160
- * Uses structuralTypeMatches for type checking when param.type is defined.
161
- * Skips type check when param.type is undefined (any-typed).
162
- * Applies defaultValue in-place on the args array before validation.
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 - Arguments array (mutated in-place when defaults applied)
193
+ * @param args - Positional arguments (already evaluated)
165
194
  * @param params - Parameter definitions
166
- * @param functionName - Function name for error messages
167
- * @param location - Source location for error reporting
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 validateCallableArgs(args: RillValue[], params: readonly RillParam[], functionName: string, location?: SourceLocation): void;
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 validateCallableArgs signature
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, structuralTypeEquals, structuralTypeMatches, anyTypeValue, } from './values.js';
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,10 +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) => {
163
- const paramType = param.type ?? { type: 'any' };
164
- return [param.name, paramType];
165
- });
162
+ const closureParams = params.map((param) => paramToFieldDef(param.name, param.type ?? { type: 'any' }, param.defaultValue));
166
163
  return Object.freeze({
167
164
  type: 'closure',
168
165
  params: closureParams,
@@ -192,54 +189,162 @@ export function validateDefaultValueType(param, _functionName) {
192
189
  }
193
190
  }
194
191
  /**
195
- * Validate arguments against RillParam[] using structural type matching.
192
+ * Hydrate missing dict/ordered field-level defaults into a value.
196
193
  *
197
- * Single validation path for all callable kinds (host, built-in, script).
198
- * Uses structuralTypeMatches for type checking when param.type is defined.
199
- * Skips type check when param.type is undefined (any-typed).
200
- * 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.
201
197
  *
202
- * @param args - Arguments array (mutated in-place when defaults applied)
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)
203
303
  * @param params - Parameter definitions
204
- * @param functionName - Function name for error messages
205
- * @param location - Source location for error reporting
206
- * @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
207
306
  */
208
- export function validateCallableArgs(args, params, functionName, location) {
209
- // Check for excess arguments
307
+ export function marshalArgs(args, params, options) {
308
+ const functionName = options?.functionName ?? '<anonymous>';
309
+ const location = options?.location;
310
+ // Stage 1: Excess args check
210
311
  if (args.length > params.length) {
211
- throw new RuntimeError('RILL-R001', `Function '${functionName}' expects ${params.length} arguments, got ${args.length}`, location, {
312
+ throw new RuntimeError('RILL-R045', `Function expects ${params.length} arguments, got ${args.length}`, location, {
212
313
  functionName,
213
314
  expectedCount: params.length,
214
315
  actualCount: args.length,
215
316
  });
216
317
  }
217
- // Validate each parameter
318
+ const result = {};
319
+ // Stage 2 + 3: Hydrate defaults, check required, type-check
218
320
  for (let i = 0; i < params.length; i++) {
219
321
  const param = params[i];
220
322
  if (param === undefined)
221
323
  continue;
222
- let arg = args[i];
223
- // Apply defaultValue in-place for missing arguments
224
- if (arg === undefined) {
324
+ let value = args[i];
325
+ // Hydrate default when no positional arg was supplied
326
+ if (value === undefined) {
225
327
  if (param.defaultValue !== undefined) {
226
- arg = param.defaultValue;
227
- args[i] = arg;
328
+ value = param.defaultValue;
228
329
  }
229
330
  else {
230
- // Missing required argument
231
- throw new RuntimeError('RILL-R001', `Missing required argument '${param.name}' for function '${functionName}'`, location, {
331
+ // Stage 2: Missing required parameter
332
+ throw new RuntimeError('RILL-R044', `Missing argument for parameter '${param.name}'`, location, {
232
333
  functionName,
233
334
  paramName: param.name,
234
335
  });
235
336
  }
236
337
  }
237
- // Type check via structuralTypeMatches when param.type is defined
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
238
343
  if (param.type !== undefined) {
239
- if (!structuralTypeMatches(arg, param.type)) {
344
+ if (!structuralTypeMatches(value, param.type)) {
240
345
  const expectedType = formatStructuralType(param.type);
241
- const actualType = inferType(arg);
242
- throw new RuntimeError('RILL-R001', `Type mismatch in ${functionName}: parameter '${param.name}' expects ${expectedType}, got ${actualType}`, location, {
346
+ const actualType = inferType(value);
347
+ throw new RuntimeError('RILL-R001', `Parameter type mismatch: ${param.name} expects ${expectedType}, got ${actualType}`, location, {
243
348
  functionName,
244
349
  paramName: param.name,
245
350
  expectedType,
@@ -247,6 +352,7 @@ export function validateCallableArgs(args, params, functionName, location) {
247
352
  });
248
353
  }
249
354
  }
355
+ result[param.name] = value;
250
356
  }
357
+ return result;
251
358
  }
252
- //# sourceMappingURL=callable.js.map
@@ -62,4 +62,3 @@ export declare function pushCallFrame(ctx: RuntimeContext, frame: import('../../
62
62
  * Pop frame from call stack after function/closure returns.
63
63
  */
64
64
  export declare function popCallFrame(ctx: RuntimeContext): void;
65
- //# sourceMappingURL=context.d.ts.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 validateCallableArgs
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
@@ -6,4 +6,3 @@
6
6
  */
7
7
  import type { ASTNode } from '../../types.js';
8
8
  export declare function astEquals(a: ASTNode, b: ASTNode): boolean;
9
- //# sourceMappingURL=equals.d.ts.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 TypeRefArg arrays for structural equality.
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.ref, bArg.ref))
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
- //# sourceMappingURL=equals.js.map
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
+ }
@@ -62,4 +62,3 @@ export declare class EvaluatorBase {
62
62
  */
63
63
  protected accessDictField(value: RillValue, field: string, location?: SourceLocation, allowMissing?: boolean): Promise<RillValue>;
64
64
  }
65
- //# sourceMappingURL=base.d.ts.map
@@ -112,4 +112,3 @@ export class EvaluatorBase {
112
112
  return dictValue;
113
113
  }
114
114
  }
115
- //# sourceMappingURL=base.js.map
@@ -122,4 +122,3 @@ export type Evaluator = InstanceType<typeof Evaluator>;
122
122
  * @internal
123
123
  */
124
124
  export declare function getEvaluator(ctx: RuntimeContext): InstanceType<typeof Evaluator>;
125
- //# sourceMappingURL=evaluator.d.ts.map
@@ -151,4 +151,3 @@ export function getEvaluator(ctx) {
151
151
  }
152
152
  return evaluator;
153
153
  }
154
- //# sourceMappingURL=evaluator.js.map
@@ -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
@@ -117,4 +117,3 @@ export async function invokeCallable(callable, args, ctx, location) {
117
117
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
118
  return evaluator.invokeCallable(callable, args, location);
119
119
  }
120
- //# sourceMappingURL=index.js.map
@@ -16,4 +16,3 @@
16
16
  * @internal
17
17
  */
18
18
  export declare const AnnotationsMixin: any;
19
- //# sourceMappingURL=annotations.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
@@ -42,4 +42,3 @@
42
42
  * @internal
43
43
  */
44
44
  export declare const ClosuresMixin: any;
45
- //# sourceMappingURL=closures.d.ts.map