wikipeg 4.0.2 → 6.0.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/HISTORY.md +556 -0
- package/README.md +230 -12
- package/VERSION +1 -1
- package/bin/wikipeg +8 -4
- package/examples/css.pegphp +9 -8
- package/lib/compiler/asts.js +30 -10
- package/lib/compiler/charsets.js +306 -0
- package/lib/compiler/language/javascript.js +107 -33
- package/lib/compiler/language/php.js +193 -55
- package/lib/compiler/passes/analyze-always-match.js +141 -0
- package/lib/compiler/passes/analyze-first.js +245 -0
- package/lib/compiler/passes/ast-to-code.js +316 -100
- package/lib/compiler/passes/inline-simple-rules.js +96 -0
- package/lib/compiler/passes/optimize-character-class.js +147 -0
- package/lib/compiler/passes/optimize-failure-reporting.js +65 -0
- package/lib/compiler/passes/remove-proxy-rules.js +7 -5
- package/lib/compiler/passes/report-infinite-loops.js +4 -1
- package/lib/compiler/passes/report-left-recursion.js +3 -4
- package/lib/compiler/passes/report-unknown-attributes.js +39 -0
- package/lib/compiler/passes/transform-common-lang.js +1 -1
- package/lib/compiler/traverser.js +1 -2
- package/lib/compiler/visitor.js +5 -7
- package/lib/compiler.js +24 -10
- package/lib/parser.js +2784 -3088
- package/lib/peg.js +7 -15
- package/lib/runtime/template.js +9 -1
- package/lib/utils/CaseFolding.txt +1654 -0
- package/lib/utils/arrays.js +0 -72
- package/lib/utils/casefold.js +697 -0
- package/lib/utils/objects.js +9 -39
- package/lib/utils/unicode.js +34 -0
- package/package.json +6 -4
- package/src/DefaultTracer.php +18 -18
- package/src/PEGParserBase.php +53 -28
- package/src/SyntaxError.php +4 -4
- package/src/Tracer.php +1 -1
- package/lib/compiler/opcodes.js +0 -54
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
module.exports = ( function () {
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
/*
|
|
5
|
+
* Generated by WikiPEG
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function peg$subclass(child, parent) {
|
|
11
|
+
function ctor() { this.constructor = child; }
|
|
12
|
+
ctor.prototype = parent.prototype;
|
|
13
|
+
child.prototype = new ctor();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function peg$SyntaxError(message, expected, found, location) {
|
|
17
|
+
this.message = message;
|
|
18
|
+
this.expected = expected;
|
|
19
|
+
this.found = found;
|
|
20
|
+
this.location = location;
|
|
21
|
+
|
|
22
|
+
this.name = "SyntaxError";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
peg$subclass(peg$SyntaxError, Error);
|
|
26
|
+
|
|
27
|
+
function peg$Reference(value) {
|
|
28
|
+
this.value = value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
peg$Reference.prototype = {
|
|
32
|
+
get: function() {
|
|
33
|
+
return this.value;
|
|
34
|
+
},
|
|
35
|
+
set: function(value) {
|
|
36
|
+
this.value = value;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
function peg$DefaultTracer() {
|
|
41
|
+
this.indentLevel = 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
peg$DefaultTracer.prototype.trace = function(event) {
|
|
45
|
+
var that = this;
|
|
46
|
+
|
|
47
|
+
function log(event) {
|
|
48
|
+
function repeat(string, n) {
|
|
49
|
+
var result = "", i;
|
|
50
|
+
|
|
51
|
+
for (i = 0; i < n; i++) {
|
|
52
|
+
result += string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function pad(string, length) {
|
|
59
|
+
return string + repeat(" ", length - string.length);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function formatArgs(argMap) {
|
|
63
|
+
var argParts = [];
|
|
64
|
+
for (let argName in argMap) {
|
|
65
|
+
if (argName === 'silence') {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (argName === 'boolParams') {
|
|
69
|
+
argParts.push('0x' + argMap[argName].toString(16));
|
|
70
|
+
} else {
|
|
71
|
+
let displayName = argName.replace(/^param_/, '');
|
|
72
|
+
if (typeof argMap[argName] === 'object' && argMap[argName].value !== undefined) {
|
|
73
|
+
argParts.push(displayName + "=&" + JSON.stringify(argMap[argName].value));
|
|
74
|
+
} else {
|
|
75
|
+
argParts.push(displayName + "=" + argMap[argName]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (argParts.length) {
|
|
80
|
+
return ' <' + argParts.join(', ') + '>';
|
|
81
|
+
} else {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log(
|
|
87
|
+
pad(
|
|
88
|
+
event.location.start.line + ":" + event.location.start.column + "-"
|
|
89
|
+
+ event.location.end.line + ":" + event.location.end.column + " ",
|
|
90
|
+
20
|
|
91
|
+
)
|
|
92
|
+
+ pad(event.type, 10) + " "
|
|
93
|
+
+ repeat(" ", that.indentLevel) + event.rule
|
|
94
|
+
+ formatArgs(event.args)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
switch (event.type) {
|
|
99
|
+
case "rule.enter":
|
|
100
|
+
log(event);
|
|
101
|
+
this.indentLevel++;
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case "rule.match":
|
|
105
|
+
this.indentLevel--;
|
|
106
|
+
log(event);
|
|
107
|
+
break;
|
|
108
|
+
|
|
109
|
+
case "rule.fail":
|
|
110
|
+
this.indentLevel--;
|
|
111
|
+
log(event);
|
|
112
|
+
break;
|
|
113
|
+
|
|
114
|
+
default:
|
|
115
|
+
throw new Error("Invalid event type: " + event.type + ".");
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function peg$parse(input, options = {}) {
|
|
120
|
+
var parser = this,
|
|
121
|
+
peg$currPos = 0,
|
|
122
|
+
peg$savedPos = 0,
|
|
123
|
+
peg$FAILED = {},
|
|
124
|
+
peg$startRule = options.startRule || '(DEFAULT)',
|
|
125
|
+
peg$result;
|
|
126
|
+
|
|
127
|
+
function text() {
|
|
128
|
+
return input.substring(peg$savedPos, peg$currPos);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function location() {
|
|
132
|
+
return peg$computeLocation(peg$savedPos, peg$currPos);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function expected(description) {
|
|
136
|
+
throw peg$buildException(
|
|
137
|
+
null,
|
|
138
|
+
[{ type: "other", description: description }],
|
|
139
|
+
input.substring(peg$savedPos, peg$currPos),
|
|
140
|
+
peg$computeLocation(peg$savedPos, peg$currPos)
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function error(message) {
|
|
145
|
+
throw peg$buildException(
|
|
146
|
+
message,
|
|
147
|
+
null,
|
|
148
|
+
input.substring(peg$savedPos, peg$currPos),
|
|
149
|
+
peg$computeLocation(peg$savedPos, peg$currPos)
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var peg$posDetailsCache = [{ line: 1, column: 1, seenCR: false }],
|
|
154
|
+
peg$maxFailPos = 0,
|
|
155
|
+
peg$maxFailExpected = [];
|
|
156
|
+
|
|
157
|
+
function peg$computePosDetails(pos) {
|
|
158
|
+
var details = peg$posDetailsCache[pos],
|
|
159
|
+
p, ch;
|
|
160
|
+
|
|
161
|
+
if (details) {
|
|
162
|
+
return details;
|
|
163
|
+
} else {
|
|
164
|
+
p = pos - 1;
|
|
165
|
+
while (!peg$posDetailsCache[p]) {
|
|
166
|
+
p--;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
details = peg$posDetailsCache[p];
|
|
170
|
+
details = {
|
|
171
|
+
line: details.line,
|
|
172
|
+
column: details.column,
|
|
173
|
+
seenCR: details.seenCR
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
while (p < pos) {
|
|
177
|
+
ch = input.charAt(p);
|
|
178
|
+
if (ch === "\n") {
|
|
179
|
+
if (!details.seenCR) { details.line++; }
|
|
180
|
+
details.column = 1;
|
|
181
|
+
details.seenCR = false;
|
|
182
|
+
} else if (ch === "\r" || ch === "\u2028" || ch === "\u2029") {
|
|
183
|
+
details.line++;
|
|
184
|
+
details.column = 1;
|
|
185
|
+
details.seenCR = true;
|
|
186
|
+
} else {
|
|
187
|
+
details.column++;
|
|
188
|
+
details.seenCR = false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
p++;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
peg$posDetailsCache[pos] = details;
|
|
195
|
+
return details;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function peg$computeLocation(startPos, endPos) {
|
|
200
|
+
if (endPos > input.length) {
|
|
201
|
+
endPos--;
|
|
202
|
+
}
|
|
203
|
+
var startPosDetails = peg$computePosDetails(startPos),
|
|
204
|
+
endPosDetails = peg$computePosDetails(endPos);
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
start: {
|
|
208
|
+
offset: startPos,
|
|
209
|
+
line: startPosDetails.line,
|
|
210
|
+
column: startPosDetails.column
|
|
211
|
+
},
|
|
212
|
+
end: {
|
|
213
|
+
offset: endPos,
|
|
214
|
+
line: endPosDetails.line,
|
|
215
|
+
column: endPosDetails.column
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function peg$fail(expected) {
|
|
221
|
+
if (peg$currPos < peg$maxFailPos) { return; }
|
|
222
|
+
|
|
223
|
+
if (peg$currPos > peg$maxFailPos) {
|
|
224
|
+
peg$maxFailPos = peg$currPos;
|
|
225
|
+
peg$maxFailExpected = [];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
peg$maxFailExpected.push(expected);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function peg$buildException(message, expected, found, location) {
|
|
232
|
+
function cleanupExpected(expected) {
|
|
233
|
+
var i = 1;
|
|
234
|
+
|
|
235
|
+
expected.sort(function(a, b) {
|
|
236
|
+
if (a.type < b.type) {
|
|
237
|
+
return -1;
|
|
238
|
+
} else if (a.type > b.type) {
|
|
239
|
+
return 1;
|
|
240
|
+
} else if (a.value < b.value) {
|
|
241
|
+
return -1;
|
|
242
|
+
} else if (a.value > b.value) {
|
|
243
|
+
return 1;
|
|
244
|
+
} else if (a.description < b.description) {
|
|
245
|
+
return -1;
|
|
246
|
+
} else if (a.description > b.description) {
|
|
247
|
+
return 1;
|
|
248
|
+
} else {
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
/*
|
|
254
|
+
* This works because the bytecode generator guarantees that every
|
|
255
|
+
* expectation object exists only once, so it's enough to use |===| instead
|
|
256
|
+
* of deeper structural comparison.
|
|
257
|
+
*/
|
|
258
|
+
while (i < expected.length) {
|
|
259
|
+
if (expected[i - 1] === expected[i]) {
|
|
260
|
+
expected.splice(i, 1);
|
|
261
|
+
} else {
|
|
262
|
+
i++;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function buildMessage(expected, found) {
|
|
268
|
+
function stringEscape(s) {
|
|
269
|
+
function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); }
|
|
270
|
+
|
|
271
|
+
/*
|
|
272
|
+
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string
|
|
273
|
+
* literal except for the closing quote character, backslash, carriage
|
|
274
|
+
* return, line separator, paragraph separator, and line feed. Any character
|
|
275
|
+
* may appear in the form of an escape sequence.
|
|
276
|
+
*
|
|
277
|
+
* For portability, we also escape all control and non-ASCII characters.
|
|
278
|
+
* Note that "\0" and "\v" escape sequences are not used because JSHint does
|
|
279
|
+
* not like the first and IE the second.
|
|
280
|
+
*/
|
|
281
|
+
return s
|
|
282
|
+
.replace(/\\/g, '\\\\') // backslash
|
|
283
|
+
.replace(/"/g, '\\"') // closing double quote
|
|
284
|
+
.replace(/\x08/g, '\\b') // backspace
|
|
285
|
+
.replace(/\t/g, '\\t') // horizontal tab
|
|
286
|
+
.replace(/\n/g, '\\n') // line feed
|
|
287
|
+
.replace(/\f/g, '\\f') // form feed
|
|
288
|
+
.replace(/\r/g, '\\r') // carriage return
|
|
289
|
+
.replace(/[\x00-\x07\x0B\x0E\x0F]/g, function(ch) { return '\\x0' + hex(ch); })
|
|
290
|
+
.replace(/[\x10-\x1F\x80-\xFF]/g, function(ch) { return '\\x' + hex(ch); })
|
|
291
|
+
.replace(/[\u0100-\u0FFF]/g, function(ch) { return '\\u0' + hex(ch); })
|
|
292
|
+
.replace(/[\u1000-\uFFFF]/g, function(ch) { return '\\u' + hex(ch); });
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
var expectedDescs = new Array(expected.length),
|
|
296
|
+
expectedDesc, foundDesc, i;
|
|
297
|
+
|
|
298
|
+
for (i = 0; i < expected.length; i++) {
|
|
299
|
+
expectedDescs[i] = expected[i].description;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
expectedDesc = expected.length > 1
|
|
303
|
+
? expectedDescs.slice(0, -1).join(", ")
|
|
304
|
+
+ " or "
|
|
305
|
+
+ expectedDescs[expected.length - 1]
|
|
306
|
+
: expectedDescs[0];
|
|
307
|
+
|
|
308
|
+
foundDesc = found ? "\"" + stringEscape(found) + "\"" : "end of input";
|
|
309
|
+
|
|
310
|
+
return "Expected " + expectedDesc + " but " + foundDesc + " found.";
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (expected !== null) {
|
|
314
|
+
cleanupExpected(expected);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return new peg$SyntaxError(
|
|
318
|
+
message !== null ? message : buildMessage(expected, found),
|
|
319
|
+
expected,
|
|
320
|
+
found,
|
|
321
|
+
location
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function peg$buildParseException() {
|
|
326
|
+
return peg$buildException(
|
|
327
|
+
null,
|
|
328
|
+
peg$maxFailExpected,
|
|
329
|
+
peg$maxFailPos < input.length ? input.charAt(peg$maxFailPos) : null,
|
|
330
|
+
peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
function peg$traceCall(parseFunc, name, argNames, args) {
|
|
336
|
+
var argMap = {};
|
|
337
|
+
for (let i = 0; i < args.length; i++) {
|
|
338
|
+
argMap[argNames[i]] = args[i];
|
|
339
|
+
}
|
|
340
|
+
var startPos = peg$currPos;
|
|
341
|
+
peg$tracer.trace({
|
|
342
|
+
type: "rule.enter",
|
|
343
|
+
rule: name,
|
|
344
|
+
location: peg$computeLocation(startPos, startPos),
|
|
345
|
+
args: argMap
|
|
346
|
+
});
|
|
347
|
+
var result = parseFunc.apply(null, args);
|
|
348
|
+
if (result !== peg$FAILED) {
|
|
349
|
+
peg$tracer.trace({
|
|
350
|
+
type: "rule.match",
|
|
351
|
+
rule: name,
|
|
352
|
+
result: result,
|
|
353
|
+
location: peg$computeLocation(startPos, peg$currPos)
|
|
354
|
+
});
|
|
355
|
+
} else {
|
|
356
|
+
peg$tracer.trace({
|
|
357
|
+
type: "rule.fail",
|
|
358
|
+
rule: name,
|
|
359
|
+
location: peg$computeLocation(startPos, startPos)
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return result;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
var peg$tracer = "tracer" in options ? options.tracer : new peg$DefaultTracer();
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
// expectations
|
|
370
|
+
var peg$c0 = {"type":"end","description":"end of input"};
|
|
371
|
+
var peg$c1 = {"type":"literal","value":";","description":"\";\""};
|
|
372
|
+
var peg$c2 = {"type":"class","value":"[0-9A-Fa-f]","description":"[0-9A-Fa-f]"};
|
|
373
|
+
var peg$c3 = {"type":"class","value":"[CFST]","description":"[CFST]"};
|
|
374
|
+
var peg$c4 = {"type":"class","value":"[ \\t]","description":"[ \\t]"};
|
|
375
|
+
|
|
376
|
+
// actions
|
|
377
|
+
function peg$a0(code, status, mapped) {
|
|
378
|
+
|
|
379
|
+
return { code, status, mapped };
|
|
380
|
+
|
|
381
|
+
}
|
|
382
|
+
function peg$a1(s) {
|
|
383
|
+
return parseInt(s, 16);
|
|
384
|
+
}
|
|
385
|
+
function peg$a2(first, rest) {
|
|
386
|
+
|
|
387
|
+
return [ first ].concat(rest);
|
|
388
|
+
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// initializer
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
// generated
|
|
395
|
+
function peg$parseFile(silence) {
|
|
396
|
+
var r1,p2,r3,r4;
|
|
397
|
+
seq_1: {
|
|
398
|
+
p2 = peg$currPos;
|
|
399
|
+
for (;;) {
|
|
400
|
+
r4 = peg$discardComment();
|
|
401
|
+
if (r4===peg$FAILED) {
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// free r4
|
|
406
|
+
r3 = true;
|
|
407
|
+
// free r3
|
|
408
|
+
r1 = [];
|
|
409
|
+
for (;;) {
|
|
410
|
+
r3 = peg$parseEntry(silence);
|
|
411
|
+
if (r3!==peg$FAILED) {
|
|
412
|
+
r1.push(r3);
|
|
413
|
+
} else {
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (r1.length === 0) {
|
|
418
|
+
r1 = peg$FAILED;
|
|
419
|
+
}
|
|
420
|
+
if (r1===peg$FAILED) {
|
|
421
|
+
peg$currPos = p2;
|
|
422
|
+
r1 = peg$FAILED;
|
|
423
|
+
break seq_1;
|
|
424
|
+
}
|
|
425
|
+
// free r3
|
|
426
|
+
for (;;) {
|
|
427
|
+
r4 = peg$discardComment();
|
|
428
|
+
if (r4===peg$FAILED) {
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
// free r4
|
|
433
|
+
r3 = true;
|
|
434
|
+
// free r3
|
|
435
|
+
} // seq_1
|
|
436
|
+
// free p2
|
|
437
|
+
return r1;
|
|
438
|
+
}
|
|
439
|
+
function peg$discardComment() {
|
|
440
|
+
var r1,p2,r3,r4,r5;
|
|
441
|
+
seq_1: {
|
|
442
|
+
p2 = peg$currPos;
|
|
443
|
+
seq_2: {
|
|
444
|
+
if (input.charCodeAt(peg$currPos) === 35) {
|
|
445
|
+
r4 = true;
|
|
446
|
+
peg$currPos += 1;
|
|
447
|
+
} else {
|
|
448
|
+
r4 = peg$FAILED;
|
|
449
|
+
r3 = peg$FAILED;
|
|
450
|
+
break seq_2;
|
|
451
|
+
}
|
|
452
|
+
r5 = /[^\n]*/y;
|
|
453
|
+
r5.lastIndex = peg$currPos;
|
|
454
|
+
if (r5.exec(input) !== null) {
|
|
455
|
+
peg$currPos = r5.lastIndex;
|
|
456
|
+
} else {
|
|
457
|
+
r5 = peg$FAILED;
|
|
458
|
+
}
|
|
459
|
+
r3 = true;
|
|
460
|
+
} // seq_2
|
|
461
|
+
if (r3===peg$FAILED) {
|
|
462
|
+
r3 = null;
|
|
463
|
+
}
|
|
464
|
+
// free r4,r5
|
|
465
|
+
if (input.charCodeAt(peg$currPos) === 10) {
|
|
466
|
+
r5 = true;
|
|
467
|
+
peg$currPos += 1;
|
|
468
|
+
} else {
|
|
469
|
+
r5 = peg$FAILED;
|
|
470
|
+
peg$currPos = p2;
|
|
471
|
+
r1 = peg$FAILED;
|
|
472
|
+
break seq_1;
|
|
473
|
+
}
|
|
474
|
+
r1 = true;
|
|
475
|
+
} // seq_1
|
|
476
|
+
// free r3,r5
|
|
477
|
+
// free p2
|
|
478
|
+
return r1;
|
|
479
|
+
}
|
|
480
|
+
function peg$parseEntry(silence) {
|
|
481
|
+
var r1,p2,p3,r4,r5,r6,r7,r8,r9,r10;
|
|
482
|
+
p2 = peg$currPos;
|
|
483
|
+
seq_1: {
|
|
484
|
+
p3 = peg$currPos;
|
|
485
|
+
r4 = peg$parseHexNumber(silence);
|
|
486
|
+
// code <- r4
|
|
487
|
+
if (r4===peg$FAILED) {
|
|
488
|
+
r1 = peg$FAILED;
|
|
489
|
+
break seq_1;
|
|
490
|
+
}
|
|
491
|
+
peg$discard__();
|
|
492
|
+
if (input.charCodeAt(peg$currPos) === 59) {
|
|
493
|
+
r5 = true;
|
|
494
|
+
peg$currPos += 1;
|
|
495
|
+
} else {
|
|
496
|
+
if (!silence) { peg$fail(peg$c1); }
|
|
497
|
+
r5 = peg$FAILED;
|
|
498
|
+
peg$currPos = p3;
|
|
499
|
+
r1 = peg$FAILED;
|
|
500
|
+
break seq_1;
|
|
501
|
+
}
|
|
502
|
+
peg$discard__();
|
|
503
|
+
r6 = peg$parseStatusChar(silence);
|
|
504
|
+
// status <- r6
|
|
505
|
+
if (r6===peg$FAILED) {
|
|
506
|
+
peg$currPos = p3;
|
|
507
|
+
r1 = peg$FAILED;
|
|
508
|
+
break seq_1;
|
|
509
|
+
}
|
|
510
|
+
peg$discard__();
|
|
511
|
+
if (input.charCodeAt(peg$currPos) === 59) {
|
|
512
|
+
r7 = true;
|
|
513
|
+
peg$currPos += 1;
|
|
514
|
+
} else {
|
|
515
|
+
if (!silence) { peg$fail(peg$c1); }
|
|
516
|
+
r7 = peg$FAILED;
|
|
517
|
+
peg$currPos = p3;
|
|
518
|
+
r1 = peg$FAILED;
|
|
519
|
+
break seq_1;
|
|
520
|
+
}
|
|
521
|
+
peg$discard__();
|
|
522
|
+
r8 = peg$parseHexNumberList(silence);
|
|
523
|
+
// mapped <- r8
|
|
524
|
+
if (r8===peg$FAILED) {
|
|
525
|
+
peg$currPos = p3;
|
|
526
|
+
r1 = peg$FAILED;
|
|
527
|
+
break seq_1;
|
|
528
|
+
}
|
|
529
|
+
peg$discard__();
|
|
530
|
+
if (input.charCodeAt(peg$currPos) === 59) {
|
|
531
|
+
r9 = true;
|
|
532
|
+
peg$currPos += 1;
|
|
533
|
+
} else {
|
|
534
|
+
if (!silence) { peg$fail(peg$c1); }
|
|
535
|
+
r9 = peg$FAILED;
|
|
536
|
+
peg$currPos = p3;
|
|
537
|
+
r1 = peg$FAILED;
|
|
538
|
+
break seq_1;
|
|
539
|
+
}
|
|
540
|
+
peg$discard__();
|
|
541
|
+
r10 = peg$discardComment();
|
|
542
|
+
if (r10===peg$FAILED) {
|
|
543
|
+
peg$currPos = p3;
|
|
544
|
+
r1 = peg$FAILED;
|
|
545
|
+
break seq_1;
|
|
546
|
+
}
|
|
547
|
+
r1 = true;
|
|
548
|
+
} // seq_1
|
|
549
|
+
if (r1!==peg$FAILED) {
|
|
550
|
+
peg$savedPos = p2;
|
|
551
|
+
r1 = peg$a0(r4, r6, r8);
|
|
552
|
+
}
|
|
553
|
+
// free r5,r7,r9,r10
|
|
554
|
+
// free p3
|
|
555
|
+
// free p2
|
|
556
|
+
return r1;
|
|
557
|
+
}
|
|
558
|
+
function peg$parseHexNumber(silence) {
|
|
559
|
+
var r1,p2,r3,p4;
|
|
560
|
+
p2 = peg$currPos;
|
|
561
|
+
p4 = peg$currPos;
|
|
562
|
+
r3 = /[0-9A-Fa-f]+/y;
|
|
563
|
+
r3.lastIndex = peg$currPos;
|
|
564
|
+
// s <- r3
|
|
565
|
+
if (r3.exec(input) !== null) {
|
|
566
|
+
peg$currPos = r3.lastIndex;
|
|
567
|
+
r3 = input.substring(p4, peg$currPos);
|
|
568
|
+
} else {
|
|
569
|
+
r3 = peg$FAILED;
|
|
570
|
+
if (!silence) { peg$fail(peg$c2); }
|
|
571
|
+
r3 = peg$FAILED;
|
|
572
|
+
}
|
|
573
|
+
// free p4
|
|
574
|
+
r1 = r3;
|
|
575
|
+
if (r1!==peg$FAILED) {
|
|
576
|
+
peg$savedPos = p2;
|
|
577
|
+
r1 = peg$a1(r3);
|
|
578
|
+
}
|
|
579
|
+
// free p2
|
|
580
|
+
return r1;
|
|
581
|
+
}
|
|
582
|
+
function peg$discard__() {
|
|
583
|
+
var r1;
|
|
584
|
+
r1 = /[ \t]*/y;
|
|
585
|
+
r1.lastIndex = peg$currPos;
|
|
586
|
+
if (r1.exec(input) !== null) {
|
|
587
|
+
peg$currPos = r1.lastIndex;
|
|
588
|
+
} else {
|
|
589
|
+
r1 = peg$FAILED;
|
|
590
|
+
}
|
|
591
|
+
return r1;
|
|
592
|
+
}
|
|
593
|
+
function peg$parseStatusChar(silence) {
|
|
594
|
+
var p1,r2;
|
|
595
|
+
p1 = peg$currPos;
|
|
596
|
+
if (/^[CFST]/.test(input.charAt(peg$currPos))) {
|
|
597
|
+
r2 = true;
|
|
598
|
+
peg$currPos++;
|
|
599
|
+
r2 = input.substring(p1, peg$currPos);
|
|
600
|
+
} else {
|
|
601
|
+
r2 = peg$FAILED;
|
|
602
|
+
if (!silence) { peg$fail(peg$c3); }
|
|
603
|
+
r2 = peg$FAILED;
|
|
604
|
+
}
|
|
605
|
+
// free p1
|
|
606
|
+
return r2;
|
|
607
|
+
}
|
|
608
|
+
function peg$parseHexNumberList(silence) {
|
|
609
|
+
var r1,p2,p3,r4,r5,r6,p7,r8;
|
|
610
|
+
p2 = peg$currPos;
|
|
611
|
+
seq_1: {
|
|
612
|
+
p3 = peg$currPos;
|
|
613
|
+
r4 = peg$parseHexNumber(silence);
|
|
614
|
+
// first <- r4
|
|
615
|
+
if (r4===peg$FAILED) {
|
|
616
|
+
r1 = peg$FAILED;
|
|
617
|
+
break seq_1;
|
|
618
|
+
}
|
|
619
|
+
r5 = [];
|
|
620
|
+
for (;;) {
|
|
621
|
+
seq_2: {
|
|
622
|
+
p7 = peg$currPos;
|
|
623
|
+
r8 = /[ \t]+/y;
|
|
624
|
+
r8.lastIndex = peg$currPos;
|
|
625
|
+
if (r8.exec(input) !== null) {
|
|
626
|
+
peg$currPos = r8.lastIndex;
|
|
627
|
+
} else {
|
|
628
|
+
r8 = peg$FAILED;
|
|
629
|
+
if (!silence) { peg$fail(peg$c4); }
|
|
630
|
+
r6 = peg$FAILED;
|
|
631
|
+
break seq_2;
|
|
632
|
+
}
|
|
633
|
+
r6 = peg$parseHexNumber(silence);
|
|
634
|
+
if (r6===peg$FAILED) {
|
|
635
|
+
peg$currPos = p7;
|
|
636
|
+
r6 = peg$FAILED;
|
|
637
|
+
break seq_2;
|
|
638
|
+
}
|
|
639
|
+
} // seq_2
|
|
640
|
+
if (r6!==peg$FAILED) {
|
|
641
|
+
r5.push(r6);
|
|
642
|
+
} else {
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
// free p7
|
|
646
|
+
}
|
|
647
|
+
// rest <- r5
|
|
648
|
+
// free r6
|
|
649
|
+
// free r8
|
|
650
|
+
r1 = true;
|
|
651
|
+
} // seq_1
|
|
652
|
+
if (r1!==peg$FAILED) {
|
|
653
|
+
peg$savedPos = p2;
|
|
654
|
+
r1 = peg$a2(r4, r5);
|
|
655
|
+
}
|
|
656
|
+
// free p3
|
|
657
|
+
// free p2
|
|
658
|
+
return r1;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// start
|
|
662
|
+
|
|
663
|
+
if (options.stream) {
|
|
664
|
+
switch (peg$startRule) {
|
|
665
|
+
|
|
666
|
+
default:
|
|
667
|
+
throw new Error(`Can't stream rule "${peg$startRule}".`);
|
|
668
|
+
}
|
|
669
|
+
} else {
|
|
670
|
+
switch (peg$startRule) {
|
|
671
|
+
case '(DEFAULT)':
|
|
672
|
+
case "File":
|
|
673
|
+
peg$result = peg$parseFile(false);
|
|
674
|
+
break;
|
|
675
|
+
default:
|
|
676
|
+
throw new Error(`Can't start parsing from rule "${peg$startRule}".`);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if (peg$result !== peg$FAILED && peg$currPos === input.length) {
|
|
681
|
+
return peg$result;
|
|
682
|
+
} else {
|
|
683
|
+
if (peg$result !== peg$FAILED && peg$currPos < input.length) {
|
|
684
|
+
peg$fail(peg$c0);
|
|
685
|
+
}
|
|
686
|
+
throw peg$buildParseException();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
return {
|
|
691
|
+
SyntaxError: peg$SyntaxError,
|
|
692
|
+
DefaultTracer: peg$DefaultTracer,
|
|
693
|
+
parse: peg$parse
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
})();
|
|
697
|
+
|