@the_dissidents/libemmm 0.0.0 → 0.0.1
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.d.mts +65 -12
- package/dist/index.d.ts +65 -12
- package/dist/index.js +420 -261
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +422 -245
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,132 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/interface.ts
|
|
8
|
+
var MessageSeverity = /* @__PURE__ */ ((MessageSeverity2) => {
|
|
9
|
+
MessageSeverity2[MessageSeverity2["Info"] = 0] = "Info";
|
|
10
|
+
MessageSeverity2[MessageSeverity2["Warning"] = 1] = "Warning";
|
|
11
|
+
MessageSeverity2[MessageSeverity2["Error"] = 2] = "Error";
|
|
12
|
+
return MessageSeverity2;
|
|
13
|
+
})(MessageSeverity || {});
|
|
14
|
+
var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
15
|
+
NodeType2[NodeType2["Root"] = 0] = "Root";
|
|
16
|
+
NodeType2[NodeType2["Paragraph"] = 1] = "Paragraph";
|
|
17
|
+
NodeType2[NodeType2["Preformatted"] = 2] = "Preformatted";
|
|
18
|
+
NodeType2[NodeType2["Text"] = 3] = "Text";
|
|
19
|
+
NodeType2[NodeType2["Escaped"] = 4] = "Escaped";
|
|
20
|
+
NodeType2[NodeType2["SystemModifier"] = 5] = "SystemModifier";
|
|
21
|
+
NodeType2[NodeType2["InlineModifier"] = 6] = "InlineModifier";
|
|
22
|
+
NodeType2[NodeType2["BlockModifier"] = 7] = "BlockModifier";
|
|
23
|
+
NodeType2[NodeType2["Interpolation"] = 8] = "Interpolation";
|
|
24
|
+
return NodeType2;
|
|
25
|
+
})(NodeType || {});
|
|
26
|
+
var ModifierFlags = /* @__PURE__ */ ((ModifierFlags2) => {
|
|
27
|
+
ModifierFlags2[ModifierFlags2["Normal"] = 0] = "Normal";
|
|
28
|
+
ModifierFlags2[ModifierFlags2["Preformatted"] = 1] = "Preformatted";
|
|
29
|
+
ModifierFlags2[ModifierFlags2["Marker"] = 2] = "Marker";
|
|
30
|
+
return ModifierFlags2;
|
|
31
|
+
})(ModifierFlags || {});
|
|
32
|
+
var ModifierBase = class {
|
|
33
|
+
constructor(name, flags = 0 /* Normal */, args) {
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.flags = flags;
|
|
36
|
+
if (args) Object.assign(this, args);
|
|
37
|
+
}
|
|
38
|
+
delayContentExpansion = false;
|
|
39
|
+
alwaysTryExpand = false;
|
|
40
|
+
beforeParseContent;
|
|
41
|
+
afterParseContent;
|
|
42
|
+
beforeProcessExpansion;
|
|
43
|
+
afterProcessExpansion;
|
|
44
|
+
prepareExpand;
|
|
45
|
+
expand;
|
|
46
|
+
};
|
|
47
|
+
var BlockModifierDefinition = class extends ModifierBase {
|
|
48
|
+
};
|
|
49
|
+
var InlineModifierDefinition = class extends ModifierBase {
|
|
50
|
+
};
|
|
51
|
+
var SystemModifierDefinition = class extends ModifierBase {
|
|
52
|
+
};
|
|
53
|
+
var ArgumentInterpolatorDefinition = class {
|
|
54
|
+
constructor(name, postfix, args) {
|
|
55
|
+
this.name = name;
|
|
56
|
+
this.postfix = postfix;
|
|
57
|
+
if (args) Object.assign(this, args);
|
|
58
|
+
}
|
|
59
|
+
alwaysTryExpand = false;
|
|
60
|
+
expand;
|
|
61
|
+
};
|
|
62
|
+
var ParseContext = class {
|
|
63
|
+
constructor(config, variables = /* @__PURE__ */ new Map()) {
|
|
64
|
+
this.config = config;
|
|
65
|
+
this.variables = variables;
|
|
66
|
+
config.initializers.forEach((x) => x(this));
|
|
67
|
+
}
|
|
68
|
+
data = {};
|
|
69
|
+
init(key, obj) {
|
|
70
|
+
assert(!(key in this.data));
|
|
71
|
+
this.data[key] = obj;
|
|
72
|
+
}
|
|
73
|
+
set(key, obj) {
|
|
74
|
+
assert(key in this.data);
|
|
75
|
+
this.data[key] = obj;
|
|
76
|
+
}
|
|
77
|
+
get(key) {
|
|
78
|
+
assert(key in this.data);
|
|
79
|
+
return this.data[key];
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var Document = class {
|
|
83
|
+
constructor(root, context, messages) {
|
|
84
|
+
this.root = root;
|
|
85
|
+
this.context = context;
|
|
86
|
+
this.messages = messages;
|
|
87
|
+
}
|
|
88
|
+
debugPrint(source) {
|
|
89
|
+
return debugDumpDocument(this, source);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var Configuration = class {
|
|
93
|
+
initializers = [];
|
|
94
|
+
blockModifiers;
|
|
95
|
+
inlineModifiers;
|
|
96
|
+
systemModifiers;
|
|
97
|
+
argumentInterpolators;
|
|
98
|
+
reparseDepthLimit = 10;
|
|
99
|
+
constructor(from) {
|
|
100
|
+
this.blockModifiers = new NameManager(from?.blockModifiers);
|
|
101
|
+
this.inlineModifiers = new NameManager(from?.inlineModifiers);
|
|
102
|
+
this.systemModifiers = new NameManager(from?.systemModifiers);
|
|
103
|
+
this.argumentInterpolators = new NameManager(from?.argumentInterpolators);
|
|
104
|
+
if (from) {
|
|
105
|
+
this.initializers = [...from.initializers];
|
|
106
|
+
this.reparseDepthLimit = from.reparseDepthLimit;
|
|
107
|
+
}
|
|
26
108
|
}
|
|
27
109
|
};
|
|
28
110
|
|
|
29
111
|
// src/messages.ts
|
|
112
|
+
var messages_exports = {};
|
|
113
|
+
__export(messages_exports, {
|
|
114
|
+
ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
|
|
115
|
+
CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
|
|
116
|
+
ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
|
|
117
|
+
ExpectedMessage: () => ExpectedMessage,
|
|
118
|
+
InlineDefinitonInvalidEntityMessage: () => InlineDefinitonInvalidEntityMessage,
|
|
119
|
+
InvalidArgumentMessage: () => InvalidArgumentMessage,
|
|
120
|
+
NameAlreadyDefinedMessage: () => NameAlreadyDefinedMessage,
|
|
121
|
+
NewBlockShouldBeOnNewlineMessage: () => NewBlockShouldBeOnNewlineMessage,
|
|
122
|
+
ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
|
|
123
|
+
ReferredMessage: () => ReferredMessage,
|
|
124
|
+
SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
|
|
125
|
+
UnclosedInlineModifierMessage: () => UnclosedInlineModifierMessage,
|
|
126
|
+
UndefinedVariableMessage: () => UndefinedVariableMessage,
|
|
127
|
+
UnknownModifierMessage: () => UnknownModifierMessage,
|
|
128
|
+
UnnecessaryNewlineMessage: () => UnnecessaryNewlineMessage
|
|
129
|
+
});
|
|
30
130
|
var ReferredMessage = class {
|
|
31
131
|
constructor(original, position, length) {
|
|
32
132
|
this.original = original;
|
|
@@ -140,29 +240,37 @@ var UnclosedInlineModifierMessage = class {
|
|
|
140
240
|
return `unclosed inline modifier ${this.what}'`;
|
|
141
241
|
}
|
|
142
242
|
};
|
|
143
|
-
var
|
|
144
|
-
constructor(position, length,
|
|
243
|
+
var ArgumentCountMismatchMessage = class {
|
|
244
|
+
constructor(position, length, min, max) {
|
|
145
245
|
this.position = position;
|
|
146
246
|
this.length = length;
|
|
147
|
-
|
|
247
|
+
if (min !== void 0) {
|
|
248
|
+
if (max == min) this.msg = `: ${min} expected`;
|
|
249
|
+
else if (max !== void 0) this.msg = `: ${min} to ${max} expected`;
|
|
250
|
+
else this.msg = `: at least ${min} expected`;
|
|
251
|
+
} else {
|
|
252
|
+
if (max !== void 0) this.msg = `: at most ${max} expected`;
|
|
253
|
+
}
|
|
148
254
|
}
|
|
255
|
+
msg = "";
|
|
149
256
|
code = 4;
|
|
150
257
|
severity = 2 /* Error */;
|
|
151
258
|
fixes = [];
|
|
152
259
|
get info() {
|
|
153
|
-
return `
|
|
260
|
+
return `argument count mismatch` + this.msg;
|
|
154
261
|
}
|
|
155
262
|
};
|
|
156
|
-
var
|
|
157
|
-
constructor(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
263
|
+
var CannotExpandArgumentMessage = class {
|
|
264
|
+
constructor(position, length, what) {
|
|
265
|
+
this.position = position;
|
|
266
|
+
this.length = length;
|
|
267
|
+
this.what = what;
|
|
268
|
+
}
|
|
269
|
+
code = 5;
|
|
270
|
+
severity = 2 /* Error */;
|
|
271
|
+
fixes = [];
|
|
272
|
+
get info() {
|
|
273
|
+
return `failed to expand argument` + (this.what === void 0 ? "" : `: ${this.what}`);
|
|
166
274
|
}
|
|
167
275
|
};
|
|
168
276
|
var InvalidArgumentMessage = class {
|
|
@@ -326,6 +434,36 @@ function assert(x) {
|
|
|
326
434
|
function has(v, f) {
|
|
327
435
|
return (v & f) === f;
|
|
328
436
|
}
|
|
437
|
+
function linePositions(src) {
|
|
438
|
+
let result = [0];
|
|
439
|
+
[...src].forEach((x, i) => {
|
|
440
|
+
if (x == "\n") result.push(i + 1);
|
|
441
|
+
});
|
|
442
|
+
result.push(Infinity);
|
|
443
|
+
return result;
|
|
444
|
+
}
|
|
445
|
+
var cloneArgument = (arg) => ({
|
|
446
|
+
start: arg.start,
|
|
447
|
+
end: arg.end,
|
|
448
|
+
content: arg.content.map((ent) => {
|
|
449
|
+
switch (ent.type) {
|
|
450
|
+
case 3 /* Text */:
|
|
451
|
+
case 4 /* Escaped */:
|
|
452
|
+
return structuredClone(ent);
|
|
453
|
+
case 8 /* Interpolation */:
|
|
454
|
+
return {
|
|
455
|
+
type: ent.type,
|
|
456
|
+
start: ent.start,
|
|
457
|
+
end: ent.end,
|
|
458
|
+
definition: ent.definition,
|
|
459
|
+
argument: cloneArgument(ent.argument),
|
|
460
|
+
expansion: ent.expansion
|
|
461
|
+
};
|
|
462
|
+
default:
|
|
463
|
+
return debug.never(ent);
|
|
464
|
+
}
|
|
465
|
+
})
|
|
466
|
+
});
|
|
329
467
|
function cloneNode(node, referring) {
|
|
330
468
|
switch (node.type) {
|
|
331
469
|
case 7 /* BlockModifier */:
|
|
@@ -338,7 +476,7 @@ function cloneNode(node, referring) {
|
|
|
338
476
|
mod: node.mod,
|
|
339
477
|
state: void 0,
|
|
340
478
|
head: structuredClone(node.head),
|
|
341
|
-
arguments:
|
|
479
|
+
arguments: node.arguments.map(cloneArgument),
|
|
342
480
|
content: node.content.map((x) => cloneNode(x, referring)),
|
|
343
481
|
expansion: node.expansion ? cloneNodes(node.expansion) : void 0
|
|
344
482
|
};
|
|
@@ -368,7 +506,7 @@ function debugPrintArgEntity(node) {
|
|
|
368
506
|
case 4 /* Escaped */:
|
|
369
507
|
return `<Escaped:${node.content}>`;
|
|
370
508
|
case 8 /* Interpolation */:
|
|
371
|
-
return `<Interp:${node.definition.name}-${node.definition.postfix}:${debugPrintArgument(node.
|
|
509
|
+
return `<Interp:${node.definition.name}-${node.definition.postfix}:${debugPrintArgument(node.argument)}${node.expansion ? `=${node.expansion}` : ""}>`;
|
|
372
510
|
default:
|
|
373
511
|
return debug.never(node);
|
|
374
512
|
}
|
|
@@ -377,7 +515,7 @@ function debugPrintArgument(arg) {
|
|
|
377
515
|
return arg.content.map(debugPrintArgEntity).join("");
|
|
378
516
|
}
|
|
379
517
|
function debugPrintNode(node, prefix = "") {
|
|
380
|
-
let result = `<${node.type}@${node.start}`;
|
|
518
|
+
let result = `<${NodeType[node.type]}@${node.start}`;
|
|
381
519
|
switch (node.type) {
|
|
382
520
|
case 0 /* Root */:
|
|
383
521
|
case 1 /* Paragraph */:
|
|
@@ -385,14 +523,14 @@ function debugPrintNode(node, prefix = "") {
|
|
|
385
523
|
if (content.length > 0)
|
|
386
524
|
result += `>
|
|
387
525
|
${content}
|
|
388
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
526
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
389
527
|
else result += `-${node.end} />`;
|
|
390
528
|
break;
|
|
391
529
|
case 4 /* Escaped */:
|
|
392
530
|
case 2 /* Preformatted */:
|
|
393
531
|
result += `>
|
|
394
532
|
${prefix} ${node.content}
|
|
395
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
533
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
396
534
|
break;
|
|
397
535
|
case 6 /* InlineModifier */:
|
|
398
536
|
case 7 /* BlockModifier */:
|
|
@@ -402,7 +540,7 @@ ${prefix} (${i})@${x.start}-${x.end}=${debugPrintArgument(x)}`).join("");
|
|
|
402
540
|
if (node.content.length > 0) {
|
|
403
541
|
result += ` id=${node.mod.name}${args}>
|
|
404
542
|
` + debugPrintNodes(node.content, prefix) + `
|
|
405
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
543
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
406
544
|
} else result += `-${node.end} id=${node.mod.name}${args} />`;
|
|
407
545
|
if (node.expansion) {
|
|
408
546
|
const content2 = debugPrintNodes(node.expansion, prefix);
|
|
@@ -428,118 +566,67 @@ function debugPrintNodes(content, prefix = "") {
|
|
|
428
566
|
if (dumps.length == 0) return "";
|
|
429
567
|
return dumps.map((x) => `${prefix} ${x}`).join("\n");
|
|
430
568
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
NodeType2[NodeType2["Paragraph"] = 1] = "Paragraph";
|
|
442
|
-
NodeType2[NodeType2["Preformatted"] = 2] = "Preformatted";
|
|
443
|
-
NodeType2[NodeType2["Text"] = 3] = "Text";
|
|
444
|
-
NodeType2[NodeType2["Escaped"] = 4] = "Escaped";
|
|
445
|
-
NodeType2[NodeType2["SystemModifier"] = 5] = "SystemModifier";
|
|
446
|
-
NodeType2[NodeType2["InlineModifier"] = 6] = "InlineModifier";
|
|
447
|
-
NodeType2[NodeType2["BlockModifier"] = 7] = "BlockModifier";
|
|
448
|
-
NodeType2[NodeType2["Interpolation"] = 8] = "Interpolation";
|
|
449
|
-
return NodeType2;
|
|
450
|
-
})(NodeType || {});
|
|
451
|
-
var ModifierFlags = /* @__PURE__ */ ((ModifierFlags2) => {
|
|
452
|
-
ModifierFlags2[ModifierFlags2["Normal"] = 0] = "Normal";
|
|
453
|
-
ModifierFlags2[ModifierFlags2["Preformatted"] = 1] = "Preformatted";
|
|
454
|
-
ModifierFlags2[ModifierFlags2["Marker"] = 2] = "Marker";
|
|
455
|
-
return ModifierFlags2;
|
|
456
|
-
})(ModifierFlags || {});
|
|
457
|
-
var ModifierBase = class {
|
|
458
|
-
constructor(name, flags = 0 /* Normal */, args) {
|
|
459
|
-
this.name = name;
|
|
460
|
-
this.flags = flags;
|
|
461
|
-
if (args) Object.assign(this, args);
|
|
462
|
-
}
|
|
463
|
-
delayContentExpansion = false;
|
|
464
|
-
alwaysTryExpand = false;
|
|
465
|
-
beforeParseContent;
|
|
466
|
-
afterParseContent;
|
|
467
|
-
beforeProcessExpansion;
|
|
468
|
-
afterProcessExpansion;
|
|
469
|
-
prepareExpand;
|
|
470
|
-
expand;
|
|
471
|
-
};
|
|
472
|
-
var BlockModifierDefinition = class extends ModifierBase {
|
|
473
|
-
};
|
|
474
|
-
var InlineModifierDefinition = class extends ModifierBase {
|
|
475
|
-
};
|
|
476
|
-
var SystemModifierDefinition = class extends ModifierBase {
|
|
477
|
-
};
|
|
478
|
-
var ArgumentInterpolatorDefinition = class {
|
|
479
|
-
constructor(name, postfix, expand) {
|
|
480
|
-
this.name = name;
|
|
481
|
-
this.postfix = postfix;
|
|
482
|
-
this.expand = expand;
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
var ParseContext = class {
|
|
486
|
-
constructor(config, variables = /* @__PURE__ */ new Map()) {
|
|
487
|
-
this.config = config;
|
|
488
|
-
this.variables = variables;
|
|
489
|
-
config.initializers.forEach((x) => x(this));
|
|
490
|
-
}
|
|
491
|
-
data = {};
|
|
492
|
-
init(key, obj) {
|
|
493
|
-
assert(!(key in this.data));
|
|
494
|
-
this.data[key] = obj;
|
|
495
|
-
}
|
|
496
|
-
set(key, obj) {
|
|
497
|
-
assert(key in this.data);
|
|
498
|
-
this.data[key] = obj;
|
|
499
|
-
}
|
|
500
|
-
get(key) {
|
|
501
|
-
assert(key in this.data);
|
|
502
|
-
return this.data[key];
|
|
503
|
-
}
|
|
504
|
-
#evalEntity(e) {
|
|
505
|
-
switch (e.type) {
|
|
506
|
-
case 3 /* Text */:
|
|
507
|
-
case 4 /* Escaped */:
|
|
508
|
-
return e.content;
|
|
509
|
-
case 8 /* Interpolation */:
|
|
510
|
-
const inner = this.evaluateArgument(e.arg);
|
|
511
|
-
return e.definition.expand(inner, this);
|
|
512
|
-
default:
|
|
513
|
-
assert(false);
|
|
569
|
+
function debugDumpDocument(doc, source) {
|
|
570
|
+
const lines = linePositions(source);
|
|
571
|
+
function pos2lc(pos) {
|
|
572
|
+
let line = -1, linepos = 0;
|
|
573
|
+
for (let i = 1; i < lines.length; i++) {
|
|
574
|
+
if (lines[i] > pos) {
|
|
575
|
+
line = i;
|
|
576
|
+
linepos = lines[i - 1];
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
514
579
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
this.context = context;
|
|
524
|
-
this.messages = messages;
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
var Configuration = class {
|
|
528
|
-
initializers = [];
|
|
529
|
-
blockModifiers;
|
|
530
|
-
inlineModifiers;
|
|
531
|
-
systemModifiers;
|
|
532
|
-
argumentInterpolators;
|
|
533
|
-
reparseDepthLimit = 10;
|
|
534
|
-
constructor(from) {
|
|
535
|
-
this.blockModifiers = new NameManager(from?.blockModifiers);
|
|
536
|
-
this.inlineModifiers = new NameManager(from?.inlineModifiers);
|
|
537
|
-
this.systemModifiers = new NameManager(from?.systemModifiers);
|
|
538
|
-
this.argumentInterpolators = new NameManager(from?.argumentInterpolators);
|
|
539
|
-
if (from) {
|
|
540
|
-
this.initializers = [...from.initializers];
|
|
541
|
-
this.reparseDepthLimit = from.reparseDepthLimit;
|
|
580
|
+
return `l${line}c${pos - linepos + 1}`;
|
|
581
|
+
}
|
|
582
|
+
function dumpMsg(m) {
|
|
583
|
+
let result = `at ${pos2lc(m.position)}, len ${m.length}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
|
|
584
|
+
while (m instanceof ReferredMessage) {
|
|
585
|
+
m = m.original;
|
|
586
|
+
result += `
|
|
587
|
+
---> original at: ${pos2lc(m.position)}, len ${m.length}`;
|
|
542
588
|
}
|
|
589
|
+
return result;
|
|
590
|
+
}
|
|
591
|
+
let root = debugPrintNode(doc.root);
|
|
592
|
+
let msgs = doc.messages.map(dumpMsg).join("\n");
|
|
593
|
+
if (msgs.length > 0) msgs += "\n";
|
|
594
|
+
return `${msgs}${root}`;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// src/debug.ts
|
|
598
|
+
var DebugLevel = /* @__PURE__ */ ((DebugLevel3) => {
|
|
599
|
+
DebugLevel3[DebugLevel3["Trace"] = 0] = "Trace";
|
|
600
|
+
DebugLevel3[DebugLevel3["Info"] = 1] = "Info";
|
|
601
|
+
DebugLevel3[DebugLevel3["Warning"] = 2] = "Warning";
|
|
602
|
+
DebugLevel3[DebugLevel3["Error"] = 3] = "Error";
|
|
603
|
+
DebugLevel3[DebugLevel3["None"] = 4] = "None";
|
|
604
|
+
return DebugLevel3;
|
|
605
|
+
})(DebugLevel || {});
|
|
606
|
+
var debug = {
|
|
607
|
+
level: 1 /* Info */,
|
|
608
|
+
trace(arg0, ...args) {
|
|
609
|
+
if (this.level > 0 /* Trace */) return;
|
|
610
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
611
|
+
console.info("TRACE", arg0, ...args);
|
|
612
|
+
},
|
|
613
|
+
info(arg0, ...args) {
|
|
614
|
+
if (this.level > 1 /* Info */) return;
|
|
615
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
616
|
+
console.info(" INFO", arg0, ...args);
|
|
617
|
+
},
|
|
618
|
+
warning(arg0, ...args) {
|
|
619
|
+
if (this.level > 2 /* Warning */) return;
|
|
620
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
621
|
+
console.warn(" WARN", arg0, ...args);
|
|
622
|
+
},
|
|
623
|
+
error(arg0, ...args) {
|
|
624
|
+
if (this.level > 3 /* Error */) return;
|
|
625
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
626
|
+
console.error("ERROR", arg0, ...args);
|
|
627
|
+
},
|
|
628
|
+
never(_) {
|
|
629
|
+
assert(false);
|
|
543
630
|
}
|
|
544
631
|
};
|
|
545
632
|
|
|
@@ -719,22 +806,61 @@ var Parser = class {
|
|
|
719
806
|
}
|
|
720
807
|
return ok;
|
|
721
808
|
}
|
|
809
|
+
#expandArgument(arg) {
|
|
810
|
+
if (arg.expansion !== void 0)
|
|
811
|
+
return arg.expansion;
|
|
812
|
+
let result = "";
|
|
813
|
+
const immediate = this.delayDepth == 0;
|
|
814
|
+
for (const e of arg.content) {
|
|
815
|
+
switch (e.type) {
|
|
816
|
+
case 3 /* Text */:
|
|
817
|
+
case 4 /* Escaped */:
|
|
818
|
+
result += e.content;
|
|
819
|
+
break;
|
|
820
|
+
case 8 /* Interpolation */:
|
|
821
|
+
if (e.expansion === void 0) {
|
|
822
|
+
const inner = this.#expandArgument(e.argument);
|
|
823
|
+
if (inner === void 0 || e.definition.expand === void 0 || !immediate && !e.definition.alwaysTryExpand)
|
|
824
|
+
return void 0;
|
|
825
|
+
e.expansion = e.definition.expand(inner, this.cxt, immediate);
|
|
826
|
+
if (e.expansion === void 0)
|
|
827
|
+
return void 0;
|
|
828
|
+
}
|
|
829
|
+
result += e.expansion;
|
|
830
|
+
break;
|
|
831
|
+
default:
|
|
832
|
+
debug.never(e);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
arg.expansion = result;
|
|
836
|
+
return result;
|
|
837
|
+
}
|
|
838
|
+
#expandArguments(node) {
|
|
839
|
+
for (const arg of node.arguments) {
|
|
840
|
+
this.#expandArgument(arg);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
722
843
|
#expand(node, depth = 0) {
|
|
723
844
|
if (node.expansion !== void 0) {
|
|
724
845
|
debug.trace("already expanded, skipping:", node.mod.name);
|
|
725
846
|
return true;
|
|
726
847
|
}
|
|
848
|
+
if (depth > 0) {
|
|
849
|
+
this.#expandArguments(node);
|
|
850
|
+
}
|
|
727
851
|
if (this.delayDepth > 0 && !node.mod.alwaysTryExpand) {
|
|
728
852
|
debug.trace("delaying expansion of", node.mod.name);
|
|
729
853
|
return true;
|
|
730
854
|
}
|
|
731
855
|
const immediate = this.delayDepth == 0;
|
|
732
|
-
if (
|
|
856
|
+
if (depth > 0) {
|
|
733
857
|
if (node.mod.beforeParseContent)
|
|
734
858
|
this.emit.message(...node.mod.beforeParseContent(node, this.cxt, immediate));
|
|
735
|
-
if (node.
|
|
736
|
-
|
|
737
|
-
|
|
859
|
+
if (node.content.length > 0) {
|
|
860
|
+
if (node.mod.delayContentExpansion) this.delayDepth++;
|
|
861
|
+
this.#reparse(node.content, depth);
|
|
862
|
+
if (node.mod.delayContentExpansion) this.delayDepth--;
|
|
863
|
+
}
|
|
738
864
|
if (node.mod.afterParseContent)
|
|
739
865
|
this.emit.message(...node.mod.afterParseContent(node, this.cxt, immediate));
|
|
740
866
|
}
|
|
@@ -773,7 +899,7 @@ var Parser = class {
|
|
|
773
899
|
}
|
|
774
900
|
parse() {
|
|
775
901
|
this.DOCUMENT();
|
|
776
|
-
return new
|
|
902
|
+
return new Document(this.emit.root, this.cxt, this.emit.messages);
|
|
777
903
|
}
|
|
778
904
|
WHITESPACES_OR_NEWLINES() {
|
|
779
905
|
while (this.scanner.acceptWhitespaceChar() !== null || this.scanner.accept("\n")) {
|
|
@@ -840,7 +966,7 @@ var Parser = class {
|
|
|
840
966
|
);
|
|
841
967
|
}
|
|
842
968
|
const args = this.ARGUMENTS();
|
|
843
|
-
debug.trace(`PARSE ${type}
|
|
969
|
+
debug.trace(`PARSE ${NodeType[type]}:`, mod.name);
|
|
844
970
|
const endsign = this.scanner.accept(MODIFIER_END_SIGN);
|
|
845
971
|
const flagMarker = has(mod.flags, 2 /* Marker */);
|
|
846
972
|
const isMarker = flagMarker || endsign;
|
|
@@ -849,16 +975,18 @@ var Parser = class {
|
|
|
849
975
|
this.scanner.position(),
|
|
850
976
|
MODIFIER_CLOSE_SIGN
|
|
851
977
|
));
|
|
978
|
+
const headEnd = this.scanner.position();
|
|
852
979
|
const node = {
|
|
853
980
|
type,
|
|
854
981
|
mod,
|
|
855
|
-
head: { start: posStart, end:
|
|
982
|
+
head: { start: posStart, end: headEnd },
|
|
856
983
|
arguments: args,
|
|
857
984
|
start: posStart,
|
|
858
|
-
end:
|
|
985
|
+
end: headEnd,
|
|
859
986
|
content: [],
|
|
860
987
|
expansion: void 0
|
|
861
988
|
};
|
|
989
|
+
this.#expandArguments(node);
|
|
862
990
|
const immediate = this.delayDepth == 0;
|
|
863
991
|
if (node.mod.beforeParseContent)
|
|
864
992
|
this.emit.message(...node.mod.beforeParseContent(node, this.cxt, immediate));
|
|
@@ -1043,10 +1171,8 @@ var Parser = class {
|
|
|
1043
1171
|
}
|
|
1044
1172
|
};
|
|
1045
1173
|
while (true) {
|
|
1046
|
-
if (end !== void 0 && this.scanner.accept(end))
|
|
1047
|
-
debug.trace("found end", end);
|
|
1174
|
+
if (end !== void 0 && this.scanner.accept(end))
|
|
1048
1175
|
break;
|
|
1049
|
-
}
|
|
1050
1176
|
if (this.scanner.accept(":")) {
|
|
1051
1177
|
ok = end === void 0;
|
|
1052
1178
|
break;
|
|
@@ -1079,7 +1205,7 @@ var Parser = class {
|
|
|
1079
1205
|
content.push({
|
|
1080
1206
|
type: 8 /* Interpolation */,
|
|
1081
1207
|
definition: result,
|
|
1082
|
-
|
|
1208
|
+
argument: inner,
|
|
1083
1209
|
start: posEnd - 2,
|
|
1084
1210
|
end: posEnd
|
|
1085
1211
|
});
|
|
@@ -1120,6 +1246,21 @@ function parse(scanner, config) {
|
|
|
1120
1246
|
return new Parser(scanner, config).parse();
|
|
1121
1247
|
}
|
|
1122
1248
|
|
|
1249
|
+
// src/modifier-helper.ts
|
|
1250
|
+
function checkArgumentLength(node, min, max = min) {
|
|
1251
|
+
if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
|
|
1252
|
+
return [new ArgumentCountMismatchMessage(node.head.start, node.head.end - node.head.start, min, max)];
|
|
1253
|
+
}
|
|
1254
|
+
return null;
|
|
1255
|
+
}
|
|
1256
|
+
function checkArguments(node, min, max = min) {
|
|
1257
|
+
const arg = node.arguments.find((x) => x.expansion === void 0);
|
|
1258
|
+
if (arg !== void 0) {
|
|
1259
|
+
return [new CannotExpandArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1260
|
+
}
|
|
1261
|
+
return checkArgumentLength(node, min, max);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1123
1264
|
// src/builtin/internal.ts
|
|
1124
1265
|
var builtins = Symbol();
|
|
1125
1266
|
function initParseContext(cxt) {
|
|
@@ -1130,15 +1271,6 @@ function initParseContext(cxt) {
|
|
|
1130
1271
|
inlineSlotData: []
|
|
1131
1272
|
});
|
|
1132
1273
|
}
|
|
1133
|
-
function checkArgumentLength(node, n) {
|
|
1134
|
-
if (node.arguments.length < n)
|
|
1135
|
-
return new ArgumentsTooFewMessage(node.head.end - 1, 0, n);
|
|
1136
|
-
if (node.arguments.length > n) {
|
|
1137
|
-
const start = node.arguments[n].start - 1;
|
|
1138
|
-
return new ArgumentsTooManyMessage(start, node.head.end - start, n);
|
|
1139
|
-
}
|
|
1140
|
-
return null;
|
|
1141
|
-
}
|
|
1142
1274
|
function customModifier(type, name, argNames, slotName, content) {
|
|
1143
1275
|
debug.info(`registered custom ${type} modifier:`, name);
|
|
1144
1276
|
debug.info("args:", argNames, `with ${slotName == "" ? "no slot name" : "slot name: " + slotName}`);
|
|
@@ -1147,9 +1279,12 @@ function customModifier(type, name, argNames, slotName, content) {
|
|
|
1147
1279
|
const isInline = type == 6 /* InlineModifier */;
|
|
1148
1280
|
mod.delayContentExpansion = true;
|
|
1149
1281
|
mod.prepareExpand = (node, cxt) => {
|
|
1150
|
-
|
|
1151
|
-
if (check) return
|
|
1152
|
-
node.state = {
|
|
1282
|
+
let check = checkArguments(node, argNames.length);
|
|
1283
|
+
if (check) return check;
|
|
1284
|
+
node.state = {
|
|
1285
|
+
ok: true,
|
|
1286
|
+
args: new Map(node.arguments.map((x, i) => [argNames[i], x.expansion]))
|
|
1287
|
+
};
|
|
1153
1288
|
return [];
|
|
1154
1289
|
};
|
|
1155
1290
|
mod.expand = (node, cxt) => {
|
|
@@ -1160,11 +1295,12 @@ function customModifier(type, name, argNames, slotName, content) {
|
|
|
1160
1295
|
mod.beforeProcessExpansion = (node, cxt) => {
|
|
1161
1296
|
if (!node.state?.ok) return [];
|
|
1162
1297
|
const store = cxt.get(builtins);
|
|
1163
|
-
const args = new Map(
|
|
1164
|
-
node.arguments.map((x, i) => [argNames[i], cxt.evaluateArgument(x)])
|
|
1165
|
-
);
|
|
1166
1298
|
const data = isInline ? store.inlineSlotData : store.blockSlotData;
|
|
1167
|
-
data.push([slotName, {
|
|
1299
|
+
data.push([slotName, {
|
|
1300
|
+
mod,
|
|
1301
|
+
args: node.state.args,
|
|
1302
|
+
slotContent: node.content
|
|
1303
|
+
}]);
|
|
1168
1304
|
debug.trace(
|
|
1169
1305
|
`pushed ${type} slot data for`,
|
|
1170
1306
|
name,
|
|
@@ -1194,28 +1330,31 @@ var DefineBlockMod = new SystemModifierDefinition("define-block", 0 /* Normal */
|
|
|
1194
1330
|
delayContentExpansion: true,
|
|
1195
1331
|
alwaysTryExpand: true,
|
|
1196
1332
|
beforeParseContent(node, cxt) {
|
|
1197
|
-
|
|
1198
|
-
|
|
1333
|
+
const check = checkArgumentLength(node, 1, Infinity);
|
|
1334
|
+
if (check) return check;
|
|
1199
1335
|
const msgs = [];
|
|
1200
1336
|
const name = node.arguments[0];
|
|
1201
|
-
const nameValue =
|
|
1202
|
-
if (cxt.config.blockModifiers.has(nameValue))
|
|
1203
|
-
msgs.push(new NameAlreadyDefinedMessage(
|
|
1204
|
-
node.start,
|
|
1205
|
-
name.end - name.start,
|
|
1206
|
-
nameValue
|
|
1207
|
-
));
|
|
1337
|
+
const nameValue = name.expansion;
|
|
1208
1338
|
let slotName = "";
|
|
1209
1339
|
if (node.arguments.length > 1) {
|
|
1210
|
-
const last =
|
|
1211
|
-
|
|
1340
|
+
const last = node.arguments.at(-1);
|
|
1341
|
+
if (last.expansion)
|
|
1342
|
+
slotName = /^\(.+\)$/.test(last.expansion) ? last.expansion.substring(1, last.expansion.length - 1) : "";
|
|
1343
|
+
else msgs.push(
|
|
1344
|
+
new InvalidArgumentMessage(last.start, last.end - last.start)
|
|
1345
|
+
);
|
|
1212
1346
|
}
|
|
1213
|
-
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) =>
|
|
1214
|
-
|
|
1347
|
+
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) => {
|
|
1348
|
+
if (!x.expansion) msgs.push(
|
|
1349
|
+
new InvalidArgumentMessage(x.start, x.end - x.start)
|
|
1350
|
+
);
|
|
1351
|
+
return x.expansion ?? "";
|
|
1352
|
+
});
|
|
1353
|
+
node.state = { name: nameValue, slotName, args, msgs };
|
|
1215
1354
|
const store = cxt.get(builtins);
|
|
1216
1355
|
store.blockSlotDelayedStack.push(node.state.slotName);
|
|
1217
1356
|
debug.trace("entering block definition:", node.state.name);
|
|
1218
|
-
return
|
|
1357
|
+
return [];
|
|
1219
1358
|
},
|
|
1220
1359
|
afterParseContent(node, cxt) {
|
|
1221
1360
|
if (!node.state) return [];
|
|
@@ -1224,9 +1363,22 @@ var DefineBlockMod = new SystemModifierDefinition("define-block", 0 /* Normal */
|
|
|
1224
1363
|
debug.trace("leaving block definition", node.state.name);
|
|
1225
1364
|
return [];
|
|
1226
1365
|
},
|
|
1366
|
+
prepareExpand(node, cxt, immediate) {
|
|
1367
|
+
if (!immediate || !node.state) return [];
|
|
1368
|
+
const arg = node.arguments[0];
|
|
1369
|
+
if (!node.state.name)
|
|
1370
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1371
|
+
if (cxt.config.blockModifiers.has(node.state.name))
|
|
1372
|
+
return [new NameAlreadyDefinedMessage(
|
|
1373
|
+
arg.start,
|
|
1374
|
+
arg.end - arg.start,
|
|
1375
|
+
node.state.name
|
|
1376
|
+
)];
|
|
1377
|
+
return [];
|
|
1378
|
+
},
|
|
1227
1379
|
expand(node, cxt, immediate) {
|
|
1228
1380
|
if (!immediate) return void 0;
|
|
1229
|
-
if (node.state) {
|
|
1381
|
+
if (node.state?.name) {
|
|
1230
1382
|
if (cxt.config.blockModifiers.has(node.state.name))
|
|
1231
1383
|
cxt.config.blockModifiers.remove(node.state.name);
|
|
1232
1384
|
cxt.config.blockModifiers.add(
|
|
@@ -1249,12 +1401,12 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1249
1401
|
delayContentExpansion: true,
|
|
1250
1402
|
alwaysTryExpand: true,
|
|
1251
1403
|
beforeParseContent(node, cxt) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1404
|
+
const check = checkArgumentLength(node, 1, Infinity);
|
|
1405
|
+
if (check) return check;
|
|
1254
1406
|
const msgs = [];
|
|
1255
1407
|
const name = node.arguments[0];
|
|
1256
|
-
const nameValue =
|
|
1257
|
-
if (cxt.config.inlineModifiers.has(nameValue))
|
|
1408
|
+
const nameValue = name.expansion;
|
|
1409
|
+
if (nameValue && cxt.config.inlineModifiers.has(nameValue))
|
|
1258
1410
|
msgs.push(new NameAlreadyDefinedMessage(
|
|
1259
1411
|
node.start,
|
|
1260
1412
|
name.end - name.start,
|
|
@@ -1262,15 +1414,24 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1262
1414
|
));
|
|
1263
1415
|
let slotName = "";
|
|
1264
1416
|
if (node.arguments.length > 1) {
|
|
1265
|
-
const last =
|
|
1266
|
-
|
|
1417
|
+
const last = node.arguments.at(-1);
|
|
1418
|
+
if (last.expansion)
|
|
1419
|
+
slotName = /^\(.+\)$/.test(last.expansion) ? last.expansion.substring(1, last.expansion.length - 1) : "";
|
|
1420
|
+
else msgs.push(
|
|
1421
|
+
new InvalidArgumentMessage(last.start, last.end - last.start)
|
|
1422
|
+
);
|
|
1267
1423
|
}
|
|
1268
|
-
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) =>
|
|
1269
|
-
|
|
1424
|
+
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) => {
|
|
1425
|
+
if (!x.expansion) msgs.push(
|
|
1426
|
+
new InvalidArgumentMessage(x.start, x.end - x.start)
|
|
1427
|
+
);
|
|
1428
|
+
return x.expansion ?? "";
|
|
1429
|
+
});
|
|
1430
|
+
node.state = { name: nameValue, slotName, args, msgs };
|
|
1270
1431
|
const store = cxt.get(builtins);
|
|
1271
1432
|
store.inlineSlotDelayedStack.push(node.state.slotName);
|
|
1272
1433
|
debug.trace("entering inline definition:", node.state.name);
|
|
1273
|
-
return
|
|
1434
|
+
return [];
|
|
1274
1435
|
},
|
|
1275
1436
|
afterParseContent(node, cxt) {
|
|
1276
1437
|
if (!node.state) return [];
|
|
@@ -1279,9 +1440,18 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1279
1440
|
debug.trace("leaving inline definition", node.state.name);
|
|
1280
1441
|
return [];
|
|
1281
1442
|
},
|
|
1282
|
-
prepareExpand(node, cxt) {
|
|
1283
|
-
if (!node.state) return [];
|
|
1443
|
+
prepareExpand(node, cxt, immediate) {
|
|
1444
|
+
if (!immediate || !node.state) return [];
|
|
1445
|
+
const arg = node.arguments[0];
|
|
1446
|
+
if (!node.state.name)
|
|
1447
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1284
1448
|
const msgs = [];
|
|
1449
|
+
if (cxt.config.inlineModifiers.has(node.state.name))
|
|
1450
|
+
msgs.push(new NameAlreadyDefinedMessage(
|
|
1451
|
+
arg.start,
|
|
1452
|
+
arg.end - arg.start,
|
|
1453
|
+
node.state.name
|
|
1454
|
+
));
|
|
1285
1455
|
let lastIsParagraph = false;
|
|
1286
1456
|
let concat = [];
|
|
1287
1457
|
for (const n of node.content) {
|
|
@@ -1309,7 +1479,7 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1309
1479
|
},
|
|
1310
1480
|
expand(node, cxt, immediate) {
|
|
1311
1481
|
if (!immediate) return void 0;
|
|
1312
|
-
if (node.state) {
|
|
1482
|
+
if (node.state?.name) {
|
|
1313
1483
|
if (cxt.config.inlineModifiers.has(node.state.name))
|
|
1314
1484
|
cxt.config.inlineModifiers.remove(node.state.name);
|
|
1315
1485
|
cxt.config.inlineModifiers.add(
|
|
@@ -1332,21 +1502,27 @@ function slotModifier(type) {
|
|
|
1332
1502
|
const isInline = type == 6 /* InlineModifier */;
|
|
1333
1503
|
mod.alwaysTryExpand = true;
|
|
1334
1504
|
mod.prepareExpand = (node, cxt, immediate) => {
|
|
1505
|
+
if (node.state) return [];
|
|
1506
|
+
const check = checkArgumentLength(node, 0, 1);
|
|
1507
|
+
if (check && immediate) {
|
|
1508
|
+
node.state = { ok: false };
|
|
1509
|
+
return check;
|
|
1510
|
+
}
|
|
1335
1511
|
const store = cxt.get(builtins);
|
|
1336
1512
|
const data = isInline ? store.inlineSlotData : store.blockSlotData;
|
|
1337
|
-
|
|
1338
|
-
if (
|
|
1339
|
-
|
|
1513
|
+
let id = "";
|
|
1514
|
+
if (node.arguments.length == 1) {
|
|
1515
|
+
const arg = node.arguments[0];
|
|
1516
|
+
if (!arg.expansion) {
|
|
1340
1517
|
node.state = { ok: false };
|
|
1341
|
-
return [new
|
|
1518
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1342
1519
|
}
|
|
1343
|
-
|
|
1520
|
+
id = arg.expansion;
|
|
1344
1521
|
}
|
|
1345
|
-
if (
|
|
1522
|
+
if (data.length == 0) {
|
|
1346
1523
|
if (immediate) {
|
|
1347
1524
|
node.state = { ok: false };
|
|
1348
|
-
|
|
1349
|
-
return [new ArgumentsTooManyMessage(start, node.head.end - start)];
|
|
1525
|
+
return [new SlotUsedOutsideDefinitionMessage(node.start, node.head.end - node.start)];
|
|
1350
1526
|
}
|
|
1351
1527
|
return [];
|
|
1352
1528
|
}
|
|
@@ -1417,10 +1593,10 @@ function resolveId(id, cxt) {
|
|
|
1417
1593
|
var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
1418
1594
|
// .$:id
|
|
1419
1595
|
prepareExpand(node, cxt) {
|
|
1420
|
-
const check =
|
|
1421
|
-
if (check) return
|
|
1596
|
+
const check = checkArguments(node, 1);
|
|
1597
|
+
if (check) return check;
|
|
1422
1598
|
const arg = node.arguments[0];
|
|
1423
|
-
const id =
|
|
1599
|
+
const id = arg.expansion;
|
|
1424
1600
|
if (id == "")
|
|
1425
1601
|
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1426
1602
|
const value = resolveId(id, cxt);
|
|
@@ -1437,20 +1613,28 @@ var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
|
1437
1613
|
var GetVarInterpolator = new ArgumentInterpolatorDefinition(
|
|
1438
1614
|
"$(",
|
|
1439
1615
|
")",
|
|
1440
|
-
|
|
1616
|
+
{
|
|
1617
|
+
alwaysTryExpand: true,
|
|
1618
|
+
expand(content, cxt, immediate) {
|
|
1619
|
+
const result = resolveId(content, cxt);
|
|
1620
|
+
if (result === void 0) debug.trace("var interp failed:", content);
|
|
1621
|
+
else debug.trace(`$(${content}) --> ${result}`);
|
|
1622
|
+
return result;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1441
1625
|
);
|
|
1442
1626
|
var VarMod = new SystemModifierDefinition("var", 2 /* Marker */, {
|
|
1443
1627
|
// .var id:value
|
|
1444
1628
|
prepareExpand(node, cxt) {
|
|
1445
|
-
const check =
|
|
1446
|
-
if (check) return
|
|
1629
|
+
const check = checkArguments(node, 2);
|
|
1630
|
+
if (check) return check;
|
|
1447
1631
|
const arg = node.arguments[0];
|
|
1448
|
-
const
|
|
1449
|
-
if (
|
|
1632
|
+
const id = arg.expansion;
|
|
1633
|
+
if (id == "")
|
|
1450
1634
|
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1451
1635
|
node.state = {
|
|
1452
|
-
id
|
|
1453
|
-
value:
|
|
1636
|
+
id,
|
|
1637
|
+
value: node.arguments[1].expansion
|
|
1454
1638
|
};
|
|
1455
1639
|
return [];
|
|
1456
1640
|
},
|
|
@@ -1471,34 +1655,27 @@ basic.blockModifiers.add(SlotBlockMod);
|
|
|
1471
1655
|
basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod);
|
|
1472
1656
|
basic.argumentInterpolators.add(GetVarInterpolator);
|
|
1473
1657
|
var BuiltinConfiguration = Object.freeze(basic);
|
|
1658
|
+
|
|
1659
|
+
// src/index.ts
|
|
1660
|
+
function setDebugLevel(level) {
|
|
1661
|
+
debug.level = level;
|
|
1662
|
+
}
|
|
1474
1663
|
export {
|
|
1475
1664
|
ArgumentInterpolatorDefinition,
|
|
1476
|
-
ArgumentsTooFewMessage,
|
|
1477
|
-
ArgumentsTooManyMessage,
|
|
1478
1665
|
BlockModifierDefinition,
|
|
1479
1666
|
BuiltinConfiguration,
|
|
1480
1667
|
Configuration,
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
ExpectedMessage,
|
|
1484
|
-
InlineDefinitonInvalidEntityMessage,
|
|
1668
|
+
DebugLevel,
|
|
1669
|
+
Document,
|
|
1485
1670
|
InlineModifierDefinition,
|
|
1486
|
-
InvalidArgumentMessage,
|
|
1487
1671
|
MessageSeverity,
|
|
1488
1672
|
ModifierFlags,
|
|
1489
|
-
NameAlreadyDefinedMessage,
|
|
1490
|
-
NewBlockShouldBeOnNewlineMessage,
|
|
1491
1673
|
NodeType,
|
|
1492
1674
|
ParseContext,
|
|
1493
|
-
ReachedRecursionLimitMessage,
|
|
1494
|
-
ReferredMessage,
|
|
1495
1675
|
SimpleScanner,
|
|
1496
|
-
SlotUsedOutsideDefinitionMessage,
|
|
1497
1676
|
SystemModifierDefinition,
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
UnnecessaryNewlineMessage,
|
|
1502
|
-
parse
|
|
1677
|
+
messages_exports as messages,
|
|
1678
|
+
parse,
|
|
1679
|
+
setDebugLevel
|
|
1503
1680
|
};
|
|
1504
1681
|
//# sourceMappingURL=index.mjs.map
|