unexpectedly 2.0.0 → 3.0.4

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.
@@ -1,25 +1,17 @@
1
1
  #!/usr/bin/env -S node --experimental-vm-modules --no-warnings
2
- /* eslint-disable no-console */
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(pkg.version)
19
- .argument('[...file]', 'Files or directories to test', './test/')
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/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
- opts.filename = pt.vars.script ?
120
- path.resolve(dir, pt.vars.script.value) :
121
- path.resolve(dir,
122
- f.replace(/(?<base>[^\\/]*)\.tests?$/, options.defaultScript));
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(([k, v]) => !v.env),
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(([k, v]) => v.env),
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, reject) => {
177
+ return new Promise((resolve, _reject) => {
169
178
  mocha.run(resolve);
170
179
  });
171
180
  }
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "unexpectedly",
3
- "version": "2.0.0",
3
+ "version": "3.0.4",
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
- },
7
+ "files": [
8
+ "index.js",
9
+ "runner.js",
10
+ "testFile.peg.js",
11
+ "utils.js",
12
+ "version.js",
13
+ "vendor/",
14
+ "bin/"
15
+ ],
16
16
  "bin": {
17
17
  "unexpectedly": "bin/unexpectedly.js"
18
18
  },
@@ -32,22 +32,17 @@
32
32
  },
33
33
  "license": "MPL-2.0",
34
34
  "dependencies": {
35
- "@peggyjs/from-mem": "1.3.0",
36
- "commander": "12.0.0",
37
- "mocha": "^10.3.0",
38
- "semver": "7.6.0"
35
+ "@peggyjs/from-mem": "3.1.3",
36
+ "commander": "14.0.3",
37
+ "mocha": "^11.7.5"
39
38
  },
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"
39
+ "pnpm": {
40
+ "overrides": {
41
+ "mocha@11.7.5>diff": "8.0.3",
42
+ "mocha@11.7.5>serialize-javascript": "7.0.4"
43
+ }
48
44
  },
49
- "packageManager": "pnpm@8.15.4",
50
45
  "engines": {
51
- "node": ">=18"
46
+ "node": ">=20"
52
47
  }
