@hyperscale0/hsx 2.4.0 → 3.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 (249) hide show
  1. package/CHANGELOG.md +2 -400
  2. package/README.md +3 -92
  3. package/dist/src/ast.d.ts +99 -310
  4. package/dist/src/ast.d.ts.map +1 -1
  5. package/dist/src/ast.js +16 -69
  6. package/dist/src/ast.js.map +1 -1
  7. package/dist/src/cli.d.ts +6 -19
  8. package/dist/src/cli.d.ts.map +1 -1
  9. package/dist/src/cli.js +76 -315
  10. package/dist/src/cli.js.map +1 -1
  11. package/dist/src/compile.d.ts +23 -73
  12. package/dist/src/compile.d.ts.map +1 -1
  13. package/dist/src/compile.js +1113 -148
  14. package/dist/src/compile.js.map +1 -1
  15. package/dist/src/cost.d.ts +8 -77
  16. package/dist/src/cost.d.ts.map +1 -1
  17. package/dist/src/cost.js +13 -422
  18. package/dist/src/cost.js.map +1 -1
  19. package/dist/src/format.d.ts +8 -7
  20. package/dist/src/format.d.ts.map +1 -1
  21. package/dist/src/format.js +9 -175
  22. package/dist/src/format.js.map +1 -1
  23. package/dist/src/headers.d.ts +35 -0
  24. package/dist/src/headers.d.ts.map +1 -0
  25. package/dist/src/headers.js +108 -0
  26. package/dist/src/headers.js.map +1 -0
  27. package/dist/src/index.d.ts +6 -12
  28. package/dist/src/index.d.ts.map +1 -1
  29. package/dist/src/index.js +4 -9
  30. package/dist/src/index.js.map +1 -1
  31. package/dist/src/lex.d.ts +8 -28
  32. package/dist/src/lex.d.ts.map +1 -1
  33. package/dist/src/lex.js +88 -146
  34. package/dist/src/lex.js.map +1 -1
  35. package/dist/src/parse.d.ts +4 -17
  36. package/dist/src/parse.d.ts.map +1 -1
  37. package/dist/src/parse.js +402 -1040
  38. package/dist/src/parse.js.map +1 -1
  39. package/dist/src/std-bundle.d.ts.map +1 -1
  40. package/dist/src/std-bundle.js +12 -20
  41. package/dist/src/std-bundle.js.map +1 -1
  42. package/dist/src/std-library.d.ts +1 -1
  43. package/dist/src/std-library.d.ts.map +1 -1
  44. package/dist/src/std-library.js +1 -5
  45. package/dist/src/std-library.js.map +1 -1
  46. package/dist/src/tunables.d.ts +7 -0
  47. package/dist/src/tunables.d.ts.map +1 -0
  48. package/dist/src/tunables.js +26 -0
  49. package/dist/src/tunables.js.map +1 -0
  50. package/dist/src/version.d.ts +2 -4
  51. package/dist/src/version.d.ts.map +1 -1
  52. package/dist/src/version.js +2 -4
  53. package/dist/src/version.js.map +1 -1
  54. package/docs/README.md +179 -41
  55. package/docs/headers.md +44 -0
  56. package/examples/cost-table.json +99 -751
  57. package/examples/library.hsx +59 -0
  58. package/package.json +9 -17
  59. package/src/ast.ts +82 -441
  60. package/src/cli.ts +77 -362
  61. package/src/compile.ts +1535 -247
  62. package/src/cost.ts +28 -671
  63. package/src/format.ts +12 -256
  64. package/src/headers.ts +126 -0
  65. package/src/index.ts +7 -39
  66. package/src/lex.ts +99 -195
  67. package/src/parse.ts +403 -1209
  68. package/src/std-bundle.ts +12 -20
  69. package/src/std-library.ts +2 -7
  70. package/src/tunables.ts +31 -0
  71. package/src/version.ts +2 -5
  72. package/std/approvals.hsx +17 -0
  73. package/std/cards.hsx +63 -0
  74. package/std/collections.hsx +31 -0
  75. package/std/escrow.hsx +43 -0
  76. package/std/financing.hsx +372 -0
  77. package/std/insurance.hsx +59 -0
  78. package/std/lending.hsx +115 -0
  79. package/std/marketplace.hsx +24 -0
  80. package/std/money.hsx +195 -0
  81. package/std/savings.hsx +44 -0
  82. package/std/travel.hsx +98 -0
  83. package/std/wallet.hsx +41 -0
  84. package/dist/src/diagnostics.d.ts +0 -13
  85. package/dist/src/diagnostics.d.ts.map +0 -1
  86. package/dist/src/diagnostics.js +0 -587
  87. package/dist/src/diagnostics.js.map +0 -1
  88. package/dist/src/emit.d.ts +0 -51
  89. package/dist/src/emit.d.ts.map +0 -1
  90. package/dist/src/emit.js +0 -192
  91. package/dist/src/emit.js.map +0 -1
  92. package/dist/src/entry-overrides.d.ts +0 -58
  93. package/dist/src/entry-overrides.d.ts.map +0 -1
  94. package/dist/src/entry-overrides.js +0 -284
  95. package/dist/src/entry-overrides.js.map +0 -1
  96. package/dist/src/ir.d.ts +0 -73
  97. package/dist/src/ir.d.ts.map +0 -1
  98. package/dist/src/ir.js +0 -15
  99. package/dist/src/ir.js.map +0 -1
  100. package/dist/src/limits.d.ts +0 -23
  101. package/dist/src/limits.d.ts.map +0 -1
  102. package/dist/src/limits.js +0 -23
  103. package/dist/src/limits.js.map +0 -1
  104. package/dist/src/lsp/server.d.ts +0 -32
  105. package/dist/src/lsp/server.d.ts.map +0 -1
  106. package/dist/src/lsp/server.js +0 -391
  107. package/dist/src/lsp/server.js.map +0 -1
  108. package/dist/src/modules.d.ts +0 -38
  109. package/dist/src/modules.d.ts.map +0 -1
  110. package/dist/src/modules.js +0 -372
  111. package/dist/src/modules.js.map +0 -1
  112. package/dist/src/typecheck.d.ts +0 -8
  113. package/dist/src/typecheck.d.ts.map +0 -1
  114. package/dist/src/typecheck.js +0 -4131
  115. package/dist/src/typecheck.js.map +0 -1
  116. package/docs/guide/01-first-program.md +0 -24
  117. package/docs/guide/02-money.md +0 -25
  118. package/docs/guide/03-instruments.md +0 -93
  119. package/docs/guide/04-lifecycles.md +0 -40
  120. package/docs/guide/05-fees-and-splits.md +0 -45
  121. package/docs/guide/06-schedules.md +0 -26
  122. package/docs/guide/07-composition.md +0 -52
  123. package/docs/guide/08-writing-a-module.md +0 -85
  124. package/docs/guide/09-cost.md +0 -24
  125. package/docs/guide/10-diagnostics.md +0 -27
  126. package/docs/llms-full.txt +0 -3684
  127. package/docs/llms.txt +0 -44
  128. package/docs/piece-plans.md +0 -120
  129. package/docs/playground.md +0 -55
  130. package/docs/reference/cli.md +0 -36
  131. package/docs/reference/diagnostics.md +0 -901
  132. package/docs/reference/grammar.md +0 -38
  133. package/docs/reference/std/advance.md +0 -112
  134. package/docs/reference/std/cancellable_booking.md +0 -159
  135. package/docs/reference/std/captured_payment.md +0 -115
  136. package/docs/reference/std/conditional_disbursement.md +0 -101
  137. package/docs/reference/std/credit_facility.md +0 -108
  138. package/docs/reference/std/held_payment.md +0 -173
  139. package/docs/reference/std/instant_transfer.md +0 -97
  140. package/docs/reference/std/metered.md +0 -89
  141. package/docs/reference/std/pooled_split.md +0 -95
  142. package/docs/reference/std/premium_forward.md +0 -119
  143. package/docs/reference/std/reconciled_payout.md +0 -103
  144. package/docs/reference/std/rotating_pool.md +0 -130
  145. package/docs/reference/std/scheduled.md +0 -136
  146. package/docs/reference/std/security_deposit.md +0 -138
  147. package/docs/reference/std/settlement_batch.md +0 -123
  148. package/docs/reference/std/swap.md +0 -133
  149. package/docs/reference/std/threshold_pool.md +0 -138
  150. package/docs/reference/std/weighted_distribution.md +0 -135
  151. package/docs/reference/types.md +0 -61
  152. package/docs/reference/udl-output.md +0 -13
  153. package/examples/01-first-program/README.md +0 -45
  154. package/examples/01-first-program/tip-jar.hsx +0 -17
  155. package/examples/02-imports-and-modules/README.md +0 -96
  156. package/examples/02-imports-and-modules/photo-booth.hsx +0 -37
  157. package/examples/03-diagnostics/README.md +0 -68
  158. package/examples/03-diagnostics/corner-shop-fixed.hsx +0 -22
  159. package/examples/03-diagnostics/corner-shop.hsx +0 -19
  160. package/examples/04-complete-product/README.md +0 -84
  161. package/examples/04-complete-product/study-hall.hsx +0 -67
  162. package/examples/05-authored-instrument/README.md +0 -5
  163. package/examples/05-authored-instrument/payment.hsx +0 -37
  164. package/examples/05-watch-club/README.md +0 -6
  165. package/examples/05-watch-club/watch-club.hsx +0 -123
  166. package/examples/README.md +0 -48
  167. package/examples/advance/README.md +0 -3
  168. package/examples/advance/advance.hsx +0 -13
  169. package/examples/advance/advance.udl +0 -367
  170. package/examples/cancellable_booking/README.md +0 -3
  171. package/examples/cancellable_booking/cancellable_booking.hsx +0 -14
  172. package/examples/cancellable_booking/cancellable_booking.udl +0 -413
  173. package/examples/captured_payment/README.md +0 -3
  174. package/examples/captured_payment/captured_payment.hsx +0 -17
  175. package/examples/captured_payment/captured_payment.udl +0 -686
  176. package/examples/conditional_disbursement/README.md +0 -3
  177. package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -15
  178. package/examples/conditional_disbursement/conditional_disbursement.udl +0 -418
  179. package/examples/credit_facility/README.md +0 -3
  180. package/examples/credit_facility/credit_facility.hsx +0 -24
  181. package/examples/credit_facility/credit_facility.udl +0 -1396
  182. package/examples/held_payment/README.md +0 -3
  183. package/examples/held_payment/held_payment.hsx +0 -13
  184. package/examples/held_payment/held_payment.udl +0 -569
  185. package/examples/instant_transfer/README.md +0 -3
  186. package/examples/instant_transfer/instant_transfer.hsx +0 -16
  187. package/examples/instant_transfer/instant_transfer.udl +0 -376
  188. package/examples/metered/README.md +0 -3
  189. package/examples/metered/metered.hsx +0 -13
  190. package/examples/metered/metered.udl +0 -253
  191. package/examples/pooled_split/README.md +0 -3
  192. package/examples/pooled_split/pooled_split.hsx +0 -15
  193. package/examples/pooled_split/pooled_split.udl +0 -432
  194. package/examples/premium_forward/README.md +0 -3
  195. package/examples/premium_forward/premium_forward.hsx +0 -19
  196. package/examples/premium_forward/premium_forward.udl +0 -604
  197. package/examples/reconciled_payout/README.md +0 -3
  198. package/examples/reconciled_payout/reconciled_payout.hsx +0 -13
  199. package/examples/reconciled_payout/reconciled_payout.udl +0 -312
  200. package/examples/rotating_pool/README.md +0 -3
  201. package/examples/rotating_pool/rotating_pool.hsx +0 -18
  202. package/examples/rotating_pool/rotating_pool.udl +0 -4370
  203. package/examples/scheduled/README.md +0 -3
  204. package/examples/scheduled/scheduled.hsx +0 -12
  205. package/examples/scheduled/scheduled.udl +0 -355
  206. package/examples/security_deposit/README.md +0 -3
  207. package/examples/security_deposit/security_deposit.hsx +0 -21
  208. package/examples/security_deposit/security_deposit.udl +0 -320
  209. package/examples/settlement_batch/README.md +0 -3
  210. package/examples/settlement_batch/settlement_batch.hsx +0 -19
  211. package/examples/settlement_batch/settlement_batch.udl +0 -757
  212. package/examples/swap/README.md +0 -3
  213. package/examples/swap/swap.hsx +0 -19
  214. package/examples/swap/swap.udl +0 -892
  215. package/examples/threshold_pool/README.md +0 -3
  216. package/examples/threshold_pool/threshold_pool.hsx +0 -16
  217. package/examples/threshold_pool/threshold_pool.udl +0 -680
  218. package/examples/weighted_distribution/README.md +0 -3
  219. package/examples/weighted_distribution/weighted_distribution.hsx +0 -20
  220. package/examples/weighted_distribution/weighted_distribution.udl +0 -348
  221. package/skills/hsx/SKILL.md +0 -449
  222. package/src/diagnostics.ts +0 -620
  223. package/src/emit.ts +0 -282
  224. package/src/entry-overrides.ts +0 -428
  225. package/src/ir.ts +0 -113
  226. package/src/limits.ts +0 -22
  227. package/src/lsp/server.ts +0 -460
  228. package/src/modules.ts +0 -452
  229. package/src/typecheck.ts +0 -5381
  230. package/std/SEMANTICS.md +0 -44
  231. package/std/money_flows/advance.hsx +0 -235
  232. package/std/money_flows/cancellable_booking.hsx +0 -402
  233. package/std/money_flows/captured_payment.hsx +0 -220
  234. package/std/money_flows/conditional_disbursement.hsx +0 -226
  235. package/std/money_flows/credit_facility.hsx +0 -214
  236. package/std/money_flows/held_payment.hsx +0 -812
  237. package/std/money_flows/index.hsx +0 -4
  238. package/std/money_flows/instant_transfer.hsx +0 -231
  239. package/std/money_flows/metered.hsx +0 -104
  240. package/std/money_flows/pooled_split.hsx +0 -109
  241. package/std/money_flows/premium_forward.hsx +0 -307
  242. package/std/money_flows/reconciled_payout.hsx +0 -119
  243. package/std/money_flows/rotating_pool.hsx +0 -305
  244. package/std/money_flows/scheduled.hsx +0 -599
  245. package/std/money_flows/security_deposit.hsx +0 -248
  246. package/std/money_flows/settlement_batch.hsx +0 -173
  247. package/std/money_flows/swap.hsx +0 -1192
  248. package/std/money_flows/threshold_pool.hsx +0 -307
  249. package/std/money_flows/weighted_distribution.hsx +0 -237
