aontu 0.56.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 (138) 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 +5 -2
  7. package/dist/aontu.js +11 -3
  8. package/dist/aontu.js.map +1 -1
  9. package/dist/cli.d.ts +8 -2
  10. package/dist/cli.js +564 -21
  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/escape.d.ts +5 -0
  16. package/dist/escape.js +455 -0
  17. package/dist/escape.js.map +1 -0
  18. package/dist/format.d.ts +9 -0
  19. package/dist/format.js +550 -55
  20. package/dist/format.js.map +1 -1
  21. package/dist/hints.js +74 -9
  22. package/dist/hints.js.map +1 -1
  23. package/dist/lang.js +374 -58
  24. package/dist/lang.js.map +1 -1
  25. package/dist/lower.d.ts +20 -0
  26. package/dist/lower.js +575 -0
  27. package/dist/lower.js.map +1 -0
  28. package/dist/lsp.d.ts +1 -1
  29. package/dist/lsp.js +4 -4
  30. package/dist/lsp.js.map +1 -1
  31. package/dist/mcp-server.js +2 -2
  32. package/dist/mcp-server.js.map +1 -1
  33. package/dist/mcp.d.ts +1 -0
  34. package/dist/mcp.js +40 -3
  35. package/dist/mcp.js.map +1 -1
  36. package/dist/mod-tool.js +8 -7
  37. package/dist/mod-tool.js.map +1 -1
  38. package/dist/mod.js +6 -6
  39. package/dist/mod.js.map +1 -1
  40. package/dist/render.d.ts +53 -0
  41. package/dist/render.js +542 -0
  42. package/dist/render.js.map +1 -0
  43. package/dist/sigdecl.js +1 -1
  44. package/dist/sigdecl.js.map +1 -1
  45. package/dist/std.d.ts +2 -0
  46. package/dist/std.js +498 -2
  47. package/dist/std.js.map +1 -1
  48. package/dist/template.d.ts +5 -0
  49. package/dist/template.js +257 -0
  50. package/dist/template.js.map +1 -0
  51. package/dist/tsconfig.tsbuildinfo +1 -1
  52. package/dist/unify.js +43 -0
  53. package/dist/unify.js.map +1 -1
  54. package/dist/val/AggFuncVal.d.ts +1 -1
  55. package/dist/val/AggFuncVal.js +10 -21
  56. package/dist/val/AggFuncVal.js.map +1 -1
  57. package/dist/val/BagVal.js +1 -1
  58. package/dist/val/BagVal.js.map +1 -1
  59. package/dist/val/ConstraintVal.js +1 -1
  60. package/dist/val/EachFuncVal.d.ts +1 -1
  61. package/dist/val/EachFuncVal.js +9 -15
  62. package/dist/val/EachFuncVal.js.map +1 -1
  63. package/dist/val/EmitFuncVal.d.ts +42 -0
  64. package/dist/val/EmitFuncVal.js +531 -0
  65. package/dist/val/EmitFuncVal.js.map +1 -0
  66. package/dist/val/FilterFuncVal.js +9 -6
  67. package/dist/val/FilterFuncVal.js.map +1 -1
  68. package/dist/val/FormFuncVal.d.ts +14 -0
  69. package/dist/val/FormFuncVal.js +55 -0
  70. package/dist/val/FormFuncVal.js.map +1 -0
  71. package/dist/val/FuncBaseVal.d.ts +1 -0
  72. package/dist/val/FuncBaseVal.js +16 -0
  73. package/dist/val/FuncBaseVal.js.map +1 -1
  74. package/dist/val/MapVal.d.ts +2 -1
  75. package/dist/val/MapVal.js +2 -1
  76. package/dist/val/MapVal.js.map +1 -1
  77. package/dist/val/PackFuncVal.d.ts +1 -1
  78. package/dist/val/PackFuncVal.js +23 -20
  79. package/dist/val/PackFuncVal.js.map +1 -1
  80. package/dist/val/PlaceVal.d.ts +3 -1
  81. package/dist/val/PlaceVal.js +9 -6
  82. package/dist/val/PlaceVal.js.map +1 -1
  83. package/dist/val/RefVal.d.ts +3 -0
  84. package/dist/val/RefVal.js +156 -17
  85. package/dist/val/RefVal.js.map +1 -1
  86. package/dist/val/StrFuncVal.d.ts +32 -0
  87. package/dist/val/StrFuncVal.js +292 -0
  88. package/dist/val/StrFuncVal.js.map +1 -0
  89. package/dist/val/Val.d.ts +7 -1
  90. package/dist/val/Val.js +12 -1
  91. package/dist/val/Val.js.map +1 -1
  92. package/dist/val/members.d.ts +9 -0
  93. package/dist/val/members.js +52 -0
  94. package/dist/val/members.js.map +1 -0
  95. package/grammar/aontu.abnf +4 -3
  96. package/grammar/aontu.gbnf +4 -3
  97. package/grammar/aontu.lark +4 -3
  98. package/grammar/aontu.tmLanguage.json +1 -1
  99. package/package.json +1 -1
  100. package/skill/SKILL.md +4 -4
  101. package/skill/error-codes.md +1 -1
  102. package/skill/examples.md +1 -1
  103. package/skill/grammar-card.md +1 -1
  104. package/src/agentsmd.ts +1 -1
  105. package/src/alias.ts +112 -0
  106. package/src/aontu.ts +20 -2
  107. package/src/cli.ts +630 -23
  108. package/src/ctx.ts +13 -0
  109. package/src/escape.ts +371 -0
  110. package/src/format.ts +648 -56
  111. package/src/hints.ts +94 -9
  112. package/src/lang.ts +430 -63
  113. package/src/lower.ts +636 -0
  114. package/src/lsp.ts +4 -4
  115. package/src/mcp-server.ts +3 -2
  116. package/src/mcp.ts +43 -4
  117. package/src/mod-tool.ts +9 -8
  118. package/src/mod.ts +6 -6
  119. package/src/render.ts +727 -0
  120. package/src/sigdecl.ts +1 -1
  121. package/src/std.ts +506 -1
  122. package/src/template.ts +291 -0
  123. package/src/unify.ts +47 -0
  124. package/src/val/AggFuncVal.ts +10 -21
  125. package/src/val/BagVal.ts +1 -1
  126. package/src/val/ConstraintVal.ts +1 -1
  127. package/src/val/EachFuncVal.ts +9 -19
  128. package/src/val/EmitFuncVal.ts +738 -0
  129. package/src/val/FilterFuncVal.ts +12 -7
  130. package/src/val/FormFuncVal.ts +119 -0
  131. package/src/val/FuncBaseVal.ts +18 -0
  132. package/src/val/MapVal.ts +3 -2
  133. package/src/val/PackFuncVal.ts +24 -22
  134. package/src/val/PlaceVal.ts +9 -6
  135. package/src/val/RefVal.ts +167 -18
  136. package/src/val/StrFuncVal.ts +334 -0
  137. package/src/val/Val.ts +42 -1
  138. package/src/val/members.ts +86 -0
