aontu 0.57.0 → 0.58.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 (117) hide show
  1. package/README.md +2 -2
  2. package/dist/agentsmd.js +1 -1
  3. package/dist/alias.d.ts +3 -0
  4. package/dist/alias.js +59 -0
  5. package/dist/alias.js.map +1 -0
  6. package/dist/aontu.d.ts +4 -2
  7. package/dist/aontu.js +11 -3
  8. package/dist/aontu.js.map +1 -1
  9. package/dist/cli.d.ts +3 -1
  10. package/dist/cli.js +475 -3
  11. package/dist/cli.js.map +1 -1
  12. package/dist/ctx.d.ts +2 -0
  13. package/dist/ctx.js +1 -0
  14. package/dist/ctx.js.map +1 -1
  15. package/dist/format.js +8 -2
  16. package/dist/format.js.map +1 -1
  17. package/dist/hints.js +40 -9
  18. package/dist/hints.js.map +1 -1
  19. package/dist/lang.js +354 -57
  20. package/dist/lang.js.map +1 -1
  21. package/dist/lower.d.ts +20 -0
  22. package/dist/lower.js +575 -0
  23. package/dist/lower.js.map +1 -0
  24. package/dist/lsp.d.ts +1 -1
  25. package/dist/lsp.js +1 -1
  26. package/dist/lsp.js.map +1 -1
  27. package/dist/mcp-server.js +1 -1
  28. package/dist/mcp.d.ts +1 -0
  29. package/dist/mcp.js +40 -3
  30. package/dist/mcp.js.map +1 -1
  31. package/dist/render.d.ts +53 -0
  32. package/dist/render.js +542 -0
  33. package/dist/render.js.map +1 -0
  34. package/dist/sigdecl.js +1 -1
  35. package/dist/sigdecl.js.map +1 -1
  36. package/dist/std.d.ts +2 -0
  37. package/dist/std.js +498 -2
  38. package/dist/std.js.map +1 -1
  39. package/dist/template.d.ts +5 -0
  40. package/dist/template.js +257 -0
  41. package/dist/template.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/dist/unify.js +43 -0
  44. package/dist/unify.js.map +1 -1
  45. package/dist/val/AggFuncVal.d.ts +1 -1
  46. package/dist/val/AggFuncVal.js +10 -21
  47. package/dist/val/AggFuncVal.js.map +1 -1
  48. package/dist/val/BagVal.js +1 -1
  49. package/dist/val/BagVal.js.map +1 -1
  50. package/dist/val/ConstraintVal.js +1 -1
  51. package/dist/val/EachFuncVal.d.ts +1 -1
  52. package/dist/val/EachFuncVal.js +8 -13
  53. package/dist/val/EachFuncVal.js.map +1 -1
  54. package/dist/val/EmitFuncVal.d.ts +23 -4
  55. package/dist/val/EmitFuncVal.js +298 -28
  56. package/dist/val/EmitFuncVal.js.map +1 -1
  57. package/dist/val/FilterFuncVal.js +8 -4
  58. package/dist/val/FilterFuncVal.js.map +1 -1
  59. package/dist/val/FormFuncVal.d.ts +14 -0
  60. package/dist/val/FormFuncVal.js +55 -0
  61. package/dist/val/FormFuncVal.js.map +1 -0
  62. package/dist/val/MapVal.d.ts +2 -1
  63. package/dist/val/MapVal.js +2 -1
  64. package/dist/val/MapVal.js.map +1 -1
  65. package/dist/val/PackFuncVal.d.ts +1 -1
  66. package/dist/val/PackFuncVal.js +22 -18
  67. package/dist/val/PackFuncVal.js.map +1 -1
  68. package/dist/val/PlaceVal.js +2 -1
  69. package/dist/val/PlaceVal.js.map +1 -1
  70. package/dist/val/RefVal.d.ts +3 -0
  71. package/dist/val/RefVal.js +156 -17
  72. package/dist/val/RefVal.js.map +1 -1
  73. package/dist/val/Val.d.ts +7 -1
  74. package/dist/val/Val.js +12 -1
  75. package/dist/val/Val.js.map +1 -1
  76. package/dist/val/members.d.ts +9 -0
  77. package/dist/val/members.js +52 -0
  78. package/dist/val/members.js.map +1 -0
  79. package/grammar/aontu.abnf +1 -1
  80. package/grammar/aontu.gbnf +1 -1
  81. package/grammar/aontu.lark +1 -1
  82. package/grammar/aontu.tmLanguage.json +1 -1
  83. package/package.json +1 -1
  84. package/skill/SKILL.md +4 -4
  85. package/skill/error-codes.md +1 -1
  86. package/skill/examples.md +1 -1
  87. package/skill/grammar-card.md +1 -1
  88. package/src/agentsmd.ts +1 -1
  89. package/src/alias.ts +112 -0
  90. package/src/aontu.ts +19 -2
  91. package/src/cli.ts +517 -3
  92. package/src/ctx.ts +13 -0
  93. package/src/format.ts +12 -2
  94. package/src/hints.ts +47 -9
  95. package/src/lang.ts +406 -62
  96. package/src/lower.ts +636 -0
  97. package/src/lsp.ts +1 -1
  98. package/src/mcp-server.ts +1 -1
  99. package/src/mcp.ts +43 -4
  100. package/src/render.ts +727 -0
  101. package/src/sigdecl.ts +1 -1
  102. package/src/std.ts +506 -1
  103. package/src/template.ts +291 -0
  104. package/src/unify.ts +47 -0
  105. package/src/val/AggFuncVal.ts +10 -21
  106. package/src/val/BagVal.ts +1 -1
  107. package/src/val/ConstraintVal.ts +1 -1
  108. package/src/val/EachFuncVal.ts +8 -16
  109. package/src/val/EmitFuncVal.ts +376 -39
  110. package/src/val/FilterFuncVal.ts +11 -4
  111. package/src/val/FormFuncVal.ts +119 -0
  112. package/src/val/MapVal.ts +3 -2
  113. package/src/val/PackFuncVal.ts +23 -19
  114. package/src/val/PlaceVal.ts +2 -1
  115. package/src/val/RefVal.ts +167 -18
  116. package/src/val/Val.ts +42 -1
  117. package/src/val/members.ts +86 -0