package/dist/src/ast.d.ts CHANGED
@@ -1,317 +1,106 @@
1
- /**
2
- * The HSX abstract syntax tree.
3
- *
4
- * Every node carries a byte-offset span into the original source. Spans are
5
- * the compiler's source-mapping currency: diagnostics at every later stage
6
- * (typecheck, lowering, verdicts) point at source coordinates, never at
7
- * lowered IR paths. Offsets convert to line/column via `lineColAt`.
8
- */
9
1
  export interface Span {
10
- /** Inclusive start byte offset into the source text. */
11
- readonly start: number;
12
- /** Exclusive end byte offset into the source text. */
13
- readonly end: number;
2
+ start: number;
3
+ end: number;
14
4
  }
15
- export interface LineCol {
16
- /** 1-indexed line. */
17
- readonly line: number;
18
- /** 1-indexed column, counted in UTF-16 code units. */
19
- readonly column: number;
20
- }
21
- /** Convert a byte offset to a 1-indexed line/column position. */
22
- export declare function lineColAt(source: string, offset: number): LineCol;
23
- /**
24
- * Convert a UTF-8 byte offset to a UTF-16 code-unit offset over a string.
25
- * Walks Unicode code points, counting UTF-8 bytes and UTF-16 code units.
26
- * Clamps to [0, source.length].
27
- */
28
- export declare function byteOffsetToCodeUnit(source: string, byteOffset: number): number;
29
- /**
30
- * One source scanned once, so many offsets resolve without rescanning it.
31
- * `lineColAt` walks from offset zero every time, which turns a run of d
32
- * diagnostics over an n-byte source into O(n*d) work. A caller holding this
33
- * pays O(n) once and O(log n) per offset.
34
- */
35
- export interface LineIndex {
36
- /** Source length, so `lineColIn` clamps exactly as `lineColAt` does. */
37
- readonly length: number;
38
- /** Offset of the first character of each line, ascending. Line 1 starts at 0. */
39
- readonly starts: readonly number[];
40
- }
41
- /** Scan a source once for the offset every line starts at. */
42
- export declare function lineIndex(source: string): LineIndex;
43
- /**
44
- * Resolve one offset against a prebuilt index. Returns exactly what
45
- * `lineColAt` returns for the same source and offset.
46
- */
47
- export declare function lineColIn(index: LineIndex, offset: number): LineCol;
48
- export interface IdentExpr {
49
- readonly kind: "ident";
50
- readonly name: string;
51
- /** A literal quoted block key keeps its exact spelling during JSON lowering. */
52
- readonly quoted?: boolean;
53
- readonly span: Span;
54
- }
55
- export interface StringExpr {
56
- readonly kind: "string";
57
- readonly span: Span;
58
- readonly value: string;
59
- }
60
- export interface NumberExpr {
61
- readonly kind: "number";
62
- /** The literal exactly as written, e.g. "99.5". Interpretation is typed later. */
63
- readonly raw: string;
64
- readonly span: Span;
65
- }
66
- export interface BooleanExpr {
67
- readonly kind: "boolean";
68
- readonly span: Span;
69
- readonly value: boolean;
70
- }
71
- /** A currency-indexed literal. The checker converts it to integer minor units. */
72
- export interface MoneyExpr {
73
- readonly currency: IdentExpr;
74
- readonly kind: "money";
75
- readonly raw: string;
76
- readonly span: Span;
77
- }
78
- /** A dotted name used for modules, UDL operations, and field paths. */
79
- export interface PathExpr {
80
- readonly kind: "path";
81
- readonly parts: readonly IdentExpr[];
82
- readonly span: Span;
83
- }
84
- /** A nominal type application such as `money<SAR>` or `ref<invoice>`. */
85
- export interface TypeApplyExpr {
86
- readonly args: readonly Expr[];
87
- readonly callee: IdentExpr;
88
- readonly kind: "type_apply";
89
- readonly span: Span;
90
- }
91
- /** A general instrument or constant application, with optional type arguments. */
92
- export interface ApplyExpr {
93
- readonly args: readonly Expr[];
94
- readonly callee: PathExpr;
95
- readonly kind: "apply";
96
- readonly span: Span;
97
- readonly typeArgs: readonly Expr[];
98
- }
99
- export interface PercentExpr {
100
- /** Exact basis points: 99.5% is 9950. Percents never round. */
101
- readonly bps: number;
102
- readonly kind: "percent";
103
- readonly raw: string;
104
- readonly span: Span;
105
- }
106
- /** A type or constructor application: `money(SAR)`, `id(vehicle)`. */
107
- export interface CallExpr {
108
- readonly args: readonly Expr[];
109
- readonly callee: IdentExpr;
110
- readonly kind: "call";
111
- readonly span: Span;
112
- }
113
- /**
114
- * An exit amount chosen by a decision port and bounded by stored money:
115
- * `decided { field: damageAmount, bound: depositAmount, remainder: return }`.
116
- */
117
- export interface DecidedAmountExpr {
118
- readonly body: BlockExpr;
119
- readonly kind: "decided_amount";
120
- readonly span: Span;
121
- }
122
- /**
123
- * A reference to a decision port, optionally bounded (`port dispute within
124
- * P14D`) or carrying the date that decides when the port has not
125
- * (`port approve_release | at(releaseDueAt)`).
126
- */
127
- export interface PortRefExpr {
128
- /** `| at(<field>)`, the stored date field that resolves an undecided hold. */
129
- readonly deadline?: IdentExpr;
130
- readonly kind: "port_ref";
131
- readonly name: IdentExpr;
132
- readonly span: Span;
133
- readonly within?: IdentExpr;
134
- }
135
- /**
136
- * `retention.release`, one settlement naming another settlement's declared
137
- * referenceable exit. The checker resolves it wholly before lowering.
138
- */
139
- export interface SettlementRefExpr {
140
- readonly kind: "settlement_ref";
141
- /** The exit named on the owner, e.g. `release`. */
142
- readonly member: IdentExpr;
143
- /** The settlement being referenced. */
144
- readonly owner: IdentExpr;
145
- readonly span: Span;
146
- }
147
- export interface ListExpr {
148
- readonly items: readonly Expr[];
149
- readonly kind: "list";
150
- readonly span: Span;
151
- }
152
- /** A brace block of entries: `{ buyer: 1%, seller: 2% }`. */
153
- export interface BlockExpr {
154
- readonly entries: readonly Entry[];
155
- readonly kind: "block";
156
- readonly span: Span;
157
- }
158
- /**
159
- * A named typed binding inside an expression position:
160
- * `amount: price: money(SAR)` binds the field name `price` to type
161
- * `money(SAR)`: the entry key is `amount`, the value is this binding.
162
- */
163
- export interface BindingExpr {
164
- readonly kind: "binding";
165
- readonly name: IdentExpr;
166
- readonly span: Span;
167
- readonly type: Expr;
168
- }
169
- export type Expr = ApplyExpr | BindingExpr | BlockExpr | BooleanExpr | CallExpr | DecidedAmountExpr | IdentExpr | ListExpr | MoneyExpr | NumberExpr | PathExpr | PercentExpr | PortRefExpr | SettlementRefExpr | StringExpr | TypeApplyExpr;
170
- /**
171
- * One keyed entry inside a declaration body. Three surface shapes normalize
172
- * here: `payer: buyer` (key + value), `fees { ... }` (key + block value),
173
- * and `on_cancel(funded) { ... }` (key + qualifiers + block value).
174
- */
5
+ export interface Diagnostic {
6
+ code: string;
7
+ message: string;
8
+ fix: string;
9
+ span: Span;
10
+ }
11
+ export type Expr = {
12
+ kind: "name" | "text" | "number" | "money" | "percent" | "duration" | "date";
13
+ value: string;
14
+ span: Span;
15
+ } | {
16
+ kind: "list";
17
+ items: Expr[];
18
+ span: Span;
19
+ } | {
20
+ kind: "block";
21
+ entries: Entry[];
22
+ span: Span;
23
+ } | {
24
+ kind: "call";
25
+ name: string;
26
+ args: Expr[];
27
+ span: Span;
28
+ } | {
29
+ kind: "type";
30
+ name: string;
31
+ target?: string;
32
+ owner?: string;
33
+ optional: boolean;
34
+ many?: boolean;
35
+ span: Span;
36
+ } | {
37
+ kind: "default";
38
+ type: Expr;
39
+ value: Expr;
40
+ span: Span;
41
+ } | {
42
+ kind: "capped";
43
+ rate: Expr;
44
+ cap: Expr;
45
+ span: Span;
46
+ };
175
47
  export interface Entry {
176
- /** Port dependencies retained through compile-time selection and substitution. */
177
- readonly conditionPorts?: readonly string[];
178
- /** `for item in bound { ... }`, expanded before binding or UDL lowering. */
179
- readonly iteration?: {
180
- readonly binding: IdentExpr;
181
- readonly bound: Expr;
182
- };
183
- readonly key: IdentExpr;
184
- readonly qualifiers: readonly IdentExpr[];
185
- readonly span: Span;
186
- readonly value: Expr;
48
+ key: string;
49
+ value: Expr;
50
+ span: Span;
187
51
  }
