@the_dissidents/libemmm 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +265 -4
- package/dist/index.d.mts +95 -17
- package/dist/index.d.ts +95 -17
- package/dist/index.js +523 -280
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +525 -264
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -21,65 +21,148 @@ 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
|
+
CannotPopNotationMessage: () => CannotPopNotationMessage,
|
|
152
|
+
ContentShouldBeOnNewlineMessage: () => ContentShouldBeOnNewlineMessage,
|
|
153
|
+
ExpectedMessage: () => ExpectedMessage,
|
|
154
|
+
InlineDefinitonInvalidEntityMessage: () => InlineDefinitonInvalidEntityMessage,
|
|
155
|
+
InvalidArgumentMessage: () => InvalidArgumentMessage,
|
|
156
|
+
NameAlreadyDefinedMessage: () => NameAlreadyDefinedMessage,
|
|
157
|
+
NewBlockShouldBeOnNewlineMessage: () => NewBlockShouldBeOnNewlineMessage,
|
|
158
|
+
ReachedRecursionLimitMessage: () => ReachedRecursionLimitMessage,
|
|
159
|
+
ReferredMessage: () => ReferredMessage,
|
|
160
|
+
SlotUsedOutsideDefinitionMessage: () => SlotUsedOutsideDefinitionMessage,
|
|
161
|
+
UnclosedInlineModifierMessage: () => UnclosedInlineModifierMessage,
|
|
162
|
+
UndefinedVariableMessage: () => UndefinedVariableMessage,
|
|
163
|
+
UnknownModifierMessage: () => UnknownModifierMessage,
|
|
164
|
+
UnnecessaryNewlineMessage: () => UnnecessaryNewlineMessage
|
|
165
|
+
});
|
|
83
166
|
var ReferredMessage = class {
|
|
84
167
|
constructor(original, position, length) {
|
|
85
168
|
this.original = original;
|
|
@@ -150,7 +233,7 @@ var ExpectedMessage = class {
|
|
|
150
233
|
code = 1;
|
|
151
234
|
severity = 2 /* Error */;
|
|
152
235
|
get length() {
|
|
153
|
-
return
|
|
236
|
+
return 0;
|
|
154
237
|
}
|
|
155
238
|
get info() {
|
|
156
239
|
return `expected '${this.what}'`;
|
|
@@ -160,13 +243,16 @@ var ExpectedMessage = class {
|
|
|
160
243
|
}
|
|
161
244
|
};
|
|
162
245
|
var UnknownModifierMessage = class {
|
|
163
|
-
constructor(position, length) {
|
|
246
|
+
constructor(position, length, what) {
|
|
164
247
|
this.position = position;
|
|
165
248
|
this.length = length;
|
|
249
|
+
this.what = what;
|
|
166
250
|
}
|
|
167
251
|
code = 2;
|
|
168
252
|
severity = 2 /* Error */;
|
|
169
|
-
info
|
|
253
|
+
get info() {
|
|
254
|
+
return `unknown modifier '${this.what}'; did you forget to escape it?`;
|
|
255
|
+
}
|
|
170
256
|
get fixes() {
|
|
171
257
|
let [pos, len] = [this.position, this.length];
|
|
172
258
|
return [{
|
|
@@ -193,29 +279,37 @@ var UnclosedInlineModifierMessage = class {
|
|
|
193
279
|
return `unclosed inline modifier ${this.what}'`;
|
|
194
280
|
}
|
|
195
281
|
};
|
|
196
|
-
var
|
|
197
|
-
constructor(position, length,
|
|
282
|
+
var ArgumentCountMismatchMessage = class {
|
|
283
|
+
constructor(position, length, min, max) {
|
|
198
284
|
this.position = position;
|
|
199
285
|
this.length = length;
|
|
200
|
-
|
|
286
|
+
if (min !== void 0) {
|
|
287
|
+
if (max == min) this.msg = `: ${min} expected`;
|
|
288
|
+
else if (max !== void 0) this.msg = `: ${min} to ${max} expected`;
|
|
289
|
+
else this.msg = `: at least ${min} expected`;
|
|
290
|
+
} else {
|
|
291
|
+
if (max !== void 0) this.msg = `: at most ${max} expected`;
|
|
292
|
+
}
|
|
201
293
|
}
|
|
294
|
+
msg = "";
|
|
202
295
|
code = 4;
|
|
203
296
|
severity = 2 /* Error */;
|
|
204
297
|
fixes = [];
|
|
205
298
|
get info() {
|
|
206
|
-
return `
|
|
299
|
+
return `argument count mismatch` + this.msg;
|
|
207
300
|
}
|
|
208
301
|
};
|
|
209
|
-
var
|
|
210
|
-
constructor(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
302
|
+
var CannotExpandArgumentMessage = class {
|
|
303
|
+
constructor(position, length, what) {
|
|
304
|
+
this.position = position;
|
|
305
|
+
this.length = length;
|
|
306
|
+
this.what = what;
|
|
307
|
+
}
|
|
308
|
+
code = 5;
|
|
309
|
+
severity = 2 /* Error */;
|
|
310
|
+
fixes = [];
|
|
311
|
+
get info() {
|
|
312
|
+
return `failed to expand argument` + (this.what === void 0 ? "" : `: ${this.what}`);
|
|
219
313
|
}
|
|
220
314
|
};
|
|
221
315
|
var InvalidArgumentMessage = class {
|
|
@@ -266,7 +360,19 @@ var SlotUsedOutsideDefinitionMessage = class {
|
|
|
266
360
|
severity = 2 /* Error */;
|
|
267
361
|
fixes = [];
|
|
268
362
|
get info() {
|
|
269
|
-
return `
|
|
363
|
+
return `slot used outside a definition`;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
var CannotPopNotationMessage = class {
|
|
367
|
+
constructor(position, length) {
|
|
368
|
+
this.position = position;
|
|
369
|
+
this.length = length;
|
|
370
|
+
}
|
|
371
|
+
code = 10;
|
|
372
|
+
severity = 2 /* Error */;
|
|
373
|
+
fixes = [];
|
|
374
|
+
get info() {
|
|
375
|
+
return `cannot pop notation`;
|
|
270
376
|
}
|
|
271
377
|
};
|
|
272
378
|
var UnnecessaryNewlineMessage = class extends RemoveThingMessage {
|
|
@@ -335,12 +441,23 @@ var UndefinedVariableMessage = class {
|
|
|
335
441
|
};
|
|
336
442
|
|
|
337
443
|
// src/util.ts
|
|
338
|
-
var NameManager = class {
|
|
444
|
+
var NameManager = class _NameManager {
|
|
339
445
|
array = [];
|
|
340
|
-
data;
|
|
446
|
+
data = /* @__PURE__ */ new Map();
|
|
341
447
|
constructor(from) {
|
|
342
|
-
|
|
343
|
-
|
|
448
|
+
if (from === void 0) return;
|
|
449
|
+
if (from instanceof _NameManager) {
|
|
450
|
+
this.array = [...from.array];
|
|
451
|
+
this.data = new Map(from.data);
|
|
452
|
+
} else {
|
|
453
|
+
assert(Array.isArray(from));
|
|
454
|
+
this.array = from.map((x) => ({ k: x.name, v: x }));
|
|
455
|
+
this.array.sort((a, b) => b.k.length - a.k.length);
|
|
456
|
+
this.data = new Map(from.map((x) => [x.name, x]));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
toArray() {
|
|
460
|
+
return this.array.map(({ v }) => v);
|
|
344
461
|
}
|
|
345
462
|
get(name) {
|
|
346
463
|
return this.data.get(name);
|
|
@@ -379,6 +496,36 @@ function assert(x) {
|
|
|
379
496
|
function has(v, f) {
|
|
380
497
|
return (v & f) === f;
|
|
381
498
|
}
|
|
499
|
+
function linePositions(src) {
|
|
500
|
+
let result = [0];
|
|
501
|
+
[...src].forEach((x, i) => {
|
|
502
|
+
if (x == "\n") result.push(i + 1);
|
|
503
|
+
});
|
|
504
|
+
result.push(Infinity);
|
|
505
|
+
return result;
|
|
506
|
+
}
|
|
507
|
+
var cloneArgument = (arg) => ({
|
|
508
|
+
start: arg.start,
|
|
509
|
+
end: arg.end,
|
|
510
|
+
content: arg.content.map((ent) => {
|
|
511
|
+
switch (ent.type) {
|
|
512
|
+
case 3 /* Text */:
|
|
513
|
+
case 4 /* Escaped */:
|
|
514
|
+
return structuredClone(ent);
|
|
515
|
+
case 8 /* Interpolation */:
|
|
516
|
+
return {
|
|
517
|
+
type: ent.type,
|
|
518
|
+
start: ent.start,
|
|
519
|
+
end: ent.end,
|
|
520
|
+
definition: ent.definition,
|
|
521
|
+
argument: cloneArgument(ent.argument),
|
|
522
|
+
expansion: ent.expansion
|
|
523
|
+
};
|
|
524
|
+
default:
|
|
525
|
+
return debug.never(ent);
|
|
526
|
+
}
|
|
527
|
+
})
|
|
528
|
+
});
|
|
382
529
|
function cloneNode(node, referring) {
|
|
383
530
|
switch (node.type) {
|
|
384
531
|
case 7 /* BlockModifier */:
|
|
@@ -391,7 +538,7 @@ function cloneNode(node, referring) {
|
|
|
391
538
|
mod: node.mod,
|
|
392
539
|
state: void 0,
|
|
393
540
|
head: structuredClone(node.head),
|
|
394
|
-
arguments:
|
|
541
|
+
arguments: node.arguments.map(cloneArgument),
|
|
395
542
|
content: node.content.map((x) => cloneNode(x, referring)),
|
|
396
543
|
expansion: node.expansion ? cloneNodes(node.expansion) : void 0
|
|
397
544
|
};
|
|
@@ -421,7 +568,7 @@ function debugPrintArgEntity(node) {
|
|
|
421
568
|
case 4 /* Escaped */:
|
|
422
569
|
return `<Escaped:${node.content}>`;
|
|
423
570
|
case 8 /* Interpolation */:
|
|
424
|
-
return `<Interp:${node.definition.name}-${node.definition.postfix}:${debugPrintArgument(node.
|
|
571
|
+
return `<Interp:${node.definition.name}-${node.definition.postfix}:${debugPrintArgument(node.argument)}${node.expansion ? `=${node.expansion}` : ""}>`;
|
|
425
572
|
default:
|
|
426
573
|
return debug.never(node);
|
|
427
574
|
}
|
|
@@ -430,7 +577,7 @@ function debugPrintArgument(arg) {
|
|
|
430
577
|
return arg.content.map(debugPrintArgEntity).join("");
|
|
431
578
|
}
|
|
432
579
|
function debugPrintNode(node, prefix = "") {
|
|
433
|
-
let result = `<${node.type}@${node.start}`;
|
|
580
|
+
let result = `<${NodeType[node.type]}@${node.start}`;
|
|
434
581
|
switch (node.type) {
|
|
435
582
|
case 0 /* Root */:
|
|
436
583
|
case 1 /* Paragraph */:
|
|
@@ -438,14 +585,14 @@ function debugPrintNode(node, prefix = "") {
|
|
|
438
585
|
if (content.length > 0)
|
|
439
586
|
result += `>
|
|
440
587
|
${content}
|
|
441
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
588
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
442
589
|
else result += `-${node.end} />`;
|
|
443
590
|
break;
|
|
444
591
|
case 4 /* Escaped */:
|
|
445
592
|
case 2 /* Preformatted */:
|
|
446
593
|
result += `>
|
|
447
594
|
${prefix} ${node.content}
|
|
448
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
595
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
449
596
|
break;
|
|
450
597
|
case 6 /* InlineModifier */:
|
|
451
598
|
case 7 /* BlockModifier */:
|
|
@@ -455,7 +602,7 @@ ${prefix} (${i})@${x.start}-${x.end}=${debugPrintArgument(x)}`).join("");
|
|
|
455
602
|
if (node.content.length > 0) {
|
|
456
603
|
result += ` id=${node.mod.name}${args}>
|
|
457
604
|
` + debugPrintNodes(node.content, prefix) + `
|
|
458
|
-
${prefix}</${node.type}@${node.end}>`;
|
|
605
|
+
${prefix}</${NodeType[node.type]}@${node.end}>`;
|
|
459
606
|
} else result += `-${node.end} id=${node.mod.name}${args} />`;
|
|
460
607
|
if (node.expansion) {
|
|
461
608
|
const content2 = debugPrintNodes(node.expansion, prefix);
|
|
@@ -481,118 +628,67 @@ function debugPrintNodes(content, prefix = "") {
|
|
|
481
628
|
if (dumps.length == 0) return "";
|
|
482
629
|
return dumps.map((x) => `${prefix} ${x}`).join("\n");
|
|
483
630
|
}
|
|
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);
|
|
631
|
+
function debugDumpDocument(doc, source) {
|
|
632
|
+
const lines = linePositions(source);
|
|
633
|
+
function pos2lc(pos) {
|
|
634
|
+
let line = -1, linepos = 0;
|
|
635
|
+
for (let i = 1; i < lines.length; i++) {
|
|
636
|
+
if (lines[i] > pos) {
|
|
637
|
+
line = i;
|
|
638
|
+
linepos = lines[i - 1];
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
567
641
|
}
|
|
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;
|
|
642
|
+
return `l${line}c${pos - linepos + 1}`;
|
|
643
|
+
}
|
|
644
|
+
function dumpMsg(m) {
|
|
645
|
+
let result = `at ${pos2lc(m.position)}, len ${m.length}: ${MessageSeverity[m.severity]}[${m.code}]: ${m.info}`;
|
|
646
|
+
while (m instanceof ReferredMessage) {
|
|
647
|
+
m = m.original;
|
|
648
|
+
result += `
|
|
649
|
+
---> original at: ${pos2lc(m.position)}, len ${m.length}`;
|
|
595
650
|
}
|
|
651
|
+
return result;
|
|
652
|
+
}
|
|
653
|
+
let root = debugPrintNode(doc.root);
|
|
654
|
+
let msgs = doc.messages.map(dumpMsg).join("\n");
|
|
655
|
+
if (msgs.length > 0) msgs += "\n";
|
|
656
|
+
return `${msgs}${root}`;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/debug.ts
|
|
660
|
+
var DebugLevel = /* @__PURE__ */ ((DebugLevel3) => {
|
|
661
|
+
DebugLevel3[DebugLevel3["Trace"] = 0] = "Trace";
|
|
662
|
+
DebugLevel3[DebugLevel3["Info"] = 1] = "Info";
|
|
663
|
+
DebugLevel3[DebugLevel3["Warning"] = 2] = "Warning";
|
|
664
|
+
DebugLevel3[DebugLevel3["Error"] = 3] = "Error";
|
|
665
|
+
DebugLevel3[DebugLevel3["None"] = 4] = "None";
|
|
666
|
+
return DebugLevel3;
|
|
667
|
+
})(DebugLevel || {});
|
|
668
|
+
var debug = {
|
|
669
|
+
level: 1 /* Info */,
|
|
670
|
+
trace(arg0, ...args) {
|
|
671
|
+
if (this.level > 0 /* Trace */) return;
|
|
672
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
673
|
+
console.info("TRACE", arg0, ...args);
|
|
674
|
+
},
|
|
675
|
+
info(arg0, ...args) {
|
|
676
|
+
if (this.level > 1 /* Info */) return;
|
|
677
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
678
|
+
console.info(" INFO", arg0, ...args);
|
|
679
|
+
},
|
|
680
|
+
warning(arg0, ...args) {
|
|
681
|
+
if (this.level > 2 /* Warning */) return;
|
|
682
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
683
|
+
console.warn(" WARN", arg0, ...args);
|
|
684
|
+
},
|
|
685
|
+
error(arg0, ...args) {
|
|
686
|
+
if (this.level > 3 /* Error */) return;
|
|
687
|
+
if (typeof arg0 == "function") arg0 = arg0();
|
|
688
|
+
console.error("ERROR", arg0, ...args);
|
|
689
|
+
},
|
|
690
|
+
never(_) {
|
|
691
|
+
assert(false);
|
|
596
692
|
}
|
|
597
693
|
};
|
|
598
694
|
|
|
@@ -772,22 +868,61 @@ var Parser = class {
|
|
|
772
868
|
}
|
|
773
869
|
return ok;
|
|
774
870
|
}
|
|
871
|
+
#expandArgument(arg) {
|
|
872
|
+
if (arg.expansion !== void 0)
|
|
873
|
+
return arg.expansion;
|
|
874
|
+
let result = "";
|
|
875
|
+
const immediate = this.delayDepth == 0;
|
|
876
|
+
for (const e of arg.content) {
|
|
877
|
+
switch (e.type) {
|
|
878
|
+
case 3 /* Text */:
|
|
879
|
+
case 4 /* Escaped */:
|
|
880
|
+
result += e.content;
|
|
881
|
+
break;
|
|
882
|
+
case 8 /* Interpolation */:
|
|
883
|
+
if (e.expansion === void 0) {
|
|
884
|
+
const inner = this.#expandArgument(e.argument);
|
|
885
|
+
if (inner === void 0 || e.definition.expand === void 0 || !immediate && !e.definition.alwaysTryExpand)
|
|
886
|
+
return void 0;
|
|
887
|
+
e.expansion = e.definition.expand(inner, this.cxt, immediate);
|
|
888
|
+
if (e.expansion === void 0)
|
|
889
|
+
return void 0;
|
|
890
|
+
}
|
|
891
|
+
result += e.expansion;
|
|
892
|
+
break;
|
|
893
|
+
default:
|
|
894
|
+
debug.never(e);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
arg.expansion = result;
|
|
898
|
+
return result;
|
|
899
|
+
}
|
|
900
|
+
#expandArguments(node) {
|
|
901
|
+
for (const arg of node.arguments) {
|
|
902
|
+
this.#expandArgument(arg);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
775
905
|
#expand(node, depth = 0) {
|
|
776
906
|
if (node.expansion !== void 0) {
|
|
777
907
|
debug.trace("already expanded, skipping:", node.mod.name);
|
|
778
908
|
return true;
|
|
779
909
|
}
|
|
910
|
+
if (depth > 0) {
|
|
911
|
+
this.#expandArguments(node);
|
|
912
|
+
}
|
|
780
913
|
if (this.delayDepth > 0 && !node.mod.alwaysTryExpand) {
|
|
781
914
|
debug.trace("delaying expansion of", node.mod.name);
|
|
782
915
|
return true;
|
|
783
916
|
}
|
|
784
917
|
const immediate = this.delayDepth == 0;
|
|
785
|
-
if (
|
|
918
|
+
if (depth > 0) {
|
|
786
919
|
if (node.mod.beforeParseContent)
|
|
787
920
|
this.emit.message(...node.mod.beforeParseContent(node, this.cxt, immediate));
|
|
788
|
-
if (node.
|
|
789
|
-
|
|
790
|
-
|
|
921
|
+
if (node.content.length > 0) {
|
|
922
|
+
if (node.mod.delayContentExpansion) this.delayDepth++;
|
|
923
|
+
this.#reparse(node.content, depth);
|
|
924
|
+
if (node.mod.delayContentExpansion) this.delayDepth--;
|
|
925
|
+
}
|
|
791
926
|
if (node.mod.afterParseContent)
|
|
792
927
|
this.emit.message(...node.mod.afterParseContent(node, this.cxt, immediate));
|
|
793
928
|
}
|
|
@@ -826,7 +961,7 @@ var Parser = class {
|
|
|
826
961
|
}
|
|
827
962
|
parse() {
|
|
828
963
|
this.DOCUMENT();
|
|
829
|
-
return new
|
|
964
|
+
return new Document(this.emit.root, this.cxt, this.emit.messages);
|
|
830
965
|
}
|
|
831
966
|
WHITESPACES_OR_NEWLINES() {
|
|
832
967
|
while (this.scanner.acceptWhitespaceChar() !== null || this.scanner.accept("\n")) {
|
|
@@ -884,16 +1019,19 @@ var Parser = class {
|
|
|
884
1019
|
const result = this.#defs(type).find((x) => this.scanner.accept(x.name));
|
|
885
1020
|
const mod = result ?? UnknownModifier[type];
|
|
886
1021
|
if (result === void 0) {
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
1022
|
+
let name = "";
|
|
1023
|
+
while (!this.scanner.isEOF() && !this.scanner.acceptWhitespaceChar() && !this.scanner.peek(MODIFIER_CLOSE_SIGN) && !this.scanner.peek(MODIFIER_END_SIGN)) {
|
|
1024
|
+
if (this.scanner.accept("\\")) {
|
|
1025
|
+
if (this.scanner.isEOF()) break;
|
|
1026
|
+
}
|
|
1027
|
+
name += this.scanner.acceptChar();
|
|
1028
|
+
}
|
|
891
1029
|
this.emit.message(
|
|
892
|
-
new UnknownModifierMessage(posStart, this.scanner.position() - posStart)
|
|
1030
|
+
new UnknownModifierMessage(posStart, this.scanner.position() - posStart, name)
|
|
893
1031
|
);
|
|
894
1032
|
}
|
|
895
1033
|
const args = this.ARGUMENTS();
|
|
896
|
-
debug.trace(`PARSE ${type}
|
|
1034
|
+
debug.trace(`PARSE ${NodeType[type]}:`, mod.name);
|
|
897
1035
|
const endsign = this.scanner.accept(MODIFIER_END_SIGN);
|
|
898
1036
|
const flagMarker = has(mod.flags, 2 /* Marker */);
|
|
899
1037
|
const isMarker = flagMarker || endsign;
|
|
@@ -902,16 +1040,18 @@ var Parser = class {
|
|
|
902
1040
|
this.scanner.position(),
|
|
903
1041
|
MODIFIER_CLOSE_SIGN
|
|
904
1042
|
));
|
|
1043
|
+
const headEnd = this.scanner.position();
|
|
905
1044
|
const node = {
|
|
906
1045
|
type,
|
|
907
1046
|
mod,
|
|
908
|
-
head: { start: posStart, end:
|
|
1047
|
+
head: { start: posStart, end: headEnd },
|
|
909
1048
|
arguments: args,
|
|
910
1049
|
start: posStart,
|
|
911
|
-
end:
|
|
1050
|
+
end: headEnd,
|
|
912
1051
|
content: [],
|
|
913
1052
|
expansion: void 0
|
|
914
1053
|
};
|
|
1054
|
+
this.#expandArguments(node);
|
|
915
1055
|
const immediate = this.delayDepth == 0;
|
|
916
1056
|
if (node.mod.beforeParseContent)
|
|
917
1057
|
this.emit.message(...node.mod.beforeParseContent(node, this.cxt, immediate));
|
|
@@ -945,6 +1085,8 @@ var Parser = class {
|
|
|
945
1085
|
}
|
|
946
1086
|
this.emit.endBlock();
|
|
947
1087
|
}
|
|
1088
|
+
const last = node.content.at(-1);
|
|
1089
|
+
node.actualEnd = last?.actualEnd ?? last?.end;
|
|
948
1090
|
if (node.mod.delayContentExpansion) this.delayDepth--;
|
|
949
1091
|
if (node.mod.afterParseContent)
|
|
950
1092
|
this.emit.message(...node.mod.afterParseContent(node, this.cxt, immediate));
|
|
@@ -1027,6 +1169,8 @@ var Parser = class {
|
|
|
1027
1169
|
while (!this.scanner.isEOF() && this.INLINE_ENTITY()) {
|
|
1028
1170
|
}
|
|
1029
1171
|
this.emit.endInline();
|
|
1172
|
+
const last = node.content.at(-1);
|
|
1173
|
+
node.actualEnd = last?.actualEnd ?? last?.end;
|
|
1030
1174
|
debug.trace("PARSE para end");
|
|
1031
1175
|
}
|
|
1032
1176
|
// returns false if breaking out of paragraph
|
|
@@ -1096,10 +1240,8 @@ var Parser = class {
|
|
|
1096
1240
|
}
|
|
1097
1241
|
};
|
|
1098
1242
|
while (true) {
|
|
1099
|
-
if (end !== void 0 && this.scanner.accept(end))
|
|
1100
|
-
debug.trace("found end", end);
|
|
1243
|
+
if (end !== void 0 && this.scanner.accept(end))
|
|
1101
1244
|
break;
|
|
1102
|
-
}
|
|
1103
1245
|
if (this.scanner.accept(":")) {
|
|
1104
1246
|
ok = end === void 0;
|
|
1105
1247
|
break;
|
|
@@ -1118,11 +1260,12 @@ var Parser = class {
|
|
|
1118
1260
|
content.push({
|
|
1119
1261
|
type: 4 /* Escaped */,
|
|
1120
1262
|
content: this.scanner.acceptChar(),
|
|
1121
|
-
start: posEnd -
|
|
1122
|
-
end: posEnd
|
|
1263
|
+
start: posEnd - 1,
|
|
1264
|
+
end: posEnd + 1
|
|
1123
1265
|
});
|
|
1124
1266
|
continue;
|
|
1125
1267
|
}
|
|
1268
|
+
const beforeInterp = this.scanner.position();
|
|
1126
1269
|
const result = this.cxt.config.argumentInterpolators.find(
|
|
1127
1270
|
(x) => this.scanner.accept(x.name)
|
|
1128
1271
|
);
|
|
@@ -1132,8 +1275,8 @@ var Parser = class {
|
|
|
1132
1275
|
content.push({
|
|
1133
1276
|
type: 8 /* Interpolation */,
|
|
1134
1277
|
definition: result,
|
|
1135
|
-
|
|
1136
|
-
start:
|
|
1278
|
+
argument: inner,
|
|
1279
|
+
start: beforeInterp,
|
|
1137
1280
|
end: posEnd
|
|
1138
1281
|
});
|
|
1139
1282
|
if (!ok2) {
|
|
@@ -1173,6 +1316,21 @@ function parse(scanner, config) {
|
|
|
1173
1316
|
return new Parser(scanner, config).parse();
|
|
1174
1317
|
}
|
|
1175
1318
|
|
|
1319
|
+
// src/modifier-helper.ts
|
|
1320
|
+
function checkArgumentLength(node, min, max = min) {
|
|
1321
|
+
if (min !== void 0 && node.arguments.length < min || max !== void 0 && node.arguments.length > max) {
|
|
1322
|
+
return [new ArgumentCountMismatchMessage(node.head.start, node.head.end - node.head.start, min, max)];
|
|
1323
|
+
}
|
|
1324
|
+
return null;
|
|
1325
|
+
}
|
|
1326
|
+
function checkArguments(node, min, max = min) {
|
|
1327
|
+
const arg = node.arguments.find((x) => x.expansion === void 0);
|
|
1328
|
+
if (arg !== void 0) {
|
|
1329
|
+
return [new CannotExpandArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1330
|
+
}
|
|
1331
|
+
return checkArgumentLength(node, min, max);
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1176
1334
|
// src/builtin/internal.ts
|
|
1177
1335
|
var builtins = Symbol();
|
|
1178
1336
|
function initParseContext(cxt) {
|
|
@@ -1180,18 +1338,10 @@ function initParseContext(cxt) {
|
|
|
1180
1338
|
blockSlotDelayedStack: [],
|
|
1181
1339
|
inlineSlotDelayedStack: [],
|
|
1182
1340
|
blockSlotData: [],
|
|
1183
|
-
inlineSlotData: []
|
|
1341
|
+
inlineSlotData: [],
|
|
1342
|
+
notationStack: []
|
|
1184
1343
|
});
|
|
1185
1344
|
}
|
|
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
1345
|
function customModifier(type, name, argNames, slotName, content) {
|
|
1196
1346
|
debug.info(`registered custom ${type} modifier:`, name);
|
|
1197
1347
|
debug.info("args:", argNames, `with ${slotName == "" ? "no slot name" : "slot name: " + slotName}`);
|
|
@@ -1200,9 +1350,12 @@ function customModifier(type, name, argNames, slotName, content) {
|
|
|
1200
1350
|
const isInline = type == 6 /* InlineModifier */;
|
|
1201
1351
|
mod.delayContentExpansion = true;
|
|
1202
1352
|
mod.prepareExpand = (node, cxt) => {
|
|
1203
|
-
|
|
1204
|
-
if (check) return
|
|
1205
|
-
node.state = {
|
|
1353
|
+
let check = checkArguments(node, argNames.length);
|
|
1354
|
+
if (check) return check;
|
|
1355
|
+
node.state = {
|
|
1356
|
+
ok: true,
|
|
1357
|
+
args: new Map(node.arguments.map((x, i) => [argNames[i], x.expansion]))
|
|
1358
|
+
};
|
|
1206
1359
|
return [];
|
|
1207
1360
|
};
|
|
1208
1361
|
mod.expand = (node, cxt) => {
|
|
@@ -1213,11 +1366,12 @@ function customModifier(type, name, argNames, slotName, content) {
|
|
|
1213
1366
|
mod.beforeProcessExpansion = (node, cxt) => {
|
|
1214
1367
|
if (!node.state?.ok) return [];
|
|
1215
1368
|
const store = cxt.get(builtins);
|
|
1216
|
-
const args = new Map(
|
|
1217
|
-
node.arguments.map((x, i) => [argNames[i], cxt.evaluateArgument(x)])
|
|
1218
|
-
);
|
|
1219
1369
|
const data = isInline ? store.inlineSlotData : store.blockSlotData;
|
|
1220
|
-
data.push([slotName, {
|
|
1370
|
+
data.push([slotName, {
|
|
1371
|
+
mod,
|
|
1372
|
+
args: node.state.args,
|
|
1373
|
+
slotContent: node.content
|
|
1374
|
+
}]);
|
|
1221
1375
|
debug.trace(
|
|
1222
1376
|
`pushed ${type} slot data for`,
|
|
1223
1377
|
name,
|
|
@@ -1247,28 +1401,31 @@ var DefineBlockMod = new SystemModifierDefinition("define-block", 0 /* Normal */
|
|
|
1247
1401
|
delayContentExpansion: true,
|
|
1248
1402
|
alwaysTryExpand: true,
|
|
1249
1403
|
beforeParseContent(node, cxt) {
|
|
1250
|
-
|
|
1251
|
-
|
|
1404
|
+
const check = checkArgumentLength(node, 1, Infinity);
|
|
1405
|
+
if (check) return check;
|
|
1252
1406
|
const msgs = [];
|
|
1253
1407
|
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
|
-
));
|
|
1408
|
+
const nameValue = name.expansion;
|
|
1261
1409
|
let slotName = "";
|
|
1262
1410
|
if (node.arguments.length > 1) {
|
|
1263
|
-
const last =
|
|
1264
|
-
|
|
1411
|
+
const last = node.arguments.at(-1);
|
|
1412
|
+
if (last.expansion)
|
|
1413
|
+
slotName = /^\(.+\)$/.test(last.expansion) ? last.expansion.substring(1, last.expansion.length - 1) : "";
|
|
1414
|
+
else msgs.push(
|
|
1415
|
+
new InvalidArgumentMessage(last.start, last.end - last.start)
|
|
1416
|
+
);
|
|
1265
1417
|
}
|
|
1266
|
-
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) =>
|
|
1267
|
-
|
|
1418
|
+
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) => {
|
|
1419
|
+
if (!x.expansion) msgs.push(
|
|
1420
|
+
new InvalidArgumentMessage(x.start, x.end - x.start)
|
|
1421
|
+
);
|
|
1422
|
+
return x.expansion ?? "";
|
|
1423
|
+
});
|
|
1424
|
+
node.state = { name: nameValue, slotName, args, msgs };
|
|
1268
1425
|
const store = cxt.get(builtins);
|
|
1269
1426
|
store.blockSlotDelayedStack.push(node.state.slotName);
|
|
1270
1427
|
debug.trace("entering block definition:", node.state.name);
|
|
1271
|
-
return
|
|
1428
|
+
return [];
|
|
1272
1429
|
},
|
|
1273
1430
|
afterParseContent(node, cxt) {
|
|
1274
1431
|
if (!node.state) return [];
|
|
@@ -1277,9 +1434,22 @@ var DefineBlockMod = new SystemModifierDefinition("define-block", 0 /* Normal */
|
|
|
1277
1434
|
debug.trace("leaving block definition", node.state.name);
|
|
1278
1435
|
return [];
|
|
1279
1436
|
},
|
|
1437
|
+
prepareExpand(node, cxt, immediate) {
|
|
1438
|
+
if (!immediate || !node.state) return [];
|
|
1439
|
+
const arg = node.arguments[0];
|
|
1440
|
+
if (!node.state.name)
|
|
1441
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1442
|
+
if (cxt.config.blockModifiers.has(node.state.name))
|
|
1443
|
+
return [new NameAlreadyDefinedMessage(
|
|
1444
|
+
arg.start,
|
|
1445
|
+
arg.end - arg.start,
|
|
1446
|
+
node.state.name
|
|
1447
|
+
)];
|
|
1448
|
+
return [];
|
|
1449
|
+
},
|
|
1280
1450
|
expand(node, cxt, immediate) {
|
|
1281
1451
|
if (!immediate) return void 0;
|
|
1282
|
-
if (node.state) {
|
|
1452
|
+
if (node.state?.name) {
|
|
1283
1453
|
if (cxt.config.blockModifiers.has(node.state.name))
|
|
1284
1454
|
cxt.config.blockModifiers.remove(node.state.name);
|
|
1285
1455
|
cxt.config.blockModifiers.add(
|
|
@@ -1302,12 +1472,12 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1302
1472
|
delayContentExpansion: true,
|
|
1303
1473
|
alwaysTryExpand: true,
|
|
1304
1474
|
beforeParseContent(node, cxt) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1475
|
+
const check = checkArgumentLength(node, 1, Infinity);
|
|
1476
|
+
if (check) return check;
|
|
1307
1477
|
const msgs = [];
|
|
1308
1478
|
const name = node.arguments[0];
|
|
1309
|
-
const nameValue =
|
|
1310
|
-
if (cxt.config.inlineModifiers.has(nameValue))
|
|
1479
|
+
const nameValue = name.expansion;
|
|
1480
|
+
if (nameValue && cxt.config.inlineModifiers.has(nameValue))
|
|
1311
1481
|
msgs.push(new NameAlreadyDefinedMessage(
|
|
1312
1482
|
node.start,
|
|
1313
1483
|
name.end - name.start,
|
|
@@ -1315,15 +1485,24 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1315
1485
|
));
|
|
1316
1486
|
let slotName = "";
|
|
1317
1487
|
if (node.arguments.length > 1) {
|
|
1318
|
-
const last =
|
|
1319
|
-
|
|
1488
|
+
const last = node.arguments.at(-1);
|
|
1489
|
+
if (last.expansion)
|
|
1490
|
+
slotName = /^\(.+\)$/.test(last.expansion) ? last.expansion.substring(1, last.expansion.length - 1) : "";
|
|
1491
|
+
else msgs.push(
|
|
1492
|
+
new InvalidArgumentMessage(last.start, last.end - last.start)
|
|
1493
|
+
);
|
|
1320
1494
|
}
|
|
1321
|
-
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) =>
|
|
1322
|
-
|
|
1495
|
+
const args = node.arguments.slice(1, slotName !== "" ? node.arguments.length - 1 : void 0).map((x) => {
|
|
1496
|
+
if (!x.expansion) msgs.push(
|
|
1497
|
+
new InvalidArgumentMessage(x.start, x.end - x.start)
|
|
1498
|
+
);
|
|
1499
|
+
return x.expansion ?? "";
|
|
1500
|
+
});
|
|
1501
|
+
node.state = { name: nameValue, slotName, args, msgs };
|
|
1323
1502
|
const store = cxt.get(builtins);
|
|
1324
1503
|
store.inlineSlotDelayedStack.push(node.state.slotName);
|
|
1325
1504
|
debug.trace("entering inline definition:", node.state.name);
|
|
1326
|
-
return
|
|
1505
|
+
return [];
|
|
1327
1506
|
},
|
|
1328
1507
|
afterParseContent(node, cxt) {
|
|
1329
1508
|
if (!node.state) return [];
|
|
@@ -1332,9 +1511,18 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1332
1511
|
debug.trace("leaving inline definition", node.state.name);
|
|
1333
1512
|
return [];
|
|
1334
1513
|
},
|
|
1335
|
-
prepareExpand(node, cxt) {
|
|
1336
|
-
if (!node.state) return [];
|
|
1514
|
+
prepareExpand(node, cxt, immediate) {
|
|
1515
|
+
if (!immediate || !node.state) return [];
|
|
1516
|
+
const arg = node.arguments[0];
|
|
1517
|
+
if (!node.state.name)
|
|
1518
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1337
1519
|
const msgs = [];
|
|
1520
|
+
if (cxt.config.inlineModifiers.has(node.state.name))
|
|
1521
|
+
msgs.push(new NameAlreadyDefinedMessage(
|
|
1522
|
+
arg.start,
|
|
1523
|
+
arg.end - arg.start,
|
|
1524
|
+
node.state.name
|
|
1525
|
+
));
|
|
1338
1526
|
let lastIsParagraph = false;
|
|
1339
1527
|
let concat = [];
|
|
1340
1528
|
for (const n of node.content) {
|
|
@@ -1362,7 +1550,7 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1362
1550
|
},
|
|
1363
1551
|
expand(node, cxt, immediate) {
|
|
1364
1552
|
if (!immediate) return void 0;
|
|
1365
|
-
if (node.state) {
|
|
1553
|
+
if (node.state?.name) {
|
|
1366
1554
|
if (cxt.config.inlineModifiers.has(node.state.name))
|
|
1367
1555
|
cxt.config.inlineModifiers.remove(node.state.name);
|
|
1368
1556
|
cxt.config.inlineModifiers.add(
|
|
@@ -1379,27 +1567,68 @@ var DefineInlineMod = new SystemModifierDefinition("define-inline", 0 /* Normal
|
|
|
1379
1567
|
}
|
|
1380
1568
|
});
|
|
1381
1569
|
|
|
1570
|
+
// src/builtin/pushpop.ts
|
|
1571
|
+
var PushNotationMod = new SystemModifierDefinition(
|
|
1572
|
+
"push-notation",
|
|
1573
|
+
2 /* Marker */,
|
|
1574
|
+
{
|
|
1575
|
+
expand(_, cxt) {
|
|
1576
|
+
const data = cxt.get(builtins);
|
|
1577
|
+
data.notationStack.push({
|
|
1578
|
+
blocks: cxt.config.blockModifiers.toArray(),
|
|
1579
|
+
inlines: cxt.config.inlineModifiers.toArray()
|
|
1580
|
+
});
|
|
1581
|
+
return [];
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
);
|
|
1585
|
+
var PopNotationMod = new SystemModifierDefinition(
|
|
1586
|
+
"pop-notation",
|
|
1587
|
+
2 /* Marker */,
|
|
1588
|
+
{
|
|
1589
|
+
prepareExpand(node, cxt) {
|
|
1590
|
+
const data = cxt.get(builtins);
|
|
1591
|
+
const result = data.notationStack.pop();
|
|
1592
|
+
if (!result) return [
|
|
1593
|
+
new CannotPopNotationMessage(node.start, node.end - node.start)
|
|
1594
|
+
];
|
|
1595
|
+
cxt.config.blockModifiers = new NameManager(result.blocks);
|
|
1596
|
+
cxt.config.inlineModifiers = new NameManager(result.inlines);
|
|
1597
|
+
return [];
|
|
1598
|
+
},
|
|
1599
|
+
expand() {
|
|
1600
|
+
return [];
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
);
|
|
1604
|
+
|
|
1382
1605
|
// src/builtin/slot.ts
|
|
1383
1606
|
function slotModifier(type) {
|
|
1384
1607
|
const mod = type == 7 /* BlockModifier */ ? new BlockModifierDefinition("slot", 2 /* Marker */) : new InlineModifierDefinition("slot", 2 /* Marker */);
|
|
1385
1608
|
const isInline = type == 6 /* InlineModifier */;
|
|
1386
1609
|
mod.alwaysTryExpand = true;
|
|
1387
1610
|
mod.prepareExpand = (node, cxt, immediate) => {
|
|
1611
|
+
if (node.state) return [];
|
|
1612
|
+
const check = checkArgumentLength(node, 0, 1);
|
|
1613
|
+
if (check && immediate) {
|
|
1614
|
+
node.state = { ok: false };
|
|
1615
|
+
return check;
|
|
1616
|
+
}
|
|
1388
1617
|
const store = cxt.get(builtins);
|
|
1389
1618
|
const data = isInline ? store.inlineSlotData : store.blockSlotData;
|
|
1390
|
-
|
|
1391
|
-
if (
|
|
1392
|
-
|
|
1619
|
+
let id = "";
|
|
1620
|
+
if (node.arguments.length == 1) {
|
|
1621
|
+
const arg = node.arguments[0];
|
|
1622
|
+
if (!arg.expansion) {
|
|
1393
1623
|
node.state = { ok: false };
|
|
1394
|
-
return [new
|
|
1624
|
+
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1395
1625
|
}
|
|
1396
|
-
|
|
1626
|
+
id = arg.expansion;
|
|
1397
1627
|
}
|
|
1398
|
-
if (
|
|
1628
|
+
if (data.length == 0) {
|
|
1399
1629
|
if (immediate) {
|
|
1400
1630
|
node.state = { ok: false };
|
|
1401
|
-
|
|
1402
|
-
return [new ArgumentsTooManyMessage(start, node.head.end - start)];
|
|
1631
|
+
return [new SlotUsedOutsideDefinitionMessage(node.start, node.head.end - node.start)];
|
|
1403
1632
|
}
|
|
1404
1633
|
return [];
|
|
1405
1634
|
}
|
|
@@ -1470,10 +1699,10 @@ function resolveId(id, cxt) {
|
|
|
1470
1699
|
var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
1471
1700
|
// .$:id
|
|
1472
1701
|
prepareExpand(node, cxt) {
|
|
1473
|
-
const check =
|
|
1474
|
-
if (check) return
|
|
1702
|
+
const check = checkArguments(node, 1);
|
|
1703
|
+
if (check) return check;
|
|
1475
1704
|
const arg = node.arguments[0];
|
|
1476
|
-
const id =
|
|
1705
|
+
const id = arg.expansion;
|
|
1477
1706
|
if (id == "")
|
|
1478
1707
|
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1479
1708
|
const value = resolveId(id, cxt);
|
|
@@ -1487,23 +1716,44 @@ var GetVarInlineMod = new InlineModifierDefinition("$", 2 /* Marker */, {
|
|
|
1487
1716
|
return [{ type: 3 /* Text */, content: node.state.value, start: -1, end: -1 }];
|
|
1488
1717
|
}
|
|
1489
1718
|
});
|
|
1719
|
+
var PrintInlineMod = new InlineModifierDefinition("print", 2 /* Marker */, {
|
|
1720
|
+
// .print:args...
|
|
1721
|
+
prepareExpand(node) {
|
|
1722
|
+
const check = checkArguments(node);
|
|
1723
|
+
if (check) return check;
|
|
1724
|
+
node.state = { value: node.arguments.map((x) => x.expansion).join("") };
|
|
1725
|
+
return [];
|
|
1726
|
+
},
|
|
1727
|
+
expand(node) {
|
|
1728
|
+
if (!node.state) return [];
|
|
1729
|
+
return [{ type: 3 /* Text */, content: node.state.value, start: -1, end: -1 }];
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1490
1732
|
var GetVarInterpolator = new ArgumentInterpolatorDefinition(
|
|
1491
1733
|
"$(",
|
|
1492
1734
|
")",
|
|
1493
|
-
|
|
1735
|
+
{
|
|
1736
|
+
alwaysTryExpand: true,
|
|
1737
|
+
expand(content, cxt, immediate) {
|
|
1738
|
+
const result = resolveId(content, cxt);
|
|
1739
|
+
if (result === void 0) debug.trace("var interp failed:", content);
|
|
1740
|
+
else debug.trace(`$(${content}) --> ${result}`);
|
|
1741
|
+
return result;
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1494
1744
|
);
|
|
1495
1745
|
var VarMod = new SystemModifierDefinition("var", 2 /* Marker */, {
|
|
1496
1746
|
// .var id:value
|
|
1497
1747
|
prepareExpand(node, cxt) {
|
|
1498
|
-
const check =
|
|
1499
|
-
if (check) return
|
|
1748
|
+
const check = checkArguments(node, 2);
|
|
1749
|
+
if (check) return check;
|
|
1500
1750
|
const arg = node.arguments[0];
|
|
1501
|
-
const
|
|
1502
|
-
if (
|
|
1751
|
+
const id = arg.expansion;
|
|
1752
|
+
if (id == "")
|
|
1503
1753
|
return [new InvalidArgumentMessage(arg.start, arg.end - arg.start)];
|
|
1504
1754
|
node.state = {
|
|
1505
|
-
id
|
|
1506
|
-
value:
|
|
1755
|
+
id,
|
|
1756
|
+
value: node.arguments[1].expansion
|
|
1507
1757
|
};
|
|
1508
1758
|
return [];
|
|
1509
1759
|
},
|
|
@@ -1519,40 +1769,33 @@ var VarMod = new SystemModifierDefinition("var", 2 /* Marker */, {
|
|
|
1519
1769
|
// src/builtin/builtin.ts
|
|
1520
1770
|
var basic = new Configuration();
|
|
1521
1771
|
basic.initializers = [initParseContext];
|
|
1522
|
-
basic.systemModifiers.add(DefineBlockMod, DefineInlineMod, VarMod);
|
|
1772
|
+
basic.systemModifiers.add(DefineBlockMod, DefineInlineMod, VarMod, PushNotationMod, PopNotationMod);
|
|
1523
1773
|
basic.blockModifiers.add(SlotBlockMod);
|
|
1524
|
-
basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod);
|
|
1774
|
+
basic.inlineModifiers.add(SlotInlineMod, GetVarInlineMod, PrintInlineMod);
|
|
1525
1775
|
basic.argumentInterpolators.add(GetVarInterpolator);
|
|
1526
1776
|
var BuiltinConfiguration = Object.freeze(basic);
|
|
1777
|
+
|
|
1778
|
+
// src/index.ts
|
|
1779
|
+
function setDebugLevel(level) {
|
|
1780
|
+
debug.level = level;
|
|
1781
|
+
}
|
|
1527
1782
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1528
1783
|
0 && (module.exports = {
|
|
1529
1784
|
ArgumentInterpolatorDefinition,
|
|
1530
|
-
ArgumentsTooFewMessage,
|
|
1531
|
-
ArgumentsTooManyMessage,
|
|
1532
1785
|
BlockModifierDefinition,
|
|
1533
1786
|
BuiltinConfiguration,
|
|
1534
1787
|
Configuration,
|
|
1535
|
-
|
|
1788
|
+
DebugLevel,
|
|
1536
1789
|
Document,
|
|
1537
|
-
ExpectedMessage,
|
|
1538
|
-
InlineDefinitonInvalidEntityMessage,
|
|
1539
1790
|
InlineModifierDefinition,
|
|
1540
|
-
InvalidArgumentMessage,
|
|
1541
1791
|
MessageSeverity,
|
|
1542
1792
|
ModifierFlags,
|
|
1543
|
-
NameAlreadyDefinedMessage,
|
|
1544
|
-
NewBlockShouldBeOnNewlineMessage,
|
|
1545
1793
|
NodeType,
|
|
1546
1794
|
ParseContext,
|
|
1547
|
-
ReachedRecursionLimitMessage,
|
|
1548
|
-
ReferredMessage,
|
|
1549
1795
|
SimpleScanner,
|
|
1550
|
-
SlotUsedOutsideDefinitionMessage,
|
|
1551
1796
|
SystemModifierDefinition,
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
UnnecessaryNewlineMessage,
|
|
1556
|
-
parse
|
|
1797
|
+
messages,
|
|
1798
|
+
parse,
|
|
1799
|
+
setDebugLevel
|
|
1557
1800
|
});
|
|
1558
1801
|
//# sourceMappingURL=index.js.map
|