package/dist/lang.js CHANGED
@@ -72,8 +72,11 @@ 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");
78
+ const EmitFuncVal_1 = require("./val/EmitFuncVal");
79
+ const StrFuncVal_1 = require("./val/StrFuncVal");
77
80
  const ArithFuncVal_1 = require("./val/ArithFuncVal");
78
81
  const AggFuncVal_1 = require("./val/AggFuncVal");
79
82
  const PlaceVal_1 = require("./val/PlaceVal");
@@ -123,10 +126,109 @@ const CC_d = 100;
123
126
  const CC_D = 68;
124
127
  // THE ALIAS SIGIL. `%` is part of an alias's name, so the name is one
125
128
  // lexeme wherever it appears and its meaning is decided by position:
126
- // a BINDING in key position (`%uint8: …` declares), a USE in value
129
+ // a BINDING in key position (`%uint8 = …` declares), a USE in value
127
130
  // position (`listen: %uint8` refers). docs/design/ALIASES.0.md §4.
128
131
  const CC_PCT = 37;
129
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 };
130
232
  let AontuJsonic = function AontuLang(jsonic) {
131
233
  jsonic.use(asPlugin(path_1.Path));
132
234
  // Only # line comments are valid Aontu syntax (see
@@ -201,6 +303,34 @@ let AontuJsonic = function AontuLang(jsonic) {
201
303
  // matched case-insensitively so the rule does not depend on which
202
304
  // prefix spellings the engine accepts.
203
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
+ },
204
334
  },
