@hyperscale0/hsx 3.3.0 → 4.0.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 (51) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +1 -1
  3. package/dist/src/ast.d.ts +17 -2
  4. package/dist/src/ast.d.ts.map +1 -1
  5. package/dist/src/ast.js.map +1 -1
  6. package/dist/src/cli.js +1 -1
  7. package/dist/src/compile.d.ts +6 -0
  8. package/dist/src/compile.d.ts.map +1 -1
  9. package/dist/src/compile.js +1162 -101
  10. package/dist/src/compile.js.map +1 -1
  11. package/dist/src/headers.d.ts +2 -2
  12. package/dist/src/headers.d.ts.map +1 -1
  13. package/dist/src/headers.js +2 -3
  14. package/dist/src/headers.js.map +1 -1
  15. package/dist/src/index.d.ts +3 -2
  16. package/dist/src/index.d.ts.map +1 -1
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/lex.d.ts +1 -1
  19. package/dist/src/lex.d.ts.map +1 -1
  20. package/dist/src/lex.js +5 -0
  21. package/dist/src/lex.js.map +1 -1
  22. package/dist/src/parse.js +87 -3
  23. package/dist/src/parse.js.map +1 -1
  24. package/dist/src/std-bundle.d.ts.map +1 -1
  25. package/dist/src/std-bundle.js +8 -9
  26. package/dist/src/std-bundle.js.map +1 -1
  27. package/dist/src/version.d.ts +2 -2
  28. package/dist/src/version.js +2 -2
  29. package/docs/README.md +45 -27
  30. package/docs/headers.md +43 -44
  31. package/examples/cost-table.json +8 -324
  32. package/examples/library.hsx +12 -64
  33. package/package.json +7 -5
  34. package/src/ast.ts +11 -1
  35. package/src/cli.ts +1 -1
  36. package/src/compile.ts +1588 -118
  37. package/src/headers.ts +2 -3
  38. package/src/index.ts +12 -1
  39. package/src/lex.ts +5 -0
  40. package/src/parse.ts +84 -3
  41. package/src/std-bundle.ts +8 -9
  42. package/src/version.ts +2 -2
  43. package/std/approvals.hsx +3 -3
  44. package/std/escrow.hsx +16 -14
  45. package/std/financing.hsx +59 -17
  46. package/std/insurance.hsx +4 -5
  47. package/std/lending.hsx +7 -8
  48. package/std/marketplace.hsx +2 -5
  49. package/std/money.hsx +15 -49
  50. package/std/travel.hsx +5 -6
  51. package/std/vehicles.hsx +0 -34
package/src/headers.ts CHANGED
@@ -17,7 +17,6 @@ export const HEADER_NAMES = [
17
17
  "cards",
18
18
  "savings",
19
19
  "reporting",
20
- "vehicles",
21
20
  ] as const;
22
21
 
23
22
  /** The compiler frontend owns header metadata used by docs and catalogue consumers. */