188
- /** `program used_car_escrow "Used-car escrow"` names the company program. */
189
- export interface ProgramDecl {
190
- readonly kind: "program";
191
- readonly name: IdentExpr;
192
- readonly span: Span;
193
- readonly title?: StringExpr;
194
- }
195
- /** `use held_settlement` selects one published catalog instrument. */
196
- export interface UseDecl {
197
- readonly instrument: IdentExpr;
198
- readonly kind: "use";
199
- readonly span: Span;
200
- }
201
- /** `expose held_settlement.release as releaseFunds` names a public action. */
202
- export interface ExposeDecl {
203
- readonly action: IdentExpr;
204
- readonly instrument: IdentExpr;
205
- readonly kind: "expose";
206
- readonly publicName: IdentExpr;
207
- readonly span: Span;
208
- }
209
- /** `import { held_payment } from "std/money_flows"`. */
210
- export interface ImportDecl {
211
- readonly from: StringExpr;
212
- readonly kind: "import";
213
- readonly names: readonly IdentExpr[];
214
- readonly span: Span;
215
- }
216
- /** `party buyer: person` with an optional attribute block. */
217
- export interface PartyDecl {
218
- readonly attrs?: BlockExpr;
219
- readonly kind: "party";
220
- readonly name: IdentExpr;
221
- readonly partyKind: IdentExpr;
222
- readonly span: Span;
223
- }
224
- /** `asset vehicle: good { title_transfer: off_platform }`. */
225
- export interface AssetDecl {
226
- readonly assetKind: IdentExpr;
227
- readonly attrs?: BlockExpr;
228
- readonly kind: "asset";
229
- readonly name: IdentExpr;
230
- readonly span: Span;
231
- }
232
- /** A full UDL subject-kind declaration. `asset` remains shorthand for this form. */
233
- export interface SubjectDecl {
234
- readonly body: BlockExpr;
235
- readonly kind: "subject";
236
- readonly name: IdentExpr;
237
- readonly span: Span;
238
- }
239
- /** `port confirm_handover { allowed: [buyer], ... }`. */
240
- export interface PortDecl {
241
- readonly body: BlockExpr;
242
- readonly kind: "port";
243
- readonly name: IdentExpr;
244
- readonly span: Span;
245
- }
246
- /** `module std.money_flows` gives a file its importable module name. */
247
- export interface ModuleDecl {
248
- readonly kind: "module";
249
- readonly name: PathExpr;
250
- readonly span: Span;
251
- }
252
- export interface TypeParameter {
253
- readonly name: IdentExpr;
254
- readonly span: Span;
255
- }
256
- export interface Parameter {
257
- readonly name: IdentExpr;
258
- readonly span: Span;
259
- readonly type: Expr;
260
- }
261
- /** The single general instrument definition form. */
262
52
  export interface InstrumentDecl {
263
- readonly body: BlockExpr;
264
- /** Module-local declarations carried only while this template is bound. */
265
- readonly declarationScope?: readonly ApplicationScopeDecl[];
266
- readonly exported: boolean;
267
- /** True when the source declared a parameter list, including an empty `()`. */
268
- readonly hasParameterList: boolean;
269
- readonly kind: "instrument";
270
- readonly name: IdentExpr;
271
- readonly parameters: readonly Parameter[];
272
- readonly span: Span;
273
- readonly typeParameters: readonly TypeParameter[];
274
- }
275
- /** Instantiation of an exported parameterized instrument. */
276
- export interface InstrumentApplyDecl {
277
- readonly application: ApplyExpr;
278
- /** Module-local declarations carried only while this application is bound. */
279
- readonly declarationScope?: readonly ApplicationScopeDecl[];
280
- readonly exported: boolean;
281
- readonly kind: "instrument_apply";
282
- readonly metadata?: BlockExpr;
283
- readonly name: IdentExpr;
284
- readonly span: Span;
285
- }
286
- export interface TypeDecl {
287
- readonly exported: boolean;
288
- readonly kind: "type";
289
- readonly name: IdentExpr;
290
- readonly span: Span;
291
- readonly value: Expr;
292
- }
293
- export interface ConstDecl {
294
- readonly exported: boolean;
295
- readonly kind: "const";
296
- readonly name: IdentExpr;
297
- readonly span: Span;
298
- readonly type?: Expr;
299
- readonly value: Expr;
300
- }
301
- export type ApplicationScopeDecl = ConstDecl | InstrumentDecl | PartyDecl | PortDecl | TypeDecl;
302
- export type Decl = AssetDecl | ConstDecl | ExposeDecl | ImportDecl | InstrumentApplyDecl | InstrumentDecl | ModuleDecl | PartyDecl | PortDecl | ProgramDecl | SubjectDecl | TypeDecl | UseDecl;
53
+ kind: "instrument";
54
+ name: string;
55
+ parameters: Entry[];
56
+ body: Extract<Expr, {
57
+ kind: "block";
58
+ }>;
59
+ span: Span;
60
+ }
61
+ export interface ObjectDecl {
62
+ kind: "object";
63
+ name: string;
64
+ object: string;
65
+ body: Extract<Expr, {
66
+ kind: "block";
67
+ }>;
68
+ span: Span;
69
+ }
70
+ export type Decl = InstrumentDecl | ObjectDecl | {
71
+ kind: "party";
72
+ name: string;
73
+ partyKind: string;
74
+ role?: string;
75
+ span: Span;
76
+ } | {
77
+ kind: "use";
78
+ name: string;
79
+ span: Span;
80
+ } | {
81
+ kind: "expose";
82
+ target: string;
83
+ name: string;
84
+ span: Span;
85
+ } | {
86
+ kind: "hide";
87
+ target: string;
88
+ span: Span;
89
+ };
303
90
  export interface Program {
304
- readonly decls: readonly Decl[];
305
- readonly span: Span;
306
- }
307
- /**
308
- * A parse-stage problem, worded for the program's author. Parsing is total:
309
- * it never throws, it returns the best-effort tree plus these.
310
- */
311
- export interface Diagnostic {
312
- readonly code?: string;
313
- readonly fix?: string;
314
- readonly message: string;
315
- readonly span: Span;
316
- }
91
+ name: string;
92
+ title: string;
93
+ currency: string;
94
+ header: boolean;
95
+ decls: Decl[];
96
+ span: Span;
97
+ }
98
+ export declare const lineColAt: (source: string, offset: number) => {
99
+ line: number;
100
+ column: number;
101
+ };
102
+ export declare function byteOffsetToCodeUnit(source: string, offset: number): number;
103
+ export type BlockExpr = Extract<Expr, {
104
+ kind: "block";
105
+ }>;
317
106
  //# sourceMappingURL=ast.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,IAAI;IACnB,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,sDAAsD;IACtD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,OAAO;IACtB,sBAAsB;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAWjE;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,MAAM,CAkBR;AAED;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,8DAA8D;AAC9D,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAMnD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAUnE;AAID,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QA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IAAI,EAAE,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;CACZ;AACD,eAAO,MAAM,SAAS,WAAY,MAAM,UAAU,MAAM;IAGpD,IAAI;IACJ,MAAM;CAET,CAAC;AACF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAS3E;AACD,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,EAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC"}