205
335
  });
206
336
  // D3 -- the `0d` literal, the only route to the exact leaves
@@ -253,12 +383,25 @@ let AontuJsonic = function AontuLang(jsonic) {
253
383
  // the token's source text (`0d1: 5` yields the key `0d1`), so a
254
384
  // declaration reads as the key `%uint8`, while a value position
255
385
  // calls the function below and gets the reference.
256
- if (CC_PCT === src.charCodeAt(pnt.sI)) {
257
- const ares = ALIAS_RE.exec(lex.refwd());
258
- if (null == ares) {
259
- return undefined;
260
- }
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) {
261
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
+ }
262
405
  const atkn = lex.token('#VL',
263
406
  // AN ALIAS REFERENCE IS A PATH REFERENCE. `%uint8` is
264
407
  // `$.%uint8`: root-absolute, one segment, spelled with the
@@ -272,53 +415,129 @@ let AontuJsonic = function AontuLang(jsonic) {
272
415
  pnt.cI += asrc.length;
273
416
  return { done: true, token: atkn };
274
417
  }
275
- if (CC_0 !== src.charCodeAt(pnt.sI)) {
276
- 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
+ }
277
451
  }
278
- const c1 = src.charCodeAt(pnt.sI + 1);
279
- if (CC_d !== c1 && CC_D !== c1) {
280
- 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 };
281
476
  }
282
- // BIG_LITERAL_RE is `^`-anchored and read against the forward
283
- // source (memoized per position by refwd), which is what lets
284
- // it claim the `.` of `0d1.5`.
285
- const res = Decimal_1.BIG_LITERAL_RE.exec(lex.refwd());
286
- if (null == res) {
287
- 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 };
288
487
  }
289
- const msrc = res[0];
290
- // The token value is a FUNCTION so Val construction happens at
291
- // parse time, where the rule and context needed for the site
292
- // exist (jsonic calls a #VL token's function value with them).
293
- // A `0d` literal never spans a line, so only the source and
294
- // column positions advance.
295
- const tkn = lex.token('#VL', (r, ctx) => addsite(bigVal(res), r, ctx), msrc, pnt);
296
- pnt.sI += msrc.length;
297
- pnt.cI += msrc.length;
298
- return { done: true, token: tkn };
488
+ return undefined;
299
489
  },
300
490
  },
301
491
  });