53
48
  }
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 4.0.2.
1
+ // @generated by Peggy 5.1.0.
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
- function peg$subclass(child, parent) {
10
- function C() { this.constructor = child; }
11
- C.prototype = parent.prototype;
12
- child.prototype = new C();
13
- }
14
-
15
- function peg$SyntaxError(message, expected, found, location) {
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
- peg$SyntaxError.prototype.format = function(sources) {
39
- var str = "Error: " + this.message;
40
- if (this.location) {
41
- var src = null;
42
- var k;
43
- for (k = 0; k < sources.length; k++) {
44
- if (sources[k].source === this.location.source) {
45
- src = sources[k].text.split(/\r\n|\n|\r/g);
46
- break;
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
- var s = this.location.start;
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
- peg$SyntaxError.buildMessage = function(expected, found) {
73
- var DESCRIBE_EXPECTATION_FNS = {
74
- literal: function(expectation) {
75
- return "\"" + literalEscape(expectation.text) + "\"";
76
- },
49
+ static buildMessage(expected, found) {
50
+ function hex(ch) {
51
+ return ch.codePointAt(0).toString(16).toUpperCase();
52
+ }
77
53
 
78
- class: function(expectation) {
79
- var escapedParts = expectation.parts.map(function(part) {
80
- return Array.isArray(part)
81
- ? classEscape(part[0]) + "-" + classEscape(part[1])
82
- : classEscape(part);
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
- return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
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
- any: function() {
89
- return "any character";
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
- end: function() {
93
- return "end of input";
94
- },
90
+ const DESCRIBE_EXPECTATION_FNS = {
91
+ literal(expectation) {
92
+ return "\"" + literalEscape(expectation.text) + "\"";
93
+ },
95
94
 
96
- other: function(expectation) {
97
- return expectation.description;
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
- function hex(ch) {
102
- return ch.charCodeAt(0).toString(16).toUpperCase();
103
- }
102
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]" + (expectation.unicode ? "u" : "");
103
+ },
104
104
 
105
- function literalEscape(s) {
106
- return s
107
- .replace(/\\/g, "\\\\")
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
- function classEscape(s) {
118
- return s
119
- .replace(/\\/g, "\\\\")
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
- function describeExpectation(expectation) {
132
- return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
133
- }
113
+ other(expectation) {
114
+ return expectation.description;
115
+ },
116
+ };
134
117
 
135
- function describeExpected(expected) {
136
- var descriptions = expected.map(describeExpectation);
137
- var i, j;
118
+ function describeExpectation(expectation) {
119
+ return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
120
+ }
138
121
 
139
- descriptions.sort();
122
+ function describeExpected(expected) {
123
+ const descriptions = expected.map(describeExpectation);
124
+ descriptions.sort();
140
125
 
141
- if (descriptions.length > 0) {
142
- for (i = 1, j = 1; i < descriptions.length; i++) {
143
- if (descriptions[i - 1] !== descriptions[i]) {
144
- descriptions[j] = descriptions[i];
145
- j++;
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
- switch (descriptions.length) {
152
- case 1:
153
- return descriptions[0];
137
+ switch (descriptions.length) {
138
+ case 1:
139
+ return descriptions[0];
154
140
 
155
- case 2:
156
- return descriptions[0] + " or " + descriptions[1];
141
+ case 2:
142
+ return descriptions[0] + " or " + descriptions[1];
157
143
 
158
- default:
159
- return descriptions.slice(0, -1).join(", ")
160
- + ", or "
161
- + descriptions[descriptions.length - 1];
144
+ default:
145
+ return descriptions.slice(0, -1).join(", ")
146
+ + ", or "
147
+ + descriptions[descriptions.length - 1];
148
+ }
162
149
  }
163
- }
164
150
 
165
- function describeFound(found) {
166
- return found ? "\"" + literalEscape(found) + "\"" : "end of input";
167
- }
151
+ function describeFound(found) {
152
+ return found ? "\"" + literalEscape(found) + "\"" : "end of input";
153
+ }
168
154
 
169
- return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
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
- var peg$FAILED = {};
176
- var peg$source = options.grammarSource;
177
-
178
- var peg$startRuleFunctions = { start: peg$parsestart };
179
- var peg$startRuleFunction = peg$parsestart;
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
- var peg$f1 = function(env, name, value) {
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
- var peg$f2 = function(value) {
255
+ }
256
+ function peg$f2(value) {
270
257
  const start = location().start;
271
258
  return { value, line: start.line, column: start.column}
272
- };
273
- var peg$f3 = function(expected, inputs) {
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
- var peg$f4 = function() { return options.EXCEPTION || "!" };
278
- var peg$f5 = function(info) { return info.join('') };
279
- var peg$f6 = function(info) { return info.join('') };
280
- var peg$f7 = function(info) { return info.join('') };
281
- var peg$f8 = function() { return '"' };
282
- var peg$f9 = function() { return "'" };
283
- var peg$f10 = function() { return "`" };
284
- var peg$f11 = function(hx) { return '0x' + hx.toLowerCase(hx) };
285
- var peg$f12 = function(chars) { return chars.join('') };
286
- var peg$f13 = function() { return '\\' };
287
- var peg$f14 = function() { return '\r' };
288
- var peg$f15 = function() { return '\n' };
289
- var peg$f16 = function() { return '\t' };
290
- var peg$f17 = function() { return '#' };
291
- var peg$f18 = function() { return ':' };
292
- var peg$f19 = function() { return ' ' };
293
- var peg$f20 = function() { return undefined };
294
- var peg$f21 = function() { return undefined };
295
- var peg$f22 = function() { return undefined};
296
- var peg$f23 = function() { return undefined };
297
- var peg$currPos = options.peg$currPos | 0;
298
- var peg$savedPos = peg$currPos;
299
- var peg$posDetailsCache = [{ line: 1, column: 1 }];
300
- var peg$maxFailPos = peg$currPos;
301
- var peg$maxFailExpected = options.peg$maxFailExpected || [];
302
- var peg$silentFails = options.peg$silentFails | 0;
303
-
304
- var peg$result;
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: text, ignoreCase: ignoreCase };
350
+ return { type: "literal", text, ignoreCase };
356
351
  }
357
352
 
358
- function peg$classExpectation(parts, inverted, ignoreCase) {
359
- return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase };
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: description };
366
+ return { type: "other", description };
372
367
  }
373
368
 
374
369
  function peg$computePosDetails(pos) {
375
- var details = peg$posDetailsCache[pos];
376
- var p;
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
- var startPosDetails = peg$computePosDetails(startPos);
413
- var endPosDetails = peg$computePosDetails(endPos);
407
+ const startPosDetails = peg$computePosDetails(startPos);
408
+ const endPosDetails = peg$computePosDetails(endPos);
414
409
 
415
- var res = {
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
- var s0, s1, s2, s3, s4, s5, s6;
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
- var s0;
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
- var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10;
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
- var s0, s1;
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
- var s0, s1, s2, s3, s4, s5;
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
- var s0, s1;
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
- var s0;
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
- var s0, s1, s2, s3;
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
- var s0, s1, s2;
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
- var s0, s1, s2;
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
- var s0, s1, s2;
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
- var s0, s1, s2, s3, s4;
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
- var s0, s1, s2;
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
- var s0, s1, s2;
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
- var s0, s1;
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
- var s0, s1, s2, s3, s4, s5;
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
- var s0, s1, s2;
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$e30); }
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$e30); }
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
- var s0, s1, s2;
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$e32); }
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$e32); }
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
- var s0, s1, s2;
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$e30); }
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$e30); }
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$e33); }
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
- var s0, s1;
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$e35); }
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$e36); }
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$e37); }
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$e34); }
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
- if (options.peg$library) {
1429
- return /** @type {any} */ ({
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 ? input.charAt(peg$maxFailPos) : null,
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
- "use strict";
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
- ? loc.column + this.start.column - 1
45
- : loc.column,
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 === "function")) {
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 === "function")) {
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
@@ -0,0 +1,4 @@
1
+ // Generated by package-extract v3.1.5
2
+ // Do not modify by hand.
3
+
4
+ export const version = '3.0.4';
package/testFile.peggy DELETED
@@ -1,111 +0,0 @@
1
- {{
2
- import { mapObj } from './utils.js'
3
- }}
4
-
5
- {
6
- let vars = {};
7
- }
8
- start
9
- = all:(WS @line? _)|.., EOL| {
10
- return all.filter(t => t && t.hasOwnProperty('expected'));
11
- }
12
-
13
- line
14
- = var
15
- / comment
16
- / test
17
- / '' // hack
18
-
19
- var
20
- = '#!' env:"!"? _ name:chunk _ ':' _ value:(@val _)? {
21
- if (!value) {
22
- const start = location().start;
23
- value = {
24
- value: undefined,
25
- line: start.line,
26
- column: start.column,
27
- }
28
- }
29
- value.env = Boolean(env);
30
- vars = {
31
- ...vars,
32
- [name]: value
33
- }
34
- }
35
-
36
- val
37
- = value:chunk {
38
- const start = location().start;
39
- return { value, line: start.line, column: start.column}
40
- }
41
-
42
- test
43
- = expected:results inputs:(LWS @chunk)* comment? {
44
- const start = location().start;
45
- return { expected, inputs, vars, line: start.line, column: start.column }
46
- }
47
-
48
- results
49
- = "!" { return options.EXCEPTION || "!" }
50
- / chunk
51
-
52
- chunk
53
- = quoted
54
- / hex
55
- / word
56
-
57
- quoted
58
- = '"' info:dqchar* '"' { return info.join('') }
59
- / "'" info:sqchar* "'" { return info.join('') }
60
- / "`" info:bqchar* "`" { return info.join('') }
61
-
62
- dqchar "characters that go inside double quotes, including escaped dquotes"
63
- = '\\"' { return '"' }
64
- / qchar
65
- / $[^\\"]+
66
-
67
- sqchar "characters that go inside single quotes, including escaped squotes"
68
- = "\\'" { return "'" }
69
- / qchar
70
- / $[^\\']+
71
-
72
- bqchar "characters that go inside back quotes, including escaped bquotes"
73
- = "\\`" { return "`" }
74
- / qchar
75
- / $[^\\`]+
76
-
77
- hex
78
- = '0x' hx:$[a-fA-F0-9]+ { return '0x' + hx.toLowerCase(hx) }
79
-
80
- word
81
- = chars:wchar+ { return chars.join('') }
82
-
83
- wchar "words can contain quoted bits"
84
- = qchar+
85
- / $[^ #:'"\t\r\n]+
86
-
87
- qchar "other quoted characters, as needed"
88
- = '\\\\' { return '\\' }
89
- / '\\r' { return '\r' }
90
- / '\\n' { return '\n' }
91
- / '\\t' { return '\t' }
92
- / '\\#' { return '#' }
93
- / '\\:' { return ':' }
94
- / '\\ ' { return ' ' }
95
-
96
- comment
97
- = WS "#" !"!" [^\r\n]* { return undefined }
98
-
99
- _ "optional whitespace"
100
- = [ \t]* { return undefined }
101
-
102
- WS "optional whitespace, including newlines"
103
- = [ \t\r\n]* { return undefined}
104
-
105
- LWS "required whitespace"
106
- = [ \t]+ { return undefined }
107
-
108
- EOL "End of line"
109
- = '\n'
110
- / '\r\n'
111
- / '\r'