package/dist/src/ast.js CHANGED
@@ -1,72 +1,19 @@
1
- /**
2
- * The HSX abstract syntax tree.
3
- *
4
- * Every node carries a byte-offset span into the original source. Spans are
5
- * the compiler's source-mapping currency: diagnostics at every later stage
6
- * (typecheck, lowering, verdicts) point at source coordinates, never at
7
- * lowered IR paths. Offsets convert to line/column via `lineColAt`.
8
- */
9
- /** Convert a byte offset to a 1-indexed line/column position. */
10
- export function lineColAt(source, offset) {
11
- let line = 1;
12
- let lineStart = 0;
13
- const clamped = Math.max(0, Math.min(offset, source.length));
14
- for (let index = 0; index < clamped; index += 1) {
15
- if (source.charCodeAt(index) === 10) {
16
- line += 1;
17
- lineStart = index + 1;
18
- }
1
+ export const lineColAt = (source, offset) => {
2
+ const before = source.slice(0, offset);
3
+ return {
4
+ line: before.split("\n").length,
5
+ column: offset - before.lastIndexOf("\n"),
6
+ };
7
+ };
8
+ export function byteOffsetToCodeUnit(source, offset) {
9
+ let bytes = 0;
10
+ let units = 0;
11
+ for (const c of source) {
12
+ bytes += new TextEncoder().encode(c).length;
13
+ if (bytes > offset)
14
+ break;
15
+ units += c.length;
19
16
  }
20
- return { column: clamped - lineStart + 1, line };
21
- }
22
- const utf8Encoder = new TextEncoder();
23
- /**
24
- * Convert a UTF-8 byte offset to a UTF-16 code-unit offset over a string.
25
- * Walks Unicode code points, counting UTF-8 bytes and UTF-16 code units.
26
- * Clamps to [0, source.length].
27
- */
28
- export function byteOffsetToCodeUnit(source, byteOffset) {
29
- if (byteOffset <= 0)
30
- return 0;
31
- let currentByte = 0;
32
- let codeUnit = 0;
33
- for (const char of source) {
34
- const charBytes = utf8Encoder.encode(char).length;
35
- if (currentByte + charBytes > byteOffset) {
36
- return codeUnit;
37
- }
38
- currentByte += charBytes;
39
- codeUnit += char.length;
40
- if (currentByte === byteOffset) {
41
- return codeUnit;
42
- }
43
- }
44
- return source.length;
45
- }
46
- /** Scan a source once for the offset every line starts at. */
47
- export function lineIndex(source) {
48
- const starts = [0];
49
- for (let index = 0; index < source.length; index += 1) {
50
- if (source.charCodeAt(index) === 10)
51
- starts.push(index + 1);
52
- }
53
- return { length: source.length, starts };
54
- }
55
- /**
56
- * Resolve one offset against a prebuilt index. Returns exactly what
57
- * `lineColAt` returns for the same source and offset.
58
- */
59
- export function lineColIn(index, offset) {
60
- const clamped = Math.max(0, Math.min(offset, index.length));
61
- let low = 0;
62
- let high = index.starts.length - 1;
63
- while (low < high) {
64
- const middle = Math.floor((low + high + 1) / 2);
65
- if (index.starts[middle] <= clamped)
66
- low = middle;
67
- else
68
- high = middle - 1;
69
- }
70
- return { column: clamped - index.starts[low] + 1, line: low + 1 };
17
+ return units;
71
18
  }
72
19
  //# sourceMappingURL=ast.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgBH,iEAAiE;AACjE,MAAM,UAAU,SAAS,CAAC,MAAc,EAAE,MAAc;IACtD,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7D,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACh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AAI,CAAC;KAC1C,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,MAAc;IACjE,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,KAAK,IAAI,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC5C,IAAI,KAAK,GAAG,MAAM;YAAE,MAAM;QAC1B,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC;IACpB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/src/cli.d.ts CHANGED
@@ -1,23 +1,10 @@
1
- /**
2
- * The `hsx` command line over the one compiler entry point and catalog.
3
- *
4
- * `check` prints diagnostics and says nothing else; `build` writes the
5
- * compiled artifacts as JSON. Neither reads the environment, neither touches
6
- * a network, and neither writes outside the path the caller names.
7
- *
8
- * Everything here is a pure function of `argv` plus the injected `Io`, so the
9
- * spec drives the real code paths with an in-memory filesystem instead of
10
- * asserting on a subprocess's scrollback.
11
- */
12
- /** Filesystem and streams, injected so the CLI stays testable. */
13
1
  export interface Io {
14
- readonly err: (line: string) => void;
15
- readonly out: (line: string) => void;
16
- readonly readFile: (path: string) => Promise<string>;
17
- readonly writeFile: (path: string, contents: string) => Promise<void>;
18
- readonly stdin?: NodeJS.ReadableStream;
19
- readonly stdout?: NodeJS.WritableStream;
2
+ out(line: string): void;
3
+ err(line: string): void;
4
+ readFile(path: string): Promise<string>;
5
+ writeFile(path: string, text: string): Promise<void>;
6
+ stdin?: NodeJS.ReadableStream;
7
+ stdout?: NodeJS.WritableStream;
20
8
  }
21
- export declare const USAGE_TEXT = "hsx 2.4.0, the HSX compiler\n\nUsage:\n hsx check <file.hsx> [--catalog <catalog.udl>] [--strict]\n hsx build <file.hsx> [--catalog <catalog.udl>] [--out <file.json>] [--strict]\n hsx cost <file.hsx> [--catalog <catalog.udl>] [--json] [--out <file.json>] [--strict]\n hsx explain <HSX####>\n hsx format <file.hsx>\n hsx lsp\n hsx --version\n hsx --help\n\nCommands:\n check Compile and report diagnostics. Prints nothing when the program is clean.\n build Compile and write canonical UDL as JSON.\n cost Compile and print the version-pinned cost manifest as a table or JSON.\n explain Print one diagnostic title, fix, and source example.\n format Print the source in the one canonical HSX style.\n lsp Run the language server over stdin and stdout.\n\nOptions:\n --catalog <file> Read the published instrument catalogue as canonical UDL JSON.\n --json Print the cost manifest as JSON instead of a table.\n --out <file> Write build or cost JSON to this path instead of stdout.\n --strict Treat warning-severity diagnostics as failures.\n\nExit codes:\n 0 the program compiled (verdict valid, or warning without --strict)\n 1 the program was refused (verdict invalid, or warning with --strict)\n 2 the command line or the input file could not be used";
22
9
  export declare function runCli(argv: readonly string[], io: Io): Promise<number>;
23
10
  //# sourceMappingURL=cli.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAWH,kEAAkE;AAClE,MAAM,WAAW,EAAE;IACjB,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IACvC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CACzC;AAUD,eAAO,MAAM,UAAU,uxCA6BmC,C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