302
- // TODO: refactor Val constructor
303
- // 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
+ };
304
509
  let addsite = (v, r, ctx) => {
305
- v.site.row = null == r.o0 ? -1 : r.o0.rI;
306
- v.site.col = null == r.o0 ? -1 : r.o0.cI;
307
- v.site.url = ctx.meta.multisource ? ctx.meta.multisource.path : '';
308
- // 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
309
511
  // come from. jsonic has carried it all along; not reading it is
310
512
  // what left a site uneditable (ts/src/site.ts).
311
- //
312
- // A TOKEN WITH NO TEXT IS NO SPAN, in both ports, and the extent is
313
- // DERIVED from the text rather than read from the token's own `len`
314
- // — so the Go twin, whose token has no len field, computes the
315
- // identical number with utf16Len and nothing has to be kept in step.
316
- v.site.src = null == r.o0 ? '' : r.o0.src;
317
- 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 : '';
318
515
  // A keyed rule always carries a path array; a keyless one has none.
319
516
  v.path = r.k ? [...r.k.path] : [];
320
517
  return v;
321
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
+ };
322
541
  jsonic.options({
323
542
  hint: {
324
543
  unknown: `
@@ -479,6 +698,13 @@ help isolate the syntax error.`,
479
698
  // G8 phase 0).
480
699
  pack: PackFuncVal_1.PackFuncVal,
481
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,
482
708
  // G8 phase 2: selection. `filter` keeps the children of a bag that
483
709
  // unify with a condition; `match` picks the first arm whose
484
710
  // pattern the scrutinee unifies with. Both select by
@@ -514,6 +740,23 @@ help isolate the syntax error.`,
514
740
  // the language does not grow a second. It is the primitive that
515
741
  // turns a bag of computed lines into a file.
516
742
  join: AggFuncVal_1.JoinFuncVal,
743
+ // G9 phase 6: apply-templates. One flat list of pieces from a
744
+ // selection and a RULE TABLE -- for each node, the first template
745
+ // whose `match` it unifies with, its `body` instantiated at that
746
+ // node. The dispatch is the engine's because a body referenced by
747
+ // path resolves its references at the definition site, and the
748
+ // relative resolution that does exist is a dot count that does not
749
+ // survive a second dispatch (docs/design/EMIT.0.md).
750
+ emit: EmitFuncVal_1.EmitFuncVal,
751
+ // G9 phase 6: the string builtins the rule layer needs. `esc`
752
+ // makes a value safe inside a literal and `usc` reads it back;
753
+ // `rep` and `split` derive names from model data. All four are
754
+ // ordinary string functions -- they know nothing about generation,
755
+ // which is why they can land before the renderer does.
756
+ esc: StrFuncVal_1.EscFuncVal,
757
+ usc: StrFuncVal_1.UscFuncVal,
758
+ rep: StrFuncVal_1.RepFuncVal,
759
+ split: StrFuncVal_1.SplitFuncVal,
517
760
  };
518
761
  // A dangling operator (`a:1|`, `a:$`, `a:*` at end of input) leaves
519
762
  // null/undefined unfilled terms. Junction ops drop them (so `a:1&`
@@ -894,17 +1137,8 @@ help isolate the syntax error.`,
894
1137
  valnode = addsite(new NullVal_1.NullVal({ peg: r.node }), r, ctx);
895
1138
  }
896
1139
  if (null != valnode && 'object' === typeof valnode && valnode.site) {
897
- let st = r.o0;
898
- valnode.site.row = st.rI;
899
- valnode.site.col = st.cI;
1140
+ siteAt(valnode, tokenSite(r.o0));
900
1141
  valnode.site.url = ctx.meta.multisource && ctx.meta.multisource.path;
901
- // No `?? ''` and no empty-text arm here: this branch runs only
902
- // for a rule that HAS an open token, and a token that opens a
903
- // value always carries text — the coverage gate refuses both
904
- // guards as dead. The unset case is the one above, where r.o0
905
- // itself can be absent.
906
- valnode.site.src = st.src;
907
- valnode.site.len = st.src.length;
908
1142
  }
909
1143
  // else { ERROR? }
910
1144
  r.node = valnode;
@@ -974,6 +1208,20 @@ help isolate the syntax error.`,
974
1208
  r.node = addsite(new NilVal_1.NilVal({ why: 'elided_value' }), r, ctx);
975
1209
  return undefined;
976
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
+ }
977
1225
  // Handle defered conjuncts, e.g. `{x:1 @"foo"}`
978
1226
  if (mo.___merge) {
979
1227
  let mop = { ...mo };
@@ -1123,9 +1371,21 @@ help isolate the syntax error.`,
1123
1371
  // Being a property of the map is also what carries it through a
1124
1372
  // meet, the way optional keys are carried.
1125
1373
  const ktkn = rule.o0;
1126
- if (null != ktkn && VL === ktkn.tin && ALIAS_RE.test('' + ktkn.src)) {
1127
- const holder = rule.parent;
1128
- 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)) {
1129
1389
  // Always recorded here; whether the map is ALLOWED to carry
1130
1390
  // declarations is decided on the VALUE (MapVal.unify), not at
1131
1391
  // the parse. The parse cannot see it: an INCLUDED file's
@@ -1133,7 +1393,7 @@ help isolate the syntax error.`,
1133
1393
  // once the loaded map is placed does it become apparent that
1134
1394
  // root is not the document's.
1135
1395
  holder.u.aontu_alias_keys = (holder.u.aontu_alias_keys || []);
1136
- holder.u.aontu_alias_keys.push(aname);
1396
+ holder.u.aontu_alias_keys.push('' + ktkn.src);
1137
1397
  }
1138
1398
  if (rule.u.spread) {
1139
1399
  rule.node[type_1.SPREAD] =
@@ -1284,19 +1544,47 @@ help isolate the syntax error.`,
1284
1544
  // mistake, not an empty value.
1285
1545
  if (true === rule.u.pair) {
1286
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;
1287
1551
  let v = rule.child.node;
1552
+ const kr = keyRefusalOf(ktkn, rule.o1);
1288
1553
  if (null == v) {
1289
1554
  v = addsite(new NilVal_1.NilVal({ why: 'elided_value' }), rule, ctx);
1290
1555
  v.path = [...(rule.k?.path ?? []),
1291
1556
  '' + rule.node.length, key];
1292
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
+ }
1293
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];
1294
1576
  // `[a?: 1]` is `[{a?: 1}]`: the key is optional IN the
1295
1577
  // element, so the two spellings stay one rule apart rather
1296
1578
  // than two behaviours apart.
1297
1579
  if (true === rule.u.aontu_optional_elem) {
1298
1580
  mv.optionalKeys = [key];
1299
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
+ }
1300
1588
  rule.node.push(mv);
1301
1589
  }
1302
1590
  return undefined;
@@ -1639,6 +1927,16 @@ function makeModelResolver(options) {
1639
1927
  err.code = 'include_extension';
1640
1928
  throw err;
1641
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
+ };
1642
1940
  // The gate every leg that RESOLVES A NAME passes through. The std and
1643
1941
  // module legs do not: both state `kind: 'aon'` because what they
1644
1942
  // serve is Aontu source by construction, not by its spelling.
@@ -1697,6 +1995,23 @@ function makeModelResolver(options) {
1697
1995
  if ('none' === capability) {
1698
1996
  deny(path);
1699
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
+ }
1700
2015
  // THE BUNDLED VOCABULARY (G4 phase 4, ts/src/std.ts): served from
1701
2016
  // the engine itself, so it needs neither the filesystem nor package
1702
2017
  // resolution and is available under every capability but `none` —
@@ -1733,7 +2048,7 @@ function makeModelResolver(options) {
1733
2048
  const found = (0, mod_1.resolveModule)(modref, from, modFs(ctx), {
1734
2049
  // The user cache lives outside any confinement root, so it is
1735
2050
  // consulted only when nothing confines this evaluation. A
1736
- // rooted profile sees the project's own `aon_vendor/` and
2051
+ // rooted profile sees the project's own `aontu_meta/vendor/` and
1737
2052
  // nothing else, which is what `root` means.
1738
2053
  ...(null == rootDir ? { cache: modCache(options) } : {}),
1739
2054
  eval: options.mod?.eval,
@@ -1923,7 +2238,7 @@ function opCharHint(src) {
1923
2238
  q = c;
1924
2239
  }
1925
2240
  else if ('<' === c || '>' === c) {
1926
- return '\nThe > and < characters are not Aontu operators: write the ' +
2241
+ return '\nThe > and < characters are not aontu operators: write the ' +
1927
2242
  'bound functions min(x), max(x), above(x), below(x) instead.';
1928
2243
  }
1929
2244
  }
@@ -2049,9 +2364,10 @@ class Lang {
2049
2364
  }
2050
2365
  catch (e) {
2051
2366
  if ('include_denied' === e?.code || 'include_extension' === e?.code ||
2052
- mod_1.MODULE_REFUSAL_CODES.has(e?.code)) {
2367
+ 'multisource_not_found' === e?.code || mod_1.MODULE_REFUSAL_CODES.has(e?.code)) {
2053
2368
  // A denied include (G5), an include whose extension is not read
2054
- // 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
2055
2371
  // missing, fails its pin, or names a path that escapes its store
2056
2372
  // (G6 phase 2) are refused the same way, for the same reason: the
2057
2373
  // resolver THROWS so a bare-member include cannot vanish in the