links-notation 0.23.0 → 0.25.0
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 +86 -0
- package/README.ru.md +48 -0
- package/dist/index.js +597 -269
- package/index.d.ts +58 -1
- package/package.json +1 -1
- package/src/Binary.js +2 -20
- package/src/IndentedDocument.js +88 -0
- package/src/Link.js +9 -51
- package/src/Parser.js +26 -1
- package/src/ReferenceLiteral.js +66 -0
- package/src/grammar.pegjs +12 -2
- package/src/index.js +9 -0
- package/src/parser-generated.js +262 -89
- package/src/references.js +63 -0
- package/tests/Binary.test.js +3 -1
- package/tests/EmptyReference.test.js +2 -2
- package/tests/IndentedDocument.test.js +256 -0
- package/tests/ReferenceFidelity.test.js +99 -0
package/dist/index.js
CHANGED
|
@@ -1,3 +1,241 @@
|
|
|
1
|
+
// src/quotes.js
|
|
2
|
+
var QUOTES = ['"', "'", "`"];
|
|
3
|
+
|
|
4
|
+
class DelimitedReferences {
|
|
5
|
+
constructor(document) {
|
|
6
|
+
this.document = document;
|
|
7
|
+
this.runsByQuote = new Map;
|
|
8
|
+
this.readings = new Map;
|
|
9
|
+
}
|
|
10
|
+
readAt(start) {
|
|
11
|
+
if (!this.readings.has(start)) {
|
|
12
|
+
this.readings.set(start, this.#read(start));
|
|
13
|
+
}
|
|
14
|
+
return this.readings.get(start);
|
|
15
|
+
}
|
|
16
|
+
endAt(start) {
|
|
17
|
+
const reading = this.readAt(start);
|
|
18
|
+
return reading === null ? null : start + reading.length;
|
|
19
|
+
}
|
|
20
|
+
#read(start) {
|
|
21
|
+
const document = this.document;
|
|
22
|
+
const quote = document[start];
|
|
23
|
+
if (!QUOTES.includes(quote)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const runs = this.#runsOf(quote);
|
|
27
|
+
const opening = runs.indexOf(start);
|
|
28
|
+
const count = runs.end(opening) - start;
|
|
29
|
+
let closing = opening + 1;
|
|
30
|
+
while (closing < runs.count) {
|
|
31
|
+
const length = runs.lengths[closing];
|
|
32
|
+
if (length < count) {
|
|
33
|
+
closing = runs.nextLonger[closing];
|
|
34
|
+
} else if (Math.floor(length / count) % 2 === 1) {
|
|
35
|
+
break;
|
|
36
|
+
} else {
|
|
37
|
+
closing++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const end = closing < runs.count ? runs.end(closing) : null;
|
|
41
|
+
return reading(document, start, quote, count, end);
|
|
42
|
+
}
|
|
43
|
+
#runsOf(quote) {
|
|
44
|
+
if (!this.runsByQuote.has(quote)) {
|
|
45
|
+
this.runsByQuote.set(quote, new DelimiterRuns(this.document, quote));
|
|
46
|
+
}
|
|
47
|
+
return this.runsByQuote.get(quote);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function readReference(document, start) {
|
|
51
|
+
const quote = document[start];
|
|
52
|
+
if (!QUOTES.includes(quote)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const count = runLength(document, start, quote);
|
|
56
|
+
let end = null;
|
|
57
|
+
let position = document.indexOf(quote, start + count);
|
|
58
|
+
while (position !== -1) {
|
|
59
|
+
const length = runLength(document, position, quote);
|
|
60
|
+
if (length >= count && Math.floor(length / count) % 2 === 1) {
|
|
61
|
+
end = position + length;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
position = document.indexOf(quote, position + length);
|
|
65
|
+
}
|
|
66
|
+
return reading(document, start, quote, count, end);
|
|
67
|
+
}
|
|
68
|
+
function reading(document, start, quote, count, end) {
|
|
69
|
+
const emptyReference = count % 2 === 0 ? { value: "", length: count } : null;
|
|
70
|
+
if (end === null) {
|
|
71
|
+
return emptyReference;
|
|
72
|
+
}
|
|
73
|
+
const parts = [];
|
|
74
|
+
let position = start + count;
|
|
75
|
+
let run = document.indexOf(quote, position);
|
|
76
|
+
while (run !== -1 && run < end) {
|
|
77
|
+
const length = runLength(document, run, quote);
|
|
78
|
+
const escaped = Math.floor(length / (2 * count)) * count;
|
|
79
|
+
const closes = run + length === end ? count : 0;
|
|
80
|
+
parts.push(document.slice(position, run));
|
|
81
|
+
parts.push(quote.repeat(length - escaped - closes));
|
|
82
|
+
position = run + length;
|
|
83
|
+
run = document.indexOf(quote, position);
|
|
84
|
+
}
|
|
85
|
+
const value = parts.join("");
|
|
86
|
+
if (emptyReference !== null && !isSubstantiveBody(value)) {
|
|
87
|
+
return emptyReference;
|
|
88
|
+
}
|
|
89
|
+
return { value, length: end - start };
|
|
90
|
+
}
|
|
91
|
+
function runLength(text, start, quote) {
|
|
92
|
+
let end = start;
|
|
93
|
+
while (end < text.length && text[end] === quote) {
|
|
94
|
+
end++;
|
|
95
|
+
}
|
|
96
|
+
return end - start;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
class DelimiterRuns {
|
|
100
|
+
constructor(document, quote) {
|
|
101
|
+
this.starts = [];
|
|
102
|
+
this.lengths = [];
|
|
103
|
+
let position = document.indexOf(quote);
|
|
104
|
+
while (position !== -1) {
|
|
105
|
+
const length = runLength(document, position, quote);
|
|
106
|
+
this.starts.push(position);
|
|
107
|
+
this.lengths.push(length);
|
|
108
|
+
position = document.indexOf(quote, position + length);
|
|
109
|
+
}
|
|
110
|
+
this.count = this.starts.length;
|
|
111
|
+
this.nextLonger = new Array(this.count);
|
|
112
|
+
const longer = [];
|
|
113
|
+
for (let run = this.count - 1;run >= 0; run--) {
|
|
114
|
+
while (longer.length > 0 && this.lengths[longer[longer.length - 1]] <= this.lengths[run]) {
|
|
115
|
+
longer.pop();
|
|
116
|
+
}
|
|
117
|
+
this.nextLonger[run] = longer.length > 0 ? longer[longer.length - 1] : this.count;
|
|
118
|
+
longer.push(run);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
end(run) {
|
|
122
|
+
return this.starts[run] + this.lengths[run];
|
|
123
|
+
}
|
|
124
|
+
indexOf(position) {
|
|
125
|
+
let low = 0;
|
|
126
|
+
let high = this.count - 1;
|
|
127
|
+
while (low < high) {
|
|
128
|
+
const middle = low + high + 1 >> 1;
|
|
129
|
+
if (this.starts[middle] <= position) {
|
|
130
|
+
low = middle;
|
|
131
|
+
} else {
|
|
132
|
+
high = middle - 1;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return low;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function isSubstantiveBody(content) {
|
|
139
|
+
let depth = 0;
|
|
140
|
+
let hasVisible = false;
|
|
141
|
+
for (const character of content) {
|
|
142
|
+
if (character === "(") {
|
|
143
|
+
depth++;
|
|
144
|
+
} else if (character === ")") {
|
|
145
|
+
depth--;
|
|
146
|
+
if (depth < 0) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!/[ \t\n\r]/.test(character)) {
|
|
151
|
+
hasVisible = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return hasVisible && depth === 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/ReferenceLiteral.js
|
|
158
|
+
function hasReferenceLiteralPrefix(text, start = 0) {
|
|
159
|
+
return /^~[0-9]+\{/.test(text.slice(start));
|
|
160
|
+
}
|
|
161
|
+
function encodeReferenceLiteral(text) {
|
|
162
|
+
if (typeof text !== "string" || !text.isWellFormed()) {
|
|
163
|
+
throw new TypeError("Reference must be well-formed Unicode text");
|
|
164
|
+
}
|
|
165
|
+
const hex = Array.from(new TextEncoder().encode(text), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
166
|
+
return `~1{${hex}}`;
|
|
167
|
+
}
|
|
168
|
+
function decodeReferenceLiteral(literal) {
|
|
169
|
+
const match = /^~([0-9]+)\{([0-9a-fA-F]*)\}$/.exec(literal);
|
|
170
|
+
if (!match || match[0] !== literal || match[1] !== "1" || match[2].length % 2 !== 0) {
|
|
171
|
+
throw new TypeError("Invalid or unsupported reference literal (expected ~1{UTF-8 hex})");
|
|
172
|
+
}
|
|
173
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(match[2].match(/../g) ?? [], (hex) => parseInt(hex, 16)));
|
|
174
|
+
}
|
|
175
|
+
function formatReference(text) {
|
|
176
|
+
if (typeof text !== "string" || !text.isWellFormed()) {
|
|
177
|
+
throw new TypeError("Reference must be well-formed Unicode text");
|
|
178
|
+
}
|
|
179
|
+
if (!text || /[\u0000-\u001f\u007f]/u.test(text)) {
|
|
180
|
+
return encodeReferenceLiteral(text);
|
|
181
|
+
}
|
|
182
|
+
if (!text.startsWith("#") && !/^~[0-9]+\{/.test(text) && !/[\p{White_Space}\ufeff():"'`]/u.test(text)) {
|
|
183
|
+
return text;
|
|
184
|
+
}
|
|
185
|
+
let choice = null;
|
|
186
|
+
for (const quote of ["'", '"', "`"]) {
|
|
187
|
+
if (text.startsWith(quote))
|
|
188
|
+
continue;
|
|
189
|
+
let longest = 0;
|
|
190
|
+
let run = 0;
|
|
191
|
+
for (const character of text) {
|
|
192
|
+
run = character === quote ? run + 1 : 0;
|
|
193
|
+
longest = Math.max(longest, run);
|
|
194
|
+
}
|
|
195
|
+
const count = longest + 1 | 1;
|
|
196
|
+
if (choice === null || count < choice.count)
|
|
197
|
+
choice = { quote, count };
|
|
198
|
+
}
|
|
199
|
+
const delimiter = choice.quote.repeat(choice.count);
|
|
200
|
+
return delimiter + text + delimiter;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/references.js
|
|
204
|
+
function escapeReference(reference, { minimal = false } = {}) {
|
|
205
|
+
if (reference === null || reference === undefined)
|
|
206
|
+
return "";
|
|
207
|
+
if (typeof reference !== "string" || !reference.isWellFormed()) {
|
|
208
|
+
throw new TypeError("Reference must be well-formed Unicode text");
|
|
209
|
+
}
|
|
210
|
+
if (!minimal || !reference || /[\u0000-\u001f\u007f]/u.test(reference)) {
|
|
211
|
+
return formatReference(reference);
|
|
212
|
+
}
|
|
213
|
+
const needsQuoting = /(^| )~[0-9]+\{/.test(reference) || /[:()'"`]|(?! )[\p{White_Space}\ufeff]/u.test(reference) || /(^ | $| {2,}|(^| )#)/.test(reference);
|
|
214
|
+
if (!needsQuoting)
|
|
215
|
+
return reference;
|
|
216
|
+
const singleQuotes = reference.split("'").length - 1;
|
|
217
|
+
const doubleQuotes = reference.split('"').length - 1;
|
|
218
|
+
let quote = singleQuotes <= doubleQuotes ? "'" : '"';
|
|
219
|
+
if (reference.startsWith(quote))
|
|
220
|
+
quote = quote === "'" ? '"' : "'";
|
|
221
|
+
return quote + reference.replaceAll(quote, quote + quote) + quote;
|
|
222
|
+
}
|
|
223
|
+
function unescapeReference(reference) {
|
|
224
|
+
if (typeof reference !== "string") {
|
|
225
|
+
throw new TypeError("Reference must be a string");
|
|
226
|
+
}
|
|
227
|
+
if (hasReferenceLiteralPrefix(reference)) {
|
|
228
|
+
return decodeReferenceLiteral(reference);
|
|
229
|
+
}
|
|
230
|
+
if (!QUOTES.includes(reference[0]))
|
|
231
|
+
return reference;
|
|
232
|
+
const reading = readReference(reference, 0);
|
|
233
|
+
if (reading === null || reading.length !== reference.length) {
|
|
234
|
+
throw new SyntaxError("Expected one complete quoted reference");
|
|
235
|
+
}
|
|
236
|
+
return reading.value;
|
|
237
|
+
}
|
|
238
|
+
|
|
1
239
|
// src/Link.js
|
|
2
240
|
class Link {
|
|
3
241
|
constructor(id = null, values = null) {
|
|
@@ -35,30 +273,11 @@ class Link {
|
|
|
35
273
|
static getValueString(value) {
|
|
36
274
|
return value && typeof value.toLinkOrIdString === "function" ? value.toLinkOrIdString() : String(value);
|
|
37
275
|
}
|
|
38
|
-
static escapeReference(reference) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return '""';
|
|
44
|
-
}
|
|
45
|
-
const hasSingleQuote = reference.includes("'");
|
|
46
|
-
const hasDoubleQuote = reference.includes('"');
|
|
47
|
-
const needsQuoting = reference.startsWith("#") || reference.includes(":") || reference.includes("(") || reference.includes(")") || reference.includes(" ") || reference.includes("\t") || reference.includes(`
|
|
48
|
-
`) || reference.includes("\r") || hasDoubleQuote || hasSingleQuote;
|
|
49
|
-
if (hasSingleQuote && hasDoubleQuote) {
|
|
50
|
-
return `'${reference.replace(/'/g, "\\'")}'`;
|
|
51
|
-
}
|
|
52
|
-
if (hasDoubleQuote) {
|
|
53
|
-
return `'${reference}'`;
|
|
54
|
-
}
|
|
55
|
-
if (hasSingleQuote) {
|
|
56
|
-
return `"${reference}"`;
|
|
57
|
-
}
|
|
58
|
-
if (needsQuoting) {
|
|
59
|
-
return `'${reference}'`;
|
|
60
|
-
}
|
|
61
|
-
return reference;
|
|
276
|
+
static escapeReference(reference, options = {}) {
|
|
277
|
+
return escapeReference(reference, options);
|
|
278
|
+
}
|
|
279
|
+
static unescapeReference(reference) {
|
|
280
|
+
return unescapeReference(reference);
|
|
62
281
|
}
|
|
63
282
|
toLinkOrIdString() {
|
|
64
283
|
if (!this.values || this.values.length === 0) {
|
|
@@ -269,6 +488,7 @@ class LinksGroup {
|
|
|
269
488
|
return list.map((item) => `(${item.id || item})`).join(" ");
|
|
270
489
|
}
|
|
271
490
|
}
|
|
491
|
+
|
|
272
492
|
// src/ParseError.js
|
|
273
493
|
var QUOTED_LINE_WIDTH = 80;
|
|
274
494
|
var ELLIPSIS = "...";
|
|
@@ -344,144 +564,6 @@ function windowAround(lineText, column) {
|
|
|
344
564
|
return [quoted, target - start + shift + 1];
|
|
345
565
|
}
|
|
346
566
|
|
|
347
|
-
// src/quotes.js
|
|
348
|
-
var QUOTES = ['"', "'", "`"];
|
|
349
|
-
|
|
350
|
-
class DelimitedReferences {
|
|
351
|
-
constructor(document) {
|
|
352
|
-
this.document = document;
|
|
353
|
-
this.runsByQuote = new Map;
|
|
354
|
-
this.readings = new Map;
|
|
355
|
-
}
|
|
356
|
-
readAt(start) {
|
|
357
|
-
if (!this.readings.has(start)) {
|
|
358
|
-
this.readings.set(start, this.#read(start));
|
|
359
|
-
}
|
|
360
|
-
return this.readings.get(start);
|
|
361
|
-
}
|
|
362
|
-
endAt(start) {
|
|
363
|
-
const reading = this.readAt(start);
|
|
364
|
-
return reading === null ? null : start + reading.length;
|
|
365
|
-
}
|
|
366
|
-
#read(start) {
|
|
367
|
-
const document = this.document;
|
|
368
|
-
const quote = document[start];
|
|
369
|
-
if (!QUOTES.includes(quote)) {
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
const runs = this.#runsOf(quote);
|
|
373
|
-
const opening = runs.indexOf(start);
|
|
374
|
-
const count = runs.end(opening) - start;
|
|
375
|
-
let closing = opening + 1;
|
|
376
|
-
while (closing < runs.count) {
|
|
377
|
-
const length = runs.lengths[closing];
|
|
378
|
-
if (length < count) {
|
|
379
|
-
closing = runs.nextLonger[closing];
|
|
380
|
-
} else if (Math.floor(length / count) % 2 === 1) {
|
|
381
|
-
break;
|
|
382
|
-
} else {
|
|
383
|
-
closing++;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
const end = closing < runs.count ? runs.end(closing) : null;
|
|
387
|
-
return reading(document, start, quote, count, end);
|
|
388
|
-
}
|
|
389
|
-
#runsOf(quote) {
|
|
390
|
-
if (!this.runsByQuote.has(quote)) {
|
|
391
|
-
this.runsByQuote.set(quote, new DelimiterRuns(this.document, quote));
|
|
392
|
-
}
|
|
393
|
-
return this.runsByQuote.get(quote);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
function reading(document, start, quote, count, end) {
|
|
397
|
-
const emptyReference = count % 2 === 0 ? { value: "", length: count } : null;
|
|
398
|
-
if (end === null) {
|
|
399
|
-
return emptyReference;
|
|
400
|
-
}
|
|
401
|
-
const parts = [];
|
|
402
|
-
let position = start + count;
|
|
403
|
-
let run = document.indexOf(quote, position);
|
|
404
|
-
while (run !== -1 && run < end) {
|
|
405
|
-
const length = runLength(document, run, quote);
|
|
406
|
-
const escaped = Math.floor(length / (2 * count)) * count;
|
|
407
|
-
const closes = run + length === end ? count : 0;
|
|
408
|
-
parts.push(document.slice(position, run));
|
|
409
|
-
parts.push(quote.repeat(length - escaped - closes));
|
|
410
|
-
position = run + length;
|
|
411
|
-
run = document.indexOf(quote, position);
|
|
412
|
-
}
|
|
413
|
-
const value = parts.join("");
|
|
414
|
-
if (emptyReference !== null && !isSubstantiveBody(value)) {
|
|
415
|
-
return emptyReference;
|
|
416
|
-
}
|
|
417
|
-
return { value, length: end - start };
|
|
418
|
-
}
|
|
419
|
-
function runLength(text, start, quote) {
|
|
420
|
-
let end = start;
|
|
421
|
-
while (end < text.length && text[end] === quote) {
|
|
422
|
-
end++;
|
|
423
|
-
}
|
|
424
|
-
return end - start;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
class DelimiterRuns {
|
|
428
|
-
constructor(document, quote) {
|
|
429
|
-
this.starts = [];
|
|
430
|
-
this.lengths = [];
|
|
431
|
-
let position = document.indexOf(quote);
|
|
432
|
-
while (position !== -1) {
|
|
433
|
-
const length = runLength(document, position, quote);
|
|
434
|
-
this.starts.push(position);
|
|
435
|
-
this.lengths.push(length);
|
|
436
|
-
position = document.indexOf(quote, position + length);
|
|
437
|
-
}
|
|
438
|
-
this.count = this.starts.length;
|
|
439
|
-
this.nextLonger = new Array(this.count);
|
|
440
|
-
const longer = [];
|
|
441
|
-
for (let run = this.count - 1;run >= 0; run--) {
|
|
442
|
-
while (longer.length > 0 && this.lengths[longer[longer.length - 1]] <= this.lengths[run]) {
|
|
443
|
-
longer.pop();
|
|
444
|
-
}
|
|
445
|
-
this.nextLonger[run] = longer.length > 0 ? longer[longer.length - 1] : this.count;
|
|
446
|
-
longer.push(run);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
end(run) {
|
|
450
|
-
return this.starts[run] + this.lengths[run];
|
|
451
|
-
}
|
|
452
|
-
indexOf(position) {
|
|
453
|
-
let low = 0;
|
|
454
|
-
let high = this.count - 1;
|
|
455
|
-
while (low < high) {
|
|
456
|
-
const middle = low + high + 1 >> 1;
|
|
457
|
-
if (this.starts[middle] <= position) {
|
|
458
|
-
low = middle;
|
|
459
|
-
} else {
|
|
460
|
-
high = middle - 1;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return low;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
function isSubstantiveBody(content) {
|
|
467
|
-
let depth = 0;
|
|
468
|
-
let hasVisible = false;
|
|
469
|
-
for (const character of content) {
|
|
470
|
-
if (character === "(") {
|
|
471
|
-
depth++;
|
|
472
|
-
} else if (character === ")") {
|
|
473
|
-
depth--;
|
|
474
|
-
if (depth < 0) {
|
|
475
|
-
return false;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
if (!/[ \t\n\r]/.test(character)) {
|
|
479
|
-
hasVisible = true;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return hasVisible && depth === 0;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
567
|
// src/comments.js
|
|
486
568
|
var COMMENT = "#";
|
|
487
569
|
var BEFORE_REFERENCE = [" ", "\t", `
|
|
@@ -631,14 +713,19 @@ function peg$parse(input, options) {
|
|
|
631
713
|
const peg$c0 = "(";
|
|
632
714
|
const peg$c1 = ")";
|
|
633
715
|
const peg$c2 = ":";
|
|
634
|
-
const peg$c3 =
|
|
635
|
-
const peg$c4 = "
|
|
636
|
-
const peg$c5 = "
|
|
637
|
-
const peg$c6 = "
|
|
716
|
+
const peg$c3 = "~";
|
|
717
|
+
const peg$c4 = "{";
|
|
718
|
+
const peg$c5 = "}";
|
|
719
|
+
const peg$c6 = '"';
|
|
720
|
+
const peg$c7 = "'";
|
|
721
|
+
const peg$c8 = "`";
|
|
722
|
+
const peg$c9 = " ";
|
|
638
723
|
const peg$r0 = /^[ \t]/;
|
|
639
724
|
const peg$r1 = /^[\r\n]/;
|
|
640
|
-
const peg$r2 = /^[
|
|
641
|
-
const peg$r3 = /^[^ \t\n
|
|
725
|
+
const peg$r2 = /^[0-9]/;
|
|
726
|
+
const peg$r3 = /^[^} \t\r\n()]/;
|
|
727
|
+
const peg$r4 = /^[ \t\n\r]/;
|
|
728
|
+
const peg$r5 = /^[^ \t\n\r(:)]/;
|
|
642
729
|
const peg$e0 = peg$classExpectation([" ", "\t"], false, false, false);
|
|
643
730
|
const peg$e1 = peg$classExpectation(["\r", `
|
|
644
731
|
`], false, false, false);
|
|
@@ -646,13 +733,19 @@ function peg$parse(input, options) {
|
|
|
646
733
|
const peg$e3 = peg$literalExpectation("(", false);
|
|
647
734
|
const peg$e4 = peg$literalExpectation(")", false);
|
|
648
735
|
const peg$e5 = peg$literalExpectation(":", false);
|
|
649
|
-
const peg$e6 = peg$literalExpectation(
|
|
650
|
-
const peg$e7 = peg$
|
|
651
|
-
const peg$e8 = peg$literalExpectation("
|
|
652
|
-
const peg$e9 = peg$
|
|
653
|
-
|
|
736
|
+
const peg$e6 = peg$literalExpectation("~", false);
|
|
737
|
+
const peg$e7 = peg$classExpectation([["0", "9"]], false, false, false);
|
|
738
|
+
const peg$e8 = peg$literalExpectation("{", false);
|
|
739
|
+
const peg$e9 = peg$classExpectation(["}", " ", "\t", "\r", `
|
|
740
|
+
`, "(", ")"], true, false, false);
|
|
741
|
+
const peg$e10 = peg$literalExpectation("}", false);
|
|
742
|
+
const peg$e11 = peg$literalExpectation('"', false);
|
|
743
|
+
const peg$e12 = peg$literalExpectation("'", false);
|
|
744
|
+
const peg$e13 = peg$literalExpectation("`", false);
|
|
745
|
+
const peg$e14 = peg$literalExpectation(" ", false);
|
|
746
|
+
const peg$e15 = peg$classExpectation([" ", "\t", `
|
|
654
747
|
`, "\r"], false, false, false);
|
|
655
|
-
const peg$
|
|
748
|
+
const peg$e16 = peg$classExpectation([" ", "\t", `
|
|
656
749
|
`, "\r", "(", ":", ")"], true, false, false);
|
|
657
750
|
function peg$f0() {
|
|
658
751
|
return resetState();
|
|
@@ -749,10 +842,19 @@ function peg$parse(input, options) {
|
|
|
749
842
|
function peg$f28(id) {
|
|
750
843
|
return { id, values: [] };
|
|
751
844
|
}
|
|
752
|
-
function peg$f29(
|
|
845
|
+
function peg$f29() {
|
|
846
|
+
return hasReferenceLiteralPrefix(input, offset());
|
|
847
|
+
}
|
|
848
|
+
function peg$f30(literal) {
|
|
849
|
+
return decodeReferenceLiteral(literal);
|
|
850
|
+
}
|
|
851
|
+
function peg$f31() {
|
|
852
|
+
return !hasReferenceLiteralPrefix(input, offset());
|
|
853
|
+
}
|
|
854
|
+
function peg$f32(chars) {
|
|
753
855
|
return chars.join("");
|
|
754
856
|
}
|
|
755
|
-
function peg$
|
|
857
|
+
function peg$f33() {
|
|
756
858
|
const pos = offset();
|
|
757
859
|
const result = parseQuotedStringAt(input, pos, '"');
|
|
758
860
|
if (result) {
|
|
@@ -762,19 +864,19 @@ function peg$parse(input, options) {
|
|
|
762
864
|
}
|
|
763
865
|
return false;
|
|
764
866
|
}
|
|
765
|
-
function peg$
|
|
867
|
+
function peg$f34(chars) {
|
|
766
868
|
return parsedValue;
|
|
767
869
|
}
|
|
768
|
-
function peg$
|
|
870
|
+
function peg$f35(c, cs) {
|
|
769
871
|
return [c].concat(cs).join("");
|
|
770
872
|
}
|
|
771
|
-
function peg$
|
|
873
|
+
function peg$f36() {
|
|
772
874
|
return parsedLength > 1 && (parsedLength--, true);
|
|
773
875
|
}
|
|
774
|
-
function peg$
|
|
876
|
+
function peg$f37(c) {
|
|
775
877
|
return c;
|
|
776
878
|
}
|
|
777
|
-
function peg$
|
|
879
|
+
function peg$f38() {
|
|
778
880
|
const pos = offset();
|
|
779
881
|
const result = parseQuotedStringAt(input, pos, "'");
|
|
780
882
|
if (result) {
|
|
@@ -784,19 +886,19 @@ function peg$parse(input, options) {
|
|
|
784
886
|
}
|
|
785
887
|
return false;
|
|
786
888
|
}
|
|
787
|
-
function peg$
|
|
889
|
+
function peg$f39(chars) {
|
|
788
890
|
return parsedValue;
|
|
789
891
|
}
|
|
790
|
-
function peg$
|
|
892
|
+
function peg$f40(c, cs) {
|
|
791
893
|
return [c].concat(cs).join("");
|
|
792
894
|
}
|
|
793
|
-
function peg$
|
|
895
|
+
function peg$f41() {
|
|
794
896
|
return parsedLength > 1 && (parsedLength--, true);
|
|
795
897
|
}
|
|
796
|
-
function peg$
|
|
898
|
+
function peg$f42(c) {
|
|
797
899
|
return c;
|
|
798
900
|
}
|
|
799
|
-
function peg$
|
|
901
|
+
function peg$f43() {
|
|
800
902
|
const pos = offset();
|
|
801
903
|
const result = parseQuotedStringAt(input, pos, "`");
|
|
802
904
|
if (result) {
|
|
@@ -806,34 +908,34 @@ function peg$parse(input, options) {
|
|
|
806
908
|
}
|
|
807
909
|
return false;
|
|
808
910
|
}
|
|
809
|
-
function peg$
|
|
911
|
+
function peg$f44(chars) {
|
|
810
912
|
return parsedValue;
|
|
811
913
|
}
|
|
812
|
-
function peg$
|
|
914
|
+
function peg$f45(c, cs) {
|
|
813
915
|
return [c].concat(cs).join("");
|
|
814
916
|
}
|
|
815
|
-
function peg$
|
|
917
|
+
function peg$f46() {
|
|
816
918
|
return parsedLength > 1 && (parsedLength--, true);
|
|
817
919
|
}
|
|
818
|
-
function peg$
|
|
920
|
+
function peg$f47(c) {
|
|
819
921
|
return c;
|
|
820
922
|
}
|
|
821
|
-
function peg$
|
|
923
|
+
function peg$f48() {
|
|
822
924
|
return indentationStack.slice();
|
|
823
925
|
}
|
|
824
|
-
function peg$
|
|
926
|
+
function peg$f49(spaces) {
|
|
825
927
|
setBaseIndentation(spaces);
|
|
826
928
|
}
|
|
827
|
-
function peg$
|
|
929
|
+
function peg$f50(spaces) {
|
|
828
930
|
return normalizeIndentation(spaces) > getCurrentIndentation();
|
|
829
931
|
}
|
|
830
|
-
function peg$
|
|
932
|
+
function peg$f51(spaces) {
|
|
831
933
|
pushIndentation(spaces);
|
|
832
934
|
}
|
|
833
|
-
function peg$
|
|
935
|
+
function peg$f52(spaces) {
|
|
834
936
|
return checkIndentation(spaces);
|
|
835
937
|
}
|
|
836
|
-
function peg$
|
|
938
|
+
function peg$f53() {
|
|
837
939
|
return isInsideNestedContext();
|
|
838
940
|
}
|
|
839
941
|
let peg$currPos = options.peg$currPos | 0;
|
|
@@ -1680,30 +1782,198 @@ function peg$parse(input, options) {
|
|
|
1680
1782
|
}
|
|
1681
1783
|
function peg$parsereference() {
|
|
1682
1784
|
let s0;
|
|
1683
|
-
s0 = peg$
|
|
1785
|
+
s0 = peg$parsereferenceLiteral();
|
|
1684
1786
|
if (s0 === peg$FAILED) {
|
|
1685
|
-
s0 = peg$
|
|
1787
|
+
s0 = peg$parsequotedReference();
|
|
1788
|
+
if (s0 === peg$FAILED) {
|
|
1789
|
+
s0 = peg$parsesimpleReference();
|
|
1790
|
+
}
|
|
1686
1791
|
}
|
|
1687
1792
|
return s0;
|
|
1688
1793
|
}
|
|
1689
|
-
function peg$
|
|
1690
|
-
let s0, s1, s2;
|
|
1794
|
+
function peg$parsereferenceLiteral() {
|
|
1795
|
+
let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
|
|
1691
1796
|
s0 = peg$currPos;
|
|
1692
|
-
s1 =
|
|
1693
|
-
|
|
1797
|
+
s1 = peg$currPos;
|
|
1798
|
+
peg$silentFails++;
|
|
1799
|
+
if (input.charCodeAt(peg$currPos) === 126) {
|
|
1800
|
+
s2 = peg$c3;
|
|
1801
|
+
peg$currPos++;
|
|
1802
|
+
} else {
|
|
1803
|
+
s2 = peg$FAILED;
|
|
1804
|
+
if (peg$silentFails === 0) {
|
|
1805
|
+
peg$fail(peg$e6);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
peg$silentFails--;
|
|
1694
1809
|
if (s2 !== peg$FAILED) {
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1810
|
+
peg$currPos = s1;
|
|
1811
|
+
s1 = undefined;
|
|
1812
|
+
} else {
|
|
1813
|
+
s1 = peg$FAILED;
|
|
1814
|
+
}
|
|
1815
|
+
if (s1 !== peg$FAILED) {
|
|
1816
|
+
peg$savedPos = peg$currPos;
|
|
1817
|
+
s2 = peg$f29();
|
|
1818
|
+
if (s2) {
|
|
1819
|
+
s2 = undefined;
|
|
1820
|
+
} else {
|
|
1821
|
+
s2 = peg$FAILED;
|
|
1822
|
+
}
|
|
1823
|
+
if (s2 !== peg$FAILED) {
|
|
1824
|
+
s3 = peg$currPos;
|
|
1825
|
+
s4 = peg$currPos;
|
|
1826
|
+
if (input.charCodeAt(peg$currPos) === 126) {
|
|
1827
|
+
s5 = peg$c3;
|
|
1828
|
+
peg$currPos++;
|
|
1829
|
+
} else {
|
|
1830
|
+
s5 = peg$FAILED;
|
|
1831
|
+
if (peg$silentFails === 0) {
|
|
1832
|
+
peg$fail(peg$e6);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
if (s5 !== peg$FAILED) {
|
|
1836
|
+
s6 = [];
|
|
1837
|
+
s7 = input.charAt(peg$currPos);
|
|
1838
|
+
if (peg$r2.test(s7)) {
|
|
1839
|
+
peg$currPos++;
|
|
1840
|
+
} else {
|
|
1841
|
+
s7 = peg$FAILED;
|
|
1842
|
+
if (peg$silentFails === 0) {
|
|
1843
|
+
peg$fail(peg$e7);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
if (s7 !== peg$FAILED) {
|
|
1847
|
+
while (s7 !== peg$FAILED) {
|
|
1848
|
+
s6.push(s7);
|
|
1849
|
+
s7 = input.charAt(peg$currPos);
|
|
1850
|
+
if (peg$r2.test(s7)) {
|
|
1851
|
+
peg$currPos++;
|
|
1852
|
+
} else {
|
|
1853
|
+
s7 = peg$FAILED;
|
|
1854
|
+
if (peg$silentFails === 0) {
|
|
1855
|
+
peg$fail(peg$e7);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
} else {
|
|
1860
|
+
s6 = peg$FAILED;
|
|
1861
|
+
}
|
|
1862
|
+
if (s6 !== peg$FAILED) {
|
|
1863
|
+
if (input.charCodeAt(peg$currPos) === 123) {
|
|
1864
|
+
s7 = peg$c4;
|
|
1865
|
+
peg$currPos++;
|
|
1866
|
+
} else {
|
|
1867
|
+
s7 = peg$FAILED;
|
|
1868
|
+
if (peg$silentFails === 0) {
|
|
1869
|
+
peg$fail(peg$e8);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
if (s7 !== peg$FAILED) {
|
|
1873
|
+
s8 = [];
|
|
1874
|
+
s9 = input.charAt(peg$currPos);
|
|
1875
|
+
if (peg$r3.test(s9)) {
|
|
1876
|
+
peg$currPos++;
|
|
1877
|
+
} else {
|
|
1878
|
+
s9 = peg$FAILED;
|
|
1879
|
+
if (peg$silentFails === 0) {
|
|
1880
|
+
peg$fail(peg$e9);
|
|
1881
|
+
}
|
|
1882
|
+
}
|
|
1883
|
+
while (s9 !== peg$FAILED) {
|
|
1884
|
+
s8.push(s9);
|
|
1885
|
+
s9 = input.charAt(peg$currPos);
|
|
1886
|
+
if (peg$r3.test(s9)) {
|
|
1887
|
+
peg$currPos++;
|
|
1888
|
+
} else {
|
|
1889
|
+
s9 = peg$FAILED;
|
|
1890
|
+
if (peg$silentFails === 0) {
|
|
1891
|
+
peg$fail(peg$e9);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
if (input.charCodeAt(peg$currPos) === 125) {
|
|
1896
|
+
s9 = peg$c5;
|
|
1897
|
+
peg$currPos++;
|
|
1898
|
+
} else {
|
|
1899
|
+
s9 = peg$FAILED;
|
|
1900
|
+
if (peg$silentFails === 0) {
|
|
1901
|
+
peg$fail(peg$e10);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
if (s9 !== peg$FAILED) {
|
|
1905
|
+
s5 = [s5, s6, s7, s8, s9];
|
|
1906
|
+
s4 = s5;
|
|
1907
|
+
} else {
|
|
1908
|
+
peg$currPos = s4;
|
|
1909
|
+
s4 = peg$FAILED;
|
|
1910
|
+
}
|
|
1911
|
+
} else {
|
|
1912
|
+
peg$currPos = s4;
|
|
1913
|
+
s4 = peg$FAILED;
|
|
1914
|
+
}
|
|
1915
|
+
} else {
|
|
1916
|
+
peg$currPos = s4;
|
|
1917
|
+
s4 = peg$FAILED;
|
|
1918
|
+
}
|
|
1919
|
+
} else {
|
|
1920
|
+
peg$currPos = s4;
|
|
1921
|
+
s4 = peg$FAILED;
|
|
1922
|
+
}
|
|
1923
|
+
if (s4 !== peg$FAILED) {
|
|
1924
|
+
s3 = input.substring(s3, peg$currPos);
|
|
1925
|
+
} else {
|
|
1926
|
+
s3 = s4;
|
|
1927
|
+
}
|
|
1928
|
+
if (s3 !== peg$FAILED) {
|
|
1929
|
+
peg$savedPos = s0;
|
|
1930
|
+
s0 = peg$f30(s3);
|
|
1931
|
+
} else {
|
|
1932
|
+
peg$currPos = s0;
|
|
1933
|
+
s0 = peg$FAILED;
|
|
1934
|
+
}
|
|
1935
|
+
} else {
|
|
1936
|
+
peg$currPos = s0;
|
|
1937
|
+
s0 = peg$FAILED;
|
|
1698
1938
|
}
|
|
1939
|
+
} else {
|
|
1940
|
+
peg$currPos = s0;
|
|
1941
|
+
s0 = peg$FAILED;
|
|
1942
|
+
}
|
|
1943
|
+
return s0;
|
|
1944
|
+
}
|
|
1945
|
+
function peg$parsesimpleReference() {
|
|
1946
|
+
let s0, s1, s2, s3;
|
|
1947
|
+
s0 = peg$currPos;
|
|
1948
|
+
peg$savedPos = peg$currPos;
|
|
1949
|
+
s1 = peg$f31();
|
|
1950
|
+
if (s1) {
|
|
1951
|
+
s1 = undefined;
|
|
1699
1952
|
} else {
|
|
1700
1953
|
s1 = peg$FAILED;
|
|
1701
1954
|
}
|
|
1702
1955
|
if (s1 !== peg$FAILED) {
|
|
1703
|
-
|
|
1704
|
-
|
|
1956
|
+
s2 = [];
|
|
1957
|
+
s3 = peg$parsereferenceSymbol();
|
|
1958
|
+
if (s3 !== peg$FAILED) {
|
|
1959
|
+
while (s3 !== peg$FAILED) {
|
|
1960
|
+
s2.push(s3);
|
|
1961
|
+
s3 = peg$parsereferenceSymbol();
|
|
1962
|
+
}
|
|
1963
|
+
} else {
|
|
1964
|
+
s2 = peg$FAILED;
|
|
1965
|
+
}
|
|
1966
|
+
if (s2 !== peg$FAILED) {
|
|
1967
|
+
peg$savedPos = s0;
|
|
1968
|
+
s0 = peg$f32(s2);
|
|
1969
|
+
} else {
|
|
1970
|
+
peg$currPos = s0;
|
|
1971
|
+
s0 = peg$FAILED;
|
|
1972
|
+
}
|
|
1973
|
+
} else {
|
|
1974
|
+
peg$currPos = s0;
|
|
1975
|
+
s0 = peg$FAILED;
|
|
1705
1976
|
}
|
|
1706
|
-
s0 = s1;
|
|
1707
1977
|
return s0;
|
|
1708
1978
|
}
|
|
1709
1979
|
function peg$parsequotedReference() {
|
|
@@ -1723,12 +1993,12 @@ function peg$parse(input, options) {
|
|
|
1723
1993
|
s1 = peg$currPos;
|
|
1724
1994
|
peg$silentFails++;
|
|
1725
1995
|
if (input.charCodeAt(peg$currPos) === 34) {
|
|
1726
|
-
s2 = peg$
|
|
1996
|
+
s2 = peg$c6;
|
|
1727
1997
|
peg$currPos++;
|
|
1728
1998
|
} else {
|
|
1729
1999
|
s2 = peg$FAILED;
|
|
1730
2000
|
if (peg$silentFails === 0) {
|
|
1731
|
-
peg$fail(peg$
|
|
2001
|
+
peg$fail(peg$e11);
|
|
1732
2002
|
}
|
|
1733
2003
|
}
|
|
1734
2004
|
peg$silentFails--;
|
|
@@ -1740,7 +2010,7 @@ function peg$parse(input, options) {
|
|
|
1740
2010
|
}
|
|
1741
2011
|
if (s1 !== peg$FAILED) {
|
|
1742
2012
|
peg$savedPos = peg$currPos;
|
|
1743
|
-
s2 = peg$
|
|
2013
|
+
s2 = peg$f33();
|
|
1744
2014
|
if (s2) {
|
|
1745
2015
|
s2 = undefined;
|
|
1746
2016
|
} else {
|
|
@@ -1750,7 +2020,7 @@ function peg$parse(input, options) {
|
|
|
1750
2020
|
s3 = peg$parseconsumeDouble();
|
|
1751
2021
|
if (s3 !== peg$FAILED) {
|
|
1752
2022
|
peg$savedPos = s0;
|
|
1753
|
-
s0 = peg$
|
|
2023
|
+
s0 = peg$f34(s3);
|
|
1754
2024
|
} else {
|
|
1755
2025
|
peg$currPos = s0;
|
|
1756
2026
|
s0 = peg$FAILED;
|
|
@@ -1785,7 +2055,7 @@ function peg$parse(input, options) {
|
|
|
1785
2055
|
s3 = peg$parseconsumeDoubleMore();
|
|
1786
2056
|
}
|
|
1787
2057
|
peg$savedPos = s0;
|
|
1788
|
-
s0 = peg$
|
|
2058
|
+
s0 = peg$f35(s1, s2);
|
|
1789
2059
|
} else {
|
|
1790
2060
|
peg$currPos = s0;
|
|
1791
2061
|
s0 = peg$FAILED;
|
|
@@ -1796,7 +2066,7 @@ function peg$parse(input, options) {
|
|
|
1796
2066
|
let s0, s1, s2;
|
|
1797
2067
|
s0 = peg$currPos;
|
|
1798
2068
|
peg$savedPos = peg$currPos;
|
|
1799
|
-
s1 = peg$
|
|
2069
|
+
s1 = peg$f36();
|
|
1800
2070
|
if (s1) {
|
|
1801
2071
|
s1 = undefined;
|
|
1802
2072
|
} else {
|
|
@@ -1814,7 +2084,7 @@ function peg$parse(input, options) {
|
|
|
1814
2084
|
}
|
|
1815
2085
|
if (s2 !== peg$FAILED) {
|
|
1816
2086
|
peg$savedPos = s0;
|
|
1817
|
-
s0 = peg$
|
|
2087
|
+
s0 = peg$f37(s2);
|
|
1818
2088
|
} else {
|
|
1819
2089
|
peg$currPos = s0;
|
|
1820
2090
|
s0 = peg$FAILED;
|
|
@@ -1831,12 +2101,12 @@ function peg$parse(input, options) {
|
|
|
1831
2101
|
s1 = peg$currPos;
|
|
1832
2102
|
peg$silentFails++;
|
|
1833
2103
|
if (input.charCodeAt(peg$currPos) === 39) {
|
|
1834
|
-
s2 = peg$
|
|
2104
|
+
s2 = peg$c7;
|
|
1835
2105
|
peg$currPos++;
|
|
1836
2106
|
} else {
|
|
1837
2107
|
s2 = peg$FAILED;
|
|
1838
2108
|
if (peg$silentFails === 0) {
|
|
1839
|
-
peg$fail(peg$
|
|
2109
|
+
peg$fail(peg$e12);
|
|
1840
2110
|
}
|
|
1841
2111
|
}
|
|
1842
2112
|
peg$silentFails--;
|
|
@@ -1848,7 +2118,7 @@ function peg$parse(input, options) {
|
|
|
1848
2118
|
}
|
|
1849
2119
|
if (s1 !== peg$FAILED) {
|
|
1850
2120
|
peg$savedPos = peg$currPos;
|
|
1851
|
-
s2 = peg$
|
|
2121
|
+
s2 = peg$f38();
|
|
1852
2122
|
if (s2) {
|
|
1853
2123
|
s2 = undefined;
|
|
1854
2124
|
} else {
|
|
@@ -1858,7 +2128,7 @@ function peg$parse(input, options) {
|
|
|
1858
2128
|
s3 = peg$parseconsumeSingle();
|
|
1859
2129
|
if (s3 !== peg$FAILED) {
|
|
1860
2130
|
peg$savedPos = s0;
|
|
1861
|
-
s0 = peg$
|
|
2131
|
+
s0 = peg$f39(s3);
|
|
1862
2132
|
} else {
|
|
1863
2133
|
peg$currPos = s0;
|
|
1864
2134
|
s0 = peg$FAILED;
|
|
@@ -1893,7 +2163,7 @@ function peg$parse(input, options) {
|
|
|
1893
2163
|
s3 = peg$parseconsumeSingleMore();
|
|
1894
2164
|
}
|
|
1895
2165
|
peg$savedPos = s0;
|
|
1896
|
-
s0 = peg$
|
|
2166
|
+
s0 = peg$f40(s1, s2);
|
|
1897
2167
|
} else {
|
|
1898
2168
|
peg$currPos = s0;
|
|
1899
2169
|
s0 = peg$FAILED;
|
|
@@ -1904,7 +2174,7 @@ function peg$parse(input, options) {
|
|
|
1904
2174
|
let s0, s1, s2;
|
|
1905
2175
|
s0 = peg$currPos;
|
|
1906
2176
|
peg$savedPos = peg$currPos;
|
|
1907
|
-
s1 = peg$
|
|
2177
|
+
s1 = peg$f41();
|
|
1908
2178
|
if (s1) {
|
|
1909
2179
|
s1 = undefined;
|
|
1910
2180
|
} else {
|
|
@@ -1922,7 +2192,7 @@ function peg$parse(input, options) {
|
|
|
1922
2192
|
}
|
|
1923
2193
|
if (s2 !== peg$FAILED) {
|
|
1924
2194
|
peg$savedPos = s0;
|
|
1925
|
-
s0 = peg$
|
|
2195
|
+
s0 = peg$f42(s2);
|
|
1926
2196
|
} else {
|
|
1927
2197
|
peg$currPos = s0;
|
|
1928
2198
|
s0 = peg$FAILED;
|
|
@@ -1939,12 +2209,12 @@ function peg$parse(input, options) {
|
|
|
1939
2209
|
s1 = peg$currPos;
|
|
1940
2210
|
peg$silentFails++;
|
|
1941
2211
|
if (input.charCodeAt(peg$currPos) === 96) {
|
|
1942
|
-
s2 = peg$
|
|
2212
|
+
s2 = peg$c8;
|
|
1943
2213
|
peg$currPos++;
|
|
1944
2214
|
} else {
|
|
1945
2215
|
s2 = peg$FAILED;
|
|
1946
2216
|
if (peg$silentFails === 0) {
|
|
1947
|
-
peg$fail(peg$
|
|
2217
|
+
peg$fail(peg$e13);
|
|
1948
2218
|
}
|
|
1949
2219
|
}
|
|
1950
2220
|
peg$silentFails--;
|
|
@@ -1956,7 +2226,7 @@ function peg$parse(input, options) {
|
|
|
1956
2226
|
}
|
|
1957
2227
|
if (s1 !== peg$FAILED) {
|
|
1958
2228
|
peg$savedPos = peg$currPos;
|
|
1959
|
-
s2 = peg$
|
|
2229
|
+
s2 = peg$f43();
|
|
1960
2230
|
if (s2) {
|
|
1961
2231
|
s2 = undefined;
|
|
1962
2232
|
} else {
|
|
@@ -1966,7 +2236,7 @@ function peg$parse(input, options) {
|
|
|
1966
2236
|
s3 = peg$parseconsumeBacktick();
|
|
1967
2237
|
if (s3 !== peg$FAILED) {
|
|
1968
2238
|
peg$savedPos = s0;
|
|
1969
|
-
s0 = peg$
|
|
2239
|
+
s0 = peg$f44(s3);
|
|
1970
2240
|
} else {
|
|
1971
2241
|
peg$currPos = s0;
|
|
1972
2242
|
s0 = peg$FAILED;
|
|
@@ -2001,7 +2271,7 @@ function peg$parse(input, options) {
|
|
|
2001
2271
|
s3 = peg$parseconsumeBacktickMore();
|
|
2002
2272
|
}
|
|
2003
2273
|
peg$savedPos = s0;
|
|
2004
|
-
s0 = peg$
|
|
2274
|
+
s0 = peg$f45(s1, s2);
|
|
2005
2275
|
} else {
|
|
2006
2276
|
peg$currPos = s0;
|
|
2007
2277
|
s0 = peg$FAILED;
|
|
@@ -2012,7 +2282,7 @@ function peg$parse(input, options) {
|
|
|
2012
2282
|
let s0, s1, s2;
|
|
2013
2283
|
s0 = peg$currPos;
|
|
2014
2284
|
peg$savedPos = peg$currPos;
|
|
2015
|
-
s1 = peg$
|
|
2285
|
+
s1 = peg$f46();
|
|
2016
2286
|
if (s1) {
|
|
2017
2287
|
s1 = undefined;
|
|
2018
2288
|
} else {
|
|
@@ -2030,7 +2300,7 @@ function peg$parse(input, options) {
|
|
|
2030
2300
|
}
|
|
2031
2301
|
if (s2 !== peg$FAILED) {
|
|
2032
2302
|
peg$savedPos = s0;
|
|
2033
|
-
s0 = peg$
|
|
2303
|
+
s0 = peg$f47(s2);
|
|
2034
2304
|
} else {
|
|
2035
2305
|
peg$currPos = s0;
|
|
2036
2306
|
s0 = peg$FAILED;
|
|
@@ -2046,7 +2316,7 @@ function peg$parse(input, options) {
|
|
|
2046
2316
|
s0 = peg$currPos;
|
|
2047
2317
|
s1 = "";
|
|
2048
2318
|
peg$savedPos = s0;
|
|
2049
|
-
s1 = peg$
|
|
2319
|
+
s1 = peg$f48();
|
|
2050
2320
|
s0 = s1;
|
|
2051
2321
|
return s0;
|
|
2052
2322
|
}
|
|
@@ -2055,28 +2325,28 @@ function peg$parse(input, options) {
|
|
|
2055
2325
|
s0 = peg$currPos;
|
|
2056
2326
|
s1 = [];
|
|
2057
2327
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2058
|
-
s2 = peg$
|
|
2328
|
+
s2 = peg$c9;
|
|
2059
2329
|
peg$currPos++;
|
|
2060
2330
|
} else {
|
|
2061
2331
|
s2 = peg$FAILED;
|
|
2062
2332
|
if (peg$silentFails === 0) {
|
|
2063
|
-
peg$fail(peg$
|
|
2333
|
+
peg$fail(peg$e14);
|
|
2064
2334
|
}
|
|
2065
2335
|
}
|
|
2066
2336
|
while (s2 !== peg$FAILED) {
|
|
2067
2337
|
s1.push(s2);
|
|
2068
2338
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2069
|
-
s2 = peg$
|
|
2339
|
+
s2 = peg$c9;
|
|
2070
2340
|
peg$currPos++;
|
|
2071
2341
|
} else {
|
|
2072
2342
|
s2 = peg$FAILED;
|
|
2073
2343
|
if (peg$silentFails === 0) {
|
|
2074
|
-
peg$fail(peg$
|
|
2344
|
+
peg$fail(peg$e14);
|
|
2075
2345
|
}
|
|
2076
2346
|
}
|
|
2077
2347
|
}
|
|
2078
2348
|
peg$savedPos = s0;
|
|
2079
|
-
s1 = peg$
|
|
2349
|
+
s1 = peg$f49(s1);
|
|
2080
2350
|
s0 = s1;
|
|
2081
2351
|
return s0;
|
|
2082
2352
|
}
|
|
@@ -2085,28 +2355,28 @@ function peg$parse(input, options) {
|
|
|
2085
2355
|
s0 = peg$currPos;
|
|
2086
2356
|
s1 = [];
|
|
2087
2357
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2088
|
-
s2 = peg$
|
|
2358
|
+
s2 = peg$c9;
|
|
2089
2359
|
peg$currPos++;
|
|
2090
2360
|
} else {
|
|
2091
2361
|
s2 = peg$FAILED;
|
|
2092
2362
|
if (peg$silentFails === 0) {
|
|
2093
|
-
peg$fail(peg$
|
|
2363
|
+
peg$fail(peg$e14);
|
|
2094
2364
|
}
|
|
2095
2365
|
}
|
|
2096
2366
|
while (s2 !== peg$FAILED) {
|
|
2097
2367
|
s1.push(s2);
|
|
2098
2368
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2099
|
-
s2 = peg$
|
|
2369
|
+
s2 = peg$c9;
|
|
2100
2370
|
peg$currPos++;
|
|
2101
2371
|
} else {
|
|
2102
2372
|
s2 = peg$FAILED;
|
|
2103
2373
|
if (peg$silentFails === 0) {
|
|
2104
|
-
peg$fail(peg$
|
|
2374
|
+
peg$fail(peg$e14);
|
|
2105
2375
|
}
|
|
2106
2376
|
}
|
|
2107
2377
|
}
|
|
2108
2378
|
peg$savedPos = peg$currPos;
|
|
2109
|
-
s2 = peg$
|
|
2379
|
+
s2 = peg$f50(s1);
|
|
2110
2380
|
if (s2) {
|
|
2111
2381
|
s2 = undefined;
|
|
2112
2382
|
} else {
|
|
@@ -2114,7 +2384,7 @@ function peg$parse(input, options) {
|
|
|
2114
2384
|
}
|
|
2115
2385
|
if (s2 !== peg$FAILED) {
|
|
2116
2386
|
peg$savedPos = s0;
|
|
2117
|
-
s0 = peg$
|
|
2387
|
+
s0 = peg$f51(s1);
|
|
2118
2388
|
} else {
|
|
2119
2389
|
peg$currPos = s0;
|
|
2120
2390
|
s0 = peg$FAILED;
|
|
@@ -2126,28 +2396,28 @@ function peg$parse(input, options) {
|
|
|
2126
2396
|
s0 = peg$currPos;
|
|
2127
2397
|
s1 = [];
|
|
2128
2398
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2129
|
-
s2 = peg$
|
|
2399
|
+
s2 = peg$c9;
|
|
2130
2400
|
peg$currPos++;
|
|
2131
2401
|
} else {
|
|
2132
2402
|
s2 = peg$FAILED;
|
|
2133
2403
|
if (peg$silentFails === 0) {
|
|
2134
|
-
peg$fail(peg$
|
|
2404
|
+
peg$fail(peg$e14);
|
|
2135
2405
|
}
|
|
2136
2406
|
}
|
|
2137
2407
|
while (s2 !== peg$FAILED) {
|
|
2138
2408
|
s1.push(s2);
|
|
2139
2409
|
if (input.charCodeAt(peg$currPos) === 32) {
|
|
2140
|
-
s2 = peg$
|
|
2410
|
+
s2 = peg$c9;
|
|
2141
2411
|
peg$currPos++;
|
|
2142
2412
|
} else {
|
|
2143
2413
|
s2 = peg$FAILED;
|
|
2144
2414
|
if (peg$silentFails === 0) {
|
|
2145
|
-
peg$fail(peg$
|
|
2415
|
+
peg$fail(peg$e14);
|
|
2146
2416
|
}
|
|
2147
2417
|
}
|
|
2148
2418
|
}
|
|
2149
2419
|
peg$savedPos = peg$currPos;
|
|
2150
|
-
s2 = peg$
|
|
2420
|
+
s2 = peg$f52(s1);
|
|
2151
2421
|
if (s2) {
|
|
2152
2422
|
s2 = undefined;
|
|
2153
2423
|
} else {
|
|
@@ -2358,7 +2628,7 @@ function peg$parse(input, options) {
|
|
|
2358
2628
|
let s0, s1, s2, s3;
|
|
2359
2629
|
s0 = peg$currPos;
|
|
2360
2630
|
peg$savedPos = peg$currPos;
|
|
2361
|
-
s1 = peg$
|
|
2631
|
+
s1 = peg$f53();
|
|
2362
2632
|
if (s1) {
|
|
2363
2633
|
s1 = undefined;
|
|
2364
2634
|
} else {
|
|
@@ -2457,12 +2727,12 @@ function peg$parse(input, options) {
|
|
|
2457
2727
|
function peg$parsewhiteSpaceSymbol() {
|
|
2458
2728
|
let s0;
|
|
2459
2729
|
s0 = input.charAt(peg$currPos);
|
|
2460
|
-
if (peg$
|
|
2730
|
+
if (peg$r4.test(s0)) {
|
|
2461
2731
|
peg$currPos++;
|
|
2462
2732
|
} else {
|
|
2463
2733
|
s0 = peg$FAILED;
|
|
2464
2734
|
if (peg$silentFails === 0) {
|
|
2465
|
-
peg$fail(peg$
|
|
2735
|
+
peg$fail(peg$e15);
|
|
2466
2736
|
}
|
|
2467
2737
|
}
|
|
2468
2738
|
return s0;
|
|
@@ -2470,12 +2740,12 @@ function peg$parse(input, options) {
|
|
|
2470
2740
|
function peg$parsereferenceSymbol() {
|
|
2471
2741
|
let s0;
|
|
2472
2742
|
s0 = input.charAt(peg$currPos);
|
|
2473
|
-
if (peg$
|
|
2743
|
+
if (peg$r5.test(s0)) {
|
|
2474
2744
|
peg$currPos++;
|
|
2475
2745
|
} else {
|
|
2476
2746
|
s0 = peg$FAILED;
|
|
2477
2747
|
if (peg$silentFails === 0) {
|
|
2478
|
-
peg$fail(peg$
|
|
2748
|
+
peg$fail(peg$e16);
|
|
2479
2749
|
}
|
|
2480
2750
|
}
|
|
2481
2751
|
return s0;
|
|
@@ -2602,6 +2872,15 @@ class Parser {
|
|
|
2602
2872
|
this.comments = options.comments ?? true;
|
|
2603
2873
|
}
|
|
2604
2874
|
parse(input) {
|
|
2875
|
+
return this._parse(input, (raw) => this.transformResult(raw));
|
|
2876
|
+
}
|
|
2877
|
+
parseGroups(input) {
|
|
2878
|
+
return this._parse(input, (raw) => raw.map((item) => this._transformGroup(item)));
|
|
2879
|
+
}
|
|
2880
|
+
_transformGroup(item) {
|
|
2881
|
+
return new LinksGroup(this.transformLink(item), (item.children || []).map((child) => this._transformGroup(child)));
|
|
2882
|
+
}
|
|
2883
|
+
_parse(input, transform) {
|
|
2605
2884
|
if (typeof input !== "string") {
|
|
2606
2885
|
throw new TypeError("Input must be a string");
|
|
2607
2886
|
}
|
|
@@ -2613,7 +2892,7 @@ class Parser {
|
|
|
2613
2892
|
const rawResult = peg$parse(prepared, {
|
|
2614
2893
|
maxDepth: this.maxDepth
|
|
2615
2894
|
});
|
|
2616
|
-
return
|
|
2895
|
+
return transform(rawResult);
|
|
2617
2896
|
} catch (error) {
|
|
2618
2897
|
if (error && error.location) {
|
|
2619
2898
|
throw new ParseError(input, error);
|
|
@@ -2735,6 +3014,64 @@ class Parser {
|
|
|
2735
3014
|
return new Link(item.id ?? null, []);
|
|
2736
3015
|
}
|
|
2737
3016
|
}
|
|
3017
|
+
|
|
3018
|
+
// src/IndentedDocument.js
|
|
3019
|
+
function lineText(link) {
|
|
3020
|
+
if (link.id !== null && link.values.length === 0)
|
|
3021
|
+
return link.id;
|
|
3022
|
+
if (link.id === null && link.values.length > 0 && link.values.every((value) => value.id !== null && value.values.length === 0)) {
|
|
3023
|
+
return link.values.map((value) => value.id).join(" ");
|
|
3024
|
+
}
|
|
3025
|
+
throw new TypeError("Indented document lines must contain only text references");
|
|
3026
|
+
}
|
|
3027
|
+
function parseIndentedDocument(input, options = {}) {
|
|
3028
|
+
const { multipleValues = "array" } = options;
|
|
3029
|
+
if (multipleValues !== "array" && multipleValues !== "join") {
|
|
3030
|
+
throw new TypeError('multipleValues must be "array" or "join"');
|
|
3031
|
+
}
|
|
3032
|
+
const groups = new Parser(options).parseGroups(input);
|
|
3033
|
+
const collected = new Map;
|
|
3034
|
+
for (const group of groups) {
|
|
3035
|
+
const parent = lineText(group.element);
|
|
3036
|
+
const values = collected.get(parent) ?? [];
|
|
3037
|
+
for (const child of group.children) {
|
|
3038
|
+
if (child.children.length > 0) {
|
|
3039
|
+
throw new TypeError("Indented documents support only immediate children");
|
|
3040
|
+
}
|
|
3041
|
+
values.push(lineText(child.element));
|
|
3042
|
+
}
|
|
3043
|
+
collected.set(parent, values);
|
|
3044
|
+
}
|
|
3045
|
+
return new Map([...collected].map(([parent, values]) => [
|
|
3046
|
+
parent,
|
|
3047
|
+
values.length === 1 ? values[0] : values.length > 1 && multipleValues === "join" ? values.join(`
|
|
3048
|
+
`) : values
|
|
3049
|
+
]));
|
|
3050
|
+
}
|
|
3051
|
+
function formatIndentedDocument(entries) {
|
|
3052
|
+
if (!(entries instanceof Map)) {
|
|
3053
|
+
throw new TypeError("Indented document entries must be a Map");
|
|
3054
|
+
}
|
|
3055
|
+
const lines = [];
|
|
3056
|
+
for (const [parent, value] of entries) {
|
|
3057
|
+
if (typeof parent !== "string") {
|
|
3058
|
+
throw new TypeError("Indented document parents must be strings");
|
|
3059
|
+
}
|
|
3060
|
+
const values = Array.isArray(value) ? value : [value];
|
|
3061
|
+
for (const child of values) {
|
|
3062
|
+
if (typeof child !== "string") {
|
|
3063
|
+
throw new TypeError("Indented document children must be strings");
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
lines.push(escapeReference(parent, { minimal: true }));
|
|
3067
|
+
for (const child of values) {
|
|
3068
|
+
lines.push(" " + escapeReference(child, { minimal: true }));
|
|
3069
|
+
}
|
|
3070
|
+
}
|
|
3071
|
+
return lines.length > 0 ? lines.join(`
|
|
3072
|
+
`) + `
|
|
3073
|
+
` : "";
|
|
3074
|
+
}
|
|
2738
3075
|
// src/StreamParser.js
|
|
2739
3076
|
import { EventEmitter } from "events";
|
|
2740
3077
|
var DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
@@ -3484,22 +3821,7 @@ function canonical(node) {
|
|
|
3484
3821
|
return new Link(node.id, node.values.map(canonical));
|
|
3485
3822
|
}
|
|
3486
3823
|
function formatBinaryReference(text) {
|
|
3487
|
-
|
|
3488
|
-
return text;
|
|
3489
|
-
let choice = null;
|
|
3490
|
-
for (const quote of ["'", '"', "`"])
|
|
3491
|
-
if (!text.startsWith(quote)) {
|
|
3492
|
-
let longest = 0, run = 0;
|
|
3493
|
-
for (const c of text) {
|
|
3494
|
-
run = c === quote ? run + 1 : 0;
|
|
3495
|
-
longest = Math.max(longest, run);
|
|
3496
|
-
}
|
|
3497
|
-
const count = longest + 1 | 1;
|
|
3498
|
-
if (choice === null || count < choice.count)
|
|
3499
|
-
choice = { quote, count };
|
|
3500
|
-
}
|
|
3501
|
-
const delimiter = choice.quote.repeat(choice.count);
|
|
3502
|
-
return delimiter + text + delimiter;
|
|
3824
|
+
return formatReference(text);
|
|
3503
3825
|
}
|
|
3504
3826
|
function formatBinaryDocument(document) {
|
|
3505
3827
|
function nested(node, top = false) {
|
|
@@ -3581,8 +3903,14 @@ export {
|
|
|
3581
3903
|
Section,
|
|
3582
3904
|
StreamParseError,
|
|
3583
3905
|
StreamParser,
|
|
3906
|
+
decodeReferenceLiteral,
|
|
3907
|
+
encodeReferenceLiteral,
|
|
3908
|
+
escapeReference,
|
|
3584
3909
|
formatBinaryDocument,
|
|
3585
3910
|
formatBinaryReference,
|
|
3911
|
+
formatIndentedDocument,
|
|
3586
3912
|
formatLinks,
|
|
3587
|
-
|
|
3913
|
+
parseIndentedDocument,
|
|
3914
|
+
stripComments,
|
|
3915
|
+
unescapeReference
|
|
3588
3916
|
};
|