unexpectedly 2.0.0 → 3.0.3
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/bin/unexpectedly.js +4 -12
- package/eslint.config.js +26 -0
- package/index.js +18 -9
- package/package.json +5 -25
- package/runner.js +0 -11
- package/testFile.peg.js +308 -311
- package/vendor/peggy/grammar-location.cjs +6 -6
- package/version.js +4 -0
package/bin/unexpectedly.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --experimental-vm-modules --no-warnings
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {Command, Option} from 'commander';
|
|
5
|
-
import fs from 'node:fs/promises';
|
|
2
|
+
import {Command} from 'commander';
|
|
6
3
|
import {suite} from '../index.js';
|
|
4
|
+
import {version} from '../version.js';
|
|
7
5
|
|
|
8
6
|
let failures = 0;
|
|
9
7
|
|
|
10
8
|
async function main() {
|
|
11
|
-
const pkg = JSON.parse(await fs.readFile(
|
|
12
|
-
new URL('../package.json', import.meta.url),
|
|
13
|
-
'utf-8'
|
|
14
|
-
));
|
|
15
|
-
|
|
16
9
|
const program = new Command();
|
|
17
10
|
const opts = program
|
|
18
|
-
.version(
|
|
19
|
-
.argument('[...
|
|
11
|
+
.version(version)
|
|
12
|
+
.argument('[file...]', 'Files or directories to test', './test/')
|
|
20
13
|
.option('-d,--defaultScript <replacement>', 'Find the script from the file name. Replace `$<base>` with the basename of the file.', '../$<base>.js')
|
|
21
14
|
.option('-f,--function <functionName>', 'Use this function for testing in the associated script', 'test')
|
|
22
|
-
.addOption(new Option('-s,--silent18', 'Silently skip mjs tests on node 18.').hideHelp())
|
|
23
15
|
.parse()
|
|
24
16
|
.opts();
|
|
25
17
|
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import base from '@cto.af/eslint-config';
|
|
2
|
+
import mocha from '@cto.af/eslint-config/mocha.js';
|
|
3
|
+
import mod from '@cto.af/eslint-config/module.js';
|
|
4
|
+
|
|
5
|
+
export default [
|
|
6
|
+
{
|
|
7
|
+
ignores: [
|
|
8
|
+
'docs/**',
|
|
9
|
+
'coverage/**',
|
|
10
|
+
'**/*.peg.js',
|
|
11
|
+
'**/*.d.ts',
|
|
12
|
+
'test/pkg_bad/package.json',
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
...base,
|
|
16
|
+
...mod,
|
|
17
|
+
...mocha,
|
|
18
|
+
{
|
|
19
|
+
files: [
|
|
20
|
+
'test/**/*.js',
|
|
21
|
+
],
|
|
22
|
+
rules: {
|
|
23
|
+
'n/no-top-level-await': 'off',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
];
|
package/index.js
CHANGED
|
@@ -116,29 +116,38 @@ export async function suite(target = '.', options = {}) {
|
|
|
116
116
|
opts.lineOffset = pt.vars.inline.line - 1;
|
|
117
117
|
opts.columnOffset = pt.vars.inline.column;
|
|
118
118
|
} else {
|
|
119
|
-
|
|
120
|
-
path.resolve(dir, pt.vars.script.value)
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
if (pt.vars.script) {
|
|
120
|
+
opts.filename = path.resolve(dir, pt.vars.script.value);
|
|
121
|
+
} else {
|
|
122
|
+
// Avoid a previous ReDOS regexp.
|
|
123
|
+
const p = path.parse(f);
|
|
124
|
+
if (/^\.tests?$/.test(p.ext)) {
|
|
125
|
+
delete p.base;
|
|
126
|
+
delete p.ext;
|
|
127
|
+
p.name = p.name.replace(/^(?<base>.*)$/, options.defaultScript);
|
|
128
|
+
opts.filename = path.resolve(dir, path.format(p));
|
|
129
|
+
} else {
|
|
130
|
+
opts.filename = path.resolve(dir, f);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
123
133
|
text = await fs.readFile(opts.filename, 'utf8');
|
|
124
134
|
}
|
|
125
135
|
if (pt.vars.timeout) {
|
|
126
136
|
msuite.timeout(parseInt(pt.vars.timeout.value, 10));
|
|
127
137
|
}
|
|
128
138
|
opts.context = mapObj(
|
|
129
|
-
Object.entries(pt.vars).filter(([
|
|
139
|
+
Object.entries(pt.vars).filter(([_k, v]) => !v.env),
|
|
130
140
|
([key, value]) => [key, value.value]
|
|
131
141
|
);
|
|
132
142
|
opts.env = mapObj(
|
|
133
|
-
Object.entries(pt.vars).filter(([
|
|
143
|
+
Object.entries(pt.vars).filter(([_k, v]) => v.env),
|
|
134
144
|
([key, value]) => [key, value.value]
|
|
135
145
|
);
|
|
136
|
-
opts.silent18 = Boolean(options.silent18);
|
|
137
146
|
|
|
138
147
|
const runner = new Runner(opts);
|
|
139
148
|
|
|
140
149
|
const firstLine = (pt.expected === EXCEPTION) ? `! ${pt.inputs[0]}` : pt.expected.split(/\n/)[0];
|
|
141
|
-
const t = new Mocha.Test(`line ${pt.line}: ${firstLine || '""'}`, async() => {
|
|
150
|
+
const t = new Mocha.Test(`line ${pt.line}: ${firstLine || '""'}`, async () => {
|
|
142
151
|
let actual = null;
|
|
143
152
|
try {
|
|
144
153
|
actual = await runner.run(text, {
|
|
@@ -165,7 +174,7 @@ export async function suite(target = '.', options = {}) {
|
|
|
165
174
|
}
|
|
166
175
|
}
|
|
167
176
|
|
|
168
|
-
return new Promise((resolve,
|
|
177
|
+
return new Promise((resolve, _reject) => {
|
|
169
178
|
mocha.run(resolve);
|
|
170
179
|
});
|
|
171
180
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unexpectedly",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Keep a bunch of test cases in a file, with their expected results",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "peggy -o testFile.peg.js --format es testFile.peggy",
|
|
9
|
-
"pretest": "npm run build",
|
|
10
|
-
"test": "c8 npm run runtests",
|
|
11
|
-
"runtests": "mocha && bin/unexpectedly.js -s test test/pkg_mjs/test test/pkg_cjs/test",
|
|
12
|
-
"lint": "eslint --ext js,cjs,mjs . bin/*",
|
|
13
|
-
"ci": "npm run lint && npm run test",
|
|
14
|
-
"clean": "rimraf coverage testFile.peg.js"
|
|
15
|
-
},
|
|
16
7
|
"bin": {
|
|
17
8
|
"unexpectedly": "bin/unexpectedly.js"
|
|
18
9
|
},
|
|
@@ -32,22 +23,11 @@
|
|
|
32
23
|
},
|
|
33
24
|
"license": "MPL-2.0",
|
|
34
25
|
"dependencies": {
|
|
35
|
-
"@peggyjs/from-mem": "1.
|
|
36
|
-
"commander": "
|
|
37
|
-
"mocha": "^
|
|
38
|
-
"semver": "7.6.0"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@cto.af/eslint-config": "3.1.0",
|
|
42
|
-
"c8": "9.1.0",
|
|
43
|
-
"eslint": "^8.57.0",
|
|
44
|
-
"eslint-plugin-jsdoc": "48.2.0",
|
|
45
|
-
"peggy": "^4.0.2",
|
|
46
|
-
"rimraf": "5.0.5",
|
|
47
|
-
"zx": "7.2.3"
|
|
26
|
+
"@peggyjs/from-mem": "3.1.1",
|
|
27
|
+
"commander": "14.0.0",
|
|
28
|
+
"mocha": "^11.7.1"
|
|
48
29
|
},
|
|
49
|
-
"packageManager": "pnpm@8.15.4",
|
|
50
30
|
"engines": {
|
|
51
|
-
"node": ">=
|
|
31
|
+
"node": ">=20"
|
|
52
32
|
}
|
|
53
33
|
}
|
package/runner.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import GrammarLocation from './vendor/peggy/grammar-location.cjs';
|
|
2
2
|
import fromMem from '@peggyjs/from-mem';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import semver from 'semver';
|
|
5
4
|
|
|
6
5
|
const PREFIX_MJS = 'export default ';
|
|
7
6
|
const PREFIX_CJS = 'module.exports = ';
|
|
8
7
|
const PREFIX_MJS_LEN = PREFIX_MJS.length;
|
|
9
8
|
const PREFIX_CJS_LEN = PREFIX_CJS.length;
|
|
10
9
|
|
|
11
|
-
const is20 = semver.satisfies(process.version, '>=20.8');
|
|
12
|
-
|
|
13
10
|
export const SKIPPED = Symbol('SKIPPED');
|
|
14
11
|
|
|
15
12
|
/**
|
|
@@ -28,7 +25,6 @@ export class Runner {
|
|
|
28
25
|
#env;
|
|
29
26
|
#filename;
|
|
30
27
|
#lineOffset;
|
|
31
|
-
#silent18;
|
|
32
28
|
#testFunction;
|
|
33
29
|
#type;
|
|
34
30
|
#skipped;
|
|
@@ -39,7 +35,6 @@ export class Runner {
|
|
|
39
35
|
columnOffset = 0,
|
|
40
36
|
context = {},
|
|
41
37
|
env = {},
|
|
42
|
-
silent18 = false,
|
|
43
38
|
testFunction = 'test',
|
|
44
39
|
type = 'guess',
|
|
45
40
|
} = {}) {
|
|
@@ -52,7 +47,6 @@ export class Runner {
|
|
|
52
47
|
this.#context = context;
|
|
53
48
|
this.#columnOffset = columnOffset;
|
|
54
49
|
this.#lineOffset = lineOffset;
|
|
55
|
-
this.#silent18 = silent18;
|
|
56
50
|
this.#skipped = null;
|
|
57
51
|
this.#type = type;
|
|
58
52
|
this.#testFunction = testFunction;
|
|
@@ -69,11 +63,6 @@ export class Runner {
|
|
|
69
63
|
|
|
70
64
|
let columnOffset = this.#columnOffset;
|
|
71
65
|
if (format === 'es') {
|
|
72
|
-
if (this.#silent18 && !is20) {
|
|
73
|
-
this.#skipped = true;
|
|
74
|
-
return SKIPPED;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
66
|
if (text.indexOf('export') === -1) {
|
|
78
67
|
text = PREFIX_MJS + text; // Most common case
|
|
79
68
|
columnOffset -= PREFIX_MJS_LEN;
|
package/testFile.peg.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by Peggy
|
|
1
|
+
// @generated by Peggy 5.0.6.
|
|
2
2
|
//
|
|
3
3
|
// https://peggyjs.org/
|
|
4
4
|
|
|
@@ -6,252 +6,239 @@
|
|
|
6
6
|
|
|
7
7
|
import { mapObj } from './utils.js'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var self = Error.call(this, message);
|
|
17
|
-
// istanbul ignore next Check is a necessary evil to support older environments
|
|
18
|
-
if (Object.setPrototypeOf) {
|
|
19
|
-
Object.setPrototypeOf(self, peg$SyntaxError.prototype);
|
|
9
|
+
class peg$SyntaxError extends SyntaxError {
|
|
10
|
+
constructor(message, expected, found, location) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.expected = expected;
|
|
13
|
+
this.found = found;
|
|
14
|
+
this.location = location;
|
|
15
|
+
this.name = "SyntaxError";
|
|
20
16
|
}
|
|
21
|
-
self.expected = expected;
|
|
22
|
-
self.found = found;
|
|
23
|
-
self.location = location;
|
|
24
|
-
self.name = "SyntaxError";
|
|
25
|
-
return self;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
peg$subclass(peg$SyntaxError, Error);
|
|
29
|
-
|
|
30
|
-
function peg$padEnd(str, targetLength, padString) {
|
|
31
|
-
padString = padString || " ";
|
|
32
|
-
if (str.length > targetLength) { return str; }
|
|
33
|
-
targetLength -= str.length;
|
|
34
|
-
padString += padString.repeat(targetLength);
|
|
35
|
-
return str + padString.slice(0, targetLength);
|
|
36
|
-
}
|
|
37
17
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
18
|
+
format(sources) {
|
|
19
|
+
let str = "Error: " + this.message;
|
|
20
|
+
if (this.location) {
|
|
21
|
+
let src = null;
|
|
22
|
+
const st = sources.find(s => s.source === this.location.source);
|
|
23
|
+
if (st) {
|
|
24
|
+
src = st.text.split(/\r\n|\n|\r/g);
|
|
25
|
+
}
|
|
26
|
+
const s = this.location.start;
|
|
27
|
+
const offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
|
|
28
|
+
? this.location.source.offset(s)
|
|
29
|
+
: s;
|
|
30
|
+
const loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
|
|
31
|
+
if (src) {
|
|
32
|
+
const e = this.location.end;
|
|
33
|
+
const filler = "".padEnd(offset_s.line.toString().length, " ");
|
|
34
|
+
const line = src[s.line - 1];
|
|
35
|
+
const last = s.line === e.line ? e.column : line.length + 1;
|
|
36
|
+
const hatLen = (last - s.column) || 1;
|
|
37
|
+
str += "\n --> " + loc + "\n"
|
|
38
|
+
+ filler + " |\n"
|
|
39
|
+
+ offset_s.line + " | " + line + "\n"
|
|
40
|
+
+ filler + " | " + "".padEnd(s.column - 1, " ")
|
|
41
|
+
+ "".padEnd(hatLen, "^");
|
|
42
|
+
} else {
|
|
43
|
+
str += "\n at " + loc;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
|
-
|
|
50
|
-
var offset_s = (this.location.source && (typeof this.location.source.offset === "function"))
|
|
51
|
-
? this.location.source.offset(s)
|
|
52
|
-
: s;
|
|
53
|
-
var loc = this.location.source + ":" + offset_s.line + ":" + offset_s.column;
|
|
54
|
-
if (src) {
|
|
55
|
-
var e = this.location.end;
|
|
56
|
-
var filler = peg$padEnd("", offset_s.line.toString().length, ' ');
|
|
57
|
-
var line = src[s.line - 1];
|
|
58
|
-
var last = s.line === e.line ? e.column : line.length + 1;
|
|
59
|
-
var hatLen = (last - s.column) || 1;
|
|
60
|
-
str += "\n --> " + loc + "\n"
|
|
61
|
-
+ filler + " |\n"
|
|
62
|
-
+ offset_s.line + " | " + line + "\n"
|
|
63
|
-
+ filler + " | " + peg$padEnd("", s.column - 1, ' ')
|
|
64
|
-
+ peg$padEnd("", hatLen, "^");
|
|
65
|
-
} else {
|
|
66
|
-
str += "\n at " + loc;
|
|
67
|
-
}
|
|
46
|
+
return str;
|
|
68
47
|
}
|
|
69
|
-
return str;
|
|
70
|
-
};
|
|
71
48
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
49
|
+
static buildMessage(expected, found) {
|
|
50
|
+
function hex(ch) {
|
|
51
|
+
return ch.codePointAt(0).toString(16).toUpperCase();
|
|
52
|
+
}
|
|
77
53
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
54
|
+
const nonPrintable = Object.prototype.hasOwnProperty.call(RegExp.prototype, "unicode")
|
|
55
|
+
? new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]", "gu")
|
|
56
|
+
: null;
|
|
57
|
+
function unicodeEscape(s) {
|
|
58
|
+
if (nonPrintable) {
|
|
59
|
+
return s.replace(nonPrintable, ch => "\\u{" + hex(ch) + "}");
|
|
60
|
+
}
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
84
63
|
|
|
85
|
-
|
|
86
|
-
|
|
64
|
+
function literalEscape(s) {
|
|
65
|
+
return unicodeEscape(s
|
|
66
|
+
.replace(/\\/g, "\\\\")
|
|
67
|
+
.replace(/"/g, "\\\"")
|
|
68
|
+
.replace(/\0/g, "\\0")
|
|
69
|
+
.replace(/\t/g, "\\t")
|
|
70
|
+
.replace(/\n/g, "\\n")
|
|
71
|
+
.replace(/\r/g, "\\r")
|
|
72
|
+
.replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
|
|
73
|
+
.replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
|
|
74
|
+
}
|
|
87
75
|
|
|
88
|
-
|
|
89
|
-
return
|
|
90
|
-
|
|
76
|
+
function classEscape(s) {
|
|
77
|
+
return unicodeEscape(s
|
|
78
|
+
.replace(/\\/g, "\\\\")
|
|
79
|
+
.replace(/\]/g, "\\]")
|
|
80
|
+
.replace(/\^/g, "\\^")
|
|
81
|
+
.replace(/-/g, "\\-")
|
|
82
|
+
.replace(/\0/g, "\\0")
|
|
83
|
+
.replace(/\t/g, "\\t")
|
|
84
|
+
.replace(/\n/g, "\\n")
|
|
85
|
+
.replace(/\r/g, "\\r")
|
|
86
|
+
.replace(/[\x00-\x0F]/g, ch => "\\x0" + hex(ch))
|
|
87
|
+
.replace(/[\x10-\x1F\x7F-\x9F]/g, ch => "\\x" + hex(ch)));
|
|
88
|
+
}
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
const DESCRIBE_EXPECTATION_FNS = {
|
|
91
|
+
literal(expectation) {
|
|
92
|
+
return "\"" + literalEscape(expectation.text) + "\"";
|
|
93
|
+
},
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
class(expectation) {
|
|
96
|
+
const escapedParts = expectation.parts.map(
|
|
97
|
+
part => (Array.isArray(part)
|
|
98
|
+
? classEscape(part[0]) + "-" + classEscape(part[1])
|
|
99
|
+
: classEscape(part))
|
|
100
|
+
);
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
102
|
+
return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
|
|
103
|
+
},
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
.replace(/"/g, "\\\"")
|
|
109
|
-
.replace(/\0/g, "\\0")
|
|
110
|
-
.replace(/\t/g, "\\t")
|
|
111
|
-
.replace(/\n/g, "\\n")
|
|
112
|
-
.replace(/\r/g, "\\r")
|
|
113
|
-
.replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
|
|
114
|
-
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
|
|
115
|
-
}
|
|
105
|
+
any() {
|
|
106
|
+
return "any character";
|
|
107
|
+
},
|
|
116
108
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
.replace(/\]/g, "\\]")
|
|
121
|
-
.replace(/\^/g, "\\^")
|
|
122
|
-
.replace(/-/g, "\\-")
|
|
123
|
-
.replace(/\0/g, "\\0")
|
|
124
|
-
.replace(/\t/g, "\\t")
|
|
125
|
-
.replace(/\n/g, "\\n")
|
|
126
|
-
.replace(/\r/g, "\\r")
|
|
127
|
-
.replace(/[\x00-\x0F]/g, function(ch) { return "\\x0" + hex(ch); })
|
|
128
|
-
.replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return "\\x" + hex(ch); });
|
|
129
|
-
}
|
|
109
|
+
end() {
|
|
110
|
+
return "end of input";
|
|
111
|
+
},
|
|
130
112
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
113
|
+
other(expectation) {
|
|
114
|
+
return expectation.description;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
134
117
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
118
|
+
function describeExpectation(expectation) {
|
|
119
|
+
return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
|
|
120
|
+
}
|
|
138
121
|
|
|
139
|
-
|
|
122
|
+
function describeExpected(expected) {
|
|
123
|
+
const descriptions = expected.map(describeExpectation);
|
|
124
|
+
descriptions.sort();
|
|
140
125
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
descriptions[
|
|
145
|
-
|
|
126
|
+
if (descriptions.length > 0) {
|
|
127
|
+
let j = 1;
|
|
128
|
+
for (let i = 1; i < descriptions.length; i++) {
|
|
129
|
+
if (descriptions[i - 1] !== descriptions[i]) {
|
|
130
|
+
descriptions[j] = descriptions[i];
|
|
131
|
+
j++;
|
|
132
|
+
}
|
|
146
133
|
}
|
|
134
|
+
descriptions.length = j;
|
|
147
135
|
}
|
|
148
|
-
descriptions.length = j;
|
|
149
|
-
}
|
|
150
136
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
137
|
+
switch (descriptions.length) {
|
|
138
|
+
case 1:
|
|
139
|
+
return descriptions[0];
|
|
154
140
|
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
case 2:
|
|
142
|
+
return descriptions[0] + " or " + descriptions[1];
|
|
157
143
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
144
|
+
default:
|
|
145
|
+
return descriptions.slice(0, -1).join(", ")
|
|
146
|
+
+ ", or "
|
|
147
|
+
+ descriptions[descriptions.length - 1];
|
|
148
|
+
}
|
|
162
149
|
}
|
|
163
|
-
}
|
|
164
150
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
151
|
+
function describeFound(found) {
|
|
152
|
+
return found ? "\"" + literalEscape(found) + "\"" : "end of input";
|
|
153
|
+
}
|
|
168
154
|
|
|
169
|
-
|
|
170
|
-
}
|
|
155
|
+
return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
171
158
|
|
|
172
159
|
function peg$parse(input, options) {
|
|
173
160
|
options = options !== undefined ? options : {};
|
|
174
161
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
var peg$c0 = "#!";
|
|
182
|
-
var peg$c1 = "!";
|
|
183
|
-
var peg$c2 = ":";
|
|
184
|
-
var peg$c3 = "\"";
|
|
185
|
-
var peg$c4 = "'";
|
|
186
|
-
var peg$c5 = "`";
|
|
187
|
-
var peg$c6 = "\\\"";
|
|
188
|
-
var peg$c7 = "\\'";
|
|
189
|
-
var peg$c8 = "\\`";
|
|
190
|
-
var peg$c9 = "0x";
|
|
191
|
-
var peg$c10 = "\\\\";
|
|
192
|
-
var peg$c11 = "\\r";
|
|
193
|
-
var peg$c12 = "\\n";
|
|
194
|
-
var peg$c13 = "\\t";
|
|
195
|
-
var peg$c14 = "\\#";
|
|
196
|
-
var peg$c15 = "\\:";
|
|
197
|
-
var peg$c16 = "\\ ";
|
|
198
|
-
var peg$c17 = "#";
|
|
199
|
-
var peg$c18 = "\n";
|
|
200
|
-
var peg$c19 = "\r\n";
|
|
201
|
-
var peg$c20 = "\r";
|
|
202
|
-
|
|
203
|
-
var peg$r0 = /^[^\\"]/;
|
|
204
|
-
var peg$r1 = /^[^\\']/;
|
|
205
|
-
var peg$r2 = /^[^\\`]/;
|
|
206
|
-
var peg$r3 = /^[a-fA-F0-9]/;
|
|
207
|
-
var peg$r4 = /^[^ #:'"\t\r\n]/;
|
|
208
|
-
var peg$r5 = /^[^\r\n]/;
|
|
209
|
-
var peg$r6 = /^[ \t]/;
|
|
210
|
-
var peg$r7 = /^[ \t\r\n]/;
|
|
211
|
-
|
|
212
|
-
var peg$e0 = peg$literalExpectation("#!", false);
|
|
213
|
-
var peg$e1 = peg$literalExpectation("!", false);
|
|
214
|
-
var peg$e2 = peg$literalExpectation(":", false);
|
|
215
|
-
var peg$e3 = peg$literalExpectation("\"", false);
|
|
216
|
-
var peg$e4 = peg$literalExpectation("'", false);
|
|
217
|
-
var peg$e5 = peg$literalExpectation("`", false);
|
|
218
|
-
var peg$e6 = peg$otherExpectation("characters that go inside double quotes, including escaped dquotes");
|
|
219
|
-
var peg$e7 = peg$literalExpectation("\\\"", false);
|
|
220
|
-
var peg$e8 = peg$classExpectation(["\\", "\""], true, false);
|
|
221
|
-
var peg$e9 = peg$otherExpectation("characters that go inside single quotes, including escaped squotes");
|
|
222
|
-
var peg$e10 = peg$literalExpectation("\\'", false);
|
|
223
|
-
var peg$e11 = peg$classExpectation(["\\", "'"], true, false);
|
|
224
|
-
var peg$e12 = peg$otherExpectation("characters that go inside back quotes, including escaped bquotes");
|
|
225
|
-
var peg$e13 = peg$literalExpectation("\\`", false);
|
|
226
|
-
var peg$e14 = peg$classExpectation(["\\", "`"], true, false);
|
|
227
|
-
var peg$e15 = peg$literalExpectation("0x", false);
|
|
228
|
-
var peg$e16 = peg$classExpectation([["a", "f"], ["A", "F"], ["0", "9"]], false, false);
|
|
229
|
-
var peg$e17 = peg$otherExpectation("words can contain quoted bits");
|
|
230
|
-
var peg$e18 = peg$classExpectation([" ", "#", ":", "'", "\"", "\t", "\r", "\n"], true, false);
|
|
231
|
-
var peg$e19 = peg$otherExpectation("other quoted characters, as needed");
|
|
232
|
-
var peg$e20 = peg$literalExpectation("\\\\", false);
|
|
233
|
-
var peg$e21 = peg$literalExpectation("\\r", false);
|
|
234
|
-
var peg$e22 = peg$literalExpectation("\\n", false);
|
|
235
|
-
var peg$e23 = peg$literalExpectation("\\t", false);
|
|
236
|
-
var peg$e24 = peg$literalExpectation("\\#", false);
|
|
237
|
-
var peg$e25 = peg$literalExpectation("\\:", false);
|
|
238
|
-
var peg$e26 = peg$literalExpectation("\\ ", false);
|
|
239
|
-
var peg$e27 = peg$literalExpectation("#", false);
|
|
240
|
-
var peg$e28 = peg$classExpectation(["\r", "\n"], true, false);
|
|
241
|
-
var peg$e29 = peg$otherExpectation("optional whitespace");
|
|
242
|
-
var peg$e30 = peg$classExpectation([" ", "\t"], false, false);
|
|
243
|
-
var peg$e31 = peg$otherExpectation("optional whitespace, including newlines");
|
|
244
|
-
var peg$e32 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false);
|
|
245
|
-
var peg$e33 = peg$otherExpectation("required whitespace");
|
|
246
|
-
var peg$e34 = peg$otherExpectation("End of line");
|
|
247
|
-
var peg$e35 = peg$literalExpectation("\n", false);
|
|
248
|
-
var peg$e36 = peg$literalExpectation("\r\n", false);
|
|
249
|
-
var peg$e37 = peg$literalExpectation("\r", false);
|
|
250
|
-
|
|
251
|
-
var peg$f0 = function(all) {
|
|
252
|
-
return all.filter(t => t && t.hasOwnProperty('expected'));
|
|
162
|
+
const peg$FAILED = {};
|
|
163
|
+
const peg$source = options.grammarSource;
|
|
164
|
+
|
|
165
|
+
const peg$startRuleFunctions = {
|
|
166
|
+
start: peg$parsestart,
|
|
253
167
|
};
|
|
254
|
-
|
|
168
|
+
let peg$startRuleFunction = peg$parsestart;
|
|
169
|
+
|
|
170
|
+
const peg$c0 = "#!";
|
|
171
|
+
const peg$c1 = "!";
|
|
172
|
+
const peg$c2 = ":";
|
|
173
|
+
const peg$c3 = "\"";
|
|
174
|
+
const peg$c4 = "'";
|
|
175
|
+
const peg$c5 = "`";
|
|
176
|
+
const peg$c6 = "\\\"";
|
|
177
|
+
const peg$c7 = "\\'";
|
|
178
|
+
const peg$c8 = "\\`";
|
|
179
|
+
const peg$c9 = "0x";
|
|
180
|
+
const peg$c10 = "\\\\";
|
|
181
|
+
const peg$c11 = "\\r";
|
|
182
|
+
const peg$c12 = "\\n";
|
|
183
|
+
const peg$c13 = "\\t";
|
|
184
|
+
const peg$c14 = "\\#";
|
|
185
|
+
const peg$c15 = "\\:";
|
|
186
|
+
const peg$c16 = "\\ ";
|
|
187
|
+
const peg$c17 = "#";
|
|
188
|
+
const peg$c18 = "\n";
|
|
189
|
+
const peg$c19 = "\r\n";
|
|
190
|
+
const peg$c20 = "\r";
|
|
191
|
+
|
|
192
|
+
const peg$r0 = /^[^\\"]/;
|
|
193
|
+
const peg$r1 = /^[^\\']/;
|
|
194
|
+
const peg$r2 = /^[^\\`]/;
|
|
195
|
+
const peg$r3 = /^[a-fA-F0-9]/;
|
|
196
|
+
const peg$r4 = /^[^ #:'"\t\r\n]/;
|
|
197
|
+
const peg$r5 = /^[^\r\n]/;
|
|
198
|
+
const peg$r6 = /^[ \t]/;
|
|
199
|
+
const peg$r7 = /^[ \t\r\n]/;
|
|
200
|
+
|
|
201
|
+
const peg$e0 = peg$literalExpectation("#!", false);
|
|
202
|
+
const peg$e1 = peg$literalExpectation("!", false);
|
|
203
|
+
const peg$e2 = peg$literalExpectation(":", false);
|
|
204
|
+
const peg$e3 = peg$literalExpectation("\"", false);
|
|
205
|
+
const peg$e4 = peg$literalExpectation("'", false);
|
|
206
|
+
const peg$e5 = peg$literalExpectation("`", false);
|
|
207
|
+
const peg$e6 = peg$otherExpectation("characters that go inside double quotes, including escaped dquotes");
|
|
208
|
+
const peg$e7 = peg$literalExpectation("\\\"", false);
|
|
209
|
+
const peg$e8 = peg$classExpectation(["\\", "\""], true, false, false);
|
|
210
|
+
const peg$e9 = peg$otherExpectation("characters that go inside single quotes, including escaped squotes");
|
|
211
|
+
const peg$e10 = peg$literalExpectation("\\'", false);
|
|
212
|
+
const peg$e11 = peg$classExpectation(["\\", "'"], true, false, false);
|
|
213
|
+
const peg$e12 = peg$otherExpectation("characters that go inside back quotes, including escaped bquotes");
|
|
214
|
+
const peg$e13 = peg$literalExpectation("\\`", false);
|
|
215
|
+
const peg$e14 = peg$classExpectation(["\\", "`"], true, false, false);
|
|
216
|
+
const peg$e15 = peg$literalExpectation("0x", false);
|
|
217
|
+
const peg$e16 = peg$classExpectation([["a", "f"], ["A", "F"], ["0", "9"]], false, false, false);
|
|
218
|
+
const peg$e17 = peg$otherExpectation("words can contain quoted bits");
|
|
219
|
+
const peg$e18 = peg$classExpectation([" ", "#", ":", "'", "\"", "\t", "\r", "\n"], true, false, false);
|
|
220
|
+
const peg$e19 = peg$otherExpectation("other quoted characters, as needed");
|
|
221
|
+
const peg$e20 = peg$literalExpectation("\\\\", false);
|
|
222
|
+
const peg$e21 = peg$literalExpectation("\\r", false);
|
|
223
|
+
const peg$e22 = peg$literalExpectation("\\n", false);
|
|
224
|
+
const peg$e23 = peg$literalExpectation("\\t", false);
|
|
225
|
+
const peg$e24 = peg$literalExpectation("\\#", false);
|
|
226
|
+
const peg$e25 = peg$literalExpectation("\\:", false);
|
|
227
|
+
const peg$e26 = peg$literalExpectation("\\ ", false);
|
|
228
|
+
const peg$e27 = peg$literalExpectation("#", false);
|
|
229
|
+
const peg$e28 = peg$classExpectation(["\r", "\n"], true, false, false);
|
|
230
|
+
const peg$e29 = peg$classExpectation([" ", "\t"], false, false, false);
|
|
231
|
+
const peg$e30 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false, false);
|
|
232
|
+
const peg$e31 = peg$otherExpectation("required whitespace");
|
|
233
|
+
const peg$e32 = peg$otherExpectation("End of line");
|
|
234
|
+
const peg$e33 = peg$literalExpectation("\n", false);
|
|
235
|
+
const peg$e34 = peg$literalExpectation("\r\n", false);
|
|
236
|
+
const peg$e35 = peg$literalExpectation("\r", false);
|
|
237
|
+
|
|
238
|
+
function peg$f0(all) {
|
|
239
|
+
return all.filter(t => t && t.hasOwnProperty('expected'));
|
|
240
|
+
}
|
|
241
|
+
function peg$f1(env, name, value) {
|
|
255
242
|
if (!value) {
|
|
256
243
|
const start = location().start;
|
|
257
244
|
value = {
|
|
@@ -265,43 +252,43 @@ function peg$parse(input, options) {
|
|
|
265
252
|
...vars,
|
|
266
253
|
[name]: value
|
|
267
254
|
}
|
|
268
|
-
}
|
|
269
|
-
|
|
255
|
+
}
|
|
256
|
+
function peg$f2(value) {
|
|
270
257
|
const start = location().start;
|
|
271
258
|
return { value, line: start.line, column: start.column}
|
|
272
|
-
}
|
|
273
|
-
|
|
259
|
+
}
|
|
260
|
+
function peg$f3(expected, inputs) {
|
|
274
261
|
const start = location().start;
|
|
275
262
|
return { expected, inputs, vars, line: start.line, column: start.column }
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
263
|
+
}
|
|
264
|
+
function peg$f4() { return options.EXCEPTION || "!" }
|
|
265
|
+
function peg$f5(info) { return info.join('') }
|
|
266
|
+
function peg$f6(info) { return info.join('') }
|
|
267
|
+
function peg$f7(info) { return info.join('') }
|
|
268
|
+
function peg$f8() { return '"' }
|
|
269
|
+
function peg$f9() { return "'" }
|
|
270
|
+
function peg$f10() { return "`" }
|
|
271
|
+
function peg$f11(hx) { return '0x' + hx.toLowerCase(hx) }
|
|
272
|
+
function peg$f12(chars) { return chars.join('') }
|
|
273
|
+
function peg$f13() { return '\\' }
|
|
274
|
+
function peg$f14() { return '\r' }
|
|
275
|
+
function peg$f15() { return '\n' }
|
|
276
|
+
function peg$f16() { return '\t' }
|
|
277
|
+
function peg$f17() { return '#' }
|
|
278
|
+
function peg$f18() { return ':' }
|
|
279
|
+
function peg$f19() { return ' ' }
|
|
280
|
+
function peg$f20() { return undefined }
|
|
281
|
+
function peg$f21() { return undefined }
|
|
282
|
+
function peg$f22() { return undefined }
|
|
283
|
+
function peg$f23() { return undefined }
|
|
284
|
+
let peg$currPos = options.peg$currPos | 0;
|
|
285
|
+
let peg$savedPos = peg$currPos;
|
|
286
|
+
const peg$posDetailsCache = [{ line: 1, column: 1 }];
|
|
287
|
+
let peg$maxFailPos = peg$currPos;
|
|
288
|
+
let peg$maxFailExpected = options.peg$maxFailExpected || [];
|
|
289
|
+
let peg$silentFails = options.peg$silentFails | 0;
|
|
290
|
+
|
|
291
|
+
let peg$result;
|
|
305
292
|
|
|
306
293
|
if (options.startRule) {
|
|
307
294
|
if (!(options.startRule in peg$startRuleFunctions)) {
|
|
@@ -323,7 +310,7 @@ function peg$parse(input, options) {
|
|
|
323
310
|
return {
|
|
324
311
|
source: peg$source,
|
|
325
312
|
start: peg$savedPos,
|
|
326
|
-
end: peg$currPos
|
|
313
|
+
end: peg$currPos,
|
|
327
314
|
};
|
|
328
315
|
}
|
|
329
316
|
|
|
@@ -351,12 +338,20 @@ function peg$parse(input, options) {
|
|
|
351
338
|
throw peg$buildSimpleError(message, location);
|
|
352
339
|
}
|
|
353
340
|
|
|
341
|
+
function peg$getUnicode(pos = peg$currPos) {
|
|
342
|
+
const cp = input.codePointAt(pos);
|
|
343
|
+
if (cp === undefined) {
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
return String.fromCodePoint(cp);
|
|
347
|
+
}
|
|
348
|
+
|
|
354
349
|
function peg$literalExpectation(text, ignoreCase) {
|
|
355
|
-
return { type: "literal", text
|
|
350
|
+
return { type: "literal", text, ignoreCase };
|
|
356
351
|
}
|
|
357
352
|
|
|
358
|
-
function peg$classExpectation(parts, inverted, ignoreCase) {
|
|
359
|
-
return { type: "class", parts
|
|
353
|
+
function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
|
|
354
|
+
return { type: "class", parts, inverted, ignoreCase, unicode };
|
|
360
355
|
}
|
|
361
356
|
|
|
362
357
|
function peg$anyExpectation() {
|
|
@@ -368,12 +363,12 @@ function peg$parse(input, options) {
|
|
|
368
363
|
}
|
|
369
364
|
|
|
370
365
|
function peg$otherExpectation(description) {
|
|
371
|
-
return { type: "other", description
|
|
366
|
+
return { type: "other", description };
|
|
372
367
|
}
|
|
373
368
|
|
|
374
369
|
function peg$computePosDetails(pos) {
|
|
375
|
-
|
|
376
|
-
|
|
370
|
+
let details = peg$posDetailsCache[pos];
|
|
371
|
+
let p;
|
|
377
372
|
|
|
378
373
|
if (details) {
|
|
379
374
|
return details;
|
|
@@ -388,7 +383,7 @@ function peg$parse(input, options) {
|
|
|
388
383
|
details = peg$posDetailsCache[p];
|
|
389
384
|
details = {
|
|
390
385
|
line: details.line,
|
|
391
|
-
column: details.column
|
|
386
|
+
column: details.column,
|
|
392
387
|
};
|
|
393
388
|
|
|
394
389
|
while (p < pos) {
|
|
@@ -409,21 +404,21 @@ function peg$parse(input, options) {
|
|
|
409
404
|
}
|
|
410
405
|
|
|
411
406
|
function peg$computeLocation(startPos, endPos, offset) {
|
|
412
|
-
|
|
413
|
-
|
|
407
|
+
const startPosDetails = peg$computePosDetails(startPos);
|
|
408
|
+
const endPosDetails = peg$computePosDetails(endPos);
|
|
414
409
|
|
|
415
|
-
|
|
410
|
+
const res = {
|
|
416
411
|
source: peg$source,
|
|
417
412
|
start: {
|
|
418
413
|
offset: startPos,
|
|
419
414
|
line: startPosDetails.line,
|
|
420
|
-
column: startPosDetails.column
|
|
415
|
+
column: startPosDetails.column,
|
|
421
416
|
},
|
|
422
417
|
end: {
|
|
423
418
|
offset: endPos,
|
|
424
419
|
line: endPosDetails.line,
|
|
425
|
-
column: endPosDetails.column
|
|
426
|
-
}
|
|
420
|
+
column: endPosDetails.column,
|
|
421
|
+
},
|
|
427
422
|
};
|
|
428
423
|
if (offset && peg$source && (typeof peg$source.offset === "function")) {
|
|
429
424
|
res.start = peg$source.offset(res.start);
|
|
@@ -457,7 +452,7 @@ function peg$parse(input, options) {
|
|
|
457
452
|
}
|
|
458
453
|
|
|
459
454
|
function peg$parsestart() {
|
|
460
|
-
|
|
455
|
+
let s0, s1, s2, s3, s4, s5, s6;
|
|
461
456
|
|
|
462
457
|
s0 = peg$currPos;
|
|
463
458
|
s1 = [];
|
|
@@ -495,7 +490,7 @@ function peg$parse(input, options) {
|
|
|
495
490
|
}
|
|
496
491
|
|
|
497
492
|
function peg$parseline() {
|
|
498
|
-
|
|
493
|
+
let s0;
|
|
499
494
|
|
|
500
495
|
s0 = peg$parsevar();
|
|
501
496
|
if (s0 === peg$FAILED) {
|
|
@@ -512,7 +507,7 @@ function peg$parse(input, options) {
|
|
|
512
507
|
}
|
|
513
508
|
|
|
514
509
|
function peg$parsevar() {
|
|
515
|
-
|
|
510
|
+
let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
|
|
516
511
|
|
|
517
512
|
s0 = peg$currPos;
|
|
518
513
|
if (input.substr(peg$currPos, 2) === peg$c0) {
|
|
@@ -577,7 +572,7 @@ function peg$parse(input, options) {
|
|
|
577
572
|
}
|
|
578
573
|
|
|
579
574
|
function peg$parseval() {
|
|
580
|
-
|
|
575
|
+
let s0, s1;
|
|
581
576
|
|
|
582
577
|
s0 = peg$currPos;
|
|
583
578
|
s1 = peg$parsechunk();
|
|
@@ -591,7 +586,7 @@ function peg$parse(input, options) {
|
|
|
591
586
|
}
|
|
592
587
|
|
|
593
588
|
function peg$parsetest() {
|
|
594
|
-
|
|
589
|
+
let s0, s1, s2, s3, s4, s5;
|
|
595
590
|
|
|
596
591
|
s0 = peg$currPos;
|
|
597
592
|
s1 = peg$parseresults();
|
|
@@ -643,7 +638,7 @@ function peg$parse(input, options) {
|
|
|
643
638
|
}
|
|
644
639
|
|
|
645
640
|
function peg$parseresults() {
|
|
646
|
-
|
|
641
|
+
let s0, s1;
|
|
647
642
|
|
|
648
643
|
s0 = peg$currPos;
|
|
649
644
|
if (input.charCodeAt(peg$currPos) === 33) {
|
|
@@ -666,7 +661,7 @@ function peg$parse(input, options) {
|
|
|
666
661
|
}
|
|
667
662
|
|
|
668
663
|
function peg$parsechunk() {
|
|
669
|
-
|
|
664
|
+
let s0;
|
|
670
665
|
|
|
671
666
|
s0 = peg$parsequoted();
|
|
672
667
|
if (s0 === peg$FAILED) {
|
|
@@ -680,7 +675,7 @@ function peg$parse(input, options) {
|
|
|
680
675
|
}
|
|
681
676
|
|
|
682
677
|
function peg$parsequoted() {
|
|
683
|
-
|
|
678
|
+
let s0, s1, s2, s3;
|
|
684
679
|
|
|
685
680
|
s0 = peg$currPos;
|
|
686
681
|
if (input.charCodeAt(peg$currPos) === 34) {
|
|
@@ -790,7 +785,7 @@ function peg$parse(input, options) {
|
|
|
790
785
|
}
|
|
791
786
|
|
|
792
787
|
function peg$parsedqchar() {
|
|
793
|
-
|
|
788
|
+
let s0, s1, s2;
|
|
794
789
|
|
|
795
790
|
peg$silentFails++;
|
|
796
791
|
s0 = peg$currPos;
|
|
@@ -849,7 +844,7 @@ function peg$parse(input, options) {
|
|
|
849
844
|
}
|
|
850
845
|
|
|
851
846
|
function peg$parsesqchar() {
|
|
852
|
-
|
|
847
|
+
let s0, s1, s2;
|
|
853
848
|
|
|
854
849
|
peg$silentFails++;
|
|
855
850
|
s0 = peg$currPos;
|
|
@@ -908,7 +903,7 @@ function peg$parse(input, options) {
|
|
|
908
903
|
}
|
|
909
904
|
|
|
910
905
|
function peg$parsebqchar() {
|
|
911
|
-
|
|
906
|
+
let s0, s1, s2;
|
|
912
907
|
|
|
913
908
|
peg$silentFails++;
|
|
914
909
|
s0 = peg$currPos;
|
|
@@ -967,7 +962,7 @@ function peg$parse(input, options) {
|
|
|
967
962
|
}
|
|
968
963
|
|
|
969
964
|
function peg$parsehex() {
|
|
970
|
-
|
|
965
|
+
let s0, s1, s2, s3, s4;
|
|
971
966
|
|
|
972
967
|
s0 = peg$currPos;
|
|
973
968
|
if (input.substr(peg$currPos, 2) === peg$c9) {
|
|
@@ -1022,7 +1017,7 @@ function peg$parse(input, options) {
|
|
|
1022
1017
|
}
|
|
1023
1018
|
|
|
1024
1019
|
function peg$parseword() {
|
|
1025
|
-
|
|
1020
|
+
let s0, s1, s2;
|
|
1026
1021
|
|
|
1027
1022
|
s0 = peg$currPos;
|
|
1028
1023
|
s1 = [];
|
|
@@ -1045,7 +1040,7 @@ function peg$parse(input, options) {
|
|
|
1045
1040
|
}
|
|
1046
1041
|
|
|
1047
1042
|
function peg$parsewchar() {
|
|
1048
|
-
|
|
1043
|
+
let s0, s1, s2;
|
|
1049
1044
|
|
|
1050
1045
|
peg$silentFails++;
|
|
1051
1046
|
s0 = [];
|
|
@@ -1098,7 +1093,7 @@ function peg$parse(input, options) {
|
|
|
1098
1093
|
}
|
|
1099
1094
|
|
|
1100
1095
|
function peg$parseqchar() {
|
|
1101
|
-
|
|
1096
|
+
let s0, s1;
|
|
1102
1097
|
|
|
1103
1098
|
peg$silentFails++;
|
|
1104
1099
|
s0 = peg$currPos;
|
|
@@ -1214,7 +1209,7 @@ function peg$parse(input, options) {
|
|
|
1214
1209
|
}
|
|
1215
1210
|
|
|
1216
1211
|
function peg$parsecomment() {
|
|
1217
|
-
|
|
1212
|
+
let s0, s1, s2, s3, s4, s5;
|
|
1218
1213
|
|
|
1219
1214
|
s0 = peg$currPos;
|
|
1220
1215
|
s1 = peg$parseWS();
|
|
@@ -1276,7 +1271,7 @@ function peg$parse(input, options) {
|
|
|
1276
1271
|
}
|
|
1277
1272
|
|
|
1278
1273
|
function peg$parse_() {
|
|
1279
|
-
|
|
1274
|
+
let s0, s1, s2;
|
|
1280
1275
|
|
|
1281
1276
|
peg$silentFails++;
|
|
1282
1277
|
s0 = peg$currPos;
|
|
@@ -1286,7 +1281,7 @@ function peg$parse(input, options) {
|
|
|
1286
1281
|
peg$currPos++;
|
|
1287
1282
|
} else {
|
|
1288
1283
|
s2 = peg$FAILED;
|
|
1289
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1284
|
+
if (peg$silentFails === 0) { peg$fail(peg$e29); }
|
|
1290
1285
|
}
|
|
1291
1286
|
while (s2 !== peg$FAILED) {
|
|
1292
1287
|
s1.push(s2);
|
|
@@ -1295,21 +1290,19 @@ function peg$parse(input, options) {
|
|
|
1295
1290
|
peg$currPos++;
|
|
1296
1291
|
} else {
|
|
1297
1292
|
s2 = peg$FAILED;
|
|
1298
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1293
|
+
if (peg$silentFails === 0) { peg$fail(peg$e29); }
|
|
1299
1294
|
}
|
|
1300
1295
|
}
|
|
1301
1296
|
peg$savedPos = s0;
|
|
1302
1297
|
s1 = peg$f21();
|
|
1303
1298
|
s0 = s1;
|
|
1304
1299
|
peg$silentFails--;
|
|
1305
|
-
s1 = peg$FAILED;
|
|
1306
|
-
if (peg$silentFails === 0) { peg$fail(peg$e29); }
|
|
1307
1300
|
|
|
1308
1301
|
return s0;
|
|
1309
1302
|
}
|
|
1310
1303
|
|
|
1311
1304
|
function peg$parseWS() {
|
|
1312
|
-
|
|
1305
|
+
let s0, s1, s2;
|
|
1313
1306
|
|
|
1314
1307
|
peg$silentFails++;
|
|
1315
1308
|
s0 = peg$currPos;
|
|
@@ -1319,7 +1312,7 @@ function peg$parse(input, options) {
|
|
|
1319
1312
|
peg$currPos++;
|
|
1320
1313
|
} else {
|
|
1321
1314
|
s2 = peg$FAILED;
|
|
1322
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1315
|
+
if (peg$silentFails === 0) { peg$fail(peg$e30); }
|
|
1323
1316
|
}
|
|
1324
1317
|
while (s2 !== peg$FAILED) {
|
|
1325
1318
|
s1.push(s2);
|
|
@@ -1328,21 +1321,19 @@ function peg$parse(input, options) {
|
|
|
1328
1321
|
peg$currPos++;
|
|
1329
1322
|
} else {
|
|
1330
1323
|
s2 = peg$FAILED;
|
|
1331
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1324
|
+
if (peg$silentFails === 0) { peg$fail(peg$e30); }
|
|
1332
1325
|
}
|
|
1333
1326
|
}
|
|
1334
1327
|
peg$savedPos = s0;
|
|
1335
1328
|
s1 = peg$f22();
|
|
1336
1329
|
s0 = s1;
|
|
1337
1330
|
peg$silentFails--;
|
|
1338
|
-
s1 = peg$FAILED;
|
|
1339
|
-
if (peg$silentFails === 0) { peg$fail(peg$e31); }
|
|
1340
1331
|
|
|
1341
1332
|
return s0;
|
|
1342
1333
|
}
|
|
1343
1334
|
|
|
1344
1335
|
function peg$parseLWS() {
|
|
1345
|
-
|
|
1336
|
+
let s0, s1, s2;
|
|
1346
1337
|
|
|
1347
1338
|
peg$silentFails++;
|
|
1348
1339
|
s0 = peg$currPos;
|
|
@@ -1352,7 +1343,7 @@ function peg$parse(input, options) {
|
|
|
1352
1343
|
peg$currPos++;
|
|
1353
1344
|
} else {
|
|
1354
1345
|
s2 = peg$FAILED;
|
|
1355
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1346
|
+
if (peg$silentFails === 0) { peg$fail(peg$e29); }
|
|
1356
1347
|
}
|
|
1357
1348
|
if (s2 !== peg$FAILED) {
|
|
1358
1349
|
while (s2 !== peg$FAILED) {
|
|
@@ -1362,7 +1353,7 @@ function peg$parse(input, options) {
|
|
|
1362
1353
|
peg$currPos++;
|
|
1363
1354
|
} else {
|
|
1364
1355
|
s2 = peg$FAILED;
|
|
1365
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1356
|
+
if (peg$silentFails === 0) { peg$fail(peg$e29); }
|
|
1366
1357
|
}
|
|
1367
1358
|
}
|
|
1368
1359
|
} else {
|
|
@@ -1376,14 +1367,14 @@ function peg$parse(input, options) {
|
|
|
1376
1367
|
peg$silentFails--;
|
|
1377
1368
|
if (s0 === peg$FAILED) {
|
|
1378
1369
|
s1 = peg$FAILED;
|
|
1379
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1370
|
+
if (peg$silentFails === 0) { peg$fail(peg$e31); }
|
|
1380
1371
|
}
|
|
1381
1372
|
|
|
1382
1373
|
return s0;
|
|
1383
1374
|
}
|
|
1384
1375
|
|
|
1385
1376
|
function peg$parseEOL() {
|
|
1386
|
-
|
|
1377
|
+
let s0, s1;
|
|
1387
1378
|
|
|
1388
1379
|
peg$silentFails++;
|
|
1389
1380
|
if (input.charCodeAt(peg$currPos) === 10) {
|
|
@@ -1391,7 +1382,7 @@ function peg$parse(input, options) {
|
|
|
1391
1382
|
peg$currPos++;
|
|
1392
1383
|
} else {
|
|
1393
1384
|
s0 = peg$FAILED;
|
|
1394
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1385
|
+
if (peg$silentFails === 0) { peg$fail(peg$e33); }
|
|
1395
1386
|
}
|
|
1396
1387
|
if (s0 === peg$FAILED) {
|
|
1397
1388
|
if (input.substr(peg$currPos, 2) === peg$c19) {
|
|
@@ -1399,7 +1390,7 @@ function peg$parse(input, options) {
|
|
|
1399
1390
|
peg$currPos += 2;
|
|
1400
1391
|
} else {
|
|
1401
1392
|
s0 = peg$FAILED;
|
|
1402
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1393
|
+
if (peg$silentFails === 0) { peg$fail(peg$e34); }
|
|
1403
1394
|
}
|
|
1404
1395
|
if (s0 === peg$FAILED) {
|
|
1405
1396
|
if (input.charCodeAt(peg$currPos) === 13) {
|
|
@@ -1407,14 +1398,14 @@ function peg$parse(input, options) {
|
|
|
1407
1398
|
peg$currPos++;
|
|
1408
1399
|
} else {
|
|
1409
1400
|
s0 = peg$FAILED;
|
|
1410
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1401
|
+
if (peg$silentFails === 0) { peg$fail(peg$e35); }
|
|
1411
1402
|
}
|
|
1412
1403
|
}
|
|
1413
1404
|
}
|
|
1414
1405
|
peg$silentFails--;
|
|
1415
1406
|
if (s0 === peg$FAILED) {
|
|
1416
1407
|
s1 = peg$FAILED;
|
|
1417
|
-
if (peg$silentFails === 0) { peg$fail(peg$
|
|
1408
|
+
if (peg$silentFails === 0) { peg$fail(peg$e32); }
|
|
1418
1409
|
}
|
|
1419
1410
|
|
|
1420
1411
|
return s0;
|
|
@@ -1425,30 +1416,36 @@ function peg$parse(input, options) {
|
|
|
1425
1416
|
|
|
1426
1417
|
peg$result = peg$startRuleFunction();
|
|
1427
1418
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
peg$result,
|
|
1431
|
-
peg$currPos,
|
|
1432
|
-
peg$FAILED,
|
|
1433
|
-
peg$maxFailExpected,
|
|
1434
|
-
peg$maxFailPos
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
if (peg$result !== peg$FAILED && peg$currPos === input.length) {
|
|
1438
|
-
return peg$result;
|
|
1439
|
-
} else {
|
|
1419
|
+
const peg$success = (peg$result !== peg$FAILED && peg$currPos === input.length);
|
|
1420
|
+
function peg$throw() {
|
|
1440
1421
|
if (peg$result !== peg$FAILED && peg$currPos < input.length) {
|
|
1441
1422
|
peg$fail(peg$endExpectation());
|
|
1442
1423
|
}
|
|
1443
1424
|
|
|
1444
1425
|
throw peg$buildStructuredError(
|
|
1445
1426
|
peg$maxFailExpected,
|
|
1446
|
-
peg$maxFailPos < input.length ?
|
|
1427
|
+
peg$maxFailPos < input.length ? peg$getUnicode(peg$maxFailPos) : null,
|
|
1447
1428
|
peg$maxFailPos < input.length
|
|
1448
1429
|
? peg$computeLocation(peg$maxFailPos, peg$maxFailPos + 1)
|
|
1449
1430
|
: peg$computeLocation(peg$maxFailPos, peg$maxFailPos)
|
|
1450
1431
|
);
|
|
1451
1432
|
}
|
|
1433
|
+
if (options.peg$library) {
|
|
1434
|
+
return /** @type {any} */ ({
|
|
1435
|
+
peg$result,
|
|
1436
|
+
peg$currPos,
|
|
1437
|
+
peg$FAILED,
|
|
1438
|
+
peg$maxFailExpected,
|
|
1439
|
+
peg$maxFailPos,
|
|
1440
|
+
peg$success,
|
|
1441
|
+
peg$throw: peg$success ? undefined : peg$throw,
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
if (peg$success) {
|
|
1445
|
+
return peg$result;
|
|
1446
|
+
} else {
|
|
1447
|
+
peg$throw();
|
|
1448
|
+
}
|
|
1452
1449
|
}
|
|
1453
1450
|
|
|
1454
1451
|
const peg$allowedStartRules = [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* When used as a grammarSource, allows grammars embedded in larger files to
|
|
@@ -40,9 +40,9 @@ class GrammarLocation {
|
|
|
40
40
|
offset(loc) {
|
|
41
41
|
return {
|
|
42
42
|
line: loc.line + this.start.line - 1,
|
|
43
|
-
column: (loc.line === 1)
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
column: (loc.line === 1) ?
|
|
44
|
+
loc.column + this.start.column - 1 :
|
|
45
|
+
loc.column,
|
|
46
46
|
offset: loc.offset + this.start.offset,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -56,7 +56,7 @@ class GrammarLocation {
|
|
|
56
56
|
* original start.
|
|
57
57
|
*/
|
|
58
58
|
static offsetStart(range) {
|
|
59
|
-
if (range.source && (typeof range.source.offset ===
|
|
59
|
+
if (range.source && (typeof range.source.offset === 'function')) {
|
|
60
60
|
return range.source.offset(range.start);
|
|
61
61
|
}
|
|
62
62
|
return range.start;
|
|
@@ -71,7 +71,7 @@ class GrammarLocation {
|
|
|
71
71
|
* original end.
|
|
72
72
|
*/
|
|
73
73
|
static offsetEnd(range) {
|
|
74
|
-
if (range.source && (typeof range.source.offset ===
|
|
74
|
+
if (range.source && (typeof range.source.offset === 'function')) {
|
|
75
75
|
return range.source.offset(range.end);
|
|
76
76
|
}
|
|
77
77
|
return range.end;
|
package/version.js
ADDED