@the_dissidents/libemmm 0.0.4 → 0.0.7
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 +28 -15
- package/dist/index.d.mts +75 -21
- package/dist/index.d.ts +75 -21
- package/dist/index.js +259 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +257 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -37,22 +37,38 @@ var ModifierBase = class {
|
|
|
37
37
|
}
|
|
38
38
|
roleHint;
|
|
39
39
|
/**
|
|
40
|
-
* If true, any modifier encountered
|
|
40
|
+
* If true, any modifier encountered inside it will *not* be expanded *during parse-content*,
|
|
41
|
+
* *unless* that modifier is `alwaysTryExpand`. In the vast majority of cases, you shouldn't
|
|
42
|
+
* be using this.
|
|
41
43
|
*/
|
|
42
44
|
delayContentExpansion = false;
|
|
43
45
|
/**
|
|
44
|
-
* If true, such a modifier will always be expanded whenever it is encountered, *even if*
|
|
46
|
+
* If true, such a modifier will always be expanded whenever it is encountered, *even if*
|
|
47
|
+
* contained in a modifier with `delayContentExpansion`. In the vast majority of cases,
|
|
48
|
+
* you shouldn't be using this.
|
|
45
49
|
*/
|
|
46
50
|
alwaysTryExpand = false;
|
|
47
|
-
/** Called before the modifier's content is parsed.
|
|
51
|
+
/** Called before the modifier's content is parsed.
|
|
52
|
+
* @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
|
|
53
|
+
*/
|
|
48
54
|
beforeParseContent;
|
|
49
|
-
/** Called after the modifier's content is parsed.
|
|
55
|
+
/** Called after the modifier's content is parsed.
|
|
56
|
+
* @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
|
|
57
|
+
*/
|
|
50
58
|
afterParseContent;
|
|
51
|
-
/** Called before reparsing of the expansion.
|
|
59
|
+
/** Called before reparsing of the expansion.
|
|
60
|
+
* @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.*/
|
|
52
61
|
beforeProcessExpansion;
|
|
53
|
-
/** Called before reparsing of the expansion.
|
|
62
|
+
/** Called before reparsing of the expansion.
|
|
63
|
+
* @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.*/
|
|
54
64
|
afterProcessExpansion;
|
|
65
|
+
/**
|
|
66
|
+
* @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
|
|
67
|
+
*/
|
|
55
68
|
prepareExpand;
|
|
69
|
+
/**
|
|
70
|
+
* @param immediate False when the node is inside a `delayContentExpansion` modifier, but it is `alwaysTryExpand`; otherwise true.
|
|
71
|
+
*/
|
|
56
72
|
expand;
|
|
57
73
|
};
|
|
58
74
|
var BlockModifierDefinition = class extends ModifierBase {
|
|
@@ -128,14 +144,6 @@ function assert(x) {
|
|
|
128
144
|
throw error;
|
|
129
145
|
}
|
|
130
146
|
}
|
|
131
|
-
function linePositions(src) {
|
|
132
|
-
let result = [0];
|
|
133
|
-
[...src].forEach((x, i) => {
|
|
134
|
-
if (x == "\n") result.push(i + 1);
|
|
135
|
-
});
|
|
136
|
-
result.push(Infinity);
|
|
137
|
-
return result;
|
|
138
|
-
}
|
|
139
147
|
var cloneArgument = (arg, options) => ({
|
|
140
148
|
location: clonePosition(arg.location, options),
|
|
141
149
|
content: arg.content.map((ent) => {
|
|
@@ -264,12 +272,52 @@ var debug = {
|
|
|
264
272
|
}
|
|
265
273
|
};
|
|
266
274
|
|
|
275
|
+
// src/source.ts
|
|
276
|
+
var StringSource = class {
|
|
277
|
+
constructor(d, src) {
|
|
278
|
+
this.src = src;
|
|
279
|
+
this.name = d.name;
|
|
280
|
+
this.lineMap = [0];
|
|
281
|
+
[...src].forEach((x, i) => {
|
|
282
|
+
if (x == "\n") this.lineMap.push(i + 1);
|
|
283
|
+
});
|
|
284
|
+
this.nLines = this.lineMap.length;
|
|
285
|
+
this.lineMap.push(Infinity);
|
|
286
|
+
}
|
|
287
|
+
name;
|
|
288
|
+
nLines;
|
|
289
|
+
lineMap;
|
|
290
|
+
getRowCol(pos) {
|
|
291
|
+
let line = -1, linepos = 0;
|
|
292
|
+
for (let i = 1; i < this.lineMap.length; i++) {
|
|
293
|
+
if (this.lineMap[i] > pos) {
|
|
294
|
+
line = i - 1;
|
|
295
|
+
linepos = this.lineMap[i - 1];
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return [line, pos - linepos];
|
|
300
|
+
}
|
|
301
|
+
getLineStart(n) {
|
|
302
|
+
assert(n >= 0);
|
|
303
|
+
if (n >= this.lineMap.length) return Infinity;
|
|
304
|
+
return this.lineMap[n];
|
|
305
|
+
}
|
|
306
|
+
getLine(n) {
|
|
307
|
+
const start = this.getLineStart(n);
|
|
308
|
+
const end = this.getLineStart(n + 1);
|
|
309
|
+
if (start === Infinity) return void 0;
|
|
310
|
+
return this.src.substring(start, end - 1);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
|
|
267
314
|
// src/scanner.ts
|
|
268
315
|
var SimpleScanner = class {
|
|
269
|
-
constructor(src,
|
|
316
|
+
constructor(src, sourceDesc = { name: "<input>" }) {
|
|
270
317
|
this.src = src;
|
|
271
|
-
this.source =
|
|
318
|
+
this.source = new StringSource(sourceDesc, src);
|
|
272
319
|
}
|
|
320
|
+
source;
|
|
273
321
|
pos = 0;
|
|
274
322
|
position() {
|
|
275
323
|
return this.pos;
|
|
@@ -311,7 +359,8 @@ var debugPrint = {
|
|
|
311
359
|
blockShorthand: (x) => x.name + x.parts.map((x2, i) => ` .. <arg${i}> .. ${x2}`).join("") + (x.mod.slotType == 2 /* None */ ? "" : ` .. <slot> .. ${x.postfix ?? "<no postfix>"}`),
|
|
312
360
|
argument: (arg) => arg.content.map(debugPrintArgEntity).join(""),
|
|
313
361
|
node: (...nodes) => nodes.map((x) => debugPrintNode(x)).join("\n"),
|
|
314
|
-
message:
|
|
362
|
+
message: debugPrintMsg,
|
|
363
|
+
range: debugPrintRange,
|
|
315
364
|
document: debugDumpDocument
|
|
316
365
|
};
|
|
317
366
|
function debugPrintArgEntity(node) {
|
|
@@ -381,38 +430,46 @@ ${prefix}<expansion />`;
|
|
|
381
430
|
}
|
|
382
431
|
return result;
|
|
383
432
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
433
|
+
function debugPrintRange(loc, context = 1) {
|
|
434
|
+
const isSingleCharacter = loc.start == loc.end;
|
|
435
|
+
let [sr, sc] = loc.source.getRowCol(loc.start);
|
|
436
|
+
let [er, ec] = loc.source.getRowCol(loc.actualEnd ?? loc.end);
|
|
437
|
+
const rowWidth = Math.max((sr + 1).toString().length, (er + 1).toString().length);
|
|
438
|
+
const startLine = Math.max(0, sr - context);
|
|
439
|
+
const endLine = Math.min(loc.source.nLines - 1, er + context);
|
|
440
|
+
let lines = [];
|
|
441
|
+
for (let i = startLine; i <= endLine; i++) {
|
|
442
|
+
const line = loc.source.getLine(i);
|
|
443
|
+
lines.push((i + 1).toString().padStart(rowWidth) + " | " + line);
|
|
444
|
+
if (i >= sr && i <= er) {
|
|
445
|
+
const startPos = i == sr ? sc : 0;
|
|
446
|
+
const endPos = i == er ? ec : line.length;
|
|
447
|
+
lines.push(
|
|
448
|
+
" ".repeat(rowWidth) + " | " + " ".repeat(startPos) + (isSingleCharacter ? "^" : "~".repeat(endPos - startPos + 1))
|
|
449
|
+
);
|
|
450
|
+
}
|
|
399
451
|
}
|
|
452
|
+
return lines.join("\n");
|
|
453
|
+
}
|
|
454
|
+
function debugPrintMsg(m) {
|
|
455
|
+
const poss = (loc2) => {
|
|
456
|
+
const [r1, c1] = loc2.source.getRowCol(loc2.start);
|
|
457
|
+
if (loc2.start == loc2.end) return `l${r1 + 1}c${c1 + 1}`;
|
|
458
|
+
const [r2, c2] = loc2.source.getRowCol(loc2.end);
|
|
459
|
+
return `l${r1 + 1}c${c1 + 1}-l${r2 + 1}c${c2 + 1}`;
|
|
460
|
+
};
|
|
400
461
|
let loc = m.location;
|
|
401
|
-
let result = `at ${
|
|
402
|
-
if (descriptor && m.location.source !== descriptor) {
|
|
403
|
-
result += `
|
|
404
|
-
warning: source descriptor mismatch: ${m.location.source.name}`;
|
|
405
|
-
}
|
|
462
|
+
let result = `at ${poss(loc)}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
|
|
406
463
|
while (loc = loc.original) {
|
|
407
464
|
let d = loc.source !== m.location.source ? `(in ${loc.source.name}) ` : "";
|
|
408
465
|
result += `
|
|
409
|
-
---> original at: ${d}${
|
|
466
|
+
---> original at: ${d}${poss(loc)}`;
|
|
410
467
|
}
|
|
411
468
|
return result;
|
|
412
469
|
}
|
|
413
|
-
function debugDumpDocument(doc
|
|
470
|
+
function debugDumpDocument(doc) {
|
|
414
471
|
let root = debugPrint.node(...doc.root.content);
|
|
415
|
-
let msgs = doc.messages.map((x) =>
|
|
472
|
+
let msgs = doc.messages.map((x) => debugPrintRange(x.location) + "\n" + debugPrintMsg(x)).join("\n");
|
|
416
473
|
if (msgs.length > 0) msgs += "\n";
|
|
417
474
|
return `Document: ${doc.root.source.name}
|
|
418
475
|
${msgs}${root}`;
|
|
@@ -424,7 +481,6 @@ __export(messages_exports, {
|
|
|
424
481
|
ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
|
|
425
482
|
CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
|
|
426
483
|
CannotUseModuleInSelfMessage: () => CannotUseModuleInSelfMessage,
|
|
427
|
-
ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
|
|
428
484
|
EitherNormalOrPreMessage: () => EitherNormalOrPreMessage,
|
|
429
485
|
EntityNotAllowedMessage: () => EntityNotAllowedMessage,
|
|
430
486
|
ExpectedMessage: () => ExpectedMessage,
|
|
@@ -437,6 +493,7 @@ __export(messages_exports, {
|
|
|
437
493
|
OverwriteDefinitionsMessage: () => OverwriteDefinitionsMessage,
|
|
438
494
|
OverwriteSpecialVariableMessage: () => OverwriteSpecialVariableMessage,
|
|
439
495
|
ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
|
|
496
|
+
ShouldBeOnNewlineMessage: () => ShouldBeOnNewlineMessage,
|
|
440
497
|
SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
|
|
441
498
|
UnclosedInlineModifierMessage: () => UnclosedInlineModifierMessage,
|
|
442
499
|
UndefinedVariableMessage: () => UndefinedVariableMessage,
|
|
@@ -503,7 +560,7 @@ var UnknownModifierMessage = class {
|
|
|
503
560
|
code = 2;
|
|
504
561
|
severity = 2 /* Error */;
|
|
505
562
|
get info() {
|
|
506
|
-
return `unknown modifier '${this.what}'
|
|
563
|
+
return `unknown modifier '${this.what}'`;
|
|
507
564
|
}
|
|
508
565
|
// get fixes(): readonly FixSuggestion[] {
|
|
509
566
|
// let [start, end] = [this.start, this.end];
|
|
@@ -673,13 +730,13 @@ var NewBlockShouldBeOnNewlineMessage = class extends AddThingMessage {
|
|
|
673
730
|
);
|
|
674
731
|
}
|
|
675
732
|
};
|
|
676
|
-
var
|
|
733
|
+
var ShouldBeOnNewlineMessage = class extends AddThingMessage {
|
|
677
734
|
constructor(location) {
|
|
678
735
|
super(
|
|
679
736
|
3,
|
|
680
737
|
1 /* Warning */,
|
|
681
738
|
location,
|
|
682
|
-
"the
|
|
739
|
+
"the following should begin in a new line to avoid confusion"
|
|
683
740
|
);
|
|
684
741
|
}
|
|
685
742
|
};
|
|
@@ -764,6 +821,41 @@ var Document = class _Document {
|
|
|
764
821
|
);
|
|
765
822
|
return doc;
|
|
766
823
|
}
|
|
824
|
+
/**
|
|
825
|
+
* Performs a depth-first walk of the node tree.
|
|
826
|
+
*/
|
|
827
|
+
walk(callback) {
|
|
828
|
+
let nodes = this.root.content;
|
|
829
|
+
let node;
|
|
830
|
+
while (node = nodes.shift()) {
|
|
831
|
+
const result = callback(node);
|
|
832
|
+
if (result == "break") break;
|
|
833
|
+
if (result == "skip") continue;
|
|
834
|
+
if ("arguments" in node)
|
|
835
|
+
nodes.push(...node.arguments.flatMap((x) => x.content));
|
|
836
|
+
if ("content" in node && Array.isArray(node.content))
|
|
837
|
+
nodes.push(...node.content);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Gets all nodes that covers the given position, from outermost to innermost (essentially a path).
|
|
842
|
+
*/
|
|
843
|
+
resolvePosition(pos) {
|
|
844
|
+
const result = [];
|
|
845
|
+
let nodes = this.root.content;
|
|
846
|
+
let node;
|
|
847
|
+
while (node = nodes.shift()) {
|
|
848
|
+
if (node.location.start <= pos && (node.location.actualEnd ?? node.location.end) >= pos) {
|
|
849
|
+
result.push(node);
|
|
850
|
+
nodes = [];
|
|
851
|
+
if ("arguments" in node)
|
|
852
|
+
nodes.push(...node.arguments.flatMap((x) => x.content));
|
|
853
|
+
if ("content" in node && Array.isArray(node.content))
|
|
854
|
+
nodes.push(...node.content);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return result;
|
|
858
|
+
}
|
|
767
859
|
};
|
|
768
860
|
var Configuration = class _Configuration {
|
|
769
861
|
initializers = [];
|
|
@@ -1020,7 +1112,7 @@ var Parser = class {
|
|
|
1020
1112
|
SHOULD_BE_A_NEWLINE() {
|
|
1021
1113
|
this.WHITESPACES();
|
|
1022
1114
|
if (!this.scanner.accept("\n")) this.emit.message(
|
|
1023
|
-
new
|
|
1115
|
+
new ShouldBeOnNewlineMessage(this.#loc())
|
|
1024
1116
|
);
|
|
1025
1117
|
}
|
|
1026
1118
|
// TODO: this is awkward and doesn't emit messages in the most appropriate way
|
|
@@ -1110,14 +1202,28 @@ var Parser = class {
|
|
|
1110
1202
|
if (grouped) this.SHOULD_BE_A_NEWLINE();
|
|
1111
1203
|
const posContentStart = this.scanner.position();
|
|
1112
1204
|
let posContentEnd = this.scanner.position();
|
|
1205
|
+
let paragraphEnd = void 0;
|
|
1113
1206
|
let string = "";
|
|
1114
1207
|
while (!this.scanner.isEOF()) {
|
|
1115
1208
|
if (this.scanner.accept("\n")) {
|
|
1116
1209
|
let white = "\n";
|
|
1117
|
-
let char
|
|
1210
|
+
let char;
|
|
1118
1211
|
while ((char = this.scanner.acceptWhitespaceChar()) !== null)
|
|
1119
1212
|
white += char;
|
|
1120
|
-
if (grouped && this.scanner.accept(GROUP_END)
|
|
1213
|
+
if (grouped && this.scanner.accept(GROUP_END)) {
|
|
1214
|
+
paragraphEnd = this.scanner.position();
|
|
1215
|
+
if (!this.scanner.isEOF()) {
|
|
1216
|
+
this.SHOULD_BE_A_NEWLINE();
|
|
1217
|
+
this.WARN_IF_MORE_NEWLINES_THAN(1);
|
|
1218
|
+
}
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
if (!grouped && this.scanner.accept("\n")) {
|
|
1222
|
+
paragraphEnd = this.scanner.position() - 1;
|
|
1223
|
+
if (!this.scanner.isEOF())
|
|
1224
|
+
this.WARN_IF_MORE_NEWLINES_THAN(0);
|
|
1225
|
+
break;
|
|
1226
|
+
}
|
|
1121
1227
|
if (this.scanner.isEOF()) {
|
|
1122
1228
|
if (grouped) this.emit.message(
|
|
1123
1229
|
new ExpectedMessage(this.#loc(), GROUP_END)
|
|
@@ -1132,7 +1238,7 @@ var Parser = class {
|
|
|
1132
1238
|
}
|
|
1133
1239
|
const node = {
|
|
1134
1240
|
type: 2 /* Preformatted */,
|
|
1135
|
-
location: this.#locFrom(posStart),
|
|
1241
|
+
location: this.#locFrom(posStart, paragraphEnd ?? posContentEnd),
|
|
1136
1242
|
content: {
|
|
1137
1243
|
start: posContentStart,
|
|
1138
1244
|
end: posContentEnd,
|
|
@@ -1149,6 +1255,10 @@ var Parser = class {
|
|
|
1149
1255
|
this.WARN_IF_MORE_NEWLINES_THAN(1);
|
|
1150
1256
|
while (!this.scanner.isEOF()) {
|
|
1151
1257
|
if (this.scanner.accept(GROUP_END)) {
|
|
1258
|
+
if (!this.scanner.isEOF()) {
|
|
1259
|
+
this.SHOULD_BE_A_NEWLINE();
|
|
1260
|
+
this.WARN_IF_MORE_NEWLINES_THAN(1);
|
|
1261
|
+
}
|
|
1152
1262
|
this.groupDepth--;
|
|
1153
1263
|
return;
|
|
1154
1264
|
}
|
|
@@ -1219,6 +1329,10 @@ var Parser = class {
|
|
|
1219
1329
|
if (node.mod.delayContentExpansion) this.delayDepth++;
|
|
1220
1330
|
let ok = true;
|
|
1221
1331
|
if (isMarker) {
|
|
1332
|
+
if (!this.scanner.isEOF() && type == 7 /* BlockModifier */) {
|
|
1333
|
+
this.SHOULD_BE_A_NEWLINE();
|
|
1334
|
+
this.WARN_IF_MORE_NEWLINES_THAN(1);
|
|
1335
|
+
}
|
|
1222
1336
|
if (type === 6 /* InlineModifier */) this.emit.addInlineNode(node);
|
|
1223
1337
|
else this.emit.addBlockNode(node);
|
|
1224
1338
|
} else if (type == 6 /* InlineModifier */) {
|
|
@@ -1265,6 +1379,10 @@ var Parser = class {
|
|
|
1265
1379
|
return this.MODIFIER(6 /* InlineModifier */);
|
|
1266
1380
|
if (this.scanner.peek(MODIFIER_SYSTEM_OPEN))
|
|
1267
1381
|
return false;
|
|
1382
|
+
if (this.scanner.peek(MODIFIER_BLOCK_OPEN)) {
|
|
1383
|
+
this.SHOULD_BE_A_NEWLINE();
|
|
1384
|
+
return false;
|
|
1385
|
+
}
|
|
1268
1386
|
const short = this.cxt.config.inlineShorthands.find((x) => this.scanner.accept(x.name));
|
|
1269
1387
|
if (short) return this.SHORTHAND(6 /* InlineModifier */, short);
|
|
1270
1388
|
if (this.scanner.accept("\\")) {
|
|
@@ -1499,28 +1617,33 @@ function onlyPermitPlaintextParagraph(node) {
|
|
|
1499
1617
|
}
|
|
1500
1618
|
return result;
|
|
1501
1619
|
}
|
|
1620
|
+
function checkContent(ents) {
|
|
1621
|
+
if (ents.length == 0) return "";
|
|
1622
|
+
else if (ents.length > 1) {
|
|
1623
|
+
let last = ents.at(-1).location;
|
|
1624
|
+
return [new MultipleBlocksNotPermittedMessage({
|
|
1625
|
+
source: last.source,
|
|
1626
|
+
start: ents[1].location.start,
|
|
1627
|
+
end: last.actualEnd ?? last.end
|
|
1628
|
+
})];
|
|
1629
|
+
}
|
|
1630
|
+
return check(ents[0]);
|
|
1631
|
+
}
|
|
1502
1632
|
function check(ent) {
|
|
1503
1633
|
if (ent.type == 7 /* BlockModifier */) {
|
|
1504
1634
|
if (!ent.expansion) return [new EntityNotAllowedMessage(
|
|
1505
1635
|
ent.location,
|
|
1506
1636
|
"it does not expand to plain text"
|
|
1507
1637
|
)];
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
return [new MultipleBlocksNotPermittedMessage({
|
|
1512
|
-
source: last.source,
|
|
1513
|
-
start: ent.expansion[1].location.start,
|
|
1514
|
-
end: last.actualEnd ?? last.end
|
|
1515
|
-
})];
|
|
1516
|
-
}
|
|
1517
|
-
return check(ent.expansion[0]);
|
|
1638
|
+
return checkContent(ent.expansion);
|
|
1639
|
+
} else if (ent.type == 2 /* Preformatted */) {
|
|
1640
|
+
return ent.content.text;
|
|
1518
1641
|
} else if (ent.type !== 1 /* Paragraph */) {
|
|
1519
1642
|
return [new OnlySimpleParagraphsPermittedMessage(ent.location)];
|
|
1520
1643
|
}
|
|
1521
1644
|
return checkInline(ent.content);
|
|
1522
1645
|
}
|
|
1523
|
-
return
|
|
1646
|
+
return checkContent(node.content);
|
|
1524
1647
|
}
|
|
1525
1648
|
function onlyPermitSimpleParagraphs(node) {
|
|
1526
1649
|
function check(nodes) {
|
|
@@ -1600,24 +1723,20 @@ function customModifier(type, name, signature, content) {
|
|
|
1600
1723
|
args: node.state.args,
|
|
1601
1724
|
slotContent: node.content
|
|
1602
1725
|
});
|
|
1726
|
+
debug.trace(`pushed ${NodeType[type]} slot data for`, name);
|
|
1603
1727
|
debug.trace(
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
signature.slotName == "" ? "(unnamed)" : `= ${signature.slotName}`
|
|
1728
|
+
`... slotName:`,
|
|
1729
|
+
signature.slotName === "" ? "<unnamed>" : signature.slotName === void 0 ? "<no slot>" : `'${signature.slotName}'`
|
|
1607
1730
|
);
|
|
1731
|
+
debug.trace(`... args:`, "{" + [...node.state.args].map(([a, b]) => `${a} => ${b}`).join(", ") + "}");
|
|
1608
1732
|
return [];
|
|
1609
1733
|
};
|
|
1610
1734
|
mod.afterProcessExpansion = (node, cxt) => {
|
|
1611
|
-
if (!node.state?.ok
|
|
1735
|
+
if (!node.state?.ok) return [];
|
|
1612
1736
|
const store = cxt.get(builtins);
|
|
1613
1737
|
const data = isInline ? store.inlineInstantiationData : store.blockInstantiationData;
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
debug.trace(
|
|
1617
|
-
`popped ${NodeType[type]} slot data for`,
|
|
1618
|
-
name,
|
|
1619
|
-
signature.slotName == "" ? "(unnamed)" : `= ${signature.slotName}`
|
|
1620
|
-
);
|
|
1738
|
+
data.pop();
|
|
1739
|
+
debug.trace(`popped ${NodeType[type]} slot data for`, name);
|
|
1621
1740
|
return [];
|
|
1622
1741
|
};
|
|
1623
1742
|
return mod;
|
|
@@ -1970,6 +2089,17 @@ var DefineInlineShorthandMod = new SystemModifierDefinition(
|
|
|
1970
2089
|
}
|
|
1971
2090
|
);
|
|
1972
2091
|
|
|
2092
|
+
// src/builtin/misc.ts
|
|
2093
|
+
var RawBlockMod = new BlockModifierDefinition(
|
|
2094
|
+
"raw",
|
|
2095
|
+
1 /* Preformatted */,
|
|
2096
|
+
{
|
|
2097
|
+
expand(node) {
|
|
2098
|
+
return node.content;
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
);
|
|
2102
|
+
|
|
1973
2103
|
// src/builtin/module.ts
|
|
1974
2104
|
function getDefs(cxt) {
|
|
1975
2105
|
const data = cxt.get(builtins);
|
|
@@ -2266,6 +2396,48 @@ function resolveId(id, cxt) {
|
|
|
2266
2396
|
value = cxt.variables.get(id);
|
|
2267
2397
|
return value;
|
|
2268
2398
|
}
|
|
2399
|
+
var ifdefBlock = (name, x) => new BlockModifierDefinition(
|
|
2400
|
+
name,
|
|
2401
|
+
0 /* Normal */,
|
|
2402
|
+
{
|
|
2403
|
+
prepareExpand(node, cxt) {
|
|
2404
|
+
const check = checkArguments(node, 1);
|
|
2405
|
+
if (check) return check;
|
|
2406
|
+
const arg = node.arguments[0];
|
|
2407
|
+
const id = arg.expansion;
|
|
2408
|
+
if (id == "") return [new InvalidArgumentMessage(arg.location)];
|
|
2409
|
+
const value = resolveId(id, cxt);
|
|
2410
|
+
node.state = value !== void 0;
|
|
2411
|
+
return [];
|
|
2412
|
+
},
|
|
2413
|
+
expand(node) {
|
|
2414
|
+
return node.state == x ? node.content : [];
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
);
|
|
2418
|
+
var ifdefInline = (name, x) => new InlineModifierDefinition(
|
|
2419
|
+
name,
|
|
2420
|
+
0 /* Normal */,
|
|
2421
|
+
{
|
|
2422
|
+
prepareExpand(node, cxt) {
|
|
2423
|
+
const check = checkArguments(node, 1);
|
|
2424
|
+
if (check) return check;
|
|
2425
|
+
const arg = node.arguments[0];
|
|
2426
|
+
const id = arg.expansion;
|
|
2427
|
+
if (id == "") return [new InvalidArgumentMessage(arg.location)];
|
|
2428
|
+
const value = resolveId(id, cxt);
|
|
2429
|
+
node.state = value !== void 0;
|
|
2430
|
+
return [];
|
|
2431
|
+
},
|
|
2432
|
+
expand(node) {
|
|
2433
|
+
return node.state == x ? node.content : [];
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
);
|
|
2437
|
+
var IfdefBlockMod = ifdefBlock("ifdef", true);
|
|
2438
|
+
var IfndefBlockMod = ifdefBlock("ifndef", false);
|
|
2439
|
+
var IfdefInlineMod = ifdefInline("ifdef", true);
|
|
2440
|
+
var IfndefInlineMod = ifdefInline("ifndef", false);
|
|
2269
2441
|
var GetVarInlineMod = new InlineModifierDefinition(
|
|
2270
2442
|
"$",
|
|
2271
2443
|
2 /* None */,
|
|
@@ -2361,14 +2533,19 @@ builtin.blockModifiers.add(
|
|
|
2361
2533
|
PreSlotBlockMod,
|
|
2362
2534
|
InjectPreSlotBlockMod,
|
|
2363
2535
|
ModuleMod,
|
|
2364
|
-
UseBlockMod
|
|
2536
|
+
UseBlockMod,
|
|
2537
|
+
IfdefBlockMod,
|
|
2538
|
+
IfndefBlockMod,
|
|
2539
|
+
RawBlockMod
|
|
2365
2540
|
);
|
|
2366
2541
|
builtin.inlineModifiers.add(
|
|
2367
2542
|
SlotInlineMod,
|
|
2368
2543
|
PreSlotInlineMod,
|
|
2369
2544
|
InjectPreSlotInlineMod,
|
|
2370
2545
|
GetVarInlineMod,
|
|
2371
|
-
PrintInlineMod
|
|
2546
|
+
PrintInlineMod,
|
|
2547
|
+
IfdefInlineMod,
|
|
2548
|
+
IfndefInlineMod
|
|
2372
2549
|
);
|
|
2373
2550
|
builtin.argumentInterpolators.add(GetVarInterpolator);
|
|
2374
2551
|
var BuiltinConfiguration = Object.freeze(builtin);
|
|
@@ -2441,9 +2618,8 @@ var headingBlock = new BlockModifierDefinition(
|
|
|
2441
2618
|
"heading",
|
|
2442
2619
|
0 /* Normal */,
|
|
2443
2620
|
{
|
|
2444
|
-
delayContentExpansion: true,
|
|
2445
2621
|
roleHint: "heading",
|
|
2446
|
-
|
|
2622
|
+
prepareExpand(node, cxt) {
|
|
2447
2623
|
let msgs = checkArguments(node, 0, 1);
|
|
2448
2624
|
if (msgs) return msgs;
|
|
2449
2625
|
msgs = onlyPermitSingleBlock(node);
|
|
@@ -2471,7 +2647,7 @@ var implicitHeadingBlock = new BlockModifierDefinition(
|
|
|
2471
2647
|
2 /* None */,
|
|
2472
2648
|
{
|
|
2473
2649
|
roleHint: "heading",
|
|
2474
|
-
|
|
2650
|
+
prepareExpand(node, cxt) {
|
|
2475
2651
|
let msgs = checkArguments(node, 0, 1);
|
|
2476
2652
|
if (msgs) return msgs;
|
|
2477
2653
|
node.state = {
|
|
@@ -2498,9 +2674,8 @@ var numberedHeadingBlock = new BlockModifierDefinition(
|
|
|
2498
2674
|
"numbered-heading",
|
|
2499
2675
|
0 /* Normal */,
|
|
2500
2676
|
{
|
|
2501
|
-
delayContentExpansion: true,
|
|
2502
2677
|
roleHint: "heading",
|
|
2503
|
-
|
|
2678
|
+
prepareExpand(node, cxt) {
|
|
2504
2679
|
let msgs = checkArguments(node, 1);
|
|
2505
2680
|
if (msgs) return msgs;
|
|
2506
2681
|
msgs = onlyPermitSingleBlock(node);
|
|
@@ -2845,7 +3020,7 @@ var MiscBlockRenderersHTML = [
|
|
|
2845
3020
|
[styleBlock, (node, cxt) => {
|
|
2846
3021
|
if (node.state === void 0)
|
|
2847
3022
|
return cxt.state.invalidBlock(node, "bad format");
|
|
2848
|
-
return `<div class="
|
|
3023
|
+
return `<div class="emmmstyle-${node.state}" style="display:contents">${cxt.state.render(node.content, cxt)}</div>`;
|
|
2849
3024
|
}],
|
|
2850
3025
|
[breakBlock, () => {
|
|
2851
3026
|
return `<hr>`;
|
|
@@ -2884,6 +3059,7 @@ function createWrapper(name, varname) {
|
|
|
2884
3059
|
if (previous)
|
|
2885
3060
|
msgs = [new OverwriteSpecialVariableMessage(node.head, varname, previous)];
|
|
2886
3061
|
cxt.variables.set(varname, result);
|
|
3062
|
+
debug.trace(varname, "->", result);
|
|
2887
3063
|
return msgs ?? [];
|
|
2888
3064
|
}
|
|
2889
3065
|
});
|
|
@@ -3019,6 +3195,7 @@ htmlConfig.addInlineRenderer(
|
|
|
3019
3195
|
var HTMLRenderConfiguration = htmlConfig;
|
|
3020
3196
|
|
|
3021
3197
|
// src/index.ts
|
|
3198
|
+
var emmmVersion = "0.0.6";
|
|
3022
3199
|
function setDebugLevel(level) {
|
|
3023
3200
|
debug.level = level;
|
|
3024
3201
|
}
|
|
@@ -3040,8 +3217,10 @@ export {
|
|
|
3040
3217
|
RenderConfiguration,
|
|
3041
3218
|
RenderContext,
|
|
3042
3219
|
SimpleScanner,
|
|
3220
|
+
StringSource,
|
|
3043
3221
|
SystemModifierDefinition,
|
|
3044
3222
|
debugPrint,
|
|
3223
|
+
emmmVersion,
|
|
3045
3224
|
messages_exports as messages,
|
|
3046
3225
|
parse,
|
|
3047
3226
|
setDebugLevel
|