package/dist/lang.js CHANGED
@@ -72,6 +72,7 @@ const ReferFuncVal_1 = require("./val/ReferFuncVal");
72
72
  const GraphAtomVal_1 = require("./val/GraphAtomVal");
73
73
  const PackFuncVal_1 = require("./val/PackFuncVal");
74
74
  const EachFuncVal_1 = require("./val/EachFuncVal");
75
+ const FormFuncVal_1 = require("./val/FormFuncVal");
75
76
  const FilterFuncVal_1 = require("./val/FilterFuncVal");
76
77
  const MatchFuncVal_1 = require("./val/MatchFuncVal");
77
78
  const EmitFuncVal_1 = require("./val/EmitFuncVal");
@@ -125,10 +126,109 @@ const CC_d = 100;
125
126
  const CC_D = 68;
126
127
  // THE ALIAS SIGIL. `%` is part of an alias's name, so the name is one
127
128
  // lexeme wherever it appears and its meaning is decided by position:
128
- // a BINDING in key position (`%uint8: …` declares), a USE in value
129
+ // a BINDING in key position (`%uint8 = …` declares), a USE in value
129
130
  // position (`listen: %uint8` refers). docs/design/ALIASES.0.md §4.
130
131
  const CC_PCT = 37;
131
132
  const ALIAS_RE = /^%[A-Za-z_][A-Za-z0-9_]*/;