@@ -25,7 +24,7 @@ export function headerManifest(
25
24
  library: StandardLibrary = bundledStandardLibrary,
26
25
  ) {
27
26
  return {
28
- version: 3,
27
+ version: 4,
29
28
  headers: HEADER_NAMES.map((name) => {
30
29
  const source = library.source(name);
31
30
  if (!source) throw new Error(`Missing standard header ${name}`);
@@ -112,7 +111,7 @@ export function headerManifest(
112
111
  requiredImport: `use ${name}`,
113
112
  instancePlaceholder: "${instance}",
114
113
  source:
115
- "${instance} = " +
114
+ "attach ${instance} = " +
116
115
  `${name}.${decl.name} { ` +
117
116
  bindings
118
117
  .map((t) => t.name + ": ${" + t.name + "}")
package/src/index.ts CHANGED
@@ -4,12 +4,23 @@ export {
4
4
  type CompileOptions,
5
5
  type CompileResult,
6
6
  type CompileOriginMapEntry,
7
+ type AdapterBindingTarget,
7
8
  } from "./compile.ts";
9
+ export type { ProviderAdapter } from "@hyperscale0/adl";
8
10
  export { parseProgram } from "./parse.ts";
9
11
  export { lex, KEYWORDS } from "./lex.ts";
10
12
  export { format } from "./format.ts";
11
13
  export { bundledStandardLibrary, type StandardLibrary } from "./std-library.ts";
12
14
  export { buildUdlCostManifest, type UdlCostManifest } from "./cost.ts";
13
- export type { Program, Decl, Expr, Span, Diagnostic } from "./ast.ts";
15
+ export type {
16
+ Program,
17
+ Decl,
18
+ AssignmentDecl,
19
+ ObjectDecl,
20
+ InstrumentDecl,
21
+ Expr,
22
+ Span,
23
+ Diagnostic,
24
+ } from "./ast.ts";
14
25
 
15
26
  export { headerManifest, HEADER_NAMES } from "./headers.ts";
package/src/lex.ts CHANGED
@@ -42,6 +42,11 @@ export const KEYWORDS = [
42
42
  "capture",
43
43
  "fee",
44
44
  "shares",
45
+ "object",
46
+ "attach",
47
+ "subject",
48
+ "rename",
49
+ "columns",
45
50
  ] as const;
46
51
  export interface Token {
47
52
  kind: "name" | "number" | "string" | "date" | "punct" | "eof";
package/src/parse.ts CHANGED
@@ -172,14 +172,30 @@ class Parser {
172
172
  });
173
173
  continue;
174
174
  }
175
+ if (this.eat("object")) {
176
+ const name = this.identifier();
177
+ const title =
178
+ this.peek().kind === "string"
179
+ ? (JSON.parse(this.take().text) as string)
180
+ : name;
181
+ const body = this.block();
182
+ program.decls.push({
183
+ kind: "object",
184
+ name,
185
+ title,
186
+ body,
187
+ span: this.span(start),
188
+ });
189
+ continue;
190
+ }
175
191
  const name = this.identifier();
176
192
  this.expect("=");
177
193
  const object = this.path();
178
194
  const body = this.block();
179
195
  program.decls.push({
180
- kind: "object",
196
+ kind: "assignment",
181
197
  name,
182
- object,
198
+ target: object,
183
199
  body,
184
200
  span: this.span(start),
185
201
  });
@@ -194,7 +210,66 @@ class Parser {
194
210
  if (this.peek().kind === "eof")
195
211
  this.fail(`unclosed block, expected ${end}`, `add ${end}`);
196
212
  const start = this.peek().span.start;
213
+ if (this.eat("attach")) {
214
+ const name = this.identifier();
215
+ this.expect("=");
216
+ const target = this.path();
217
+ const body = this.block();
218
+ entries.push({
219
+ key: `attach ${name} = ${target}`,
220
+ value: body,
221
+ span: this.span(start),
222
+ });
223
+ this.separators();
224
+ continue;
225
+ }
226
+ if (this.eat("rename")) {
227
+ const body = this.block();
228
+ entries.push({
229
+ key: "rename",
230
+ value: body,
231
+ span: this.span(start),
232
+ });
233
+ this.separators();
234
+ continue;
235
+ }
236
+ if (this.eat("expose")) {
237
+ const action = this.identifier();
238
+ let publicName = action;
239
+ if (this.eat("as")) {
240
+ publicName = this.identifier();
241
+ }
242
+ entries.push({
243
+ key: "expose",
244
+ value: {
245
+ kind: "call",
246
+ name: action,
247
+ args: [{ kind: "name", value: publicName, span: this.span(start) }],
248
+ span: this.span(start),
249
+ },
250
+ span: this.span(start),
251
+ });
252
+ this.separators();
253
+ continue;
254
+ }
197
255
  let key = this.path();
256
+ if (key === "columns" && !this.at(":")) {
257
+ let value: Expr;
258
+ if (this.at("[")) {
259
+ value = this.atom();
260
+ } else if (this.at("{")) {
261
+ value = this.block();
262
+ } else {
263
+ value = { kind: "list", items: [], span: this.span(start) };
264
+ }
265
+ entries.push({
266
+ key: "columns",
267
+ value,
268
+ span: this.span(start),
269
+ });
270
+ this.separators();
271
+ continue;
272
+ }
198
273
  if (key === "action" && !this.at(":")) key += " " + this.identifier();
199
274
  if (key === "when") {
200
275
  const tunable = this.identifier();
@@ -242,7 +317,8 @@ class Parser {
242
317
  private operand(): BlockExpr {
243
318
  const value = this.atom();
244
319
  return this.record({
245
- [value.kind === "name" && /^(self|input|party)\./.test(value.value)
320
+ [value.kind === "name" &&
321
+ /^(self|input|party|subject)\./.test(value.value)
246
322
  ? "field"
247
323
  : "literal"]: value,
248
324
  });
@@ -264,6 +340,8 @@ class Parser {
264
340
  };
265
341
  if (this.eat("for")) values.action = this.atom();
266
342
  if (this.eat("is")) values.decision = this.atom();
343
+ for (const key of ["protectedRequest", "differentFromInitiator"])
344
+ if (this.eat(key)) values[key] = this.atom();
267
345
  return this.record(values);
268
346
  }
269
347
  if (this.eat("unique")) {
@@ -316,6 +394,7 @@ class Parser {
316
394
  this.expect(key);
317
395
  values[key] = this.atom();
318
396
  }
397
+ if (this.eat("instruction")) values.instruction = this.atom();
319
398
  return this.record(values);
320
399
  }
321
400
  const left = this.operand();
@@ -361,6 +440,8 @@ class Parser {
361
440
  }
362
441
  for (const key of ["fee", "capture", "key"])
363
442
  if (this.eat(key)) values[key] = this.atom();
443
+ if (this.eat("boundary"))
444
+ values.boundary = this.record({ adapter: this.atom() });
364
445
  return this.record(values);
365
446
  }
366
447
  private block(): BlockExpr {