@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.js
CHANGED
|
@@ -21,65 +21,147 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ArgumentInterpolatorDefinition: () => ArgumentInterpolatorDefinition,
|
|
24
|
-
ArgumentsTooFewMessage: () => ArgumentsTooFewMessage,
|
|
25
|
-
ArgumentsTooManyMessage: () => ArgumentsTooManyMessage,
|
|
26
24
|
BlockModifierDefinition: () => BlockModifierDefinition,
|
|
27
25
|
BuiltinConfiguration: () => BuiltinConfiguration,
|
|
28
26
|
Configuration: () => Configuration,
|
|
29
|
-
|
|
30
|
-
Document: () =>
|
|
31
|
-
ExpectedMessage: () => ExpectedMessage,
|
|
32
|
-
InlineDefinitonInvalidEntityMessage: () => InlineDefinitonInvalidEntityMessage,
|
|
27
|
+
DebugLevel: () => DebugLevel,
|
|
28
|
+
Document: () => Document,
|
|
33
29
|
InlineModifierDefinition: () => InlineModifierDefinition,
|
|
34
|
-
InvalidArgumentMessage: () => InvalidArgumentMessage,
|
|
35
30
|
MessageSeverity: () => MessageSeverity,
|
|
36
31
|
ModifierFlags: () => ModifierFlags,
|
|
37
|
-
NameAlreadyDefinedMessage: () => NameAlreadyDefinedMessage,
|
|
38
|
-
NewBlockShouldBeOnNewlineMessage: () => NewBlockShouldBeOnNewlineMessage,
|
|
39
32
|
NodeType: () => NodeType,
|
|
40
33
|
ParseContext: () => ParseContext,
|
|
41
|
-
ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
|
|
42
|
-
ReferredMessage: () => ReferredMessage,
|
|
43
34
|
SimpleScanner: () => SimpleScanner,
|
|
44
|
-
SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
|
|
45
35
|
SystemModifierDefinition: () => SystemModifierDefinition,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
UnnecessaryNewlineMessage: () => UnnecessaryNewlineMessage,
|
|
50
|
-
parse: () => parse
|
|
36
|
+
messages: () => messages_exports,
|
|
37
|
+
parse: () => parse,
|
|
38
|
+
setDebugLevel: () => setDebugLevel
|
|
51
39
|
});
|
|
52
40
|
module.exports = __toCommonJS(index_exports);
|
|
53
41
|
|
|
54
|
-
// src/
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
// src/interface.ts
|
|
43
|
+
var MessageSeverity = /* @__PURE__ */ ((MessageSeverity2) => {
|
|
44
|
+
MessageSeverity2[MessageSeverity2["Info"] = 0] = "Info";
|
|
45
|
+
MessageSeverity2[MessageSeverity2["Warning"] = 1] = "Warning";
|
|
46
|
+
MessageSeverity2[MessageSeverity2["Error"] = 2] = "Error";
|
|
47
|
+
return MessageSeverity2;
|
|
48
|
+
})(MessageSeverity || {});
|
|
49
|
+
var NodeType = /* @__PURE__ */ ((NodeType2) => {
|
|
50
|
+
NodeType2[NodeType2["Root"] = 0] = "Root";
|
|
51
|
+
NodeType2[NodeType2["Paragraph"] = 1] = "Paragraph";
|
|
52
|
+
NodeType2[NodeType2["Preformatted"] = 2] = "Preformatted";
|
|
53
|
+
NodeType2[NodeType2["Text"] = 3] = "Text";
|
|
54
|
+
NodeType2[NodeType2["Escaped"] = 4] = "Escaped";
|
|
55
|
+
NodeType2[NodeType2["SystemModifier"] = 5] = "SystemModifier";
|
|
56
|
+
NodeType2[NodeType2["InlineModifier"] = 6] = "InlineModifier";
|
|
57
|
+
NodeType2[NodeType2["BlockModifier"] = 7] = "BlockModifier";
|
|
58
|
+
NodeType2[NodeType2["Interpolation"] = 8] = "Interpolation";
|
|
59
|
+
return NodeType2;
|
|
60
|
+
})(NodeType || {});
|
|
61
|
+
var ModifierFlags = /* @__PURE__ */ ((ModifierFlags2) => {
|
|
62
|
+
ModifierFlags2[ModifierFlags2["Normal"] = 0] = "Normal";
|
|
63
|
+
ModifierFlags2[ModifierFlags2["Preformatted"] = 1] = "Preformatted";
|
|
64
|
+
ModifierFlags2[ModifierFlags2["Marker"] = 2] = "Marker";
|
|
65
|
+
return ModifierFlags2;
|
|
66
|
+
})(ModifierFlags || {});
|
|
67
|
+
var ModifierBase = class {
|
|
68
|
+
constructor(name, flags = 0 /* Normal */, args) {
|
|
69
|
+
this.name = name;
|
|
70
|
+
this.flags = flags;
|
|
71
|
+
if (args) Object.assign(this, args);
|
|
72
|
+
}
|
|
73
|
+
delayContentExpansion = false;
|
|
74
|
+
alwaysTryExpand = false;
|
|
75
|
+
beforeParseContent;
|
|
76
|
+
afterParseContent;
|
|
77
|
+
beforeProcessExpansion;
|
|
78
|
+
afterProcessExpansion;
|
|
79
|
+
prepareExpand;
|
|
80
|
+
expand;
|
|
81
|
+
};
|
|
82
|
+
var BlockModifierDefinition = class extends ModifierBase {
|
|
83
|
+
};
|
|
84
|
+
var InlineModifierDefinition = class extends ModifierBase {
|
|
85
|
+
};
|
|
86
|
+
var SystemModifierDefinition = class extends ModifierBase {
|
|
87
|
+
};
|
|
88
|
+
var ArgumentInterpolatorDefinition = class {
|
|
89
|
+
constructor(name, postfix, args) {
|
|
90
|
+
this.name = name;
|
|
91
|
+
this.postfix = postfix;
|
|
92
|
+
if (args) Object.assign(this, args);
|
|
93
|
+
}
|
|
94
|
+
alwaysTryExpand = false;
|
|
95
|
+
expand;
|
|
96
|
+
};
|
|
97
|
+
var ParseContext = class {
|
|
98
|
+
constructor(config, variables = /* @__PURE__ */ new Map()) {
|
|
99
|
+
this.config = config;
|
|
100
|
+
this.variables = variables;
|
|
101
|
+
config.initializers.forEach((x) => x(this));
|
|
102
|
+
}
|
|
103
|
+
data = {};
|
|
104
|
+
init(key, obj) {
|
|
105
|
+
assert(!(key in this.data));
|
|
106
|
+
this.data[key] = obj;
|
|
107
|
+
}
|
|
108
|
+
set(key, obj) {
|
|
109
|
+
assert(key in this.data);
|
|
110
|
+
this.data[key] = obj;
|
|
111
|
+
}
|
|
112
|
+
get(key) {
|
|
113
|
+
assert(key in this.data);
|
|
114
|
+
return this.data[key];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var Document = class {
|
|
118
|
+
constructor(root, context, messages) {
|
|
119
|
+
this.root = root;
|
|
120
|
+
this.context = context;
|
|
121
|
+
this.messages = messages;
|
|
122
|
+
}
|
|
123
|
+
debugPrint(source) {
|
|
124
|
+
return debugDumpDocument(this, source);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var Configuration = class {
|
|
128
|
+
initializers = [];
|
|
129
|
+
blockModifiers;
|
|
130
|
+
inlineModifiers;
|
|
131
|
+
systemModifiers;
|
|
132
|
+
argumentInterpolators;
|
|
133
|
+
reparseDepthLimit = 10;
|
|
134
|
+
constructor(from) {
|
|
135
|
+
this.blockModifiers = new NameManager(from?.blockModifiers);
|
|
136
|
+
this.inlineModifiers = new NameManager(from?.inlineModifiers);
|
|
137
|
+
this.systemModifiers = new NameManager(from?.systemModifiers);
|
|
138
|
+
this.argumentInterpolators = new NameManager(from?.argumentInterpolators);
|
|
139
|
+
if (from) {
|
|
140
|
+
this.initializers = [...from.initializers];
|
|
141
|
+
this.reparseDepthLimit = from.reparseDepthLimit;
|
|
142
|
+
}
|
|
79
143
|
}
|
|
80
144
|
};
|
|
81
145
|
|
|
82
146
|
// src/messages.ts
|
|
147
|
+
var messages_exports = {};
|
|
148
|
+
__export(messages_exports, {
|
|
149
|
+
ArgumentCountMismatchMessage: () => ArgumentCountMismatchMessage,
|
|
150
|
+
CannotExpandArgumentMessage: () => CannotExpandArgumentMessage,
|
|
151
|
+
ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
|
|
152
|
+
ExpectedMessage: () => ExpectedMessage,
|
|
153
|
+
InlineDefinitonInvalidEntityMessage: () => InlineDefinitonInvalidEntityMessage,
|
|
154
|
+
InvalidArgumentMessage: () => InvalidArgumentMessage,
|
|
155
|
+
NameAlreadyDefinedMessage: () => NameAlreadyDefinedMessage,
|
|
156
|
+
NewBlockShouldBeOnNewlineMessage: () => NewBlockShouldBeOnNewlineMessage,
|
|
157
|
+
ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
|
|
158
|
+
ReferredMessage: () => ReferredMessage,
|
|
159
|
+
SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
|
|
160
|
+
UnclosedInlineModifierMessage: () => UnclosedInlineModifierMessage,
|
|
161
|
+
UndefinedVariableMessage: () => UndefinedVariableMessage,
|
|
162
|
+
UnknownModifierMessage: () => UnknownModifierMessage,
|
|
163
|
+
UnnecessaryNewlineMessage: () => UnnecessaryNewlineMessage
|
|
164
|
+
});
|
|
83
165
|
var ReferredMessage = class {
|
|
84
166
|
constructor(original, position, length) {
|
|
85
167
|
this.original = original;
|
|
@@ -193,29 +275,37 @@ var UnclosedInlineModifierMessage = class {
|
|
|
193
275
|
return `unclosed inline modifier ${this.what}'`;
|
|
194
276
|
}
|
|
195
277
|
};
|
|
196
|
-
var
|
|
197
|
-
constructor(position, length,
|
|
278
|
+
var ArgumentCountMismatchMessage = class {
|
|
279
|
+
constructor(position, length, min, max) {
|
|
198
280
|
this.position = position;
|
|
199
281
|
this.length = length;
|
|
200
|
-
|
|
282
|
+
if (min !== void 0) {
|
|
283
|
+
if (max == min) this.msg = `: ${min} expected`;
|
|
284
|
+
else if (max !== void 0) this.msg = `: ${min} to ${max} expected`;
|
|
285
|
+
else this.msg = `: at least ${min} expected`;
|
|
286
|
+
} else {
|
|
287
|
+
if (max !== void 0) this.msg = `: at most ${max} expected`;
|
|
288
|
+
}
|
|
201
289
|
}
|
|
290
|
+
msg = "";
|
|
202
291
|
code = 4;
|
|
203
292
|
severity = 2 /* Error */;
|
|
204
293
|
fixes = [];
|
|
205
294
|
get info() {
|
|
206
|
-
return `
|
|
295
|
+
return `argument count mismatch` + this.msg;
|
|
207
296
|
}
|
|
208
297
|
};
|
|
209
|
-
var
|
|
210
|
-
constructor(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
298
|
+
var CannotExpandArgumentMessage = class {
|
|
299
|
+
constructor(position, length, what) {
|
|
300
|
+
this.position = position;
|
|
301
|
+
this.length = length;
|
|
302
|
+
this.what = what;
|
|
303
|
+
}
|
|
304
|
+
code = 5;
|
|
305
|
+
severity = 2 /* Error */;
|
|
306
|
+
fixes = [];
|
|
307
|
+
get info() {
|
|
308
|
+
return `failed to expand argument` + (this.what === void 0 ? "" : `: ${this.what}`);
|
|
219
309
|
}
|
|
220
310
|
};
|
|
221
311
|
var InvalidArgumentMessage = class {
|
|
@@ -379,6 +469,36 @@ function assert(x) {
|
|
|
379
469
|
function has(v, f) {
|
|
380
470
|
return (v & f) === f;
|
|
381
471
|
}
|
|
472
|
+
function linePositions(src) {
|
|
473
|
+
let result = [0];
|
|
474
|
+
[...src].forEach((x, i) => {
|
|
475
|
+
if (x == "\n") result.push(i + 1);
|
|
476
|
+
});
|
|
477
|
+
result.push(Infinity);
|
|
478
|
+
return result;
|
|
479
|
+
}
|
|
480
|
+
var cloneArgument = (arg) => ({
|
|
481
|
+
start: arg.start,
|
|
482
|
+
end: arg.end,
|
|
483
|
+
content: arg.content.map((ent) => {
|
|
484
|
+
switch (ent.type) {
|
|
485
|
+
case 3 /* Text */:
|
|
486
|
+
case 4 /* Escaped */:
|
|
487
|
+
return structuredClone(ent);
|
|
488
|
+
case 8 /* Interpolation */:
|
|
489
|
+
return {
|
|
490
|
+
type: ent.type,
|
|
491
|
+
start: ent.start,
|
|
492
|
+
end: ent.end,
|
|
493
|
+
definition: ent.definition,
|
|
494
|
+
argument: cloneArgument(ent.argument),
|
|
495
|
+
expansion: ent.expansion
|
|
496
|
+
};
|
|
497
|
+
default:
|
|
498
|
+
return debug.never(ent);
|
|
499
|
+
}
|
|
500
|
+
})
|
|
501
|
+
});
|
|
382
502
|
function cloneNode(node, referring) {
|
|
383
503
|
switch (node.type) {
|
|
384
504
|
case 7 /* BlockModifier */:
|
|
@@ -391,7 +511,7 @@ function cloneNode(node, referring) {
|
|
|
391
511
|
mod: node.mod,
|
|
392
512
|
state: void 0,
|
|
393
513
|
head: structuredClone(node.head),
|
|
394
|
-
arguments:
|
|
514
|
+
arguments: node.arguments.map(cloneArgument),
|
|
395
515
|
content: node.content.map((x) => cloneNode(x, referring)),
|
|
396
516
|
expansion: node.expansion ? cloneNodes(node.expansion) : void 0
|
|
397
517
|
};
|
|
@@ -421,7 +541,7 @@ function debugPrintArgEntity(node) {
|
|
|
421
541
|
case 4 /* Escaped */:
|
|
422
542
|
return `<Escaped:${node.content}>`;
|
|
423
543
|
case 8 /* Interpolation */:
|
|
424
|
-
return `<Interp:${node.definition.name}-${node.definition.postfix}:${debugPrintArgument(node.
|
|
544
|
+
return `<Interp:${node.definition.name}-${node.definition.postfix}:${debugPrintArgument(node.argument)}${node.expansion ? `=${node.expansion}` : ""}>`;
|
|
425
545
|
default:
|
|
426
546
|
return debug.never(node);
|
|
427
547
|
}
|
|
@@ -430,7 +550,7 @@ function debugPrintArgument(arg) {
|
|
|
430
550
|
return arg.content.map(debugPrintArgEntity).join("");
|
|
431
551
|
}
|
|
432
552
|
function debugPrintNode(node, prefix = "") {
|
|
433
|
-
let result = `<${node.type}@${node.start}`;
|
|
553
|
+
let result = `<${NodeType[node.type]}@${node.start}`;
|
|
434
554
|
switch (node.type) {
|
|
435
555
|
case 0 /* Root */:
|
|
436
556
|
case 1 /* Paragraph */:
|
|
@@ -438,14 +558,14 @@ function debugPrintNode(node, prefix = "") {
|
|
|
438
558
|
if (content.length > 0)
|
|
439
559
|
result += `>
|
|
440
560
|
${content}
|
|
441
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
561
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
442
562
|
else result += `-${node.end} />`;
|
|
443
563
|
break;
|
|
444
564
|
case 4 /* Escaped */:
|
|
445
565
|
case 2 /* Preformatted */:
|
|
446
566
|
result += `>
|
|
447
567
|
${prefix} ${node.content}
|
|
448
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
568
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
449
569
|
break;
|
|
450
570
|
case 6 /* InlineModifier */:
|
|
451
571
|
case 7 /* BlockModifier */:
|
|
@@ -455,7 +575,7 @@ ${prefix} (${i})@${x.start}-${x.end}=${debugPrintArgument(x)}`).join("");
|
|
|
455
575
|
if (node.content.length > 0) {
|
|
456
576
|
result += ` id=${node.mod.name}${args}>
|
|
457
577
|
` + debugPrintNodes(node.content, prefix) + `
|
|
458
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
578
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
459
579
|
} else result += `-${node.end} id=${node.mod.name}${args} />`;
|
|
460
580
|
if (node.expansion) {
|
|
461
581
|
const content2 = debugPrintNodes(node.expansion, prefix);
|
|
@@ -481,118 +601,67 @@ function debugPrintNodes(content, prefix = "") {
|
|
|
481
601
|
if (dumps.length == 0) return "";
|
|
482
602
|
return dumps.map((x) => `${prefix} ${x}`).join("\n");
|
|
483
603
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
NodeType2[NodeType2["Paragraph"] = 1] = "Paragraph";
|
|
495
|
-
NodeType2[NodeType2["Preformatted"] = 2] = "Preformatted";
|
|
496
|
-
NodeType2[NodeType2["Text"] = 3] = "Text";
|
|
497
|
-
NodeType2[NodeType2["Escaped"] = 4] = "Escaped";
|
|
498
|
-
NodeType2[NodeType2["SystemModifier"] = 5] = "SystemModifier";
|
|
499
|
-
NodeType2[NodeType2["InlineModifier"] = 6] = "InlineModifier";
|
|
500
|
-
NodeType2[NodeType2["BlockModifier"] = 7] = "BlockModifier";
|
|
501
|
-
NodeType2[NodeType2["Interpolation"] = 8] = "Interpolation";
|
|
502
|
-
return NodeType2;
|
|
503
|
-
})(NodeType || {});
|
|
504
|
-
var ModifierFlags = /* @__PURE__ */ ((ModifierFlags2) => {
|
|
505
|
-
ModifierFlags2[ModifierFlags2["Normal"] = 0] = "Normal";
|
|
506
|
-
ModifierFlags2[ModifierFlags2["Preformatted"] = 1] = "Preformatted";
|
|
507
|
-
ModifierFlags2[ModifierFlags2["Marker"] = 2] = "Marker";
|
|
508
|
-
return ModifierFlags2;
|
|
509
|
-
})(ModifierFlags || {});
|
|
510
|
-
var ModifierBase = class {
|
|
511
|
-
constructor(name, flags = 0 /* Normal */, args) {
|
|
512
|
-
this.name = name;
|
|
513
|
-
this.flags = flags;
|
|
514
|
-
if (args) Object.assign(this, args);
|
|
515
|
-
}
|
|
516
|
-
delayContentExpansion = false;
|
|
517
|
-
alwaysTryExpand = false;
|
|
518
|
-
beforeParseContent;
|
|
519
|
-
afterParseContent;
|
|
520
|
-
beforeProcessExpansion;
|
|
521
|
-
afterProcessExpansion;
|
|
522
|
-
prepareExpand;
|
|
523
|
-
expand;
|
|
524
|
-
};
|
|
525
|
-
var BlockModifierDefinition = class extends ModifierBase {
|
|
526
|
-
};
|
|
527
|
-
var InlineModifierDefinition = class extends ModifierBase {
|
|
528
|
-
};
|
|
529
|
-
var SystemModifierDefinition = class extends ModifierBase {
|
|
530
|
-
};
|
|
531
|
-
var ArgumentInterpolatorDefinition = class {
|
|
532
|
-
constructor(name, postfix, expand) {
|
|
533
|
-
this.name = name;
|
|
534
|
-
this.postfix = postfix;
|
|
535
|
-
this.expand = expand;
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
var ParseContext = class {
|
|
539
|
-
constructor(config, variables = /* @__PURE__ */ new Map()) {
|
|
540
|
-
this.config = config;
|
|
541
|
-
this.variables = variables;
|
|
542
|
-
config.initializers.forEach((x) => x(this));
|
|
543
|
-
}
|
|
544
|
-
data = {};
|
|
545
|
-
init(key, obj) {
|
|
546
|
-
assert(!(key in this.data));
|
|
547
|
-
this.data[key] = obj;
|
|
548
|
-
}
|
|
549
|
-
set(key, obj) {
|
|
550
|
-
assert(key in this.data);
|
|
551
|
-
this.data[key] = obj;
|
|
552
|
-
}
|
|
553
|
-
get(key) {
|
|
554
|
-
assert(key in this.data);
|
|
555
|
-
return this.data[key];
|
|
556
|
-
}
|
|
557
|
-
#evalEntity(e) {
|
|
558
|
-
switch (e.type) {
|
|
559
|
-
case 3 /* Text */:
|
|
560
|
-
case 4 /* Escaped */:
|
|
561
|
-
return e.content;
|
|
562
|
-
case 8 /* Interpolation */:
|
|
563
|
-
const inner = this.evaluateArgument(e.arg);
|
|
564
|
-
return e.definition.expand(inner, this);
|
|
565
|
-
default:
|
|
566
|
-
assert(false);
|
|
604
|
+
function debugDumpDocument(doc, source) {
|
|
605
|
+
const lines = linePositions(source);
|
|
606
|
+
function pos2lc(pos) {
|
|
607
|
+
let line = -1, linepos = 0;
|
|
608
|
+
for (let i = 1; i < lines.length; i++) {
|
|
609
|
+
if (lines[i] > pos) {
|
|
610
|
+
line = i;
|
|
611
|
+
linepos = lines[i - 1];
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
567
614
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
this.context = context;
|
|
577
|
-
this.messages = messages;
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
|
-
var Configuration = class {
|
|
581
|
-
initializers = [];
|
|
582
|
-
blockModifiers;
|
|
583
|
-
inlineModifiers;
|
|
584
|
-
systemModifiers;
|
|
585
|
-
argumentInterpolators;
|
|
586
|
-
reparseDepthLimit = 10;
|
|
587
|
-
constructor(from) {
|
|
588
|
-
this.blockModifiers = new NameManager(from?.blockModifiers);
|
|
589
|
-
this.inlineModifiers = new NameManager(from?.inlineModifiers);
|
|
590
|
-
this.systemModifiers = new NameManager(from?.systemModifiers);
|
|
591
|
-
this.argumentInterpolators = new NameManager(from?.argumentInterpolators);
|
|
592
|
-
if (from) {
|
|
593
|
-
this.initializers = [...from.initializers];
|
|
594
|
-
this.reparseDepthLimit = from.reparseDepthLimit;
|
|
615
|
+
return `l${line}c${pos - linepos + 1}`;
|
|
616
|
+
}
|
|
617
|
+
function dumpMsg(m) {
|
|
618
|
+
let result = `at ${pos2lc(m.position)}, len ${m.length}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
|
|
619
|
+
while (m instanceof ReferredMessage) {
|
|
620
|
+
m = m.original;
|
|
621
|
+
result += `
|
|
622
|
+
---> original at: ${pos2lc(m.position)}, len ${m.length}`;
|
|
595
623
|
}
|
|
624
|
+
return result;
|
|
625
|
+
}
|
|
626
|
+
let root = debugPrintNode(doc.root);
|
|
627
|
+
let msgs = doc.messages.map(dumpMsg).join("\n");
|
|
628
|
+
if (msgs.length > 0) msgs += "\n";
|
|
629
|
+
return `${msgs}${root}`;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/debug.ts
|
|
633
|
+
var DebugLevel = /* @__PURE__ */ ((DebugLevel3) => {
|
|
634
|
+
DebugLevel3[DebugLevel3["Trace"] = 0] = "Trace";
|
|
635
|
+
DebugLevel3[DebugLevel3["Info"] = 1] = "Info";
|
|
636
|
+
DebugLevel3[DebugLevel3["Warning"] = 2] = "Warning";
|
|
637
|
+
DebugLevel3[DebugLevel3["Error"] = 3] = "Error";
|
|
638
|
+
DebugLevel3[DebugLevel3["None"] = 4] = "None";
|
|
639
|
+
return DebugLevel3;
|
|
640
|
+
})(DebugLevel || {});
|
|
641
|
+
var debug = {
|
|
642
|
+
level: 1 /* Info */,
|
|
643
|
+
trace(arg0, ...args) {
|
|
644
|
+
if (this.level > 0 /* Trace */) return;
|
|
645
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
646
|
+
console.info("TRACE", arg0, ...args);
|
|
647
|
+
},
|
|
648
|
+
info(arg0, ...args) {
|
|
649
|
+
if (this.level > 1 /* Info */) return;
|
|
650
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
651
|
+
console.info(" INFO", arg0, ...args);
|
|
652
|
+
},
|
|
653
|
+
warning(arg0, ...args) {
|
|
654
|
+
if (this.level > 2 /* Warning */) return;
|
|
655
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
656
|
+
console.warn(" WARN", arg0, ...args);
|
|
657
|
+
},
|
|
658
|
+
error(arg0, ...args) {
|
|
659
|
+
if (this.level > 3 /* Error */) return;
|
|
660
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
661
|
+
console.error("ERROR", arg0, ...args);
|
|
662
|
+
},
|
|
663
|
+
never(_) {
|
|
664
|
+
assert(false);
|
|
596
665
|
}
|
|
597
666
|
};
|
|
598
667
|
|
|
@@ -772,22 +841,61 @@ var Parser = class {
|
|
|
772
841
|
}
|
|
773
842
|
return ok;
|
|
774
843
|
}
|
|
844
|
+
#expandArgument(arg) {
|
|
845
|
+
if (arg.expansion !== void 0)
|
|
846
|
+
return arg.expansion;
|
|
847
|
+
let result = "";
|
|
848
|
+
const immediate = this.delayDepth == 0;
|
|
849
|
+
for (const e of arg.content) {
|
|
850
|
+
switch (e.type) {
|
|
851
|
+
case 3 /* Text */:
|
|
852
|
+
case 4 /* Escaped */:
|
|
853
|
+
result += e.content;
|
|
854
|
+
break;
|
|
855
|
+
case 8 /* Interpolation */:
|
|
856
|
+
if (e.expansion === void 0) {
|
|
857
|
+
const inner = this.#expandArgument(e.argument);
|
|
858
|
+
if (inner === void 0 || e.definition.expand === void 0 || !immediate && !e.definition.alwaysTryExpand)
|
|
859
|
+
return void 0;
|
|
860
|
+
e.expansion = e.definition.expand(inner, this.cxt, immediate);
|
|
861
|
+
if (e.expansion === void 0)
|
|
862
|
+
return void 0;
|
|
863
|
+
}
|
|
864
|
+
result += e.expansion;
|
|
865
|
+
break;
|
|
866
|
+
default:
|
|
867
|
+
debug.never(e);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
arg.expansion = result;
|
|
871
|
+
return result;
|
|
872
|
+
}
|
|
873
|
+
#expandArguments(node) {
|
|
874
|
+
for (const arg of node.arguments) {
|
|
875
|
+
this.#expandArgument(arg);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
775
878
|
#expand(node, depth = 0) {
|
|
776
879
|
if (node.expansion !== void 0) {
|
|
777
880
|
debug.trace("already expanded, skipping:", node.mod.name);
|
|
778
881
|
return true;
|
|
779
882
|
}
|
|
883
|
+
if (depth > 0) {
|
|
884
|
+
this.#expandArguments(node);
|
|
885
|
+
}
|
|
780
886
|
if (this.delayDepth > 0 && !node.mod.alwaysTryExpand) {
|
|
781
887
|
debug.trace("delaying expansion of", node.mod.name);
|
|
782
888
|
return true;
|
|
783
889
|
}
|
|
784
890
|
const immediate = this.delayDepth == 0;
|
|
785
|
-
if (
|
|
891
|
+
if (depth > 0) {
|
|
786
892
|
if (node.mod.beforeParseContent)
|
|
787
893
|
this.emit.message(...node.mod.beforeParseContent(node, this.cxt, immediate));
|
|
788
|
-
if (node.
|
|
789
|
-
|
|
790
|
-
|
|
894
|
+
if (node.content.length > 0) {
|
|
895
|
+
if (node.mod.delayContentExpansion) this.delayDepth++;
|
|
896
|
+
this.#reparse(node.content, depth);
|
|
897
|
+
if (node.mod.delayContentExpansion) this.delayDepth--;
|
|
898
|
+
}
|
|
791
899
|
if (node.mod.afterParseContent)
|
|
792
900
|
this.emit.message(...node.mod.afterParseContent(node, this.cxt, immediate));
|
|
793
901
|
}
|
|
@@ -826,7 +934,7 @@ var Parser = class {
|
|
|
826
934
|
}
|
|
827
935
|
parse() {
|
|
828
936
|
this.DOCUMENT();
|
|
829
|
-
return new
|
|
937
|
+
return new Document(this.emit.root, this.cxt, this.emit.messages);
|
|
830
938
|
}
|
|
831
939
|
WHITESPACES_OR_NEWLINES() {
|
|
832
940
|
while (this.scanner.acceptWhitespaceChar() !== null || this.scanner.accept("\n")) {
|
|
@@ -893,7 +1001,7 @@ var Parser = class {
|
|
|
893
1001
|
);
|
|
894
1002
|
}
|
|
895
1003
|
const args = this.ARGUMENTS();
|
|
896
|
-
debug.trace(`PARSE ${type}
|
|
1004
|
+
debug.trace(`PARSE ${NodeType[type]}:`, mod.name);
|
|
897
1005
|
const endsign = this.scanner.accept(MODIFIER_END_SIGN);
|
|
898
1006
|
const flagMarker = has(mod.flags, 2 /* Marker */);
|
|
899
1007
|
const isMarker = flagMarker || endsign;
|
|
@@ -902,16 +1010,18 @@ var Parser = class {
|
|
|
902
1010
|
this.scanner.position(),
|
|
903
1011
|
MODIFIER_CLOSE_SIGN
|
|
904
1012
|
));
|
|
1013
|
+
const headEnd = this.scanner.position();
|
|
905
1014
|
const node = {
|
|
906
1015
|
type,
|
|
907
1016
|
mod,
|
|
908
|
-
head: { start: posStart, end:
|
|
1017
|
+
head: { start: posStart, end: headEnd },
|
|
909
1018
|
arguments: args,
|
|
910
1019
|
start: posStart,
|
|
911
|
-
end:
|
|
1020
|
+
end: headEnd,
|
|
912
1021
|
content: [],
|
|
913
1022
|
expansion: void 0
|
|
914
1023
|
};
|
|
1024
|
+
this.#expandArguments(node);
|
|
915
1025
|
const immediate = this.delayDepth == 0;
|
|
916
1026
|
if (node.mod.beforeParseContent)
|
|
917
1027
|
this.emit.message(...node.mod.beforeParseContent(node, this.cxt, immediate));
|
|
@@ -1096,10 +1206,8 @@ var Parser = class {
|
|
|
1096
1206
|
}
|
|
1097
1207
|
};
|
|
1098
1208
|
while (true) {
|
|
1099
|
-
if (end !== void 0 && this.scanner.accept(end))
|
|
1100
|
-
debug.trace("found end", end);
|
|
1209
|
+
if (end !== void 0 && this.scanner.accept(end))
|
|
1101
1210
|
break;
|
|
1102
|
-
}
|
|
1103
1211
|
if (this.scanner.accept(":")) {
|
|
1104
1212
|
ok = end === void 0;
|
|
1105
1213
|
break;
|
|
@@ -1132,7 +1240,7 @@ var Parser = class {
|
|
|
1132
1240
|
content.push({
|
|
1133
1241
|
type: 8 /* Interpolation */,
|
|
1134
1242
|
definition: result,
|
|
1135
|
-
|
|
1243
|
+
argument: inner,
|
|
1136
1244
|
start: posEnd - 2,
|
|
1137
1245
|
end: posEnd
|
|
1138
1246
|
});
|
|
@@ -1173,6 +1281,21 @@ function parse(scanner, config) {
|
|
|
1173
1281
|
return new Parser(scanner, config).parse();
|
|
1174
1282
|
}
|
|
1175
1283
|
|
|
1284
|
+
// src/modifier-helper.ts
|
|
1285
|
+
function checkArgumentLength(node, min, max = min) {
|
|
1286
|
+
if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
|
|
1287
|
+
return [new ArgumentCountMismatchMessage(node.head.start, node.head.end - node.head.start, min, max)];
|
|
1288
|
+
}
|
|
1289
|
+
return null;
|
|
1290
|
+
}
|
|
1291
|
+
function checkArguments(node, min, max = min) {
|
|
1292
|
+
const arg = node.arguments.find((x) => x.expansion === void 0);
|
|
1293
|
+
if (arg !== void 0) {
|
|
1294
|
+
return [new CannotExpandArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1295
|
+
}
|
|
1296
|
+
return checkArgumentLength(node, min, max);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1176
1299
|
// src/builtin/internal.ts
|
|
1177
1300
|
var builtins = Symbol();
|
|
1178
1301
|
function initParseContext(cxt) {
|
|
@@ -1183,15 +1306,6 @@ function initParseContext(cxt) {
|
|
|
1183
1306
|
inlineSlotData: []
|
|
1184
1307
|
});
|
|
1185
1308
|
}
|
|
1186
|
-
function checkArgumentLength(node, n) {
|
|
1187
|
-
if (node.arguments.length < n)
|
|
1188
|
-
return new ArgumentsTooFewMessage(node.head.end - 1, 0, n);
|
|
1189
|
-
if (node.arguments.length > n) {
|
|
1190
|
-
const start = node.arguments[n].start - 1;
|
|
1191
|
-
return new ArgumentsTooManyMessage(start, node.head.end - start, n);
|
|
1192
|
-
}
|
|
1193
|
-
return null;
|
|
1194
|
-
}
|
|
1195
1309
|
function customModifier(type, name, argNames, slotName, content) {
|
|
1196
1310
|
debug.info(`registered custom ${type} modifier:`, name);
|
|
1197
1311
|
debug.info("args:", argNames, `with ${slotName == "" ? "no slot name" : "slot name: " + slotName}`);
|
|
@@ -1200,9 +1314,12 @@ function customModifier(type, name, argNames, slotName, content) {
|
|
|
1200
1314
|
const isInline = type == 6 /* InlineModifier */;
|
|
1201
1315
|
mod.delayContentExpansion = true;
|
|
1202
1316
|
mod.prepareExpand = (node, cxt) => {
|
|
1203
|
-
|
|
1204
|
-
if (check) return
|
|
1205
|
-
node.state = {
|
|
1317
|
+
let check = checkArguments(node, argNames.length);
|
|
1318
|
+
if (check) return check;
|
|
1319
|
+
node.state = {
|
|
1320
|
+
ok: true,
|
|
1321
|
+
args: new Map(node.arguments.map((x, i) => [argNames[i], x.expansion]))
|
|
1322
|
+
};
|
|
1206
1323
|
return [];
|
|
1207
1324
|
};
|
|
1208
1325
|
mod.expand = (node, cxt) => {
|
|
@@ -1213,11 +1330,12 @@ function customModifier(type, name, argNames, slotName, content) {
|
|
|
1213
1330
|
mod.beforeProcessExpansion = (node, cxt) => {
|
|
1214
1331
|
if (!node.state?.ok) return [];
|
|
1215
1332
|
const store = cxt.get(builtins);
|
|
1216
|
-
const args = new Map(
|
|
1217
|
-
node.arguments.map((x, i) => [argNames[i], cxt.evaluateArgument(x)])
|
|
1218
|
-
);
|
|
1219
1333
|
const data = isInline ? store.inlineSlotData : store.blockSlotData;
|
|
1220
|
-
data.push([slotName, {
|
|
1334
|
+
data.push([slotName, {
|
|
1335
|
+
mod,
|
|
1336
|
+
args: node.state.args,
|
|
1337
|
+
slotContent: node.content
|
|
1338
|
+
}]);
|
|
1221
1339
|
debug.trace(
|
|
1222
1340
|
`pushed ${type} slot data for`,
|
|
1223
1341
|
name,
|
|
@@ -1247,28 +1365,31 @@ var DefineBlockMod = new SystemModifierDefinition("define-block", 0 /* Normal */
|
|
|
1247
1365
|
delayContentExpansion: true,
|
|
1248
1366
|
alwaysTryExpand: true,
|
|
1249
1367
|
beforeParseContent(node, cxt) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1368
|
+
const check = checkArgumentLength(node, 1, Infinity);
|
|
1369
|
+
if (check) return check;
|
|
1252
1370
|
const msgs = [];
|
|
1253
1371
|
const name = node.arguments[0];
|
|
1254
|
-
const nameValue =
|
|
1255
|
-
if (cxt.config.blockModifiers.has(nameValue))
|
|
1256
|
-
msgs.push(new NameAlreadyDefinedMessage(
|
|
1257
|
-
node.start,
|
|
1258
|
-
name.end - name.start,
|
|
1259
|
-
nameValue
|
|
1260
|
-
));
|
|
1372
|
+
const nameValue = name.expansion;
|
|
1261
1373
|
let slotName = "";
|
|
1262
1374
|
if (node.arguments.length > 1) {
|
|
1263
|
-
const last =
|
|
1264
|
-
|
|
1375
|
+
const last = node.arguments.at(-1);
|
|
1376
|
+
if (last.expansion)
|
|
1377
|
+
slotName = /^\(.+\)$/.test(last.expansion) ? last.expansion.substring(1, last.expansion.length - 1) : "";
|
|
1378
|
+
else msgs.push(
|
|
1379
|
+
new InvalidArgumentMessage(last.start, last.end - last.start)
|
|
1380
|
+
);
|
|
1265
1381
|
}
|
|
1266
|
-
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) =>
|
|
1267
|
-
|
|
1382
|
+
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) => {
|
|
1383
|
+
if (!x.expansion) msgs.push(
|
|
1384
|
+
new InvalidArgumentMessage(x.start, x.end - x.start)
|
|
1385
|
+
);
|
|
1386
|
+
return x.expansion ?? "";
|
|
1387
|
+
});
|
|
1388
|
+
node.state = { name: nameValue, slotName, args, msgs };
|
|
1268
1389
|
const store = cxt.get(builtins);
|
|
1269
1390
|
store.blockSlotDelayedStack.push(node.state.slotName);
|
|
1270
1391
|
debug.trace("entering block definition:", node.state.name);
|
|
1271
|
-
return
|
|
1392
|
+
return [];
|
|
1272
1393
|
},
|
|
1273
1394
|
afterParseContent(node, cxt) {
|
|
1274
1395
|
if (!node.state) return [];
|
|
@@ -1277,9 +1398,22 @@ var DefineBlockMod = new SystemModifierDefinition("define-block", 0 /* Normal */
|
|
|
1277
1398
|
debug.trace("leaving block definition", node.state.name);
|
|
1278
1399
|
return [];
|
|
1279
1400
|
},
|
|
1401
|
+
prepareExpand(node, cxt, immediate) {
|
|
1402
|
+
if (!immediate || !node.state) return [];
|
|
1403
|
+
const arg = node.arguments[0];
|
|
1404
|
+
if (!node.state.name)
|
|
1405
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1406
|
+
if (cxt.config.blockModifiers.has(node.state.name))
|
|
1407
|
+
return [new NameAlreadyDefinedMessage(
|
|
1408
|
+
arg.start,
|
|
1409
|
+
arg.end - arg.start,
|
|
1410
|
+
node.state.name
|
|
1411
|
+
)];
|
|
1412
|
+
return [];
|
|
1413
|
+
},
|
|
1280
1414
|
expand(node, cxt, immediate) {
|
|
1281
1415
|
if (!immediate) return void 0;
|
|
1282
|
-
if (node.state) {
|
|
1416
|
+
if (node.state?.name) {
|
|
1283
1417
|
if (cxt.config.blockModifiers.has(node.state.name))
|
|
1284
1418
|
cxt.config.blockModifiers.remove(node.state.name);
|
|
1285
1419
|
cxt.config.blockModifiers.add(
|
|
@@ -1302,12 +1436,12 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1302
1436
|
delayContentExpansion: true,
|
|
1303
1437
|
alwaysTryExpand: true,
|
|
1304
1438
|
beforeParseContent(node, cxt) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1439
|
+
const check = checkArgumentLength(node, 1, Infinity);
|
|
1440
|
+
if (check) return check;
|
|
1307
1441
|
const msgs = [];
|
|
1308
1442
|
const name = node.arguments[0];
|
|
1309
|
-
const nameValue =
|
|
1310
|
-
if (cxt.config.inlineModifiers.has(nameValue))
|
|
1443
|
+
const nameValue = name.expansion;
|
|
1444
|
+
if (nameValue && cxt.config.inlineModifiers.has(nameValue))
|
|
1311
1445
|
msgs.push(new NameAlreadyDefinedMessage(
|
|
1312
1446
|
node.start,
|
|
1313
1447
|
name.end - name.start,
|
|
@@ -1315,15 +1449,24 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1315
1449
|
));
|
|
1316
1450
|
let slotName = "";
|
|
1317
1451
|
if (node.arguments.length > 1) {
|
|
1318
|
-
const last =
|
|
1319
|
-
|
|
1452
|
+
const last = node.arguments.at(-1);
|
|
1453
|
+
if (last.expansion)
|
|
1454
|
+
slotName = /^\(.+\)$/.test(last.expansion) ? last.expansion.substring(1, last.expansion.length - 1) : "";
|
|
1455
|
+
else msgs.push(
|
|
1456
|
+
new InvalidArgumentMessage(last.start, last.end - last.start)
|
|
1457
|
+
);
|
|
1320
1458
|
}
|
|
1321
|
-
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) =>
|
|
1322
|
-
|
|
1459
|
+
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) => {
|
|
1460
|
+
if (!x.expansion) msgs.push(
|
|
1461
|
+
new InvalidArgumentMessage(x.start, x.end - x.start)
|
|
1462
|
+
);
|
|
1463
|
+
return x.expansion ?? "";
|
|
1464
|
+
});
|
|
1465
|
+
node.state = { name: nameValue, slotName, args, msgs };
|
|
1323
1466
|
const store = cxt.get(builtins);
|
|
1324
1467
|
store.inlineSlotDelayedStack.push(node.state.slotName);
|
|
1325
1468
|
debug.trace("entering inline definition:", node.state.name);
|
|
1326
|
-
return
|
|
1469
|
+
return [];
|
|
1327
1470
|
},
|
|
1328
1471
|
afterParseContent(node, cxt) {
|
|
1329
1472
|
if (!node.state) return [];
|
|
@@ -1332,9 +1475,18 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1332
1475
|
debug.trace("leaving inline definition", node.state.name);
|
|
1333
1476
|
return [];
|
|
1334
1477
|
},
|
|
1335
|
-
prepareExpand(node, cxt) {
|
|
1336
|
-
if (!node.state) return [];
|
|
1478
|
+
prepareExpand(node, cxt, immediate) {
|
|
1479
|
+
if (!immediate || !node.state) return [];
|
|
1480
|
+
const arg = node.arguments[0];
|
|
1481
|
+
if (!node.state.name)
|
|
1482
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1337
1483
|
const msgs = [];
|
|
1484
|
+
if (cxt.config.inlineModifiers.has(node.state.name))
|
|
1485
|
+
msgs.push(new NameAlreadyDefinedMessage(
|
|
1486
|
+
arg.start,
|
|
1487
|
+
arg.end - arg.start,
|
|
1488
|
+
node.state.name
|
|
1489
|
+
));
|
|
1338
1490
|
let lastIsParagraph = false;
|
|
1339
1491
|
let concat = [];
|
|
1340
1492
|
for (const n of node.content) {
|
|
@@ -1362,7 +1514,7 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1362
1514
|
},
|
|
1363
1515
|
expand(node, cxt, immediate) {
|
|
1364
1516
|
if (!immediate) return void 0;
|
|
1365
|
-
if (node.state) {
|
|
1517
|
+
if (node.state?.name) {
|
|
1366
1518
|
if (cxt.config.inlineModifiers.has(node.state.name))
|
|
1367
1519
|
cxt.config.inlineModifiers.remove(node.state.name);
|
|
1368
1520
|
cxt.config.inlineModifiers.add(
|
|
@@ -1385,21 +1537,27 @@ function slotModifier(type) {
|
|
|
1385
1537
|
const isInline = type == 6 /* InlineModifier */;
|
|
1386
1538
|
mod.alwaysTryExpand = true;
|
|
1387
1539
|
mod.prepareExpand = (node, cxt, immediate) => {
|
|
1540
|
+
if (node.state) return [];
|
|
1541
|
+
const check = checkArgumentLength(node, 0, 1);
|
|
1542
|
+
if (check && immediate) {
|
|
1543
|
+
node.state = { ok: false };
|
|
1544
|
+
return check;
|
|
1545
|
+
}
|
|
1388
1546
|
const store = cxt.get(builtins);
|
|
1389
1547
|
const data = isInline ? store.inlineSlotData : store.blockSlotData;
|
|
1390
|
-
|
|
1391
|
-
if (
|
|
1392
|
-
|
|
1548
|
+
let id = "";
|
|
1549
|
+
if (node.arguments.length == 1) {
|
|
1550
|
+
const arg = node.arguments[0];
|
|
1551
|
+
if (!arg.expansion) {
|
|
1393
1552
|
node.state = { ok: false };
|
|
1394
|
-
return [new
|
|
1553
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1395
1554
|
}
|
|
1396
|
-
|
|
1555
|
+
id = arg.expansion;
|
|
1397
1556
|
}
|
|
1398
|
-
if (
|
|
1557
|
+
if (data.length == 0) {
|
|
1399
1558
|
if (immediate) {
|
|
1400
1559
|
node.state = { ok: false };
|
|
1401
|
-
|
|
1402
|
-
return [new ArgumentsTooManyMessage(start, node.head.end - start)];
|
|
1560
|
+
return [new SlotUsedOutsideDefinitionMessage(node.start, node.head.end - node.start)];
|
|
1403
1561
|
}
|
|
1404
1562
|
return [];
|
|
1405
1563
|
}
|
|
@@ -1470,10 +1628,10 @@ function resolveId(id, cxt) {
|
|
|
1470
1628
|
var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
1471
1629
|
// .$:id
|
|
1472
1630
|
prepareExpand(node, cxt) {
|
|
1473
|
-
const check =
|
|
1474
|
-
if (check) return
|
|
1631
|
+
const check = checkArguments(node, 1);
|
|
1632
|
+
if (check) return check;
|
|
1475
1633
|
const arg = node.arguments[0];
|
|
1476
|
-
const id =
|
|
1634
|
+
const id = arg.expansion;
|
|
1477
1635
|
if (id == "")
|
|
1478
1636
|
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1479
1637
|
const value = resolveId(id, cxt);
|
|
@@ -1490,20 +1648,28 @@ var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
|
1490
1648
|
var GetVarInterpolator = new ArgumentInterpolatorDefinition(
|
|
1491
1649
|
"$(",
|
|
1492
1650
|
")",
|
|
1493
|
-
|
|
1651
|
+
{
|
|
1652
|
+
alwaysTryExpand: true,
|
|
1653
|
+
expand(content, cxt, immediate) {
|
|
1654
|
+
const result = resolveId(content, cxt);
|
|
1655
|
+
if (result === void 0) debug.trace("var interp failed:", content);
|
|
1656
|
+
else debug.trace(`$(${content}) --> ${result}`);
|
|
1657
|
+
return result;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1494
1660
|
);
|
|
1495
1661
|
var VarMod = new SystemModifierDefinition("var", 2 /* Marker */, {
|
|
1496
1662
|
// .var id:value
|
|
1497
1663
|
prepareExpand(node, cxt) {
|
|
1498
|
-
const check =
|
|
1499
|
-
if (check) return
|
|
1664
|
+
const check = checkArguments(node, 2);
|
|
1665
|
+
if (check) return check;
|
|
1500
1666
|
const arg = node.arguments[0];
|
|
1501
|
-
const
|
|
1502
|
-
if (
|
|
1667
|
+
const id = arg.expansion;
|
|
1668
|
+
if (id == "")
|
|
1503
1669
|
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1504
1670
|
node.state = {
|
|
1505
|
-
id
|
|
1506
|
-
value:
|
|
1671
|
+
id,
|
|
1672
|
+
value: node.arguments[1].expansion
|
|
1507
1673
|
};
|
|
1508
1674
|
return [];
|
|
1509
1675
|
},
|
|
@@ -1524,35 +1690,28 @@ basic.blockModifiers.add(SlotBlockMod);
|
|
|
1524
1690
|
basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod);
|
|
1525
1691
|
basic.argumentInterpolators.add(GetVarInterpolator);
|
|
1526
1692
|
var BuiltinConfiguration = Object.freeze(basic);
|
|
1693
|
+
|
|
1694
|
+
// src/index.ts
|
|
1695
|
+
function setDebugLevel(level) {
|
|
1696
|
+
debug.level = level;
|
|
1697
|
+
}
|
|
1527
1698
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1528
1699
|
0 && (module.exports = {
|
|
1529
1700
|
ArgumentInterpolatorDefinition,
|
|
1530
|
-
ArgumentsTooFewMessage,
|
|
1531
|
-
ArgumentsTooManyMessage,
|
|
1532
1701
|
BlockModifierDefinition,
|
|
1533
1702
|
BuiltinConfiguration,
|
|
1534
1703
|
Configuration,
|
|
1535
|
-
|
|
1704
|
+
DebugLevel,
|
|
1536
1705
|
Document,
|
|
1537
|
-
ExpectedMessage,
|
|
1538
|
-
InlineDefinitonInvalidEntityMessage,
|
|
1539
1706
|
InlineModifierDefinition,
|
|
1540
|
-
InvalidArgumentMessage,
|
|
1541
1707
|
MessageSeverity,
|
|
1542
1708
|
ModifierFlags,
|
|
1543
|
-
NameAlreadyDefinedMessage,
|
|
1544
|
-
NewBlockShouldBeOnNewlineMessage,
|
|
1545
1709
|
NodeType,
|
|
1546
1710
|
ParseContext,
|
|
1547
|
-
ReachedRecursionLimitMessage,
|
|
1548
|
-
ReferredMessage,
|
|
1549
1711
|
SimpleScanner,
|
|
1550
|
-
SlotUsedOutsideDefinitionMessage,
|
|
1551
1712
|
SystemModifierDefinition,
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
UnnecessaryNewlineMessage,
|
|
1556
|
-
parse
|
|
1713
|
+
messages,
|
|
1714
|
+
parse,
|
|
1715
|
+
setDebugLevel
|
|
1557
1716
|
});
|
|
1558
1717
|
//# sourceMappingURL=index.js.map
|