133
+ // THE DECLARATION OPERATOR. `%name = value` declares; the `=` is the
134
+ // pair's separator, lexed as the colon token so the declaration then
135
+ // parses as a pair whose key is the alias name (ALIASES.0.md X-1, as
136
+ // settled 2026-09-05). `=` is syntax ONLY there: anywhere else it is
137
+ // punctuation outside its syntax, and the bare-text scan below refuses
138
+ // it (`foo = 1`, `a: x=y`).
139
+ const CC_EQ = 61;
140
+ const CC_SP = 32;
141
+ const CC_TAB = 9;
142
+ // THE BARE-TEXT RULE. A bare string holds letters, digits, `-` and `_`,
143
+ // and nothing else. Every other punctuation character is either SYNTAX,
144
+ // where the grammar gives it a meaning, or an ERROR where it does not
145
+ // -- never silently part of a string. `x=y`, `6/2`, `50%` and `>10`
146
+ // were all bare strings once, each a well-formed wrong document, and
147
+ // each is refused now, naming the character (bare_punct).
148
+ //
149
+ // scanBareRun classifies each character of a run three ways, in this
150
+ // order: TEXT continues the run; an ENDER stops it; anything else is
151
+ // BAD. The ender set is the lexer's own -- space, line, fixed tokens,
152
+ // comment starters -- read from the config its text matcher was built
153
+ // from, so it cannot drift from the grammar. A bad run is still scanned
154
+ // to its ender, so the refusal claims the whole spelling and the lexer
155
+ // never reads the tail of it as syntax.
156
+ //
157
+ // `-` is text wherever the scan sees it. A run never STARTS on one:
158
+ // `-` is the sign of a number and the negation prefix, a fixed token
159
+ // the fixed matcher claims before either scanning stage can run, so
160
+ // `a:-1` is the negation of 1 and `a:6-2` the string. The `+` of an
161
+ // exponent (`1e+2`) is admitted only by the NUMBER stage's scan, the
162
+ // one stage that can make a number of it. Mirrors scanBareRun in
163
+ // go/lang.go, decision for decision.
164
+ const CC_9 = 57;
165
+ const CC_A = 65;
166
+ const CC_Z = 90;
167
+ const CC_a = 97;
168
+ const CC_z = 122;
169
+ const CC_E = 69;
170
+ const CC_e = 101;
171
+ const CC_US = 95;
172
+ const CC_MINUS = 45;
173
+ const CC_PLUS = 43;
174
+ // Beyond ASCII a letter, a digit or a combining mark is text (`café`);
175
+ // a dash, a symbol or a space of any other kind is not.
176
+ const UNICODE_TEXT_RE = /^[\p{L}\p{N}\p{M}]$/u;
177
+ function textChar(c) {
178
+ return (CC_0 <= c && c <= CC_9) ||
179
+ (CC_a <= c && c <= CC_z) ||
180
+ (CC_A <= c && c <= CC_Z) ||
181
+ CC_US === c ||
182
+ CC_MINUS === c ||
183
+ (127 < c && UNICODE_TEXT_RE.test(String.fromCodePoint(c)));
184
+ }
185
+ // The lexer's text ender, at i. The regexp is the text matcher's own
186
+ // ender alternation (cfg.rePart.ender) made sticky, built once per
187
+ // config and cached on it.
188
+ function enderAt(cfg, src, i) {
189
+ let re = cfg.aontu_ender_re;
190
+ if (null == re) {
191
+ re = cfg.aontu_ender_re = new RegExp(cfg.rePart.ender.join(''), 'y');
192
+ }
193
+ re.lastIndex = i;
194
+ return re.test(src);
195
+ }
196
+ function scanBareRun(cfg, src, start, expo) {
197
+ let i = start;
198
+ let bad = -1;
199
+ let ch = '';
200
+ while (i < src.length) {
201
+ const c = src.codePointAt(i);
202
+ const w = 0xffff < c ? 2 : 1;
203
+ if (textChar(c)) {
204
+ i += w;
205
+ continue;
206
+ }
207
+ if (expo && CC_PLUS === c && start < i) {
208
+ const p = src.charCodeAt(i - 1);
209
+ const n = src.charCodeAt(i + 1);
210
+ if ((CC_e === p || CC_E === p) && CC_0 <= n && n <= CC_9) {
211
+ i += 1;
212
+ continue;
213
+ }
214
+ }
215
+ if (enderAt(cfg, src, i)) {
216
+ break;
217
+ }
218
+ if (-1 === bad) {
219
+ bad = i;
220
+ ch = String.fromCodePoint(c);
221
+ }
222
+ i += w;
223
+ }
224
+ return { end: i, bad, ch };
225
+ }
226
+ // A run the number matcher may lex: its own number grammar, less the
227
+ // fraction -- `.` is a fixed token, so a run never holds one, and the
228
+ // matcher reads it past the run by itself (`1.5` is the run `1`).
229
+ const NUMBER_RUN_RE = /^[-+]?(?:0(?:[xX][0-9a-fA-F_]+|[oO][0-7_]+|[bB][01_]+)|[0-9][0-9_]*(?:[eE][-+]?[0-9][0-9_]*)?)$/;
230
+ // The number matcher's hook result where the run is not its to lex.
231
+ const NOT_A_NUMBER = { done: true, token: undefined };
132
232
  let AontuJsonic = function AontuLang(jsonic) {
133
233
  jsonic.use(asPlugin(path_1.Path));
134
234
  // Only # line comments are valid Aontu syntax (see
@@ -203,6 +303,34 @@ let AontuJsonic = function AontuLang(jsonic) {
203
303
  // matched case-insensitively so the rule does not depend on which
204
304
  // prefix spellings the engine accepts.
205
305
  exclude: /__|^[-+]?0[xXoObB]_|_$/,
306
+ // THE NUMBER STAGE OF THE BARE-TEXT RULE. The matcher runs before
307
+ // the text matcher and reads a number up to the next ender -- and
308
+ // `-` is an ender, being the negation prefix's fixed token, so it
309
+ // would take the `2026` of `2026-09-05` and leave `-09-05` to the
310
+ // grammar. The hook scans the whole run first and declines for
311
+ // the matcher wherever the run is not its to lex: a run with a
312
+ // bad character (the text stage refuses it), a run that is not a
313
+ // number at all (`2026-09-05`, `6-2` are text). Twin of tsNumCheck
314
+ // in go/lang.go.
315
+ check: (lex) => {
316
+ const pnt = lex.pnt;
317
+ const src = lex.src;
318
+ // The hook makes the matcher a candidate at every position, so
319
+ // the common case -- a run no number can open -- declines for it
320
+ // in one char read. A DIGIT opens a number here and nothing
321
+ // else: the sign and the dot open the matcher's own grammar, but
322
+ // they are fixed tokens (the prefix operators and member
323
+ // access), claimed before this hook can run.
324
+ const c = src.charCodeAt(pnt.sI);
325
+ if (!(CC_0 <= c && c <= CC_9)) {
326
+ return NOT_A_NUMBER;
327
+ }
328
+ const run = scanBareRun(lex.cfg, src, pnt.sI, true);
329
+ if (-1 !== run.bad || !NUMBER_RUN_RE.test(src.slice(pnt.sI, run.end))) {
330
+ return NOT_A_NUMBER;
331
+ }
332
+ return undefined;
333
+ },
206
334
  },
207
335
  });
