@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/README.md +265 -4
- package/dist/index.d.mts +32 -7
- package/dist/index.d.ts +32 -7
- package/dist/index.js +103 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -148,6 +148,7 @@ var messages_exports = {};
|
|
|
148
148
|
__export(messages_exports, {
|
|
149
149
|
ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
|
|
150
150
|
CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
|
|
151
|
+
CannotPopNotationMessage: () => CannotPopNotationMessage,
|
|
151
152
|
ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
|
|
152
153
|
ExpectedMessage: () => ExpectedMessage,
|
|
153
154
|
InlineDefinitonInvalidEntityMessage: () => InlineDefinitonInvalidEntityMessage,
|
|
@@ -232,7 +233,7 @@ var ExpectedMessage = class {
|
|
|
232
233
|
code = 1;
|
|
233
234
|
severity = 2 /* Error */;
|
|
234
235
|
get length() {
|
|
235
|
-
return
|
|
236
|
+
return 0;
|
|
236
237
|
}
|
|
237
238
|
get info() {
|
|
238
239
|
return `expected '${this.what}'`;
|
|
@@ -242,13 +243,16 @@ var ExpectedMessage = class {
|
|
|
242
243
|
}
|
|
243
244
|
};
|
|
244
245
|
var UnknownModifierMessage = class {
|
|
245
|
-
constructor(position, length) {
|
|
246
|
+
constructor(position, length, what) {
|
|
246
247
|
this.position = position;
|
|
247
248
|
this.length = length;
|
|
249
|
+
this.what = what;
|
|
248
250
|
}
|
|
249
251
|
code = 2;
|
|
250
252
|
severity = 2 /* Error */;
|
|
251
|
-
info
|
|
253
|
+
get info() {
|
|
254
|
+
return `unknown modifier '${this.what}'; did you forget to escape it?`;
|
|
255
|
+
}
|
|
252
256
|
get fixes() {
|
|
253
257
|
let [pos, len] = [this.position, this.length];
|
|
254
258
|
return [{
|
|
@@ -356,7 +360,19 @@ var SlotUsedOutsideDefinitionMessage = class {
|
|
|
356
360
|
severity = 2 /* Error */;
|
|
357
361
|
fixes = [];
|
|
358
362
|
get info() {
|
|
359
|
-
return `
|
|
363
|
+
return `slot used outside a definition`;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
var CannotPopNotationMessage = class {
|
|
367
|
+
constructor(position, length) {
|
|
368
|
+
this.position = position;
|
|
369
|
+
this.length = length;
|
|
370
|
+
}
|
|
371
|
+
code = 10;
|
|
372
|
+
severity = 2 /* Error */;
|
|
373
|
+
fixes = [];
|
|
374
|
+
get info() {
|
|
375
|
+
return `cannot pop notation`;
|
|
360
376
|
}
|
|
361
377
|
};
|
|
362
378
|
var UnnecessaryNewlineMessage = class extends RemoveThingMessage {
|
|
@@ -425,12 +441,23 @@ var UndefinedVariableMessage = class {
|
|
|
425
441
|
};
|
|
426
442
|
|
|
427
443
|
// src/util.ts
|
|
428
|
-
var NameManager = class {
|
|
444
|
+
var NameManager = class _NameManager {
|
|
429
445
|
array = [];
|
|
430
|
-
data;
|
|
446
|
+
data = /* @__PURE__ */ new Map();
|
|
431
447
|
constructor(from) {
|
|
432
|
-
|
|
433
|
-
|
|
448
|
+
if (from === void 0) return;
|
|
449
|
+
if (from instanceof _NameManager) {
|
|
450
|
+
this.array = [...from.array];
|
|
451
|
+
this.data = new Map(from.data);
|
|
452
|
+
} else {
|
|
453
|
+
assert(Array.isArray(from));
|
|
454
|
+
this.array = from.map((x) => ({ k: x.name, v: x }));
|
|
455
|
+
this.array.sort((a, b) => b.k.length - a.k.length);
|
|
456
|
+
this.data = new Map(from.map((x) => [x.name, x]));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
toArray() {
|
|
460
|
+
return this.array.map(({ v }) => v);
|
|
434
461
|
}
|
|
435
462
|
get(name) {
|
|
436
463
|
return this.data.get(name);
|
|
@@ -992,12 +1019,15 @@ var Parser = class {
|
|
|
992
1019
|
const result = this.#defs(type).find((x) => this.scanner.accept(x.name));
|
|
993
1020
|
const mod = result ?? UnknownModifier[type];
|
|
994
1021
|
if (result === void 0) {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1022
|
+
let name = "";
|
|
1023
|
+
while (!this.scanner.isEOF() && !this.scanner.acceptWhitespaceChar() && !this.scanner.peek(MODIFIER_CLOSE_SIGN) && !this.scanner.peek(MODIFIER_END_SIGN)) {
|
|
1024
|
+
if (this.scanner.accept("\\")) {
|
|
1025
|
+
if (this.scanner.isEOF()) break;
|
|
1026
|
+
}
|
|
1027
|
+
name += this.scanner.acceptChar();
|
|
1028
|
+
}
|
|
999
1029
|
this.emit.message(
|
|
1000
|
-
new UnknownModifierMessage(posStart, this.scanner.position() - posStart)
|
|
1030
|
+
new UnknownModifierMessage(posStart, this.scanner.position() - posStart, name)
|
|
1001
1031
|
);
|
|
1002
1032
|
}
|
|
1003
1033
|
const args = this.ARGUMENTS();
|
|
@@ -1055,6 +1085,8 @@ var Parser = class {
|
|
|
1055
1085
|
}
|
|
1056
1086
|
this.emit.endBlock();
|
|
1057
1087
|
}
|
|
1088
|
+
const last = node.content.at(-1);
|
|
1089
|
+
node.actualEnd = last?.actualEnd ?? last?.end;
|
|
1058
1090
|
if (node.mod.delayContentExpansion) this.delayDepth--;
|
|
1059
1091
|
if (node.mod.afterParseContent)
|
|
1060
1092
|
this.emit.message(...node.mod.afterParseContent(node, this.cxt, immediate));
|
|
@@ -1137,6 +1169,8 @@ var Parser = class {
|
|
|
1137
1169
|
while (!this.scanner.isEOF() && this.INLINE_ENTITY()) {
|
|
1138
1170
|
}
|
|
1139
1171
|
this.emit.endInline();
|
|
1172
|
+
const last = node.content.at(-1);
|
|
1173
|
+
node.actualEnd = last?.actualEnd ?? last?.end;
|
|
1140
1174
|
debug.trace("PARSE para end");
|
|
1141
1175
|
}
|
|
1142
1176
|
// returns false if breaking out of paragraph
|
|
@@ -1226,11 +1260,12 @@ var Parser = class {
|
|
|
1226
1260
|
content.push({
|
|
1227
1261
|
type: 4 /* Escaped */,
|
|
1228
1262
|
content: this.scanner.acceptChar(),
|
|
1229
|
-
start: posEnd -
|
|
1230
|
-
end: posEnd
|
|
1263
|
+
start: posEnd - 1,
|
|
1264
|
+
end: posEnd + 1
|
|
1231
1265
|
});
|
|
1232
1266
|
continue;
|
|
1233
1267
|
}
|
|
1268
|
+
const beforeInterp = this.scanner.position();
|
|
1234
1269
|
const result = this.cxt.config.argumentInterpolators.find(
|
|
1235
1270
|
(x) => this.scanner.accept(x.name)
|
|
1236
1271
|
);
|
|
@@ -1241,7 +1276,7 @@ var Parser = class {
|
|
|
1241
1276
|
type: 8 /* Interpolation */,
|
|
1242
1277
|
definition: result,
|
|
1243
1278
|
argument: inner,
|
|
1244
|
-
start:
|
|
1279
|
+
start: beforeInterp,
|
|
1245
1280
|
end: posEnd
|
|
1246
1281
|
});
|
|
1247
1282
|
if (!ok2) {
|
|
@@ -1303,7 +1338,8 @@ function initParseContext(cxt) {
|
|
|
1303
1338
|
blockSlotDelayedStack: [],
|
|
1304
1339
|
inlineSlotDelayedStack: [],
|
|
1305
1340
|
blockSlotData: [],
|
|
1306
|
-
inlineSlotData: []
|
|
1341
|
+
inlineSlotData: [],
|
|
1342
|
+
notationStack: []
|
|
1307
1343
|
});
|
|
1308
1344
|
}
|
|
1309
1345
|
function customModifier(type, name, argNames, slotName, content) {
|
|
@@ -1531,6 +1567,41 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1531
1567
|
}
|
|
1532
1568
|
});
|
|
1533
1569
|
|
|
1570
|
+
// src/builtin/pushpop.ts
|
|
1571
|
+
var PushNotationMod = new SystemModifierDefinition(
|
|
1572
|
+
"push-notation",
|
|
1573
|
+
2 /* Marker */,
|
|
1574
|
+
{
|
|
1575
|
+
expand(_, cxt) {
|
|
1576
|
+
const data = cxt.get(builtins);
|
|
1577
|
+
data.notationStack.push({
|
|
1578
|
+
blocks: cxt.config.blockModifiers.toArray(),
|
|
1579
|
+
inlines: cxt.config.inlineModifiers.toArray()
|
|
1580
|
+
});
|
|
1581
|
+
return [];
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
);
|
|
1585
|
+
var PopNotationMod = new SystemModifierDefinition(
|
|
1586
|
+
"pop-notation",
|
|
1587
|
+
2 /* Marker */,
|
|
1588
|
+
{
|
|
1589
|
+
prepareExpand(node, cxt) {
|
|
1590
|
+
const data = cxt.get(builtins);
|
|
1591
|
+
const result = data.notationStack.pop();
|
|
1592
|
+
if (!result) return [
|
|
1593
|
+
new CannotPopNotationMessage(node.start, node.end - node.start)
|
|
1594
|
+
];
|
|
1595
|
+
cxt.config.blockModifiers = new NameManager(result.blocks);
|
|
1596
|
+
cxt.config.inlineModifiers = new NameManager(result.inlines);
|
|
1597
|
+
return [];
|
|
1598
|
+
},
|
|
1599
|
+
expand() {
|
|
1600
|
+
return [];
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
);
|
|
1604
|
+
|
|
1534
1605
|
// src/builtin/slot.ts
|
|
1535
1606
|
function slotModifier(type) {
|
|
1536
1607
|
const mod = type == 7 /* BlockModifier */ ? new BlockModifierDefinition("slot", 2 /* Marker */) : new InlineModifierDefinition("slot", 2 /* Marker */);
|
|
@@ -1645,6 +1716,19 @@ var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
|
1645
1716
|
return [{ type: 3 /* Text */, content: node.state.value, start: -1, end: -1 }];
|
|
1646
1717
|
}
|
|
1647
1718
|
});
|
|
1719
|
+
var PrintInlineMod = new InlineModifierDefinition("print", 2 /* Marker */, {
|
|
1720
|
+
// .print:args...
|
|
1721
|
+
prepareExpand(node) {
|
|
1722
|
+
const check = checkArguments(node);
|
|
1723
|
+
if (check) return check;
|
|
1724
|
+
node.state = { value: node.arguments.map((x) => x.expansion).join("") };
|
|
1725
|
+
return [];
|
|
1726
|
+
},
|
|
1727
|
+
expand(node) {
|
|
1728
|
+
if (!node.state) return [];
|
|
1729
|
+
return [{ type: 3 /* Text */, content: node.state.value, start: -1, end: -1 }];
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1648
1732
|
var GetVarInterpolator = new ArgumentInterpolatorDefinition(
|
|
1649
1733
|
"$(",
|
|
1650
1734
|
")",
|
|
@@ -1685,9 +1769,9 @@ var VarMod = new SystemModifierDefinition("var", 2 /* Marker */, {
|
|
|
1685
1769
|
// src/builtin/builtin.ts
|
|
1686
1770
|
var basic = new Configuration();
|
|
1687
1771
|
basic.initializers = [initParseContext];
|
|
1688
|
-
basic.systemModifiers.add(DefineBlockMod, DefineInlineMod, VarMod);
|
|
1772
|
+
basic.systemModifiers.add(DefineBlockMod, DefineInlineMod, VarMod, PushNotationMod, PopNotationMod);
|
|
1689
1773
|
basic.blockModifiers.add(SlotBlockMod);
|
|
1690
|
-
basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod);
|
|
1774
|
+
basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod, PrintInlineMod);
|
|
1691
1775
|
basic.argumentInterpolators.add(GetVarInterpolator);
|
|
1692
1776
|
var BuiltinConfiguration = Object.freeze(basic);
|
|
1693
1777
|
|