@the_dissidents/libemmm 0.0.1 → 0.0.2

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.
package/dist/index.mjs CHANGED
@@ -113,6 +113,7 @@ var messages_exports = {};
113
113
  __export(messages_exports, {
114
114
  ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
115
115
  CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
116
+ CannotPopNotationMessage: () => CannotPopNotationMessage,
116
117
  ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
117
118
  ExpectedMessage: () => ExpectedMessage,
118
119
  InlineDefinitonInvalidEntityMessage: () => InlineDefinitonInvalidEntityMessage,
@@ -197,7 +198,7 @@ var ExpectedMessage = class {
197
198
  code = 1;
198
199
  severity = 2 /* Error */;
199
200
  get length() {
200
- return this.what.length;
201
+ return 0;
201
202
  }
202
203
  get info() {
203
204
  return `expected '${this.what}'`;
@@ -207,13 +208,16 @@ var ExpectedMessage = class {
207
208
  }
208
209
  };
209
210
  var UnknownModifierMessage = class {
210
- constructor(position, length) {
211
+ constructor(position, length, what) {
211
212
  this.position = position;
212
213
  this.length = length;
214
+ this.what = what;
213
215
  }
214
216
  code = 2;
215
217
  severity = 2 /* Error */;
216
- info = `unknown modifier; did you forget to escape it?`;
218
+ get info() {
219
+ return `unknown modifier '${this.what}'; did you forget to escape it?`;
220
+ }
217
221
  get fixes() {
218
222
  let [pos, len] = [this.position, this.length];
219
223
  return [{
@@ -321,7 +325,19 @@ var SlotUsedOutsideDefinitionMessage = class {
321
325
  severity = 2 /* Error */;
322
326
  fixes = [];
323
327
  get info() {
324
- return `[.slot] used outside a block definition`;
328
+ return `slot used outside a definition`;
329
+ }
330
+ };
331
+ var CannotPopNotationMessage = class {
332
+ constructor(position, length) {
333
+ this.position = position;
334
+ this.length = length;
335
+ }
336
+ code = 10;
337
+ severity = 2 /* Error */;
338
+ fixes = [];
339
+ get info() {
340
+ return `cannot pop notation`;
325
341
  }
326
342
  };
327
343
  var UnnecessaryNewlineMessage = class extends RemoveThingMessage {
@@ -390,12 +406,23 @@ var UndefinedVariableMessage = class {
390
406
  };
391
407
 
392
408
  // src/util.ts
393
- var NameManager = class {
409
+ var NameManager = class _NameManager {
394
410
  array = [];
395
- data;
411
+ data = /* @__PURE__ */ new Map();
396
412
  constructor(from) {
397
- this.array = [...from?.array ?? []];
398
- this.data = new Map(from?.data);
413
+ if (from === void 0) return;
414
+ if (from instanceof _NameManager) {
415
+ this.array = [...from.array];
416
+ this.data = new Map(from.data);
417
+ } else {
418
+ assert(Array.isArray(from));
419
+ this.array = from.map((x) => ({ k: x.name, v: x }));
420
+ this.array.sort((a, b) => b.k.length - a.k.length);
421
+ this.data = new Map(from.map((x) => [x.name, x]));
422
+ }
423
+ }
424
+ toArray() {
425
+ return this.array.map(({ v }) => v);
399
426
  }
400
427
  get(name) {
401
428
  return this.data.get(name);
@@ -957,12 +984,15 @@ var Parser = class {
957
984
  const result = this.#defs(type).find((x) => this.scanner.accept(x.name));
958
985
  const mod = result ?? UnknownModifier[type];
959
986
  if (result === void 0) {
960
- const args2 = this.scanner.acceptUntil(MODIFIER_CLOSE_SIGN);
961
- if (args2 === null) this.emit.message(
962
- new ExpectedMessage(this.scanner.position(), MODIFIER_CLOSE_SIGN)
963
- );
987
+ let name = "";
988
+ while (!this.scanner.isEOF() && !this.scanner.acceptWhitespaceChar() && !this.scanner.peek(MODIFIER_CLOSE_SIGN) && !this.scanner.peek(MODIFIER_END_SIGN)) {
989
+ if (this.scanner.accept("\\")) {
990
+ if (this.scanner.isEOF()) break;
991
+ }
992
+ name += this.scanner.acceptChar();
993
+ }
964
994
  this.emit.message(
965
- new UnknownModifierMessage(posStart, this.scanner.position() - posStart)
995
+ new UnknownModifierMessage(posStart, this.scanner.position() - posStart, name)
966
996
  );
967
997
  }
968
998
  const args = this.ARGUMENTS();
@@ -1020,6 +1050,8 @@ var Parser = class {
1020
1050
  }
1021
1051
  this.emit.endBlock();
1022
1052
  }
1053
+ const last = node.content.at(-1);
1054
+ node.actualEnd = last?.actualEnd ?? last?.end;
1023
1055
  if (node.mod.delayContentExpansion) this.delayDepth--;
1024
1056
  if (node.mod.afterParseContent)
1025
1057
  this.emit.message(...node.mod.afterParseContent(node, this.cxt, immediate));
@@ -1102,6 +1134,8 @@ var Parser = class {
1102
1134
  while (!this.scanner.isEOF() && this.INLINE_ENTITY()) {
1103
1135
  }
1104
1136
  this.emit.endInline();
1137
+ const last = node.content.at(-1);
1138
+ node.actualEnd = last?.actualEnd ?? last?.end;
1105
1139
  debug.trace("PARSE para end");
1106
1140
  }
1107
1141
  // returns false if breaking out of paragraph
@@ -1191,11 +1225,12 @@ var Parser = class {
1191
1225
  content.push({
1192
1226
  type: 4 /* Escaped */,
1193
1227
  content: this.scanner.acceptChar(),
1194
- start: posEnd - 2,
1195
- end: posEnd
1228
+ start: posEnd - 1,
1229
+ end: posEnd + 1
1196
1230
  });
1197
1231
  continue;
1198
1232
  }
1233
+ const beforeInterp = this.scanner.position();
1199
1234
  const result = this.cxt.config.argumentInterpolators.find(
1200
1235
  (x) => this.scanner.accept(x.name)
1201
1236
  );
@@ -1206,7 +1241,7 @@ var Parser = class {
1206
1241
  type: 8 /* Interpolation */,
1207
1242
  definition: result,
1208
1243
  argument: inner,
1209
- start: posEnd - 2,
1244
+ start: beforeInterp,
1210
1245
  end: posEnd
1211
1246
  });
1212
1247
  if (!ok2) {
@@ -1268,7 +1303,8 @@ function initParseContext(cxt) {
1268
1303
  blockSlotDelayedStack: [],
1269
1304
  inlineSlotDelayedStack: [],
1270
1305
  blockSlotData: [],
1271
- inlineSlotData: []
1306
+ inlineSlotData: [],
1307
+ notationStack: []
1272
1308
  });
1273
1309
  }
1274
1310
  function customModifier(type, name, argNames, slotName, content) {
@@ -1496,6 +1532,41 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
1496
1532
  }
1497
1533
  });
1498
1534
 
1535
+ // src/builtin/pushpop.ts
1536
+ var PushNotationMod = new SystemModifierDefinition(
1537
+ "push-notation",
1538
+ 2 /* Marker */,
1539
+ {
1540
+ expand(_, cxt) {
1541
+ const data = cxt.get(builtins);
1542
+ data.notationStack.push({
1543
+ blocks: cxt.config.blockModifiers.toArray(),
1544
+ inlines: cxt.config.inlineModifiers.toArray()
1545
+ });
1546
+ return [];
1547
+ }
1548
+ }
1549
+ );
1550
+ var PopNotationMod = new SystemModifierDefinition(
1551
+ "pop-notation",
1552
+ 2 /* Marker */,
1553
+ {
1554
+ prepareExpand(node, cxt) {
1555
+ const data = cxt.get(builtins);
1556
+ const result = data.notationStack.pop();
1557
+ if (!result) return [
1558
+ new CannotPopNotationMessage(node.start, node.end - node.start)
1559
+ ];
1560
+ cxt.config.blockModifiers = new NameManager(result.blocks);
1561
+ cxt.config.inlineModifiers = new NameManager(result.inlines);
1562
+ return [];
1563
+ },
1564
+ expand() {
1565
+ return [];
1566
+ }
1567
+ }
1568
+ );
1569
+
1499
1570
  // src/builtin/slot.ts
1500
1571
  function slotModifier(type) {
1501
1572
  const mod = type == 7 /* BlockModifier */ ? new BlockModifierDefinition("slot", 2 /* Marker */) : new InlineModifierDefinition("slot", 2 /* Marker */);
@@ -1610,6 +1681,19 @@ var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
1610
1681
  return [{ type: 3 /* Text */, content: node.state.value, start: -1, end: -1 }];
1611
1682
  }
1612
1683
  });
1684
+ var PrintInlineMod = new InlineModifierDefinition("print", 2 /* Marker */, {
1685
+ // .print:args...
1686
+ prepareExpand(node) {
1687
+ const check = checkArguments(node);
1688
+ if (check) return check;
1689
+ node.state = { value: node.arguments.map((x) => x.expansion).join("") };
1690
+ return [];
1691
+ },
1692
+ expand(node) {
1693
+ if (!node.state) return [];
1694
+ return [{ type: 3 /* Text */, content: node.state.value, start: -1, end: -1 }];
1695
+ }
1696
+ });
1613
1697
  var GetVarInterpolator = new ArgumentInterpolatorDefinition(
1614
1698
  "$(",
1615
1699
  ")",
@@ -1650,9 +1734,9 @@ var VarMod = new SystemModifierDefinition("var", 2 /* Marker */, {
1650
1734
  // src/builtin/builtin.ts
1651
1735
  var basic = new Configuration();
1652
1736
  basic.initializers = [initParseContext];
1653
- basic.systemModifiers.add(DefineBlockMod, DefineInlineMod, VarMod);
1737
+ basic.systemModifiers.add(DefineBlockMod, DefineInlineMod, VarMod, PushNotationMod, PopNotationMod);
1654
1738
  basic.blockModifiers.add(SlotBlockMod);
1655
- basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod);
1739
+ basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod, PrintInlineMod);
1656
1740
  basic.argumentInterpolators.add(GetVarInterpolator);
1657
1741
  var BuiltinConfiguration = Object.freeze(basic);
1658
1742