208
336
  // D3 -- the `0d` literal, the only route to the exact leaves
@@ -255,12 +383,25 @@ let AontuJsonic = function AontuLang(jsonic) {
255
383
  // the token's source text (`0d1: 5` yields the key `0d1`), so a
256
384
  // declaration reads as the key `%uint8`, while a value position
257
385
  // calls the function below and gets the reference.
258
- if (CC_PCT === src.charCodeAt(pnt.sI)) {
259
- const ares = ALIAS_RE.exec(lex.refwd());
260
- if (null == ares) {
261
- return undefined;
262
- }
386
+ // A `%` that opens no name (`%`, `%1`, `50%`) falls through to
387
+ // the bare-text scan below, which refuses it.
388
+ const ares = CC_PCT === src.charCodeAt(pnt.sI) ?
389
+ ALIAS_RE.exec(lex.refwd()) : null;
390
+ if (null != ares) {
263
391
  const asrc = ares[0];
392
+ // A lone `=` after the name, across horizontal space only, is
393
+ // the declaration operator. Decided HERE, where the name is
394
+ // claimed, and only its position is kept: the very next text
395
+ // position is that `=`, since nothing but space sits between,
396
+ // so the mark cannot outlive its one use. `==` is not it.
397
+ let j = pnt.sI + asrc.length;
398
+ while (j < src.length &&
399
+ (CC_SP === src.charCodeAt(j) || CC_TAB === src.charCodeAt(j))) {
400
+ j++;
401
+ }
402
+ if (CC_EQ === src.charCodeAt(j) && CC_EQ !== src.charCodeAt(j + 1)) {
403
+ lex.aontu_eq_at = j;
404
+ }
264
405
  const atkn = lex.token('#VL',
265
406
  // AN ALIAS REFERENCE IS A PATH REFERENCE. `%uint8` is
266
407
  // `$.%uint8`: root-absolute, one segment, spelled with the
@@ -274,53 +415,129 @@ let AontuJsonic = function AontuLang(jsonic) {
274
415
  pnt.cI += asrc.length;
275
416
  return { done: true, token: atkn };
276
417
  }
277
- if (CC_0 !== src.charCodeAt(pnt.sI)) {
278
- return undefined;
418
+ // The `=` the alias arm above marked: the separator of a
419
+ // declaration, as a colon token whose source is `=`. The pair rule
420
+ // is then the pair rule, and the formatter writes the spelling it
421
+ // read. Marked in `use` so the pair rule can tell it from a colon,
422
+ // which no longer declares.
423
+ if (CC_EQ === src.charCodeAt(pnt.sI) && lex.aontu_eq_at === pnt.sI) {
424
+ delete lex.aontu_eq_at;
425
+ const eqtkn = lex.token('#CL', undefined, '=', pnt, { aontu_eq: true });
426
+ pnt.sI += 1;
427
+ pnt.cI += 1;
428
+ return { done: true, token: eqtkn };
429
+ }
430
+ if (CC_0 === src.charCodeAt(pnt.sI)) {
431
+ const c1 = src.charCodeAt(pnt.sI + 1);
432
+ if (CC_d === c1 || CC_D === c1) {
433
+ // BIG_LITERAL_RE is `^`-anchored and read against the
434
+ // forward source (memoized per position by refwd), which is
435
+ // what lets it claim the `.` of `0d1.5`. A `0d` run it does
436
+ // not match falls through to the bare-text scan below.
437
+ const res = Decimal_1.BIG_LITERAL_RE.exec(lex.refwd());
438
+ if (null != res) {
439
+ const msrc = res[0];
440
+ // The token value is a FUNCTION so Val construction
441
+ // happens at parse time, where the rule and context needed
442
+ // for the site exist (jsonic calls a #VL token's function
443
+ // value with them). A `0d` literal never spans a line, so
444
+ // only the source and column positions advance.
445
+ const tkn = lex.token('#VL', (r, ctx) => addsite(bigVal(res), r, ctx), msrc, pnt);
446
+ pnt.sI += msrc.length;
447
+ pnt.cI += msrc.length;
448
+ return { done: true, token: tkn };
449
+ }
450
+ }
279
451
  }
280
- const c1 = src.charCodeAt(pnt.sI + 1);
281
- if (CC_d !== c1 && CC_D !== c1) {
282
- return undefined;
452
+ // THE BARE-TEXT RULE (scanBareRun). Last, so that a name, a
453
+ // declaration operator and an exact literal are read before a
454
+ // run is judged as text.
455
+ // The run is never empty: every ender is a token an earlier
456
+ // matcher claims, so the text stage only opens on a character
457
+ // the scan classifies as text or as bad.
458
+ const run = scanBareRun(lex.cfg, src, pnt.sI, false);
459
+ const msrc = src.slice(pnt.sI, run.end);
460
+ if (-1 !== run.bad) {
461
+ // BAD: the run is refused whole, sited at the character (the
462
+ // mark in `use` is what tokenSite reads). As a VALUE the
463
+ // token's function builds the refusal at the parse, where the
464
+ // rule carries the position. As a KEY the token is read for
465
+ // its source alone, so the mark is what the pair and elem
466
+ // rules read to write the refusal where the map is built.
467
+ const ch = run.ch;
468
+ const tkn = lex.token('#VL', (r, ctx) => {
469
+ const nv = addsite(new NilVal_1.NilVal({ why: 'bare_punct' }), r, ctx);
470
+ nv.details = { char: ch, text: msrc };
471
+ return nv;
472
+ }, msrc, pnt, { aontu_bad: ch });
473
+ pnt.sI += msrc.length;
474
+ pnt.cI += msrc.length;
475
+ return { done: true, token: tkn };
283
476
  }
284
- // BIG_LITERAL_RE is `^`-anchored and read against the forward
285
- // source (memoized per position by refwd), which is what lets
286
- // it claim the `.` of `0d1.5`.
287
- const res = Decimal_1.BIG_LITERAL_RE.exec(lex.refwd());
288
- if (null == res) {
289
- return undefined;
477
+ // CLEAN, with a `-` past its start (`team-payments`,
478
+ // `2026-09-05`): claimed here as one text token, because the
479
+ // default matcher's ender set would carve the run at the `-`.
480
+ // Any other clean run is the default matcher's, which also reads
481
+ // the value keywords and the `_` hole.
482
+ if (-1 !== msrc.indexOf('-')) {
483
+ const tkn = lex.token('#TX', msrc, msrc, pnt);
484
+ pnt.sI += msrc.length;
485
+ pnt.cI += msrc.length;
486
+ return { done: true, token: tkn };
290
487
  }
291
- const msrc = res[0];
292
- // The token value is a FUNCTION so Val construction happens at
293
- // parse time, where the rule and context needed for the site
294
- // exist (jsonic calls a #VL token's function value with them).
295
- // A `0d` literal never spans a line, so only the source and
296
- // column positions advance.
297
- const tkn = lex.token('#VL', (r, ctx) => addsite(bigVal(res), r, ctx), msrc, pnt);
298
- pnt.sI += msrc.length;
299
- pnt.cI += msrc.length;
300
- return { done: true, token: tkn };
488
+ return undefined;
301
489
  },
302
490
  },
303
491
  });
304
- // TODO: refactor Val constructor
305
- // let addsite = (v: Val, p: string[]) => (v.path = [...(p || [])], v)
492
+ const NO_SITE = { row: -1, col: -1, src: '', len: -1 };
493
+ const tokenSite = (tkn) => {
494
+ const src = tkn.src;
495
+ const bad = tkn.use?.aontu_bad;
496
+ if (null != bad) {
497
+ const ch = '' + bad;
498
+ return { row: tkn.rI, col: tkn.cI + src.indexOf(ch), src: ch, len: ch.length };
499
+ }
500
+ return { row: tkn.rI, col: tkn.cI, src, len: '' === src ? -1 : src.length };
501
+ };
502
+ const siteAt = (v, ts) => {
503
+ v.site.row = ts.row;
504
+ v.site.col = ts.col;
505
+ v.site.src = ts.src;
506
+ v.site.len = ts.len;
507
+ return v;
508
+ };
306
509
  let addsite = (v, r, ctx) => {
307
- v.site.row = null == r.o0 ? -1 : r.o0.rI;
308
- v.site.col = null == r.o0 ? -1 : r.o0.cI;
309
- v.site.url = ctx.meta.multisource ? ctx.meta.multisource.path : '';
310
- // The source text, from the SAME token the row and column above
510
+ // The source text comes from the SAME token the row and column
311
511
  // come from. jsonic has carried it all along; not reading it is
312
512
  // what left a site uneditable (ts/src/site.ts).
313
- //
314
- // A TOKEN WITH NO TEXT IS NO SPAN, in both ports, and the extent is
315
- // DERIVED from the text rather than read from the token's own `len`
316
- // — so the Go twin, whose token has no len field, computes the
317
- // identical number with utf16Len and nothing has to be kept in step.
318
- v.site.src = null == r.o0 ? '' : r.o0.src;
319
- v.site.len = '' === v.site.src ? -1 : v.site.src.length;
513
+ siteAt(v, null == r.o0 ? NO_SITE : tokenSite(r.o0));
514
+ v.site.url = ctx.meta.multisource ? ctx.meta.multisource.path : '';
320
515
  // A keyed rule always carries a path array; a keyless one has none.
321
516
  v.path = r.k ? [...r.k.path] : [];
322
517
  return v;
323
518
  };
519
+ // THE KEY REFUSALS a pair may carry, decided from its key TOKEN --
520
+ // never from the key text alone, since a quoted `"%a"` or `"x=y"` is
521
+ // an ordinary key: a declaration spelled with a colon (alias_colon),
522
+ // and a key the bare-text rule refuses (bare_punct). Undefined for an
523
+ // ordinary key, and for a declaration (`%a = 1`), which is a binding
524
+ // (isAliasDecl), not a refusal. Asked FIRST by the pair rule and by
525
+ // the elem rule, before the declaration is, so a pair in list
526
+ // position is held to the map's rules.
527
+ const isAliasDecl = (ktkn, sep) => null != ktkn && VL === ktkn.tin && ALIAS_RE.test('' + ktkn.src) &&
528
+ true === sep?.use?.aontu_eq;
529
+ const keyRefusalOf = (ktkn, sep) => {
530
+ if (null == ktkn || VL !== ktkn.tin) {
531
+ return undefined;
532
+ }
533
+ const kname = '' + ktkn.src;
534
+ if (ALIAS_RE.test(kname)) {
535
+ return isAliasDecl(ktkn, sep) ? undefined : { why: 'alias_colon' };
536
+ }
537
+ const bad = ktkn.use?.aontu_bad;
538
+ return null == bad ? undefined :
539
+ { why: 'bare_punct', details: { char: '' + bad, text: kname } };
540
+ };
324
541
  jsonic.options({
325
542
  hint: {
326
543
  unknown: `
@@ -481,6 +698,13 @@ help isolate the syntax error.`,
481
698
  // G8 phase 0).
482
699
  pack: PackFuncVal_1.PackFuncVal,
483
700
  each: EachFuncVal_1.EachFuncVal,
701
+ // RENDER P6: the order-preserving map. `form` makes one list
702
+ // element per child of its data, being the template with `_`
703
+ // bound to the source child -- a construction, where `each` is a
704
+ // bound (G9 §4). It exists because `pick(pack(...))` re-sorts to
705
+ // code-point order, and a struct's fields or a file's imports
706
+ // are the model's order or they are wrong.
707
+ form: FormFuncVal_1.FormFuncVal,
484
708
  // G8 phase 2: selection. `filter` keeps the children of a bag that
485
709
  // unify with a condition; `match` picks the first arm whose
486
710
  // pattern the scrutinee unifies with. Both select by
@@ -913,17 +1137,8 @@ help isolate the syntax error.`,
913
1137
  valnode = addsite(new NullVal_1.NullVal({ peg: r.node }), r, ctx);
914
1138
  }
915
1139
  if (null != valnode && 'object' === typeof valnode && valnode.site) {
916
- let st = r.o0;
917
- valnode.site.row = st.rI;
918
- valnode.site.col = st.cI;
1140
+ siteAt(valnode, tokenSite(r.o0));
919
1141
  valnode.site.url = ctx.meta.multisource && ctx.meta.multisource.path;
920
- // No `?? ''` and no empty-text arm here: this branch runs only
921
- // for a rule that HAS an open token, and a token that opens a
922
- // value always carries text — the coverage gate refuses both
923
- // guards as dead. The unset case is the one above, where r.o0
924
- // itself can be absent.
925
- valnode.site.src = st.src;
926
- valnode.site.len = st.src.length;
927
1142
  }
928
1143
  // else { ERROR? }
929
1144
  r.node = valnode;
@@ -993,6 +1208,20 @@ help isolate the syntax error.`,
993
1208
  r.node = addsite(new NilVal_1.NilVal({ why: 'elided_value' }), r, ctx);
994
1209
  return undefined;
995
1210
  }
1211
+ // A KEY REFUSAL (the pair rule records them: a declaration
1212
+ // spelled with a colon, a key the bare-text rule refuses) becomes
1213
+ // the refusal, in place of whatever followed the colon and sited
1214
+ // at the KEY rather than at the map -- at the offending character
1215
+ // of it, where there is one -- so the frame points at the
1216
+ // spelling to change.
1217
+ for (const { key, tkn, why, details } of (r.u.aontu_key_refusals ?? [])) {
1218
+ const en = siteAt(addsite(new NilVal_1.NilVal({ why }), r, ctx), tokenSite(tkn));
1219
+ if (null != details) {
1220
+ en.details = details;
1221
+ }
1222
+ en.path = [...(r.k?.path ?? []), key];
1223
+ mo[key] = en;
1224
+ }
996
1225
  // Handle defered conjuncts, e.g. `{x:1 @"foo"}`
997
1226
  if (mo.___merge) {
998
1227
  let mop = { ...mo };
@@ -1142,9 +1371,21 @@ help isolate the syntax error.`,
1142
1371
  // Being a property of the map is also what carries it through a
1143
1372
  // meet, the way optional keys are carried.
1144
1373
  const ktkn = rule.o0;
1145
- if (null != ktkn && VL === ktkn.tin && ALIAS_RE.test('' + ktkn.src)) {
1146
- const holder = rule.parent;
1147
- const aname = '' + ktkn.src;
1374
+ const holder = rule.parent;
1375
+ const kr = keyRefusalOf(ktkn, rule.o1);
1376
+ if (null != kr) {
1377
+ // A KEY REFUSAL (keyRefusalOf) is written where the map is
1378
+ // built, in the value's place and sited at the key, so the
1379
+ // frame points at the spelling to change. A declaration
1380
+ // spelled with a colon is refused rather than read as the
1381
+ // ordinary key `%foo` the text would otherwise become -- a
1382
+ // document written for the old form would then generate a
1383
+ // "%foo" field and every `%foo` use would resolve to nothing,
1384
+ // and neither says why.
1385
+ holder.u.aontu_key_refusals = (holder.u.aontu_key_refusals || []);
1386
+ holder.u.aontu_key_refusals.push({ key: '' + ktkn.src, tkn: ktkn, ...kr });
1387
+ }
1388
+ else if (isAliasDecl(ktkn, rule.o1)) {
1148
1389
  // Always recorded here; whether the map is ALLOWED to carry
1149
1390
  // declarations is decided on the VALUE (MapVal.unify), not at
1150
1391
  // the parse. The parse cannot see it: an INCLUDED file's
@@ -1152,7 +1393,7 @@ help isolate the syntax error.`,
1152
1393
  // once the loaded map is placed does it become apparent that
1153
1394
  // root is not the document's.
1154
1395
  holder.u.aontu_alias_keys = (holder.u.aontu_alias_keys || []);
1155
- holder.u.aontu_alias_keys.push(aname);
1396
+ holder.u.aontu_alias_keys.push('' + ktkn.src);
1156
1397
  }
1157
1398
  if (rule.u.spread) {
1158
1399
  rule.node[type_1.SPREAD] =
@@ -1303,19 +1544,47 @@ help isolate the syntax error.`,
1303
1544
  // mistake, not an empty value.
1304
1545
  if (true === rule.u.pair) {
1305
1546
  const key = '' + rule.u.key;
1547
+ // The key TOKEN: the optional spelling's sits on the elem rule
1548
+ // before this one (`[x?: 1]` is two elem rules).
1549
+ const ktkn = true === rule.u.aontu_optional_elem ?
1550
+ rule.prev.o0 : rule.o0;
1306
1551
  let v = rule.child.node;
1552
+ const kr = keyRefusalOf(ktkn, rule.o1);
1307
1553
  if (null == v) {
1308
1554
  v = addsite(new NilVal_1.NilVal({ why: 'elided_value' }), rule, ctx);
1309
1555
  v.path = [...(rule.k?.path ?? []),
1310
1556
  '' + rule.node.length, key];
1311
1557
  }
1558
+ // THE KEY IS HELD TO THE MAP'S RULES: a key the map rule would
1559
+ // refuse (a colon declaration, a bare-text refusal) is refused
1560
+ // here too, in the value's place and sited at the key, rather
1561
+ // than generated as the element `[{"x=y": 1}]`.
1562
+ else if (null != kr) {
1563
+ v = siteAt(addsite(new NilVal_1.NilVal({ why: kr.why }), rule, ctx), tokenSite(ktkn));
1564
+ if (null != kr.details) {
1565
+ v.details = kr.details;
1566
+ }
1567
+ v.path = [...(rule.k?.path ?? []),
1568
+ '' + rule.node.length, key];
1569
+ }
1312
1570
  const mv = addsite(new MapVal_1.MapVal({ peg: { [key]: v } }), rule, ctx);
1571
+ // The element's path is the list's plus its index, as any
1572
+ // element's is (and as the Go port paths it): the map rule's
1573
+ // "is this the top level" test reads the path, so an element
1574
+ // of a top-level list must not read as the root.
1575
+ mv.path = [...(rule.k?.path ?? []), '' + rule.node.length];
1313
1576
  // `[a?: 1]` is `[{a?: 1}]`: the key is optional IN the
1314
1577
  // element, so the two spellings stay one rule apart rather
1315
1578
  // than two behaviours apart.
1316
1579
  if (true === rule.u.aontu_optional_elem) {
1317
1580
  mv.optionalKeys = [key];
1318
1581
  }
1582
+ // ... and a declaration is a declaration IN the element, which
1583
+ // is where MapVal.unify refuses it: a list element is not the
1584
+ // top level.
1585
+ if (isAliasDecl(ktkn, rule.o1)) {
1586
+ mv.aliasKeys = [key];
1587
+ }
1319
1588
  rule.node.push(mv);
1320
1589
  }
1321
1590
  return undefined;
@@ -1658,6 +1927,16 @@ function makeModelResolver(options) {
1658
1927
  err.code = 'include_extension';
1659
1928
  throw err;
1660
1929
  };
1930
+ // A LANGUAGE-SUPPLIED MODEL THAT DOES NOT EXIST THROWS, as a denial
1931
+ // does and for the same bare-member reason, with the not-found code
1932
+ // the include machinery already uses and a message that names the
1933
+ // set: a typo in an `aontu:` name must not go looking on disk.
1934
+ const modelNotFound = (path) => {
1935
+ const err = new Error('source not found: ' + path +
1936
+ ' (the language-supplied models are ' + std_1.AONTU_MODELS.join(', ') + ')');
1937
+ err.code = 'multisource_not_found';
1938
+ throw err;
1939
+ };
1661
1940
  // The gate every leg that RESOLVES A NAME passes through. The std and
1662
1941
  // module legs do not: both state `kind: 'aon'` because what they
1663
1942
  // serve is Aontu source by construction, not by its spelling.
@@ -1716,6 +1995,23 @@ function makeModelResolver(options) {
1716
1995
  if ('none' === capability) {
1717
1996
  deny(path);
1718
1997
  }
1998
+ // THE LANGUAGE-SUPPLIED MODELS (docs/design/MODELS.0.md D1): an
1999
+ // `aontu:` name resolves from the engine's own table and nowhere
2000
+ // else -- the memory, module, file and package legs are never
2001
+ // asked, so nothing on disk can shadow one and a typo is refused
2002
+ // here, naming the set, rather than searched for. Available under
2003
+ // every capability but `none`, checked just above, like the std
2004
+ // names below. A path that is not a string (`a: @1`) is not a name
2005
+ // at all: it falls through to the legs below and is not found there,
2006
+ // as it always was.
2007
+ if ('string' === typeof path && path.startsWith(std_1.AONTU_SCHEME)) {
2008
+ const model = std_1.STD_SOURCES[path];
2009
+ if (null == model) {
2010
+ modelNotFound(path);
2011
+ }
2012
+ record(ctx, path, 'std');
2013
+ return { found: true, path, full: path, kind: 'aon', src: model, search: [] };
2014
+ }
1719
2015
  // THE BUNDLED VOCABULARY (G4 phase 4, ts/src/std.ts): served from
1720
2016
  // the engine itself, so it needs neither the filesystem nor package
1721
2017
  // resolution and is available under every capability but `none` —
@@ -1942,7 +2238,7 @@ function opCharHint(src) {
1942
2238
  q = c;
1943
2239
  }
1944
2240
  else if ('<' === c || '>' === c) {
1945
- return '\nThe > and < characters are not Aontu operators: write the ' +
2241
+ return '\nThe > and < characters are not aontu operators: write the ' +
1946
2242
  'bound functions min(x), max(x), above(x), below(x) instead.';
1947
2243
  }
1948
2244
  }
@@ -2068,9 +2364,10 @@ class Lang {
2068
2364
  }
2069
2365
  catch (e) {
2070
2366
  if ('include_denied' === e?.code || 'include_extension' === e?.code ||
2071
- mod_1.MODULE_REFUSAL_CODES.has(e?.code)) {
2367
+ 'multisource_not_found' === e?.code || mod_1.MODULE_REFUSAL_CODES.has(e?.code)) {
2072
2368
  // A denied include (G5), an include whose extension is not read
2073
- // as Aontu source (ADR-012, INCLUDE_KINDS), and a module that is
2369
+ // as Aontu source (ADR-012, INCLUDE_KINDS), an `aontu:` name the
2370
+ // engine does not serve (MODELS.0.md D1), and a module that is
2074
2371
  // missing, fails its pin, or names a path that escapes its store
2075
2372
  // (G6 phase 2) are refused the same way, for the same reason: the
2076
2373
  // resolver THROWS so a bare-member include cannot vanish in the