├── .editorconfig
├── .envrc
├── .gitattributes
├── .github
└── workflows
│ └── tests.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE-MIT.txt
├── README.md
├── flake.lock
├── flake.nix
├── package-lock.json
├── package.json
├── regjsgen.js
└── tests
├── equiv.js
├── test-data-lookbehind.json
├── test-data-modifiers-group.json
├── test-data-named-groups-unicode-properties.json
├── test-data-named-groups-unicode.json
├── test-data-named-groups.json
├── test-data-nonstandard.json
├── test-data-unicode-properties.json
├── test-data-unicode-set.json
├── test-data-unicode.json
├── test-data.json
├── tests.js
└── update-fixtures.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | # This file is for unifying the coding style for different editors and IDEs
2 | # editorconfig.org
3 |
4 | root = true
5 |
6 | [*]
7 | charset = utf-8
8 | end_of_line = lf
9 | indent_size = 2
10 | indent_style = space
11 | insert_final_newline = true
12 | trim_trailing_whitespace = true
13 |
--------------------------------------------------------------------------------
/.envrc:
--------------------------------------------------------------------------------
1 | use flake
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/.github/workflows/tests.yml:
--------------------------------------------------------------------------------
1 | name: Tests
2 | on:
3 | push:
4 | pull_request:
5 | jobs:
6 | tests:
7 | name: Run tests
8 | runs-on: ubuntu-latest
9 | strategy:
10 | matrix:
11 | node-version:
12 | - 16.x
13 | - 18.x
14 | - 20.x
15 | - 22.x
16 | permissions:
17 | contents: read
18 | id-token: write
19 | steps:
20 | - uses: actions/checkout@v4
21 | with:
22 | persist-credentials: false
23 | - name: Use Node.js ${{ matrix.node-version }}
24 | uses: actions/setup-node@v4
25 | with:
26 | node-version: ${{ matrix.node-version }}
27 | - run: npm clean-install
28 | - run: npm run test
29 | - run: npm run coverage
30 | - uses: codecov/codecov-action@v5
31 | with:
32 | use_oidc: true
33 | directory: coverage
34 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | coverage
3 | .nyc_output
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to regjsgen
2 |
3 | Contributions are always welcome. Before contributing, please [search the issue tracker](https://github.com/bnjmnt4n/regjsgen/issues);
4 | your issue may have already been discussed or fixed in `master`. To contribute, [fork](https://help.github.com/articles/fork-a-repo/) regjsgen, commit your changes, & [send a pull request](https://help.github.com/articles/using-pull-requests/).
5 |
6 | ## Tests
7 |
8 | Include updated unit tests in the `tests` directory as part of your pull request.
9 |
10 | Before running the unit tests you’ll need to install, `npm i`, [development dependencies](https://docs.npmjs.com/files/package.json#devdependencies).
11 | Run unit tests from the command-line via `npm test`.
12 | Fixtures can be updated from the [regjsparser](https://github.com/jviereck/regjsparser) repository via `npm run update-fixtures`.
13 |
14 | ## Coding Guidelines
15 |
16 | In addition to the following guidelines, please follow the conventions already established in the code.
17 |
18 | - **Spacing**:
19 | Use two spaces for indentation. No tabs.
20 |
21 | - **Naming**:
22 | Keep variable & method names concise & descriptive.
23 |
24 | - **Quotes**:
25 | Single-quoted strings are preferred to double-quoted strings; however, please use a double-quoted string if the value contains a single-quote character to avoid unnecessary escaping.
26 |
27 | - **Comments**:
28 | Please use single-line comments to annotate significant additions.
29 |
--------------------------------------------------------------------------------
/LICENSE-MIT.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright 2014-2020 Benjamin Tan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | "Software"), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # regjsgen [![Build status][ci-img]][ci] [![Code coverage status][codecov-img]][codecov]
2 |
3 | Generate regular expressions from [regjsparser][regjsparser]’s AST.
4 |
5 | ## Installation
6 |
7 | ```sh
8 | npm i regjsgen
9 | ```
10 |
11 | ## API
12 |
13 | ### `regjsgen.generate(ast)`
14 |
15 | This function accepts an abstract syntax tree representing a regular expression (see [regjsparser][regjsparser]), and returns the generated regular expression string.
16 |
17 | ```js
18 | const regjsparser = require('regjsparser');
19 | const regjsgen = require('regjsgen');
20 |
21 | // Generate an AST with `regjsparser`.
22 | let ast = regjsparser.parse(regex);
23 |
24 | // Modify AST
25 | // …
26 |
27 | // Generate `RegExp` string with `regjsgen`.
28 | let regex = regjsgen.generate(ast);
29 | ```
30 |
31 | ## Support
32 |
33 | Tested on Node.js 16, 18, 20, and 22.
34 | Compatible with regjsparser v0.12.0’s AST.
35 |
36 |
37 | [ci]: https://github.com/bnjmnt4n/regjsgen/actions
38 | [ci-img]: https://github.com/bnjmnt4n/regjsgen/workflows/Tests/badge.svg
39 | [codecov]: https://codecov.io/gh/bnjmnt4n/regjsgen
40 | [codecov-img]: https://codecov.io/gh/bnjmnt4n/regjsgen/branch/main/graph/badge.svg
41 | [regjsparser]: https://github.com/jviereck/regjsparser
42 |
--------------------------------------------------------------------------------
/flake.lock:
--------------------------------------------------------------------------------
1 | {
2 | "nodes": {
3 | "nixpkgs": {
4 | "locked": {
5 | "lastModified": 1747060738,
6 | "narHash": "sha256-ByfPRQuqj+nhtVV0koinEpmJw0KLzNbgcgi9EF+NVow=",
7 | "owner": "NixOS",
8 | "repo": "nixpkgs",
9 | "rev": "eaeed9530c76ce5f1d2d8232e08bec5e26f18ec1",
10 | "type": "github"
11 | },
12 | "original": {
13 | "owner": "NixOS",
14 | "ref": "nixpkgs-unstable",
15 | "repo": "nixpkgs",
16 | "type": "github"
17 | }
18 | },
19 | "root": {
20 | "inputs": {
21 | "nixpkgs": "nixpkgs"
22 | }
23 | }
24 | },
25 | "root": "root",
26 | "version": 7
27 | }
28 |
--------------------------------------------------------------------------------
/flake.nix:
--------------------------------------------------------------------------------
1 | {
2 | inputs = {
3 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
4 | };
5 |
6 | outputs = {nixpkgs, ...}: let
7 | systems = ["aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux"];
8 | forEachSystem = systems: f: builtins.foldl' (acc: system: nixpkgs.lib.recursiveUpdate acc (f system)) {} systems;
9 | in
10 | forEachSystem systems (system: let
11 | pkgs = nixpkgs.legacyPackages.${system};
12 | in {
13 | devShells.${system}.default = pkgs.mkShell {
14 | buildInputs = with pkgs; [
15 | nodejs
16 | ];
17 | };
18 | });
19 | }
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "regjsgen",
3 | "version": "0.8.0",
4 | "description": "Generate regular expressions from regjsparser’s AST.",
5 | "homepage": "https://github.com/bnjmnt4n/regjsgen",
6 | "main": "regjsgen.js",
7 | "keywords": [
8 | "ast",
9 | "generate",
10 | "regex",
11 | "regexp",
12 | "regular expressions"
13 | ],
14 | "license": "MIT",
15 | "author": {
16 | "name": "Benjamin Tan",
17 | "url": "https://ofcr.se/"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "https://github.com/bnjmnt4n/regjsgen.git"
22 | },
23 | "bugs": "https://github.com/bnjmnt4n/regjsgen/issues",
24 | "files": [
25 | "LICENSE-MIT.txt",
26 | "regjsgen.js"
27 | ],
28 | "scripts": {
29 | "test": "node tests/tests.js",
30 | "coverage": "nyc --reporter=lcov --reporter=text-summary npm run test",
31 | "update-fixtures": "node tests/update-fixtures.js"
32 | },
33 | "devDependencies": {
34 | "nyc": "^17.1.0",
35 | "regjsparser": "^0.12.0"
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/regjsgen.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * regjsgen 0.8.0
3 | * Copyright 2014-2023 Benjamin Tan
4 | * Available under the MIT license
5 | */
6 | ;(function() {
7 | 'use strict';
8 |
9 | // Used to determine if values are of the language type `Object`.
10 | var objectTypes = {
11 | 'function': true,
12 | 'object': true
13 | };
14 |
15 | // Used as a reference to the global object.
16 | var root = (objectTypes[typeof window] && window) || this;
17 |
18 | // Detect free variable `exports`.
19 | var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
20 |
21 | // Detect free variable `module`.
22 | var hasFreeModule = objectTypes[typeof module] && module && !module.nodeType;
23 |
24 | // Detect free variable `global` from Node.js or Browserified code and use it as `root`.
25 | var freeGlobal = freeExports && hasFreeModule && typeof global == 'object' && global;
26 | if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
27 | root = freeGlobal;
28 | }
29 |
30 | // Used to check objects for own properties.
31 | var hasOwnProperty = Object.prototype.hasOwnProperty;
32 |
33 | /*--------------------------------------------------------------------------*/
34 |
35 | // Generates a string based on the given code point.
36 | // Based on https://mths.be/fromcodepoint by @mathias.
37 | function fromCodePoint() {
38 | var codePoint = Number(arguments[0]);
39 |
40 | if (
41 | !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
42 | codePoint < 0 || // not a valid Unicode code point
43 | codePoint > 0x10FFFF || // not a valid Unicode code point
44 | Math.floor(codePoint) != codePoint // not an integer
45 | ) {
46 | throw RangeError('Invalid code point: ' + codePoint);
47 | }
48 |
49 | if (codePoint <= 0xFFFF) {
50 | // BMP code point
51 | return String.fromCharCode(codePoint);
52 | } else {
53 | // Astral code point; split in surrogate halves
54 | // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
55 | codePoint -= 0x10000;
56 | var highSurrogate = (codePoint >> 10) + 0xD800;
57 | var lowSurrogate = (codePoint % 0x400) + 0xDC00;
58 | return String.fromCharCode(highSurrogate, lowSurrogate);
59 | }
60 | }
61 |
62 | /*--------------------------------------------------------------------------*/
63 |
64 | // Ensures that nodes have the correct types.
65 | var assertTypeRegexMap = {};
66 | function assertType(type, expected) {
67 | if (expected.indexOf('|') == -1) {
68 | if (type == expected) {
69 | return;
70 | }
71 |
72 | throw Error('Invalid node type: ' + type + '; expected type: ' + expected);
73 | }
74 |
75 | expected = hasOwnProperty.call(assertTypeRegexMap, expected)
76 | ? assertTypeRegexMap[expected]
77 | : (assertTypeRegexMap[expected] = RegExp('^(?:' + expected + ')$'));
78 |
79 | if (expected.test(type)) {
80 | return;
81 | }
82 |
83 | throw Error('Invalid node type: ' + type + '; expected types: ' + expected);
84 | }
85 |
86 | /*--------------------------------------------------------------------------*/
87 |
88 | // Generates a regular expression string based on an AST.
89 | function generate(node) {
90 | var type = node.type;
91 |
92 | if (hasOwnProperty.call(generators, type)) {
93 | return generators[type](node);
94 | }
95 |
96 | throw Error('Invalid node type: ' + type);
97 | }
98 |
99 | // Constructs a string by concatentating the output of each term.
100 | function generateSequence(generator, terms, /* optional */ separator) {
101 | var i = -1,
102 | length = terms.length,
103 | result = '',
104 | term;
105 |
106 | while (++i < length) {
107 | term = terms[i];
108 |
109 | if (separator && i > 0) result += separator;
110 |
111 | // Ensure that `\0` null escapes followed by number symbols are not
112 | // treated as backreferences.
113 | if (
114 | i + 1 < length &&
115 | terms[i].type == 'value' &&
116 | terms[i].kind == 'null' &&
117 | terms[i + 1].type == 'value' &&
118 | terms[i + 1].kind == 'symbol' &&
119 | terms[i + 1].codePoint >= 48 &&
120 | terms[i + 1].codePoint <= 57
121 | ) {
122 | result += '\\000';
123 | continue;
124 | }
125 |
126 | result += generator(term);
127 | }
128 |
129 | return result;
130 | }
131 |
132 | /*--------------------------------------------------------------------------*/
133 |
134 | function generateAlternative(node) {
135 | assertType(node.type, 'alternative');
136 |
137 | return generateSequence(generateTerm, node.body);
138 | }
139 |
140 | function generateAnchor(node) {
141 | assertType(node.type, 'anchor');
142 |
143 | switch (node.kind) {
144 | case 'start':
145 | return '^';
146 | case 'end':
147 | return '$';
148 | case 'boundary':
149 | return '\\b';
150 | case 'not-boundary':
151 | return '\\B';
152 | default:
153 | throw Error('Invalid assertion');
154 | }
155 | }
156 |
157 | var atomType = 'anchor|characterClass|characterClassEscape|dot|group|reference|unicodePropertyEscape|value';
158 |
159 | function generateAtom(node) {
160 | assertType(node.type, atomType);
161 |
162 | return generate(node);
163 | }
164 |
165 | function generateCharacterClass(node) {
166 | assertType(node.type, 'characterClass');
167 |
168 | var kind = node.kind;
169 | var separator = kind === 'intersection' ? '&&' : kind === 'subtraction' ? '--' : '';
170 |
171 | return '[' +
172 | (node.negative ? '^' : '') +
173 | generateSequence(generateClassAtom, node.body, separator) +
174 | ']';
175 | }
176 |
177 | function generateCharacterClassEscape(node) {
178 | assertType(node.type, 'characterClassEscape');
179 |
180 | return '\\' + node.value;
181 | }
182 |
183 | function generateCharacterClassRange(node) {
184 | assertType(node.type, 'characterClassRange');
185 |
186 | var min = node.min,
187 | max = node.max;
188 |
189 | if (min.type == 'characterClassRange' || max.type == 'characterClassRange') {
190 | throw Error('Invalid character class range');
191 | }
192 |
193 | return generateClassAtom(min) + '-' + generateClassAtom(max);
194 | }
195 |
196 | function generateClassAtom(node) {
197 | assertType(node.type, 'anchor|characterClass|characterClassEscape|characterClassRange|dot|value|unicodePropertyEscape|classStrings');
198 |
199 | return generate(node);
200 | }
201 |
202 | function generateClassStrings(node) {
203 | assertType(node.type, 'classStrings');
204 |
205 | return '\\q{' + generateSequence(generateClassString, node.strings, '|') + '}';
206 | }
207 |
208 | function generateClassString(node) {
209 | assertType(node.type, 'classString');
210 |
211 | return generateSequence(generate, node.characters);
212 | }
213 |
214 | function generateDisjunction(node) {
215 | assertType(node.type, 'disjunction');
216 |
217 | return generateSequence(generate, node.body, '|');
218 | }
219 |
220 |
221 | function generateDot(node) {
222 | assertType(node.type, 'dot');
223 |
224 | return '.';
225 | }
226 |
227 | function generateGroup(node) {
228 | assertType(node.type, 'group');
229 |
230 | var result = '';
231 |
232 | switch (node.behavior) {
233 | case 'normal':
234 | if (node.name) {
235 | result += '?<' + generateIdentifier(node.name) + '>';
236 | }
237 | break;
238 | case 'ignore':
239 | if (node.modifierFlags) {
240 | result += '?';
241 | if (node.modifierFlags.enabling) result += node.modifierFlags.enabling;
242 | if (node.modifierFlags.disabling) result += "-" + node.modifierFlags.disabling;
243 | result += ':';
244 | } else {
245 | result += '?:';
246 | }
247 | break;
248 | case 'lookahead':
249 | result += '?=';
250 | break;
251 | case 'negativeLookahead':
252 | result += '?!';
253 | break;
254 | case 'lookbehind':
255 | result += '?<=';
256 | break;
257 | case 'negativeLookbehind':
258 | result += '?';
313 | }
314 |
315 | throw new Error('Unknown reference type');
316 | }
317 |
318 | function generateTerm(node) {
319 | assertType(node.type, atomType + '|empty|quantifier');
320 |
321 | return generate(node);
322 | }
323 |
324 | function generateUnicodePropertyEscape(node) {
325 | assertType(node.type, 'unicodePropertyEscape');
326 |
327 | return '\\' + (node.negative ? 'P' : 'p') + '{' + node.value + '}';
328 | }
329 |
330 | function generateValue(node) {
331 | assertType(node.type, 'value');
332 |
333 | var kind = node.kind,
334 | codePoint = node.codePoint;
335 |
336 | if (typeof codePoint != 'number') {
337 | throw new Error('Invalid code point: ' + codePoint);
338 | }
339 |
340 | switch (kind) {
341 | case 'controlLetter':
342 | return '\\c' + fromCodePoint(codePoint + 64);
343 | case 'hexadecimalEscape':
344 | return '\\x' + ('00' + codePoint.toString(16).toUpperCase()).slice(-2);
345 | case 'identifier':
346 | return '\\' + fromCodePoint(codePoint);
347 | case 'null':
348 | return '\\' + codePoint;
349 | case 'octal':
350 | return '\\' + ('000' + codePoint.toString(8)).slice(-3);
351 | case 'singleEscape':
352 | switch (codePoint) {
353 | case 0x0008:
354 | return '\\b';
355 | case 0x0009:
356 | return '\\t';
357 | case 0x000A:
358 | return '\\n';
359 | case 0x000B:
360 | return '\\v';
361 | case 0x000C:
362 | return '\\f';
363 | case 0x000D:
364 | return '\\r';
365 | case 0x002D:
366 | return '\\-';
367 | default:
368 | throw Error('Invalid code point: ' + codePoint);
369 | }
370 | case 'symbol':
371 | return fromCodePoint(codePoint);
372 | case 'unicodeEscape':
373 | return '\\u' + ('0000' + codePoint.toString(16).toUpperCase()).slice(-4);
374 | case 'unicodeCodePointEscape':
375 | return '\\u{' + codePoint.toString(16).toUpperCase() + '}';
376 | default:
377 | throw Error('Unsupported node kind: ' + kind);
378 | }
379 | }
380 |
381 | /*--------------------------------------------------------------------------*/
382 |
383 | // Used to generate strings for each node type.
384 | var generators = {
385 | 'alternative': generateAlternative,
386 | 'anchor': generateAnchor,
387 | 'characterClass': generateCharacterClass,
388 | 'characterClassEscape': generateCharacterClassEscape,
389 | 'characterClassRange': generateCharacterClassRange,
390 | 'classStrings': generateClassStrings,
391 | 'disjunction': generateDisjunction,
392 | 'dot': generateDot,
393 | 'group': generateGroup,
394 | 'quantifier': generateQuantifier,
395 | 'reference': generateReference,
396 | 'unicodePropertyEscape': generateUnicodePropertyEscape,
397 | 'value': generateValue
398 | };
399 |
400 | /*--------------------------------------------------------------------------*/
401 |
402 | // Export regjsgen.
403 | var regjsgen = {
404 | 'generate': generate
405 | };
406 |
407 | // Some AMD build optimizers, like r.js, check for condition patterns like the following:
408 | if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
409 | // Define as an anonymous module so it can be aliased through path mapping.
410 | define(function() {
411 | return regjsgen;
412 | });
413 |
414 | root.regjsgen = regjsgen;
415 | }
416 | // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
417 | else if (freeExports && hasFreeModule) {
418 | // Export for CommonJS support.
419 | freeExports.generate = generate;
420 | }
421 | else {
422 | // Export to the global object.
423 | root.regjsgen = regjsgen;
424 | }
425 | }.call(this));
426 |
--------------------------------------------------------------------------------
/tests/equiv.js:
--------------------------------------------------------------------------------
1 | // Simple AST node equivalence checker.
2 | function astNodesAreEquivalent(a, b) {
3 | var aType = typeof a;
4 | var bType = typeof b;
5 | if (aType !== bType) {
6 | return false;
7 | }
8 |
9 | switch (aType) {
10 | case "boolean":
11 | case "number":
12 | case "string":
13 | case "undefined":
14 | // Simple comparison.
15 | return a === b;
16 |
17 | case "object":
18 | var aTag = Object.prototype.toString.call(a);
19 | var bTag = Object.prototype.toString.call(b);
20 |
21 | if (aTag != bTag) {
22 | return false;
23 | }
24 |
25 | if (aTag == "[object Array]") {
26 | if (a.length !== b.length) {
27 | return false;
28 | }
29 |
30 | for (var i = 0, length = a.length; i < length; i++) {
31 | if (i in a !== i in b) {
32 | return false;
33 | }
34 |
35 | if (!astNodesAreEquivalent(a[i], b[i])) {
36 | return false;
37 | }
38 | }
39 |
40 | return true;
41 | }
42 |
43 | if (aTag != "[object Object]") {
44 | return false;
45 | }
46 |
47 | // Fast path for a common property of AST nodes.
48 | if (a.type != b.type) {
49 | return false;
50 | }
51 |
52 | // Avoid comparing regular expression literals.
53 | var aNames = Object.keys(a).filter(function(name) { return name != "range" && name != "raw"; });
54 | var bNames = Object.keys(b).filter(function(name) { return name != "range" && name != "raw"; });
55 | var aNameCount = aNames.length;
56 |
57 | // Avoid comparing actual symbols for quantifiers.
58 | if (a.type == "quantifier" && b.type == "quantifier") {
59 | delete a.symbol;
60 | delete b.symbol;
61 | }
62 |
63 | if (aNameCount == bNames.length) {
64 | for (var i = 0; i < aNameCount; ++i) {
65 | var name = aNames[i];
66 |
67 | if (!astNodesAreEquivalent(a[name], b[name])) {
68 | return false;
69 | }
70 | }
71 |
72 | return true;
73 | }
74 |
75 | default:
76 | return false;
77 | }
78 | }
79 |
80 | module.exports = astNodesAreEquivalent;
81 |
--------------------------------------------------------------------------------
/tests/test-data-lookbehind.json:
--------------------------------------------------------------------------------
1 | {
2 | "(?<=\\$)\\d+(\\.\\d*)?": {
3 | "type": "alternative",
4 | "body": [
5 | {
6 | "type": "group",
7 | "behavior": "lookbehind",
8 | "body": [
9 | {
10 | "type": "value",
11 | "kind": "identifier",
12 | "codePoint": 36,
13 | "range": [
14 | 4,
15 | 6
16 | ],
17 | "raw": "\\$"
18 | }
19 | ],
20 | "range": [
21 | 0,
22 | 7
23 | ],
24 | "raw": "(?<=\\$)"
25 | },
26 | {
27 | "type": "quantifier",
28 | "min": 1,
29 | "max": null,
30 | "greedy": true,
31 | "body": [
32 | {
33 | "type": "characterClassEscape",
34 | "value": "d",
35 | "range": [
36 | 7,
37 | 9
38 | ],
39 | "raw": "\\d"
40 | }
41 | ],
42 | "symbol": "+",
43 | "range": [
44 | 7,
45 | 10
46 | ],
47 | "raw": "\\d+"
48 | },
49 | {
50 | "type": "quantifier",
51 | "min": 0,
52 | "max": 1,
53 | "greedy": true,
54 | "body": [
55 | {
56 | "type": "group",
57 | "behavior": "normal",
58 | "body": [
59 | {
60 | "type": "value",
61 | "kind": "identifier",
62 | "codePoint": 46,
63 | "range": [
64 | 11,
65 | 13
66 | ],
67 | "raw": "\\."
68 | },
69 | {
70 | "type": "quantifier",
71 | "min": 0,
72 | "max": null,
73 | "greedy": true,
74 | "body": [
75 | {
76 | "type": "characterClassEscape",
77 | "value": "d",
78 | "range": [
79 | 13,
80 | 15
81 | ],
82 | "raw": "\\d"
83 | }
84 | ],
85 | "symbol": "*",
86 | "range": [
87 | 13,
88 | 16
89 | ],
90 | "raw": "\\d*"
91 | }
92 | ],
93 | "range": [
94 | 10,
95 | 17
96 | ],
97 | "raw": "(\\.\\d*)"
98 | }
99 | ],
100 | "symbol": "?",
101 | "range": [
102 | 10,
103 | 18
104 | ],
105 | "raw": "(\\.\\d*)?"
106 | }
107 | ],
108 | "range": [
109 | 0,
110 | 18
111 | ],
112 | "raw": "(?<=\\$)\\d+(\\.\\d*)?"
113 | },
114 | "(?<=\\$\\d+\\.)\\d+": {
115 | "type": "alternative",
116 | "body": [
117 | {
118 | "type": "group",
119 | "behavior": "lookbehind",
120 | "body": [
121 | {
122 | "type": "value",
123 | "kind": "identifier",
124 | "codePoint": 36,
125 | "range": [
126 | 4,
127 | 6
128 | ],
129 | "raw": "\\$"
130 | },
131 | {
132 | "type": "quantifier",
133 | "min": 1,
134 | "max": null,
135 | "greedy": true,
136 | "body": [
137 | {
138 | "type": "characterClassEscape",
139 | "value": "d",
140 | "range": [
141 | 6,
142 | 8
143 | ],
144 | "raw": "\\d"
145 | }
146 | ],
147 | "symbol": "+",
148 | "range": [
149 | 6,
150 | 9
151 | ],
152 | "raw": "\\d+"
153 | },
154 | {
155 | "type": "value",
156 | "kind": "identifier",
157 | "codePoint": 46,
158 | "range": [
159 | 9,
160 | 11
161 | ],
162 | "raw": "\\."
163 | }
164 | ],
165 | "range": [
166 | 0,
167 | 12
168 | ],
169 | "raw": "(?<=\\$\\d+\\.)"
170 | },
171 | {
172 | "type": "quantifier",
173 | "min": 1,
174 | "max": null,
175 | "greedy": true,
176 | "body": [
177 | {
178 | "type": "characterClassEscape",
179 | "value": "d",
180 | "range": [
181 | 12,
182 | 14
183 | ],
184 | "raw": "\\d"
185 | }
186 | ],
187 | "symbol": "+",
188 | "range": [
189 | 12,
190 | 15
191 | ],
192 | "raw": "\\d+"
193 | }
194 | ],
195 | "range": [
196 | 0,
197 | 15
198 | ],
199 | "raw": "(?<=\\$\\d+\\.)\\d+"
200 | },
201 | "(?\\p{ASCII_Hex_Digit}.)\\k\\p{ASCII_Hex_Digit}": {
3 | "type": "alternative",
4 | "body": [
5 | {
6 | "type": "group",
7 | "behavior": "normal",
8 | "body": [
9 | {
10 | "type": "unicodePropertyEscape",
11 | "negative": false,
12 | "value": "ASCII_Hex_Digit",
13 | "range": [
14 | 8,
15 | 27
16 | ],
17 | "raw": "\\p{ASCII_Hex_Digit}"
18 | },
19 | {
20 | "type": "dot",
21 | "range": [
22 | 27,
23 | 28
24 | ],
25 | "raw": "."
26 | }
27 | ],
28 | "range": [
29 | 0,
30 | 29
31 | ],
32 | "raw": "(?\\p{ASCII_Hex_Digit}.)",
33 | "name": {
34 | "type": "identifier",
35 | "value": "name",
36 | "range": [
37 | 3,
38 | 7
39 | ],
40 | "raw": "name"
41 | }
42 | },
43 | {
44 | "type": "reference",
45 | "name": {
46 | "type": "identifier",
47 | "value": "name",
48 | "range": [
49 | 32,
50 | 36
51 | ],
52 | "raw": "name"
53 | },
54 | "range": [
55 | 29,
56 | 37
57 | ],
58 | "raw": "\\k"
59 | },
60 | {
61 | "type": "unicodePropertyEscape",
62 | "negative": false,
63 | "value": "ASCII_Hex_Digit",
64 | "range": [
65 | 37,
66 | 56
67 | ],
68 | "raw": "\\p{ASCII_Hex_Digit}"
69 | }
70 | ],
71 | "range": [
72 | 0,
73 | 56
74 | ],
75 | "raw": "(?\\p{ASCII_Hex_Digit}.)\\k\\p{ASCII_Hex_Digit}"
76 | },
77 | "(?.)": {
78 | "type": "error",
79 | "name": "SyntaxError",
80 | "message": "Invalid escape sequence at position 7\n (?.)"
82 | },
83 | "(?)\\k": {
84 | "type": "error",
85 | "name": "SyntaxError",
86 | "message": "Invalid escape sequence at position 16\n e>)\\k)\\k"
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/tests/test-data-named-groups-unicode.json:
--------------------------------------------------------------------------------
1 | {
2 | "(?<\\u{41}bc\\u{41}>)\\k<\\u{41}bc\\u{41}>": {
3 | "type": "alternative",
4 | "body": [
5 | {
6 | "type": "group",
7 | "behavior": "normal",
8 | "body": [],
9 | "range": [
10 | 0,
11 | 19
12 | ],
13 | "raw": "(?<\\u{41}bc\\u{41}>)",
14 | "name": {
15 | "type": "identifier",
16 | "value": "AbcA",
17 | "range": [
18 | 3,
19 | 17
20 | ],
21 | "raw": "\\u{41}bc\\u{41}"
22 | }
23 | },
24 | {
25 | "type": "reference",
26 | "name": {
27 | "type": "identifier",
28 | "value": "AbcA",
29 | "range": [
30 | 22,
31 | 36
32 | ],
33 | "raw": "\\u{41}bc\\u{41}"
34 | },
35 | "range": [
36 | 19,
37 | 37
38 | ],
39 | "raw": "\\k<\\u{41}bc\\u{41}>"
40 | }
41 | ],
42 | "range": [
43 | 0,
44 | 37
45 | ],
46 | "raw": "(?<\\u{41}bc\\u{41}>)\\k<\\u{41}bc\\u{41}>"
47 | },
48 | "(?<\\u{0}>)": {
49 | "type": "error",
50 | "name": "SyntaxError",
51 | "message": "Invalid escape sequence at position 3\n (?<\\u{0}>)\n ^",
52 | "input": "(?<\\u{0}>)"
53 | },
54 | "(?<\\u{x}>)": {
55 | "type": "error",
56 | "name": "SyntaxError",
57 | "message": "Invalid escape sequence at position 3\n (?<\\u{x}>)\n ^",
58 | "input": "(?<\\u{x}>)"
59 | },
60 | "(?<\\u{ffffff})": {
61 | "type": "error",
62 | "name": "RangeError",
63 | "message": "Invalid code point 16777215",
64 | "input": "(?<\\u{ffffff})"
65 | },
66 | "(?<$\uD801\uDCA4>a)": {
67 | "type": "group",
68 | "behavior": "normal",
69 | "body": [
70 | {
71 | "type": "value",
72 | "kind": "symbol",
73 | "codePoint": 97,
74 | "range": [
75 | 7,
76 | 8
77 | ],
78 | "raw": "a"
79 | }
80 | ],
81 | "range": [
82 | 0,
83 | 9
84 | ],
85 | "raw": "(?<$\uD801\uDCA4>a)",
86 | "name": {
87 | "type": "identifier",
88 | "value": "$\uD801\uDCA4",
89 | "range": [
90 | 3,
91 | 6
92 | ],
93 | "raw": "$\uD801\uDCA4"
94 | }
95 | },
96 | "(?<\\u{102A7}\u0220>)": {
97 | "type": "group",
98 | "behavior": "normal",
99 | "body": [],
100 | "range": [
101 | 0,
102 | 15
103 | ],
104 | "raw": "(?<\\u{102A7}\u0220>)",
105 | "name": {
106 | "type": "identifier",
107 | "value": "\uD800\uDEA7\u0220",
108 | "range": [
109 | 3,
110 | 13
111 | ],
112 | "raw": "\\u{102A7}\u0220"
113 | }
114 | },
115 | "(?<\\u{2EBF0}\\u{200C}\\u{200D}>)": {
116 | "type": "group",
117 | "behavior": "normal",
118 | "body": [],
119 | "range": [
120 | 0,
121 | 30
122 | ],
123 | "raw": "(?<\\u{2EBF0}\\u{200C}\\u{200D}>)",
124 | "name": {
125 | "type": "identifier",
126 | "value": "\uD87A\uDFF0\u200C\u200D",
127 | "range": [
128 | 3,
129 | 28
130 | ],
131 | "raw": "\\u{2EBF0}\\u{200C}\\u{200D}"
132 | }
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/tests/test-data-named-groups.json:
--------------------------------------------------------------------------------
1 | {
2 | "(?a)": {
3 | "type": "group",
4 | "behavior": "normal",
5 | "body": [
6 | {
7 | "type": "value",
8 | "kind": "symbol",
9 | "codePoint": 97,
10 | "range": [
11 | 8,
12 | 9
13 | ],
14 | "raw": "a"
15 | }
16 | ],
17 | "range": [
18 | 0,
19 | 10
20 | ],
21 | "raw": "(?a)",
22 | "name": {
23 | "type": "identifier",
24 | "value": "name",
25 | "range": [
26 | 3,
27 | 7
28 | ],
29 | "raw": "name"
30 | }
31 | },
32 | "(?<$>)(?<_>)": {
33 | "type": "alternative",
34 | "body": [
35 | {
36 | "type": "group",
37 | "behavior": "normal",
38 | "body": [],
39 | "range": [
40 | 0,
41 | 6
42 | ],
43 | "raw": "(?<$>)",
44 | "name": {
45 | "type": "identifier",
46 | "value": "$",
47 | "range": [
48 | 3,
49 | 4
50 | ],
51 | "raw": "$"
52 | }
53 | },
54 | {
55 | "type": "group",
56 | "behavior": "normal",
57 | "body": [],
58 | "range": [
59 | 6,
60 | 12
61 | ],
62 | "raw": "(?<_>)",
63 | "name": {
64 | "type": "identifier",
65 | "value": "_",
66 | "range": [
67 | 9,
68 | 10
69 | ],
70 | "raw": "_"
71 | }
72 | }
73 | ],
74 | "range": [
75 | 0,
76 | 12
77 | ],
78 | "raw": "(?<$>)(?<_>)"
79 | },
80 | "(?)\\1": {
81 | "type": "alternative",
82 | "body": [
83 | {
84 | "type": "group",
85 | "behavior": "normal",
86 | "body": [],
87 | "range": [
88 | 0,
89 | 6
90 | ],
91 | "raw": "(?)",
92 | "name": {
93 | "type": "identifier",
94 | "value": "a",
95 | "range": [
96 | 3,
97 | 4
98 | ],
99 | "raw": "a"
100 | }
101 | },
102 | {
103 | "type": "reference",
104 | "matchIndex": 1,
105 | "range": [
106 | 6,
107 | 8
108 | ],
109 | "raw": "\\1"
110 | }
111 | ],
112 | "range": [
113 | 0,
114 | 8
115 | ],
116 | "raw": "(?)\\1"
117 | },
118 | "(?)\\k": {
119 | "type": "alternative",
120 | "body": [
121 | {
122 | "type": "group",
123 | "behavior": "normal",
124 | "body": [],
125 | "range": [
126 | 0,
127 | 9
128 | ],
129 | "raw": "(?)",
130 | "name": {
131 | "type": "identifier",
132 | "value": "name",
133 | "range": [
134 | 3,
135 | 7
136 | ],
137 | "raw": "name"
138 | }
139 | },
140 | {
141 | "type": "reference",
142 | "name": {
143 | "type": "identifier",
144 | "value": "name",
145 | "range": [
146 | 12,
147 | 16
148 | ],
149 | "raw": "name"
150 | },
151 | "range": [
152 | 9,
153 | 17
154 | ],
155 | "raw": "\\k"
156 | }
157 | ],
158 | "range": [
159 | 0,
160 | 17
161 | ],
162 | "raw": "(?)\\k"
163 | },
164 | "(?<\\u{41})": {
165 | "type": "error",
166 | "name": "SyntaxError",
167 | "message": "character at position 9: >\n (?<\\u{41})\n ^",
168 | "input": "(?<\\u{41})"
169 | },
170 | "(?<\\u0041bc\\u0041>)\\k<\\u0041bc\\u0041>": {
171 | "type": "alternative",
172 | "body": [
173 | {
174 | "type": "group",
175 | "behavior": "normal",
176 | "body": [],
177 | "range": [
178 | 0,
179 | 19
180 | ],
181 | "raw": "(?<\\u0041bc\\u0041>)",
182 | "name": {
183 | "type": "identifier",
184 | "value": "AbcA",
185 | "range": [
186 | 3,
187 | 17
188 | ],
189 | "raw": "\\u0041bc\\u0041"
190 | }
191 | },
192 | {
193 | "type": "reference",
194 | "name": {
195 | "type": "identifier",
196 | "value": "AbcA",
197 | "range": [
198 | 22,
199 | 36
200 | ],
201 | "raw": "\\u0041bc\\u0041"
202 | },
203 | "range": [
204 | 19,
205 | 37
206 | ],
207 | "raw": "\\k<\\u0041bc\\u0041>"
208 | }
209 | ],
210 | "range": [
211 | 0,
212 | 37
213 | ],
214 | "raw": "(?<\\u0041bc\\u0041>)\\k<\\u0041bc\\u0041>"
215 | },
216 | "(?<\\u0000>)": {
217 | "type": "error",
218 | "name": "SyntaxError",
219 | "message": "Invalid escape sequence at position 3\n (?<\\u0000>)\n ^",
220 | "input": "(?<\\u0000>)"
221 | },
222 | "(?<\\u{10000}>b008-A)\\k<\\u{10000}>": {
223 | "type": "alternative",
224 | "body": [
225 | {
226 | "type": "group",
227 | "behavior": "normal",
228 | "body": [
229 | {
230 | "type": "value",
231 | "kind": "symbol",
232 | "codePoint": 98,
233 | "range": [
234 | 13,
235 | 14
236 | ],
237 | "raw": "b"
238 | },
239 | {
240 | "type": "value",
241 | "kind": "symbol",
242 | "codePoint": 48,
243 | "range": [
244 | 14,
245 | 15
246 | ],
247 | "raw": "0"
248 | },
249 | {
250 | "type": "value",
251 | "kind": "symbol",
252 | "codePoint": 48,
253 | "range": [
254 | 15,
255 | 16
256 | ],
257 | "raw": "0"
258 | },
259 | {
260 | "type": "value",
261 | "kind": "symbol",
262 | "codePoint": 56,
263 | "range": [
264 | 16,
265 | 17
266 | ],
267 | "raw": "8"
268 | },
269 | {
270 | "type": "value",
271 | "kind": "symbol",
272 | "codePoint": 45,
273 | "range": [
274 | 17,
275 | 18
276 | ],
277 | "raw": "-"
278 | },
279 | {
280 | "type": "value",
281 | "kind": "symbol",
282 | "codePoint": 65,
283 | "range": [
284 | 18,
285 | 19
286 | ],
287 | "raw": "A"
288 | }
289 | ],
290 | "range": [
291 | 0,
292 | 20
293 | ],
294 | "raw": "(?<\\u{10000}>b008-A)",
295 | "name": {
296 | "type": "identifier",
297 | "value": "\uD800\uDC00",
298 | "range": [
299 | 3,
300 | 12
301 | ],
302 | "raw": "\\u{10000}"
303 | }
304 | },
305 | {
306 | "type": "reference",
307 | "name": {
308 | "type": "identifier",
309 | "value": "\uD800\uDC00",
310 | "range": [
311 | 23,
312 | 32
313 | ],
314 | "raw": "\\u{10000}"
315 | },
316 | "range": [
317 | 20,
318 | 33
319 | ],
320 | "raw": "\\k<\\u{10000}>"
321 | }
322 | ],
323 | "range": [
324 | 0,
325 | 33
326 | ],
327 | "raw": "(?<\\u{10000}>b008-A)\\k<\\u{10000}>"
328 | },
329 | "(?b008-A)\\k": {
330 | "type": "alternative",
331 | "body": [
332 | {
333 | "type": "group",
334 | "behavior": "normal",
335 | "body": [
336 | {
337 | "type": "value",
338 | "kind": "symbol",
339 | "codePoint": 98,
340 | "range": [
341 | 14,
342 | 15
343 | ],
344 | "raw": "b"
345 | },
346 | {
347 | "type": "value",
348 | "kind": "symbol",
349 | "codePoint": 48,
350 | "range": [
351 | 15,
352 | 16
353 | ],
354 | "raw": "0"
355 | },
356 | {
357 | "type": "value",
358 | "kind": "symbol",
359 | "codePoint": 48,
360 | "range": [
361 | 16,
362 | 17
363 | ],
364 | "raw": "0"
365 | },
366 | {
367 | "type": "value",
368 | "kind": "symbol",
369 | "codePoint": 56,
370 | "range": [
371 | 17,
372 | 18
373 | ],
374 | "raw": "8"
375 | },
376 | {
377 | "type": "value",
378 | "kind": "symbol",
379 | "codePoint": 45,
380 | "range": [
381 | 18,
382 | 19
383 | ],
384 | "raw": "-"
385 | },
386 | {
387 | "type": "value",
388 | "kind": "symbol",
389 | "codePoint": 65,
390 | "range": [
391 | 19,
392 | 20
393 | ],
394 | "raw": "A"
395 | }
396 | ],
397 | "range": [
398 | 0,
399 | 21
400 | ],
401 | "raw": "(?b008-A)",
402 | "name": {
403 | "type": "identifier",
404 | "value": "A\uD800\uDC00",
405 | "range": [
406 | 3,
407 | 13
408 | ],
409 | "raw": "A\\u{10000}"
410 | }
411 | },
412 | {
413 | "type": "reference",
414 | "name": {
415 | "type": "identifier",
416 | "value": "A\uD800\uDC00",
417 | "range": [
418 | 24,
419 | 34
420 | ],
421 | "raw": "A\\u{10000}"
422 | },
423 | "range": [
424 | 21,
425 | 35
426 | ],
427 | "raw": "\\k"
428 | }
429 | ],
430 | "range": [
431 | 0,
432 | 35
433 | ],
434 | "raw": "(?b008-A)\\k"
435 | },
436 | "(?<\\ud800\\udc00>b008-A)\\k<\\ud800\\udc00>": {
437 | "type": "alternative",
438 | "body": [
439 | {
440 | "type": "group",
441 | "behavior": "normal",
442 | "body": [
443 | {
444 | "type": "value",
445 | "kind": "symbol",
446 | "codePoint": 98,
447 | "range": [
448 | 16,
449 | 17
450 | ],
451 | "raw": "b"
452 | },
453 | {
454 | "type": "value",
455 | "kind": "symbol",
456 | "codePoint": 48,
457 | "range": [
458 | 17,
459 | 18
460 | ],
461 | "raw": "0"
462 | },
463 | {
464 | "type": "value",
465 | "kind": "symbol",
466 | "codePoint": 48,
467 | "range": [
468 | 18,
469 | 19
470 | ],
471 | "raw": "0"
472 | },
473 | {
474 | "type": "value",
475 | "kind": "symbol",
476 | "codePoint": 56,
477 | "range": [
478 | 19,
479 | 20
480 | ],
481 | "raw": "8"
482 | },
483 | {
484 | "type": "value",
485 | "kind": "symbol",
486 | "codePoint": 45,
487 | "range": [
488 | 20,
489 | 21
490 | ],
491 | "raw": "-"
492 | },
493 | {
494 | "type": "value",
495 | "kind": "symbol",
496 | "codePoint": 65,
497 | "range": [
498 | 21,
499 | 22
500 | ],
501 | "raw": "A"
502 | }
503 | ],
504 | "range": [
505 | 0,
506 | 23
507 | ],
508 | "raw": "(?<\\ud800\\udc00>b008-A)",
509 | "name": {
510 | "type": "identifier",
511 | "value": "\uD800\uDC00",
512 | "range": [
513 | 3,
514 | 15
515 | ],
516 | "raw": "\\ud800\\udc00"
517 | }
518 | },
519 | {
520 | "type": "reference",
521 | "name": {
522 | "type": "identifier",
523 | "value": "\uD800\uDC00",
524 | "range": [
525 | 26,
526 | 38
527 | ],
528 | "raw": "\\ud800\\udc00"
529 | },
530 | "range": [
531 | 23,
532 | 39
533 | ],
534 | "raw": "\\k<\\ud800\\udc00>"
535 | }
536 | ],
537 | "range": [
538 | 0,
539 | 39
540 | ],
541 | "raw": "(?<\\ud800\\udc00>b008-A)\\k<\\ud800\\udc00>"
542 | },
543 | "(?b008-A)\\k": {
544 | "type": "alternative",
545 | "body": [
546 | {
547 | "type": "group",
548 | "behavior": "normal",
549 | "body": [
550 | {
551 | "type": "value",
552 | "kind": "symbol",
553 | "codePoint": 98,
554 | "range": [
555 | 17,
556 | 18
557 | ],
558 | "raw": "b"
559 | },
560 | {
561 | "type": "value",
562 | "kind": "symbol",
563 | "codePoint": 48,
564 | "range": [
565 | 18,
566 | 19
567 | ],
568 | "raw": "0"
569 | },
570 | {
571 | "type": "value",
572 | "kind": "symbol",
573 | "codePoint": 48,
574 | "range": [
575 | 19,
576 | 20
577 | ],
578 | "raw": "0"
579 | },
580 | {
581 | "type": "value",
582 | "kind": "symbol",
583 | "codePoint": 56,
584 | "range": [
585 | 20,
586 | 21
587 | ],
588 | "raw": "8"
589 | },
590 | {
591 | "type": "value",
592 | "kind": "symbol",
593 | "codePoint": 45,
594 | "range": [
595 | 21,
596 | 22
597 | ],
598 | "raw": "-"
599 | },
600 | {
601 | "type": "value",
602 | "kind": "symbol",
603 | "codePoint": 65,
604 | "range": [
605 | 22,
606 | 23
607 | ],
608 | "raw": "A"
609 | }
610 | ],
611 | "range": [
612 | 0,
613 | 24
614 | ],
615 | "raw": "(?b008-A)",
616 | "name": {
617 | "type": "identifier",
618 | "value": "A\uD800\uDC00",
619 | "range": [
620 | 3,
621 | 16
622 | ],
623 | "raw": "A\\ud800\\udc00"
624 | }
625 | },
626 | {
627 | "type": "reference",
628 | "name": {
629 | "type": "identifier",
630 | "value": "A\uD800\uDC00",
631 | "range": [
632 | 27,
633 | 40
634 | ],
635 | "raw": "A\\ud800\\udc00"
636 | },
637 | "range": [
638 | 24,
639 | 41
640 | ],
641 | "raw": "\\k"
642 | }
643 | ],
644 | "range": [
645 | 0,
646 | 41
647 | ],
648 | "raw": "(?b008-A)\\k"
649 | },
650 | "{(?)}": {
651 | "type": "alternative",
652 | "body": [
653 | {
654 | "type": "value",
655 | "kind": "symbol",
656 | "codePoint": 123,
657 | "range": [
658 | 0,
659 | 1
660 | ],
661 | "raw": "{"
662 | },
663 | {
664 | "type": "group",
665 | "behavior": "normal",
666 | "body": [],
667 | "range": [
668 | 1,
669 | 7
670 | ],
671 | "raw": "(?)",
672 | "name": {
673 | "type": "identifier",
674 | "value": "x",
675 | "range": [
676 | 4,
677 | 5
678 | ],
679 | "raw": "x"
680 | }
681 | },
682 | {
683 | "type": "value",
684 | "kind": "symbol",
685 | "codePoint": 125,
686 | "range": [
687 | 7,
688 | 8
689 | ],
690 | "raw": "}"
691 | }
692 | ],
693 | "range": [
694 | 0,
695 | 8
696 | ],
697 | "raw": "{(?)}"
698 | },
699 | "(a)": {
700 | "type": "group",
701 | "behavior": "normal",
702 | "body": [
703 | {
704 | "type": "value",
705 | "kind": "symbol",
706 | "codePoint": 97,
707 | "range": [
708 | 1,
709 | 2
710 | ],
711 | "raw": "a"
712 | }
713 | ],
714 | "range": [
715 | 0,
716 | 3
717 | ],
718 | "raw": "(a)"
719 | }
720 | }
721 |
--------------------------------------------------------------------------------
/tests/test-data-nonstandard.json:
--------------------------------------------------------------------------------
1 | {
2 | "\\1": {
3 | "type": "value",
4 | "kind": "octal",
5 | "codePoint": 1,
6 | "range": [
7 | 0,
8 | 2
9 | ],
10 | "raw": "\\1"
11 | },
12 | "a\\91": {
13 | "type": "alternative",
14 | "body": [
15 | {
16 | "type": "value",
17 | "kind": "symbol",
18 | "codePoint": 97,
19 | "range": [
20 | 0,
21 | 1
22 | ],
23 | "raw": "a"
24 | },
25 | {
26 | "type": "value",
27 | "kind": "symbol",
28 | "codePoint": 57,
29 | "range": [
30 | 1,
31 | 3
32 | ],
33 | "raw": "\\9"
34 | },
35 | {
36 | "type": "value",
37 | "kind": "symbol",
38 | "codePoint": 49,
39 | "range": [
40 | 3,
41 | 4
42 | ],
43 | "raw": "1"
44 | }
45 | ],
46 | "range": [
47 | 0,
48 | 4
49 | ],
50 | "raw": "a\\91"
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/test-data-unicode-properties.json:
--------------------------------------------------------------------------------
1 | {
2 | "\\p{ASCII_Hex_Digit}": {
3 | "type": "unicodePropertyEscape",
4 | "negative": false,
5 | "value": "ASCII_Hex_Digit",
6 | "range": [
7 | 0,
8 | 19
9 | ],
10 | "raw": "\\p{ASCII_Hex_Digit}"
11 | },
12 | "foo\\p{ASCII_Hex_Digit}bar": {
13 | "type": "alternative",
14 | "body": [
15 | {
16 | "type": "value",
17 | "kind": "symbol",
18 | "codePoint": 102,
19 | "range": [
20 | 0,
21 | 1
22 | ],
23 | "raw": "f"
24 | },
25 | {
26 | "type": "value",
27 | "kind": "symbol",
28 | "codePoint": 111,
29 | "range": [
30 | 1,
31 | 2
32 | ],
33 | "raw": "o"
34 | },
35 | {
36 | "type": "value",
37 | "kind": "symbol",
38 | "codePoint": 111,
39 | "range": [
40 | 2,
41 | 3
42 | ],
43 | "raw": "o"
44 | },
45 | {
46 | "type": "unicodePropertyEscape",
47 | "negative": false,
48 | "value": "ASCII_Hex_Digit",
49 | "range": [
50 | 3,
51 | 22
52 | ],
53 | "raw": "\\p{ASCII_Hex_Digit}"
54 | },
55 | {
56 | "type": "value",
57 | "kind": "symbol",
58 | "codePoint": 98,
59 | "range": [
60 | 22,
61 | 23
62 | ],
63 | "raw": "b"
64 | },
65 | {
66 | "type": "value",
67 | "kind": "symbol",
68 | "codePoint": 97,
69 | "range": [
70 | 23,
71 | 24
72 | ],
73 | "raw": "a"
74 | },
75 | {
76 | "type": "value",
77 | "kind": "symbol",
78 | "codePoint": 114,
79 | "range": [
80 | 24,
81 | 25
82 | ],
83 | "raw": "r"
84 | }
85 | ],
86 | "range": [
87 | 0,
88 | 25
89 | ],
90 | "raw": "foo\\p{ASCII_Hex_Digit}bar"
91 | },
92 | "\\P{ASCII_Hex_Digit}": {
93 | "type": "unicodePropertyEscape",
94 | "negative": true,
95 | "value": "ASCII_Hex_Digit",
96 | "range": [
97 | 0,
98 | 19
99 | ],
100 | "raw": "\\P{ASCII_Hex_Digit}"
101 | },
102 | "foo\\P{ASCII_Hex_Digit}bar": {
103 | "type": "alternative",
104 | "body": [
105 | {
106 | "type": "value",
107 | "kind": "symbol",
108 | "codePoint": 102,
109 | "range": [
110 | 0,
111 | 1
112 | ],
113 | "raw": "f"
114 | },
115 | {
116 | "type": "value",
117 | "kind": "symbol",
118 | "codePoint": 111,
119 | "range": [
120 | 1,
121 | 2
122 | ],
123 | "raw": "o"
124 | },
125 | {
126 | "type": "value",
127 | "kind": "symbol",
128 | "codePoint": 111,
129 | "range": [
130 | 2,
131 | 3
132 | ],
133 | "raw": "o"
134 | },
135 | {
136 | "type": "unicodePropertyEscape",
137 | "negative": true,
138 | "value": "ASCII_Hex_Digit",
139 | "range": [
140 | 3,
141 | 22
142 | ],
143 | "raw": "\\P{ASCII_Hex_Digit}"
144 | },
145 | {
146 | "type": "value",
147 | "kind": "symbol",
148 | "codePoint": 98,
149 | "range": [
150 | 22,
151 | 23
152 | ],
153 | "raw": "b"
154 | },
155 | {
156 | "type": "value",
157 | "kind": "symbol",
158 | "codePoint": 97,
159 | "range": [
160 | 23,
161 | 24
162 | ],
163 | "raw": "a"
164 | },
165 | {
166 | "type": "value",
167 | "kind": "symbol",
168 | "codePoint": 114,
169 | "range": [
170 | 24,
171 | 25
172 | ],
173 | "raw": "r"
174 | }
175 | ],
176 | "range": [
177 | 0,
178 | 25
179 | ],
180 | "raw": "foo\\P{ASCII_Hex_Digit}bar"
181 | },
182 | "\\p{ASCII_Hex_Digit}{4}": {
183 | "type": "quantifier",
184 | "min": 4,
185 | "max": 4,
186 | "greedy": true,
187 | "body": [
188 | {
189 | "type": "unicodePropertyEscape",
190 | "negative": false,
191 | "value": "ASCII_Hex_Digit",
192 | "range": [
193 | 0,
194 | 19
195 | ],
196 | "raw": "\\p{ASCII_Hex_Digit}"
197 | }
198 | ],
199 | "symbol": null,
200 | "range": [
201 | 0,
202 | 22
203 | ],
204 | "raw": "\\p{ASCII_Hex_Digit}{4}"
205 | },
206 | "\\p{ASCII_Hex_Digit}+": {
207 | "type": "quantifier",
208 | "min": 1,
209 | "max": null,
210 | "greedy": true,
211 | "body": [
212 | {
213 | "type": "unicodePropertyEscape",
214 | "negative": false,
215 | "value": "ASCII_Hex_Digit",
216 | "range": [
217 | 0,
218 | 19
219 | ],
220 | "raw": "\\p{ASCII_Hex_Digit}"
221 | }
222 | ],
223 | "symbol": "+",
224 | "range": [
225 | 0,
226 | 20
227 | ],
228 | "raw": "\\p{ASCII_Hex_Digit}+"
229 | },
230 | "\\p{}": {
231 | "type": "error",
232 | "name": "SyntaxError",
233 | "message": "atomEscape at position 1\n \\p{}\n ^",
234 | "input": "\\p{}"
235 | },
236 | "\\P{}": {
237 | "type": "error",
238 | "name": "SyntaxError",
239 | "message": "atomEscape at position 1\n \\P{}\n ^",
240 | "input": "\\P{}"
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/tests/test-data-unicode-set.json:
--------------------------------------------------------------------------------
1 | {
2 | "[]": {
3 | "type": "characterClass",
4 | "kind": "union",
5 | "body": [],
6 | "negative": false,
7 | "range": [
8 | 0,
9 | 2
10 | ],
11 | "raw": "[]"
12 | },
13 | "[^]": {
14 | "type": "characterClass",
15 | "kind": "union",
16 | "body": [],
17 | "negative": true,
18 | "range": [
19 | 0,
20 | 3
21 | ],
22 | "raw": "[^]"
23 | },
24 | "[A--B]": {
25 | "type": "characterClass",
26 | "kind": "subtraction",
27 | "body": [
28 | {
29 | "type": "value",
30 | "kind": "symbol",
31 | "codePoint": 65,
32 | "range": [
33 | 1,
34 | 2
35 | ],
36 | "raw": "A"
37 | },
38 | {
39 | "type": "value",
40 | "kind": "symbol",
41 | "codePoint": 66,
42 | "range": [
43 | 4,
44 | 5
45 | ],
46 | "raw": "B"
47 | }
48 | ],
49 | "negative": false,
50 | "range": [
51 | 0,
52 | 6
53 | ],
54 | "raw": "[A--B]"
55 | },
56 | "[A&&B]": {
57 | "type": "characterClass",
58 | "kind": "intersection",
59 | "body": [
60 | {
61 | "type": "value",
62 | "kind": "symbol",
63 | "codePoint": 65,
64 | "range": [
65 | 1,
66 | 2
67 | ],
68 | "raw": "A"
69 | },
70 | {
71 | "type": "value",
72 | "kind": "symbol",
73 | "codePoint": 66,
74 | "range": [
75 | 4,
76 | 5
77 | ],
78 | "raw": "B"
79 | }
80 | ],
81 | "negative": false,
82 | "range": [
83 | 0,
84 | 6
85 | ],
86 | "raw": "[A&&B]"
87 | },
88 | "[A--[0-9]]": {
89 | "type": "characterClass",
90 | "kind": "subtraction",
91 | "body": [
92 | {
93 | "type": "value",
94 | "kind": "symbol",
95 | "codePoint": 65,
96 | "range": [
97 | 1,
98 | 2
99 | ],
100 | "raw": "A"
101 | },
102 | {
103 | "type": "characterClass",
104 | "kind": "union",
105 | "body": [
106 | {
107 | "type": "characterClassRange",
108 | "min": {
109 | "type": "value",
110 | "kind": "symbol",
111 | "codePoint": 48,
112 | "range": [
113 | 5,
114 | 6
115 | ],
116 | "raw": "0"
117 | },
118 | "max": {
119 | "type": "value",
120 | "kind": "symbol",
121 | "codePoint": 57,
122 | "range": [
123 | 7,
124 | 8
125 | ],
126 | "raw": "9"
127 | },
128 | "range": [
129 | 5,
130 | 8
131 | ],
132 | "raw": "0-9"
133 | }
134 | ],
135 | "negative": false,
136 | "range": [
137 | 4,
138 | 9
139 | ],
140 | "raw": "[0-9]"
141 | }
142 | ],
143 | "negative": false,
144 | "range": [
145 | 0,
146 | 10
147 | ],
148 | "raw": "[A--[0-9]]"
149 | },
150 | "[\\p{Decimal_Number}--[0-9]]": {
151 | "type": "characterClass",
152 | "kind": "subtraction",
153 | "body": [
154 | {
155 | "type": "unicodePropertyEscape",
156 | "negative": false,
157 | "value": "Decimal_Number",
158 | "range": [
159 | 1,
160 | 19
161 | ],
162 | "raw": "\\p{Decimal_Number}"
163 | },
164 | {
165 | "type": "characterClass",
166 | "kind": "union",
167 | "body": [
168 | {
169 | "type": "characterClassRange",
170 | "min": {
171 | "type": "value",
172 | "kind": "symbol",
173 | "codePoint": 48,
174 | "range": [
175 | 22,
176 | 23
177 | ],
178 | "raw": "0"
179 | },
180 | "max": {
181 | "type": "value",
182 | "kind": "symbol",
183 | "codePoint": 57,
184 | "range": [
185 | 24,
186 | 25
187 | ],
188 | "raw": "9"
189 | },
190 | "range": [
191 | 22,
192 | 25
193 | ],
194 | "raw": "0-9"
195 | }
196 | ],
197 | "negative": false,
198 | "range": [
199 | 21,
200 | 26
201 | ],
202 | "raw": "[0-9]"
203 | }
204 | ],
205 | "negative": false,
206 | "range": [
207 | 0,
208 | 27
209 | ],
210 | "raw": "[\\p{Decimal_Number}--[0-9]]"
211 | },
212 | "[\\p{Script=Khmer}&&[\\p{Letter}\\p{Mark}\\p{Number}]]": {
213 | "type": "characterClass",
214 | "kind": "intersection",
215 | "body": [
216 | {
217 | "type": "unicodePropertyEscape",
218 | "negative": false,
219 | "value": "Script=Khmer",
220 | "range": [
221 | 1,
222 | 17
223 | ],
224 | "raw": "\\p{Script=Khmer}"
225 | },
226 | {
227 | "type": "characterClass",
228 | "kind": "union",
229 | "body": [
230 | {
231 | "type": "unicodePropertyEscape",
232 | "negative": false,
233 | "value": "Letter",
234 | "range": [
235 | 20,
236 | 30
237 | ],
238 | "raw": "\\p{Letter}"
239 | },
240 | {
241 | "type": "unicodePropertyEscape",
242 | "negative": false,
243 | "value": "Mark",
244 | "range": [
245 | 30,
246 | 38
247 | ],
248 | "raw": "\\p{Mark}"
249 | },
250 | {
251 | "type": "unicodePropertyEscape",
252 | "negative": false,
253 | "value": "Number",
254 | "range": [
255 | 38,
256 | 48
257 | ],
258 | "raw": "\\p{Number}"
259 | }
260 | ],
261 | "negative": false,
262 | "range": [
263 | 19,
264 | 49
265 | ],
266 | "raw": "[\\p{Letter}\\p{Mark}\\p{Number}]"
267 | }
268 | ],
269 | "negative": false,
270 | "range": [
271 | 0,
272 | 50
273 | ],
274 | "raw": "[\\p{Script=Khmer}&&[\\p{Letter}\\p{Mark}\\p{Number}]]"
275 | },
276 | "[\\p{White_Space}--\\p{Line_Break=Glue}]": {
277 | "type": "characterClass",
278 | "kind": "subtraction",
279 | "body": [
280 | {
281 | "type": "unicodePropertyEscape",
282 | "negative": false,
283 | "value": "White_Space",
284 | "range": [
285 | 1,
286 | 16
287 | ],
288 | "raw": "\\p{White_Space}"
289 | },
290 | {
291 | "type": "unicodePropertyEscape",
292 | "negative": false,
293 | "value": "Line_Break=Glue",
294 | "range": [
295 | 18,
296 | 37
297 | ],
298 | "raw": "\\p{Line_Break=Glue}"
299 | }
300 | ],
301 | "negative": false,
302 | "range": [
303 | 0,
304 | 38
305 | ],
306 | "raw": "[\\p{White_Space}--\\p{Line_Break=Glue}]"
307 | },
308 | "[\\p{Emoji}--[#*0-9]]": {
309 | "type": "characterClass",
310 | "kind": "subtraction",
311 | "body": [
312 | {
313 | "type": "unicodePropertyEscape",
314 | "negative": false,
315 | "value": "Emoji",
316 | "range": [
317 | 1,
318 | 10
319 | ],
320 | "raw": "\\p{Emoji}"
321 | },
322 | {
323 | "type": "characterClass",
324 | "kind": "union",
325 | "body": [
326 | {
327 | "type": "value",
328 | "kind": "symbol",
329 | "codePoint": 35,
330 | "range": [
331 | 13,
332 | 14
333 | ],
334 | "raw": "#"
335 | },
336 | {
337 | "type": "value",
338 | "kind": "symbol",
339 | "codePoint": 42,
340 | "range": [
341 | 14,
342 | 15
343 | ],
344 | "raw": "*"
345 | },
346 | {
347 | "type": "characterClassRange",
348 | "min": {
349 | "type": "value",
350 | "kind": "symbol",
351 | "codePoint": 48,
352 | "range": [
353 | 15,
354 | 16
355 | ],
356 | "raw": "0"
357 | },
358 | "max": {
359 | "type": "value",
360 | "kind": "symbol",
361 | "codePoint": 57,
362 | "range": [
363 | 17,
364 | 18
365 | ],
366 | "raw": "9"
367 | },
368 | "range": [
369 | 15,
370 | 18
371 | ],
372 | "raw": "0-9"
373 | }
374 | ],
375 | "negative": false,
376 | "range": [
377 | 12,
378 | 19
379 | ],
380 | "raw": "[#*0-9]"
381 | }
382 | ],
383 | "negative": false,
384 | "range": [
385 | 0,
386 | 20
387 | ],
388 | "raw": "[\\p{Emoji}--[#*0-9]]"
389 | },
390 | "[\\p{Nonspacing_Mark}&&[\\p{Script=Inherited}\\p{Script=Common}]]": {
391 | "type": "characterClass",
392 | "kind": "intersection",
393 | "body": [
394 | {
395 | "type": "unicodePropertyEscape",
396 | "negative": false,
397 | "value": "Nonspacing_Mark",
398 | "range": [
399 | 1,
400 | 20
401 | ],
402 | "raw": "\\p{Nonspacing_Mark}"
403 | },
404 | {
405 | "type": "characterClass",
406 | "kind": "union",
407 | "body": [
408 | {
409 | "type": "unicodePropertyEscape",
410 | "negative": false,
411 | "value": "Script=Inherited",
412 | "range": [
413 | 23,
414 | 43
415 | ],
416 | "raw": "\\p{Script=Inherited}"
417 | },
418 | {
419 | "type": "unicodePropertyEscape",
420 | "negative": false,
421 | "value": "Script=Common",
422 | "range": [
423 | 43,
424 | 60
425 | ],
426 | "raw": "\\p{Script=Common}"
427 | }
428 | ],
429 | "negative": false,
430 | "range": [
431 | 22,
432 | 61
433 | ],
434 | "raw": "[\\p{Script=Inherited}\\p{Script=Common}]"
435 | }
436 | ],
437 | "negative": false,
438 | "range": [
439 | 0,
440 | 62
441 | ],
442 | "raw": "[\\p{Nonspacing_Mark}&&[\\p{Script=Inherited}\\p{Script=Common}]]"
443 | },
444 | "[[\\p{Other}\\p{Separator}\\p{White_Space}\\p{Default_Ignorable_Code_Point}]--\\x20]": {
445 | "type": "characterClass",
446 | "kind": "subtraction",
447 | "body": [
448 | {
449 | "type": "characterClass",
450 | "kind": "union",
451 | "body": [
452 | {
453 | "type": "unicodePropertyEscape",
454 | "negative": false,
455 | "value": "Other",
456 | "range": [
457 | 2,
458 | 11
459 | ],
460 | "raw": "\\p{Other}"
461 | },
462 | {
463 | "type": "unicodePropertyEscape",
464 | "negative": false,
465 | "value": "Separator",
466 | "range": [
467 | 11,
468 | 24
469 | ],
470 | "raw": "\\p{Separator}"
471 | },
472 | {
473 | "type": "unicodePropertyEscape",
474 | "negative": false,
475 | "value": "White_Space",
476 | "range": [
477 | 24,
478 | 39
479 | ],
480 | "raw": "\\p{White_Space}"
481 | },
482 | {
483 | "type": "unicodePropertyEscape",
484 | "negative": false,
485 | "value": "Default_Ignorable_Code_Point",
486 | "range": [
487 | 39,
488 | 71
489 | ],
490 | "raw": "\\p{Default_Ignorable_Code_Point}"
491 | }
492 | ],
493 | "negative": false,
494 | "range": [
495 | 1,
496 | 72
497 | ],
498 | "raw": "[\\p{Other}\\p{Separator}\\p{White_Space}\\p{Default_Ignorable_Code_Point}]"
499 | },
500 | {
501 | "type": "value",
502 | "kind": "hexadecimalEscape",
503 | "codePoint": 32,
504 | "range": [
505 | 74,
506 | 78
507 | ],
508 | "raw": "\\x20"
509 | }
510 | ],
511 | "negative": false,
512 | "range": [
513 | 0,
514 | 79
515 | ],
516 | "raw": "[[\\p{Other}\\p{Separator}\\p{White_Space}\\p{Default_Ignorable_Code_Point}]--\\x20]"
517 | },
518 | "[\\P{NFC_Quick_Check=No}--\\p{Script=Common}--\\p{Script=Inherited}--\\p{Script=Unknown}]": {
519 | "type": "characterClass",
520 | "kind": "subtraction",
521 | "body": [
522 | {
523 | "type": "unicodePropertyEscape",
524 | "negative": true,
525 | "value": "NFC_Quick_Check=No",
526 | "range": [
527 | 1,
528 | 23
529 | ],
530 | "raw": "\\P{NFC_Quick_Check=No}"
531 | },
532 | {
533 | "type": "unicodePropertyEscape",
534 | "negative": false,
535 | "value": "Script=Common",
536 | "range": [
537 | 25,
538 | 42
539 | ],
540 | "raw": "\\p{Script=Common}"
541 | },
542 | {
543 | "type": "unicodePropertyEscape",
544 | "negative": false,
545 | "value": "Script=Inherited",
546 | "range": [
547 | 44,
548 | 64
549 | ],
550 | "raw": "\\p{Script=Inherited}"
551 | },
552 | {
553 | "type": "unicodePropertyEscape",
554 | "negative": false,
555 | "value": "Script=Unknown",
556 | "range": [
557 | 66,
558 | 84
559 | ],
560 | "raw": "\\p{Script=Unknown}"
561 | }
562 | ],
563 | "negative": false,
564 | "range": [
565 | 0,
566 | 85
567 | ],
568 | "raw": "[\\P{NFC_Quick_Check=No}--\\p{Script=Common}--\\p{Script=Inherited}--\\p{Script=Unknown}]"
569 | },
570 | "[^A--B]": {
571 | "type": "characterClass",
572 | "kind": "subtraction",
573 | "body": [
574 | {
575 | "type": "value",
576 | "kind": "symbol",
577 | "codePoint": 65,
578 | "range": [
579 | 2,
580 | 3
581 | ],
582 | "raw": "A"
583 | },
584 | {
585 | "type": "value",
586 | "kind": "symbol",
587 | "codePoint": 66,
588 | "range": [
589 | 5,
590 | 6
591 | ],
592 | "raw": "B"
593 | }
594 | ],
595 | "negative": true,
596 | "range": [
597 | 0,
598 | 7
599 | ],
600 | "raw": "[^A--B]"
601 | },
602 | "[^A&&B]": {
603 | "type": "characterClass",
604 | "kind": "intersection",
605 | "body": [
606 | {
607 | "type": "value",
608 | "kind": "symbol",
609 | "codePoint": 65,
610 | "range": [
611 | 2,
612 | 3
613 | ],
614 | "raw": "A"
615 | },
616 | {
617 | "type": "value",
618 | "kind": "symbol",
619 | "codePoint": 66,
620 | "range": [
621 | 5,
622 | 6
623 | ],
624 | "raw": "B"
625 | }
626 | ],
627 | "negative": true,
628 | "range": [
629 | 0,
630 | 7
631 | ],
632 | "raw": "[^A&&B]"
633 | },
634 | "[^[A--B]&&[^C--D]]": {
635 | "type": "characterClass",
636 | "kind": "intersection",
637 | "body": [
638 | {
639 | "type": "characterClass",
640 | "kind": "subtraction",
641 | "body": [
642 | {
643 | "type": "value",
644 | "kind": "symbol",
645 | "codePoint": 65,
646 | "range": [
647 | 3,
648 | 4
649 | ],
650 | "raw": "A"
651 | },
652 | {
653 | "type": "value",
654 | "kind": "symbol",
655 | "codePoint": 66,
656 | "range": [
657 | 6,
658 | 7
659 | ],
660 | "raw": "B"
661 | }
662 | ],
663 | "negative": false,
664 | "range": [
665 | 2,
666 | 8
667 | ],
668 | "raw": "[A--B]"
669 | },
670 | {
671 | "type": "characterClass",
672 | "kind": "subtraction",
673 | "body": [
674 | {
675 | "type": "value",
676 | "kind": "symbol",
677 | "codePoint": 67,
678 | "range": [
679 | 12,
680 | 13
681 | ],
682 | "raw": "C"
683 | },
684 | {
685 | "type": "value",
686 | "kind": "symbol",
687 | "codePoint": 68,
688 | "range": [
689 | 15,
690 | 16
691 | ],
692 | "raw": "D"
693 | }
694 | ],
695 | "negative": true,
696 | "range": [
697 | 10,
698 | 17
699 | ],
700 | "raw": "[^C--D]"
701 | }
702 | ],
703 | "negative": true,
704 | "range": [
705 | 0,
706 | 18
707 | ],
708 | "raw": "[^[A--B]&&[^C--D]]"
709 | },
710 | "[A&&&]": {
711 | "type": "error",
712 | "name": "SyntaxError",
713 | "message": "&& cannot be followed by &. Wrap it in brackets: &&[&]. at position 4\n [A&&&]\n ^",
714 | "input": "[A&&&]"
715 | },
716 | "[A&&[&]]": {
717 | "type": "characterClass",
718 | "kind": "intersection",
719 | "body": [
720 | {
721 | "type": "value",
722 | "kind": "symbol",
723 | "codePoint": 65,
724 | "range": [
725 | 1,
726 | 2
727 | ],
728 | "raw": "A"
729 | },
730 | {
731 | "type": "characterClass",
732 | "kind": "union",
733 | "body": [
734 | {
735 | "type": "value",
736 | "kind": "symbol",
737 | "codePoint": 38,
738 | "range": [
739 | 5,
740 | 6
741 | ],
742 | "raw": "&"
743 | }
744 | ],
745 | "negative": false,
746 | "range": [
747 | 4,
748 | 7
749 | ],
750 | "raw": "[&]"
751 | }
752 | ],
753 | "negative": false,
754 | "range": [
755 | 0,
756 | 8
757 | ],
758 | "raw": "[A&&[&]]"
759 | },
760 | "[A&&\\q{&}]": {
761 | "type": "characterClass",
762 | "kind": "intersection",
763 | "body": [
764 | {
765 | "type": "value",
766 | "kind": "symbol",
767 | "codePoint": 65,
768 | "range": [
769 | 1,
770 | 2
771 | ],
772 | "raw": "A"
773 | },
774 | {
775 | "type": "classStrings",
776 | "strings": [
777 | {
778 | "type": "classString",
779 | "characters": [
780 | {
781 | "type": "value",
782 | "kind": "symbol",
783 | "codePoint": 38,
784 | "range": [
785 | 7,
786 | 8
787 | ],
788 | "raw": "&"
789 | }
790 | ],
791 | "range": [
792 | 7,
793 | 8
794 | ],
795 | "raw": "&"
796 | }
797 | ],
798 | "range": [
799 | 4,
800 | 9
801 | ],
802 | "raw": "\\q{&}"
803 | }
804 | ],
805 | "negative": false,
806 | "range": [
807 | 0,
808 | 10
809 | ],
810 | "raw": "[A&&\\q{&}]"
811 | },
812 | "[A---B]": {
813 | "type": "error",
814 | "name": "SyntaxError",
815 | "message": "Invalid character at position 4: -\n [A---B]\n ^",
816 | "input": "[A---B]"
817 | },
818 | "[a-z&&p-s]": {
819 | "type": "error",
820 | "name": "SyntaxError",
821 | "message": "character at position 7: &\n [a-z&&p-s]\n ^",
822 | "input": "[a-z&&p-s]"
823 | },
824 | "[[a-z]&&[p-s]]": {
825 | "type": "characterClass",
826 | "kind": "intersection",
827 | "body": [
828 | {
829 | "type": "characterClass",
830 | "kind": "union",
831 | "body": [
832 | {
833 | "type": "characterClassRange",
834 | "min": {
835 | "type": "value",
836 | "kind": "symbol",
837 | "codePoint": 97,
838 | "range": [
839 | 2,
840 | 3
841 | ],
842 | "raw": "a"
843 | },
844 | "max": {
845 | "type": "value",
846 | "kind": "symbol",
847 | "codePoint": 122,
848 | "range": [
849 | 4,
850 | 5
851 | ],
852 | "raw": "z"
853 | },
854 | "range": [
855 | 2,
856 | 5
857 | ],
858 | "raw": "a-z"
859 | }
860 | ],
861 | "negative": false,
862 | "range": [
863 | 1,
864 | 6
865 | ],
866 | "raw": "[a-z]"
867 | },
868 | {
869 | "type": "characterClass",
870 | "kind": "union",
871 | "body": [
872 | {
873 | "type": "characterClassRange",
874 | "min": {
875 | "type": "value",
876 | "kind": "symbol",
877 | "codePoint": 112,
878 | "range": [
879 | 9,
880 | 10
881 | ],
882 | "raw": "p"
883 | },
884 | "max": {
885 | "type": "value",
886 | "kind": "symbol",
887 | "codePoint": 115,
888 | "range": [
889 | 11,
890 | 12
891 | ],
892 | "raw": "s"
893 | },
894 | "range": [
895 | 9,
896 | 12
897 | ],
898 | "raw": "p-s"
899 | }
900 | ],
901 | "negative": false,
902 | "range": [
903 | 8,
904 | 13
905 | ],
906 | "raw": "[p-s]"
907 | }
908 | ],
909 | "negative": false,
910 | "range": [
911 | 0,
912 | 14
913 | ],
914 | "raw": "[[a-z]&&[p-s]]"
915 | },
916 | "[AB&&CD]": {
917 | "type": "error",
918 | "name": "SyntaxError",
919 | "message": "Invalid set operation in character class at position 5\n [AB&&CD]\n ^",
920 | "input": "[AB&&CD]"
921 | },
922 | "[AB--CD]": {
923 | "type": "error",
924 | "name": "SyntaxError",
925 | "message": "Invalid character at position 3: -\n [AB--CD]\n ^",
926 | "input": "[AB--CD]"
927 | },
928 | "[A--B&&C]": {
929 | "type": "error",
930 | "name": "SyntaxError",
931 | "message": "character at position 5: -\n [A--B&&C]\n ^",
932 | "input": "[A--B&&C]"
933 | },
934 | "[\\q{AB|CD|DE}]": {
935 | "type": "characterClass",
936 | "kind": "union",
937 | "body": [
938 | {
939 | "type": "classStrings",
940 | "strings": [
941 | {
942 | "type": "classString",
943 | "characters": [
944 | {
945 | "type": "value",
946 | "kind": "symbol",
947 | "codePoint": 65,
948 | "range": [
949 | 4,
950 | 5
951 | ],
952 | "raw": "A"
953 | },
954 | {
955 | "type": "value",
956 | "kind": "symbol",
957 | "codePoint": 66,
958 | "range": [
959 | 5,
960 | 6
961 | ],
962 | "raw": "B"
963 | }
964 | ],
965 | "range": [
966 | 4,
967 | 6
968 | ],
969 | "raw": "AB"
970 | },
971 | {
972 | "type": "classString",
973 | "characters": [
974 | {
975 | "type": "value",
976 | "kind": "symbol",
977 | "codePoint": 67,
978 | "range": [
979 | 7,
980 | 8
981 | ],
982 | "raw": "C"
983 | },
984 | {
985 | "type": "value",
986 | "kind": "symbol",
987 | "codePoint": 68,
988 | "range": [
989 | 8,
990 | 9
991 | ],
992 | "raw": "D"
993 | }
994 | ],
995 | "range": [
996 | 7,
997 | 9
998 | ],
999 | "raw": "CD"
1000 | },
1001 | {
1002 | "type": "classString",
1003 | "characters": [
1004 | {
1005 | "type": "value",
1006 | "kind": "symbol",
1007 | "codePoint": 68,
1008 | "range": [
1009 | 10,
1010 | 11
1011 | ],
1012 | "raw": "D"
1013 | },
1014 | {
1015 | "type": "value",
1016 | "kind": "symbol",
1017 | "codePoint": 69,
1018 | "range": [
1019 | 11,
1020 | 12
1021 | ],
1022 | "raw": "E"
1023 | }
1024 | ],
1025 | "range": [
1026 | 10,
1027 | 12
1028 | ],
1029 | "raw": "DE"
1030 | }
1031 | ],
1032 | "range": [
1033 | 1,
1034 | 13
1035 | ],
1036 | "raw": "\\q{AB|CD|DE}"
1037 | }
1038 | ],
1039 | "negative": false,
1040 | "range": [
1041 | 0,
1042 | 14
1043 | ],
1044 | "raw": "[\\q{AB|CD|DE}]"
1045 | },
1046 | "[\\q{}]": {
1047 | "type": "characterClass",
1048 | "kind": "union",
1049 | "body": [
1050 | {
1051 | "type": "classStrings",
1052 | "strings": [
1053 | {
1054 | "type": "classString",
1055 | "characters": [],
1056 | "range": [
1057 | 4,
1058 | 4
1059 | ],
1060 | "raw": ""
1061 | }
1062 | ],
1063 | "range": [
1064 | 1,
1065 | 5
1066 | ],
1067 | "raw": "\\q{}"
1068 | }
1069 | ],
1070 | "negative": false,
1071 | "range": [
1072 | 0,
1073 | 6
1074 | ],
1075 | "raw": "[\\q{}]"
1076 | },
1077 | "[\\q{|||}]": {
1078 | "type": "characterClass",
1079 | "kind": "union",
1080 | "body": [
1081 | {
1082 | "type": "classStrings",
1083 | "strings": [
1084 | {
1085 | "type": "classString",
1086 | "characters": [],
1087 | "range": [
1088 | 4,
1089 | 4
1090 | ],
1091 | "raw": ""
1092 | },
1093 | {
1094 | "type": "classString",
1095 | "characters": [],
1096 | "range": [
1097 | 5,
1098 | 5
1099 | ],
1100 | "raw": ""
1101 | },
1102 | {
1103 | "type": "classString",
1104 | "characters": [],
1105 | "range": [
1106 | 6,
1107 | 6
1108 | ],
1109 | "raw": ""
1110 | },
1111 | {
1112 | "type": "classString",
1113 | "characters": [],
1114 | "range": [
1115 | 7,
1116 | 7
1117 | ],
1118 | "raw": ""
1119 | }
1120 | ],
1121 | "range": [
1122 | 1,
1123 | 8
1124 | ],
1125 | "raw": "\\q{|||}"
1126 | }
1127 | ],
1128 | "negative": false,
1129 | "range": [
1130 | 0,
1131 | 9
1132 | ],
1133 | "raw": "[\\q{|||}]"
1134 | },
1135 | "[\\q{a|b|c}--[b-d]]": {
1136 | "type": "characterClass",
1137 | "kind": "subtraction",
1138 | "body": [
1139 | {
1140 | "type": "classStrings",
1141 | "strings": [
1142 | {
1143 | "type": "classString",
1144 | "characters": [
1145 | {
1146 | "type": "value",
1147 | "kind": "symbol",
1148 | "codePoint": 97,
1149 | "range": [
1150 | 4,
1151 | 5
1152 | ],
1153 | "raw": "a"
1154 | }
1155 | ],
1156 | "range": [
1157 | 4,
1158 | 5
1159 | ],
1160 | "raw": "a"
1161 | },
1162 | {
1163 | "type": "classString",
1164 | "characters": [
1165 | {
1166 | "type": "value",
1167 | "kind": "symbol",
1168 | "codePoint": 98,
1169 | "range": [
1170 | 6,
1171 | 7
1172 | ],
1173 | "raw": "b"
1174 | }
1175 | ],
1176 | "range": [
1177 | 6,
1178 | 7
1179 | ],
1180 | "raw": "b"
1181 | },
1182 | {
1183 | "type": "classString",
1184 | "characters": [
1185 | {
1186 | "type": "value",
1187 | "kind": "symbol",
1188 | "codePoint": 99,
1189 | "range": [
1190 | 8,
1191 | 9
1192 | ],
1193 | "raw": "c"
1194 | }
1195 | ],
1196 | "range": [
1197 | 8,
1198 | 9
1199 | ],
1200 | "raw": "c"
1201 | }
1202 | ],
1203 | "range": [
1204 | 1,
1205 | 10
1206 | ],
1207 | "raw": "\\q{a|b|c}"
1208 | },
1209 | {
1210 | "type": "characterClass",
1211 | "kind": "union",
1212 | "body": [
1213 | {
1214 | "type": "characterClassRange",
1215 | "min": {
1216 | "type": "value",
1217 | "kind": "symbol",
1218 | "codePoint": 98,
1219 | "range": [
1220 | 13,
1221 | 14
1222 | ],
1223 | "raw": "b"
1224 | },
1225 | "max": {
1226 | "type": "value",
1227 | "kind": "symbol",
1228 | "codePoint": 100,
1229 | "range": [
1230 | 15,
1231 | 16
1232 | ],
1233 | "raw": "d"
1234 | },
1235 | "range": [
1236 | 13,
1237 | 16
1238 | ],
1239 | "raw": "b-d"
1240 | }
1241 | ],
1242 | "negative": false,
1243 | "range": [
1244 | 12,
1245 | 17
1246 | ],
1247 | "raw": "[b-d]"
1248 | }
1249 | ],
1250 | "negative": false,
1251 | "range": [
1252 | 0,
1253 | 18
1254 | ],
1255 | "raw": "[\\q{a|b|c}--[b-d]]"
1256 | },
1257 | "[[b-d]--\\q{a|b|c}]": {
1258 | "type": "characterClass",
1259 | "kind": "subtraction",
1260 | "body": [
1261 | {
1262 | "type": "characterClass",
1263 | "kind": "union",
1264 | "body": [
1265 | {
1266 | "type": "characterClassRange",
1267 | "min": {
1268 | "type": "value",
1269 | "kind": "symbol",
1270 | "codePoint": 98,
1271 | "range": [
1272 | 2,
1273 | 3
1274 | ],
1275 | "raw": "b"
1276 | },
1277 | "max": {
1278 | "type": "value",
1279 | "kind": "symbol",
1280 | "codePoint": 100,
1281 | "range": [
1282 | 4,
1283 | 5
1284 | ],
1285 | "raw": "d"
1286 | },
1287 | "range": [
1288 | 2,
1289 | 5
1290 | ],
1291 | "raw": "b-d"
1292 | }
1293 | ],
1294 | "negative": false,
1295 | "range": [
1296 | 1,
1297 | 6
1298 | ],
1299 | "raw": "[b-d]"
1300 | },
1301 | {
1302 | "type": "classStrings",
1303 | "strings": [
1304 | {
1305 | "type": "classString",
1306 | "characters": [
1307 | {
1308 | "type": "value",
1309 | "kind": "symbol",
1310 | "codePoint": 97,
1311 | "range": [
1312 | 11,
1313 | 12
1314 | ],
1315 | "raw": "a"
1316 | }
1317 | ],
1318 | "range": [
1319 | 11,
1320 | 12
1321 | ],
1322 | "raw": "a"
1323 | },
1324 | {
1325 | "type": "classString",
1326 | "characters": [
1327 | {
1328 | "type": "value",
1329 | "kind": "symbol",
1330 | "codePoint": 98,
1331 | "range": [
1332 | 13,
1333 | 14
1334 | ],
1335 | "raw": "b"
1336 | }
1337 | ],
1338 | "range": [
1339 | 13,
1340 | 14
1341 | ],
1342 | "raw": "b"
1343 | },
1344 | {
1345 | "type": "classString",
1346 | "characters": [
1347 | {
1348 | "type": "value",
1349 | "kind": "symbol",
1350 | "codePoint": 99,
1351 | "range": [
1352 | 15,
1353 | 16
1354 | ],
1355 | "raw": "c"
1356 | }
1357 | ],
1358 | "range": [
1359 | 15,
1360 | 16
1361 | ],
1362 | "raw": "c"
1363 | }
1364 | ],
1365 | "range": [
1366 | 8,
1367 | 17
1368 | ],
1369 | "raw": "\\q{a|b|c}"
1370 | }
1371 | ],
1372 | "negative": false,
1373 | "range": [
1374 | 0,
1375 | 18
1376 | ],
1377 | "raw": "[[b-d]--\\q{a|b|c}]"
1378 | },
1379 | "[^\\q{AB}]": {
1380 | "type": "characterClass",
1381 | "kind": "union",
1382 | "body": [
1383 | {
1384 | "type": "classStrings",
1385 | "strings": [
1386 | {
1387 | "type": "classString",
1388 | "characters": [
1389 | {
1390 | "type": "value",
1391 | "kind": "symbol",
1392 | "codePoint": 65,
1393 | "range": [
1394 | 5,
1395 | 6
1396 | ],
1397 | "raw": "A"
1398 | },
1399 | {
1400 | "type": "value",
1401 | "kind": "symbol",
1402 | "codePoint": 66,
1403 | "range": [
1404 | 6,
1405 | 7
1406 | ],
1407 | "raw": "B"
1408 | }
1409 | ],
1410 | "range": [
1411 | 5,
1412 | 7
1413 | ],
1414 | "raw": "AB"
1415 | }
1416 | ],
1417 | "range": [
1418 | 2,
1419 | 8
1420 | ],
1421 | "raw": "\\q{AB}"
1422 | }
1423 | ],
1424 | "negative": true,
1425 | "range": [
1426 | 0,
1427 | 9
1428 | ],
1429 | "raw": "[^\\q{AB}]"
1430 | },
1431 | "\\1": {
1432 | "type": "error",
1433 | "name": "SyntaxError",
1434 | "message": "Invalid decimal escape in unicode mode at position 1\n \\1\n ^",
1435 | "input": "\\1"
1436 | },
1437 | "[\\u{14630}]": {
1438 | "type": "characterClass",
1439 | "kind": "union",
1440 | "body": [
1441 | {
1442 | "type": "value",
1443 | "kind": "unicodeCodePointEscape",
1444 | "codePoint": 83504,
1445 | "range": [
1446 | 1,
1447 | 10
1448 | ],
1449 | "raw": "\\u{14630}"
1450 | }
1451 | ],
1452 | "negative": false,
1453 | "range": [
1454 | 0,
1455 | 11
1456 | ],
1457 | "raw": "[\\u{14630}]"
1458 | },
1459 | "[\\u{14630}-\\u{14633}]": {
1460 | "type": "characterClass",
1461 | "kind": "union",
1462 | "body": [
1463 | {
1464 | "type": "characterClassRange",
1465 | "min": {
1466 | "type": "value",
1467 | "kind": "unicodeCodePointEscape",
1468 | "codePoint": 83504,
1469 | "range": [
1470 | 1,
1471 | 10
1472 | ],
1473 | "raw": "\\u{14630}"
1474 | },
1475 | "max": {
1476 | "type": "value",
1477 | "kind": "unicodeCodePointEscape",
1478 | "codePoint": 83507,
1479 | "range": [
1480 | 11,
1481 | 20
1482 | ],
1483 | "raw": "\\u{14633}"
1484 | },
1485 | "range": [
1486 | 1,
1487 | 20
1488 | ],
1489 | "raw": "\\u{14630}-\\u{14633}"
1490 | }
1491 | ],
1492 | "negative": false,
1493 | "range": [
1494 | 0,
1495 | 21
1496 | ],
1497 | "raw": "[\\u{14630}-\\u{14633}]"
1498 | },
1499 | ".(?=.){2,3}": {
1500 | "type": "error",
1501 | "name": "SyntaxError",
1502 | "message": "Expected atom at position 6\n .(?=.){2,3}\n ^",
1503 | "input": ".(?=.){2,3}"
1504 | },
1505 | ".(?!.){2,3}": {
1506 | "type": "error",
1507 | "name": "SyntaxError",
1508 | "message": "Expected atom at position 6\n .(?!.){2,3}\n ^",
1509 | "input": ".(?!.){2,3}"
1510 | },
1511 | "[\\__]": {
1512 | "type": "error",
1513 | "name": "SyntaxError",
1514 | "message": "Invalid escape at position 1: \\_\n [\\__]\n ^",
1515 | "input": "[\\__]"
1516 | },
1517 | "[&&]": {
1518 | "type": "error",
1519 | "name": "SyntaxError",
1520 | "message": "Invalid set operation in character class at position 3\n [&&]\n ^",
1521 | "input": "[&&]"
1522 | },
1523 | "[!!]": {
1524 | "type": "error",
1525 | "name": "SyntaxError",
1526 | "message": "Invalid set operation in character class at position 3\n [!!]\n ^",
1527 | "input": "[!!]"
1528 | },
1529 | "[##]": {
1530 | "type": "error",
1531 | "name": "SyntaxError",
1532 | "message": "Invalid set operation in character class at position 3\n [##]\n ^",
1533 | "input": "[##]"
1534 | },
1535 | "[$$]": {
1536 | "type": "error",
1537 | "name": "SyntaxError",
1538 | "message": "Invalid set operation in character class at position 3\n [$$]\n ^",
1539 | "input": "[$$]"
1540 | },
1541 | "[%%]": {
1542 | "type": "error",
1543 | "name": "SyntaxError",
1544 | "message": "Invalid set operation in character class at position 3\n [%%]\n ^",
1545 | "input": "[%%]"
1546 | },
1547 | "[**]": {
1548 | "type": "error",
1549 | "name": "SyntaxError",
1550 | "message": "Invalid set operation in character class at position 3\n [**]\n ^",
1551 | "input": "[**]"
1552 | },
1553 | "[++]": {
1554 | "type": "error",
1555 | "name": "SyntaxError",
1556 | "message": "Invalid set operation in character class at position 3\n [++]\n ^",
1557 | "input": "[++]"
1558 | },
1559 | "[,,]": {
1560 | "type": "error",
1561 | "name": "SyntaxError",
1562 | "message": "Invalid set operation in character class at position 3\n [,,]\n ^",
1563 | "input": "[,,]"
1564 | },
1565 | "[..]": {
1566 | "type": "error",
1567 | "name": "SyntaxError",
1568 | "message": "Invalid set operation in character class at position 3\n [..]\n ^",
1569 | "input": "[..]"
1570 | },
1571 | "[::]": {
1572 | "type": "error",
1573 | "name": "SyntaxError",
1574 | "message": "Invalid set operation in character class at position 3\n [::]\n ^",
1575 | "input": "[::]"
1576 | },
1577 | "[;;]": {
1578 | "type": "error",
1579 | "name": "SyntaxError",
1580 | "message": "Invalid set operation in character class at position 3\n [;;]\n ^",
1581 | "input": "[;;]"
1582 | },
1583 | "[<<]": {
1584 | "type": "error",
1585 | "name": "SyntaxError",
1586 | "message": "Invalid set operation in character class at position 3\n [<<]\n ^",
1587 | "input": "[<<]"
1588 | },
1589 | "[==]": {
1590 | "type": "error",
1591 | "name": "SyntaxError",
1592 | "message": "Invalid set operation in character class at position 3\n [==]\n ^",
1593 | "input": "[==]"
1594 | },
1595 | "[>>]": {
1596 | "type": "error",
1597 | "name": "SyntaxError",
1598 | "message": "Invalid set operation in character class at position 3\n [>>]\n ^",
1599 | "input": "[>>]"
1600 | },
1601 | "[??]": {
1602 | "type": "error",
1603 | "name": "SyntaxError",
1604 | "message": "Invalid set operation in character class at position 3\n [??]\n ^",
1605 | "input": "[??]"
1606 | },
1607 | "[@@]": {
1608 | "type": "error",
1609 | "name": "SyntaxError",
1610 | "message": "Invalid set operation in character class at position 3\n [@@]\n ^",
1611 | "input": "[@@]"
1612 | },
1613 | "[^^^]": {
1614 | "type": "error",
1615 | "name": "SyntaxError",
1616 | "message": "Invalid set operation in character class at position 4\n [^^^]\n ^",
1617 | "input": "[^^^]"
1618 | },
1619 | "[``]": {
1620 | "type": "error",
1621 | "name": "SyntaxError",
1622 | "message": "Invalid set operation in character class at position 3\n [``]\n ^",
1623 | "input": "[``]"
1624 | },
1625 | "[~~]": {
1626 | "type": "error",
1627 | "name": "SyntaxError",
1628 | "message": "Invalid set operation in character class at position 3\n [~~]\n ^",
1629 | "input": "[~~]"
1630 | },
1631 | "\\q{a}": {
1632 | "type": "error",
1633 | "name": "SyntaxError",
1634 | "message": "atomEscape at position 1\n \\q{a}\n ^",
1635 | "input": "\\q{a}"
1636 | }
1637 | }
1638 |
--------------------------------------------------------------------------------
/tests/test-data-unicode.json:
--------------------------------------------------------------------------------
1 | {
2 | "\\u{000000}": {
3 | "type": "value",
4 | "kind": "unicodeCodePointEscape",
5 | "codePoint": 0,
6 | "range": [
7 | 0,
8 | 10
9 | ],
10 | "raw": "\\u{000000}"
11 | },
12 | "\\u{0000000000000000000}": {
13 | "type": "value",
14 | "kind": "unicodeCodePointEscape",
15 | "codePoint": 0,
16 | "range": [
17 | 0,
18 | 23
19 | ],
20 | "raw": "\\u{0000000000000000000}"
21 | },
22 | "\\u{0}": {
23 | "type": "value",
24 | "kind": "unicodeCodePointEscape",
25 | "codePoint": 0,
26 | "range": [
27 | 0,
28 | 5
29 | ],
30 | "raw": "\\u{0}"
31 | },
32 | "\\u{1}": {
33 | "type": "value",
34 | "kind": "unicodeCodePointEscape",
35 | "codePoint": 1,
36 | "range": [
37 | 0,
38 | 5
39 | ],
40 | "raw": "\\u{1}"
41 | },
42 | "\\u{02}": {
43 | "type": "value",
44 | "kind": "unicodeCodePointEscape",
45 | "codePoint": 2,
46 | "range": [
47 | 0,
48 | 6
49 | ],
50 | "raw": "\\u{02}"
51 | },
52 | "\\u{003}": {
53 | "type": "value",
54 | "kind": "unicodeCodePointEscape",
55 | "codePoint": 3,
56 | "range": [
57 | 0,
58 | 7
59 | ],
60 | "raw": "\\u{003}"
61 | },
62 | "\\u{0004}": {
63 | "type": "value",
64 | "kind": "unicodeCodePointEscape",
65 | "codePoint": 4,
66 | "range": [
67 | 0,
68 | 8
69 | ],
70 | "raw": "\\u{0004}"
71 | },
72 | "\\u{00005}": {
73 | "type": "value",
74 | "kind": "unicodeCodePointEscape",
75 | "codePoint": 5,
76 | "range": [
77 | 0,
78 | 9
79 | ],
80 | "raw": "\\u{00005}"
81 | },
82 | "\\u{1D306}": {
83 | "type": "value",
84 | "kind": "unicodeCodePointEscape",
85 | "codePoint": 119558,
86 | "range": [
87 | 0,
88 | 9
89 | ],
90 | "raw": "\\u{1D306}"
91 | },
92 | "\\u{01D306}": {
93 | "type": "value",
94 | "kind": "unicodeCodePointEscape",
95 | "codePoint": 119558,
96 | "range": [
97 | 0,
98 | 10
99 | ],
100 | "raw": "\\u{01D306}"
101 | },
102 | "\\u{10FFFF}": {
103 | "type": "value",
104 | "kind": "unicodeCodePointEscape",
105 | "codePoint": 1114111,
106 | "range": [
107 | 0,
108 | 10
109 | ],
110 | "raw": "\\u{10FFFF}"
111 | },
112 | "[\\u{0}-\\u{A}]": {
113 | "type": "characterClass",
114 | "kind": "union",
115 | "body": [
116 | {
117 | "type": "characterClassRange",
118 | "min": {
119 | "type": "value",
120 | "kind": "unicodeCodePointEscape",
121 | "codePoint": 0,
122 | "range": [
123 | 1,
124 | 6
125 | ],
126 | "raw": "\\u{0}"
127 | },
128 | "max": {
129 | "type": "value",
130 | "kind": "unicodeCodePointEscape",
131 | "codePoint": 10,
132 | "range": [
133 | 7,
134 | 12
135 | ],
136 | "raw": "\\u{A}"
137 | },
138 | "range": [
139 | 1,
140 | 12
141 | ],
142 | "raw": "\\u{0}-\\u{A}"
143 | }
144 | ],
145 | "negative": false,
146 | "range": [
147 | 0,
148 | 13
149 | ],
150 | "raw": "[\\u{0}-\\u{A}]"
151 | },
152 | "[\\u{02}-\\u{003}]": {
153 | "type": "characterClass",
154 | "kind": "union",
155 | "body": [
156 | {
157 | "type": "characterClassRange",
158 | "min": {
159 | "type": "value",
160 | "kind": "unicodeCodePointEscape",
161 | "codePoint": 2,
162 | "range": [
163 | 1,
164 | 7
165 | ],
166 | "raw": "\\u{02}"
167 | },
168 | "max": {
169 | "type": "value",
170 | "kind": "unicodeCodePointEscape",
171 | "codePoint": 3,
172 | "range": [
173 | 8,
174 | 15
175 | ],
176 | "raw": "\\u{003}"
177 | },
178 | "range": [
179 | 1,
180 | 15
181 | ],
182 | "raw": "\\u{02}-\\u{003}"
183 | }
184 | ],
185 | "negative": false,
186 | "range": [
187 | 0,
188 | 16
189 | ],
190 | "raw": "[\\u{02}-\\u{003}]"
191 | },
192 | "[\uD83D\uDCA9-\uD83D\uDCAB]": {
193 | "type": "characterClass",
194 | "kind": "union",
195 | "body": [
196 | {
197 | "type": "characterClassRange",
198 | "min": {
199 | "type": "value",
200 | "kind": "symbol",
201 | "codePoint": 128169,
202 | "range": [
203 | 1,
204 | 3
205 | ],
206 | "raw": "\uD83D\uDCA9"
207 | },
208 | "max": {
209 | "type": "value",
210 | "kind": "symbol",
211 | "codePoint": 128171,
212 | "range": [
213 | 4,
214 | 6
215 | ],
216 | "raw": "\uD83D\uDCAB"
217 | },
218 | "range": [
219 | 1,
220 | 6
221 | ],
222 | "raw": "\uD83D\uDCA9-\uD83D\uDCAB"
223 | }
224 | ],
225 | "negative": false,
226 | "range": [
227 | 0,
228 | 7
229 | ],
230 | "raw": "[\uD83D\uDCA9-\uD83D\uDCAB]"
231 | },
232 | "[\\uD83D\\uDCA9-\\uD83D\\uDCAB]": {
233 | "type": "characterClass",
234 | "kind": "union",
235 | "body": [
236 | {
237 | "type": "characterClassRange",
238 | "min": {
239 | "type": "value",
240 | "kind": "unicodeCodePointEscape",
241 | "codePoint": 128169,
242 | "range": [
243 | 1,
244 | 13
245 | ],
246 | "raw": "\\uD83D\\uDCA9"
247 | },
248 | "max": {
249 | "type": "value",
250 | "kind": "unicodeCodePointEscape",
251 | "codePoint": 128171,
252 | "range": [
253 | 14,
254 | 26
255 | ],
256 | "raw": "\\uD83D\\uDCAB"
257 | },
258 | "range": [
259 | 1,
260 | 26
261 | ],
262 | "raw": "\\uD83D\\uDCA9-\\uD83D\\uDCAB"
263 | }
264 | ],
265 | "negative": false,
266 | "range": [
267 | 0,
268 | 27
269 | ],
270 | "raw": "[\\uD83D\\uDCA9-\\uD83D\\uDCAB]"
271 | },
272 | "[a-b\uD83D\uDCA9-\uD83D\uDCAB]": {
273 | "type": "characterClass",
274 | "kind": "union",
275 | "body": [
276 | {
277 | "type": "characterClassRange",
278 | "min": {
279 | "type": "value",
280 | "kind": "symbol",
281 | "codePoint": 97,
282 | "range": [
283 | 1,
284 | 2
285 | ],
286 | "raw": "a"
287 | },
288 | "max": {
289 | "type": "value",
290 | "kind": "symbol",
291 | "codePoint": 98,
292 | "range": [
293 | 3,
294 | 4
295 | ],
296 | "raw": "b"
297 | },
298 | "range": [
299 | 1,
300 | 4
301 | ],
302 | "raw": "a-b"
303 | },
304 | {
305 | "type": "characterClassRange",
306 | "min": {
307 | "type": "value",
308 | "kind": "symbol",
309 | "codePoint": 128169,
310 | "range": [
311 | 4,
312 | 6
313 | ],
314 | "raw": "\uD83D\uDCA9"
315 | },
316 | "max": {
317 | "type": "value",
318 | "kind": "symbol",
319 | "codePoint": 128171,
320 | "range": [
321 | 7,
322 | 9
323 | ],
324 | "raw": "\uD83D\uDCAB"
325 | },
326 | "range": [
327 | 4,
328 | 9
329 | ],
330 | "raw": "\uD83D\uDCA9-\uD83D\uDCAB"
331 | }
332 | ],
333 | "negative": false,
334 | "range": [
335 | 0,
336 | 10
337 | ],
338 | "raw": "[a-b\uD83D\uDCA9-\uD83D\uDCAB]"
339 | },
340 | "[a-b\\uD83D\\uDCA9-\\uD83D\\uDCAB]": {
341 | "type": "characterClass",
342 | "kind": "union",
343 | "body": [
344 | {
345 | "type": "characterClassRange",
346 | "min": {
347 | "type": "value",
348 | "kind": "symbol",
349 | "codePoint": 97,
350 | "range": [
351 | 1,
352 | 2
353 | ],
354 | "raw": "a"
355 | },
356 | "max": {
357 | "type": "value",
358 | "kind": "symbol",
359 | "codePoint": 98,
360 | "range": [
361 | 3,
362 | 4
363 | ],
364 | "raw": "b"
365 | },
366 | "range": [
367 | 1,
368 | 4
369 | ],
370 | "raw": "a-b"
371 | },
372 | {
373 | "type": "characterClassRange",
374 | "min": {
375 | "type": "value",
376 | "kind": "unicodeCodePointEscape",
377 | "codePoint": 128169,
378 | "range": [
379 | 4,
380 | 16
381 | ],
382 | "raw": "\\uD83D\\uDCA9"
383 | },
384 | "max": {
385 | "type": "value",
386 | "kind": "unicodeCodePointEscape",
387 | "codePoint": 128171,
388 | "range": [
389 | 17,
390 | 29
391 | ],
392 | "raw": "\\uD83D\\uDCAB"
393 | },
394 | "range": [
395 | 4,
396 | 29
397 | ],
398 | "raw": "\\uD83D\\uDCA9-\\uD83D\\uDCAB"
399 | }
400 | ],
401 | "negative": false,
402 | "range": [
403 | 0,
404 | 30
405 | ],
406 | "raw": "[a-b\\uD83D\\uDCA9-\\uD83D\\uDCAB]"
407 | },
408 | "[\uD83D\uDCA9-\uD83D\uDCABa-b]": {
409 | "type": "characterClass",
410 | "kind": "union",
411 | "body": [
412 | {
413 | "type": "characterClassRange",
414 | "min": {
415 | "type": "value",
416 | "kind": "symbol",
417 | "codePoint": 128169,
418 | "range": [
419 | 1,
420 | 3
421 | ],
422 | "raw": "\uD83D\uDCA9"
423 | },
424 | "max": {
425 | "type": "value",
426 | "kind": "symbol",
427 | "codePoint": 128171,
428 | "range": [
429 | 4,
430 | 6
431 | ],
432 | "raw": "\uD83D\uDCAB"
433 | },
434 | "range": [
435 | 1,
436 | 6
437 | ],
438 | "raw": "\uD83D\uDCA9-\uD83D\uDCAB"
439 | },
440 | {
441 | "type": "characterClassRange",
442 | "min": {
443 | "type": "value",
444 | "kind": "symbol",
445 | "codePoint": 97,
446 | "range": [
447 | 6,
448 | 7
449 | ],
450 | "raw": "a"
451 | },
452 | "max": {
453 | "type": "value",
454 | "kind": "symbol",
455 | "codePoint": 98,
456 | "range": [
457 | 8,
458 | 9
459 | ],
460 | "raw": "b"
461 | },
462 | "range": [
463 | 6,
464 | 9
465 | ],
466 | "raw": "a-b"
467 | }
468 | ],
469 | "negative": false,
470 | "range": [
471 | 0,
472 | 10
473 | ],
474 | "raw": "[\uD83D\uDCA9-\uD83D\uDCABa-b]"
475 | },
476 | "[\\uD83D\\uDCA9-\\uD83D\\uDCABa-b]": {
477 | "type": "characterClass",
478 | "kind": "union",
479 | "body": [
480 | {
481 | "type": "characterClassRange",
482 | "min": {
483 | "type": "value",
484 | "kind": "unicodeCodePointEscape",
485 | "codePoint": 128169,
486 | "range": [
487 | 1,
488 | 13
489 | ],
490 | "raw": "\\uD83D\\uDCA9"
491 | },
492 | "max": {
493 | "type": "value",
494 | "kind": "unicodeCodePointEscape",
495 | "codePoint": 128171,
496 | "range": [
497 | 14,
498 | 26
499 | ],
500 | "raw": "\\uD83D\\uDCAB"
501 | },
502 | "range": [
503 | 1,
504 | 26
505 | ],
506 | "raw": "\\uD83D\\uDCA9-\\uD83D\\uDCAB"
507 | },
508 | {
509 | "type": "characterClassRange",
510 | "min": {
511 | "type": "value",
512 | "kind": "symbol",
513 | "codePoint": 97,
514 | "range": [
515 | 26,
516 | 27
517 | ],
518 | "raw": "a"
519 | },
520 | "max": {
521 | "type": "value",
522 | "kind": "symbol",
523 | "codePoint": 98,
524 | "range": [
525 | 28,
526 | 29
527 | ],
528 | "raw": "b"
529 | },
530 | "range": [
531 | 26,
532 | 29
533 | ],
534 | "raw": "a-b"
535 | }
536 | ],
537 | "negative": false,
538 | "range": [
539 | 0,
540 | 30
541 | ],
542 | "raw": "[\\uD83D\\uDCA9-\\uD83D\\uDCABa-b]"
543 | },
544 | "[\uD83D\uDCA9\uD83D\uDCAB]": {
545 | "type": "characterClass",
546 | "kind": "union",
547 | "body": [
548 | {
549 | "type": "value",
550 | "kind": "symbol",
551 | "codePoint": 128169,
552 | "range": [
553 | 1,
554 | 3
555 | ],
556 | "raw": "\uD83D\uDCA9"
557 | },
558 | {
559 | "type": "value",
560 | "kind": "symbol",
561 | "codePoint": 128171,
562 | "range": [
563 | 3,
564 | 5
565 | ],
566 | "raw": "\uD83D\uDCAB"
567 | }
568 | ],
569 | "negative": false,
570 | "range": [
571 | 0,
572 | 6
573 | ],
574 | "raw": "[\uD83D\uDCA9\uD83D\uDCAB]"
575 | },
576 | "[\\uD83D\\uDCA9\\uD83D\\uDCAB]": {
577 | "type": "characterClass",
578 | "kind": "union",
579 | "body": [
580 | {
581 | "type": "value",
582 | "kind": "unicodeCodePointEscape",
583 | "codePoint": 128169,
584 | "range": [
585 | 1,
586 | 13
587 | ],
588 | "raw": "\\uD83D\\uDCA9"
589 | },
590 | {
591 | "type": "value",
592 | "kind": "unicodeCodePointEscape",
593 | "codePoint": 128171,
594 | "range": [
595 | 13,
596 | 25
597 | ],
598 | "raw": "\\uD83D\\uDCAB"
599 | }
600 | ],
601 | "negative": false,
602 | "range": [
603 | 0,
604 | 26
605 | ],
606 | "raw": "[\\uD83D\\uDCA9\\uD83D\\uDCAB]"
607 | },
608 | "[a-b\uD83D\uDCA9\uD83D\uDCAB]": {
609 | "type": "characterClass",
610 | "kind": "union",
611 | "body": [
612 | {
613 | "type": "characterClassRange",
614 | "min": {
615 | "type": "value",
616 | "kind": "symbol",
617 | "codePoint": 97,
618 | "range": [
619 | 1,
620 | 2
621 | ],
622 | "raw": "a"
623 | },
624 | "max": {
625 | "type": "value",
626 | "kind": "symbol",
627 | "codePoint": 98,
628 | "range": [
629 | 3,
630 | 4
631 | ],
632 | "raw": "b"
633 | },
634 | "range": [
635 | 1,
636 | 4
637 | ],
638 | "raw": "a-b"
639 | },
640 | {
641 | "type": "value",
642 | "kind": "symbol",
643 | "codePoint": 128169,
644 | "range": [
645 | 4,
646 | 6
647 | ],
648 | "raw": "\uD83D\uDCA9"
649 | },
650 | {
651 | "type": "value",
652 | "kind": "symbol",
653 | "codePoint": 128171,
654 | "range": [
655 | 6,
656 | 8
657 | ],
658 | "raw": "\uD83D\uDCAB"
659 | }
660 | ],
661 | "negative": false,
662 | "range": [
663 | 0,
664 | 9
665 | ],
666 | "raw": "[a-b\uD83D\uDCA9\uD83D\uDCAB]"
667 | },
668 | "[a-b\\uD83D\\uDCA9\\uD83D\\uDCAB]": {
669 | "type": "characterClass",
670 | "kind": "union",
671 | "body": [
672 | {
673 | "type": "characterClassRange",
674 | "min": {
675 | "type": "value",
676 | "kind": "symbol",
677 | "codePoint": 97,
678 | "range": [
679 | 1,
680 | 2
681 | ],
682 | "raw": "a"
683 | },
684 | "max": {
685 | "type": "value",
686 | "kind": "symbol",
687 | "codePoint": 98,
688 | "range": [
689 | 3,
690 | 4
691 | ],
692 | "raw": "b"
693 | },
694 | "range": [
695 | 1,
696 | 4
697 | ],
698 | "raw": "a-b"
699 | },
700 | {
701 | "type": "value",
702 | "kind": "unicodeCodePointEscape",
703 | "codePoint": 128169,
704 | "range": [
705 | 4,
706 | 16
707 | ],
708 | "raw": "\\uD83D\\uDCA9"
709 | },
710 | {
711 | "type": "value",
712 | "kind": "unicodeCodePointEscape",
713 | "codePoint": 128171,
714 | "range": [
715 | 16,
716 | 28
717 | ],
718 | "raw": "\\uD83D\\uDCAB"
719 | }
720 | ],
721 | "negative": false,
722 | "range": [
723 | 0,
724 | 29
725 | ],
726 | "raw": "[a-b\\uD83D\\uDCA9\\uD83D\\uDCAB]"
727 | },
728 | "[\uD83D\uDCA9\uD83D\uDCABa-b]": {
729 | "type": "characterClass",
730 | "kind": "union",
731 | "body": [
732 | {
733 | "type": "value",
734 | "kind": "symbol",
735 | "codePoint": 128169,
736 | "range": [
737 | 1,
738 | 3
739 | ],
740 | "raw": "\uD83D\uDCA9"
741 | },
742 | {
743 | "type": "value",
744 | "kind": "symbol",
745 | "codePoint": 128171,
746 | "range": [
747 | 3,
748 | 5
749 | ],
750 | "raw": "\uD83D\uDCAB"
751 | },
752 | {
753 | "type": "characterClassRange",
754 | "min": {
755 | "type": "value",
756 | "kind": "symbol",
757 | "codePoint": 97,
758 | "range": [
759 | 5,
760 | 6
761 | ],
762 | "raw": "a"
763 | },
764 | "max": {
765 | "type": "value",
766 | "kind": "symbol",
767 | "codePoint": 98,
768 | "range": [
769 | 7,
770 | 8
771 | ],
772 | "raw": "b"
773 | },
774 | "range": [
775 | 5,
776 | 8
777 | ],
778 | "raw": "a-b"
779 | }
780 | ],
781 | "negative": false,
782 | "range": [
783 | 0,
784 | 9
785 | ],
786 | "raw": "[\uD83D\uDCA9\uD83D\uDCABa-b]"
787 | },
788 | "[\\uD83D\\uDCA9\\uD83D\\uDCABa-b]": {
789 | "type": "characterClass",
790 | "kind": "union",
791 | "body": [
792 | {
793 | "type": "value",
794 | "kind": "unicodeCodePointEscape",
795 | "codePoint": 128169,
796 | "range": [
797 | 1,
798 | 13
799 | ],
800 | "raw": "\\uD83D\\uDCA9"
801 | },
802 | {
803 | "type": "value",
804 | "kind": "unicodeCodePointEscape",
805 | "codePoint": 128171,
806 | "range": [
807 | 13,
808 | 25
809 | ],
810 | "raw": "\\uD83D\\uDCAB"
811 | },
812 | {
813 | "type": "characterClassRange",
814 | "min": {
815 | "type": "value",
816 | "kind": "symbol",
817 | "codePoint": 97,
818 | "range": [
819 | 25,
820 | 26
821 | ],
822 | "raw": "a"
823 | },
824 | "max": {
825 | "type": "value",
826 | "kind": "symbol",
827 | "codePoint": 98,
828 | "range": [
829 | 27,
830 | 28
831 | ],
832 | "raw": "b"
833 | },
834 | "range": [
835 | 25,
836 | 28
837 | ],
838 | "raw": "a-b"
839 | }
840 | ],
841 | "negative": false,
842 | "range": [
843 | 0,
844 | 29
845 | ],
846 | "raw": "[\\uD83D\\uDCA9\\uD83D\\uDCABa-b]"
847 | },
848 | "\uD83D\uDCA9": {
849 | "type": "value",
850 | "kind": "symbol",
851 | "codePoint": 128169,
852 | "range": [
853 | 0,
854 | 2
855 | ],
856 | "raw": "\uD83D\uDCA9"
857 | },
858 | "\\uD83D\\uDCA9": {
859 | "type": "value",
860 | "kind": "unicodeCodePointEscape",
861 | "codePoint": 128169,
862 | "range": [
863 | 0,
864 | 12
865 | ],
866 | "raw": "\\uD83D\\uDCA9"
867 | },
868 | "(?:\uD83D\uDCA9)": {
869 | "type": "group",
870 | "behavior": "ignore",
871 | "body": [
872 | {
873 | "type": "value",
874 | "kind": "symbol",
875 | "codePoint": 128169,
876 | "range": [
877 | 3,
878 | 5
879 | ],
880 | "raw": "\uD83D\uDCA9"
881 | }
882 | ],
883 | "range": [
884 | 0,
885 | 6
886 | ],
887 | "raw": "(?:\uD83D\uDCA9)"
888 | },
889 | "(?:\\uD83D\\uDCA9)": {
890 | "type": "group",
891 | "behavior": "ignore",
892 | "body": [
893 | {
894 | "type": "value",
895 | "kind": "unicodeCodePointEscape",
896 | "codePoint": 128169,
897 | "range": [
898 | 3,
899 | 15
900 | ],
901 | "raw": "\\uD83D\\uDCA9"
902 | }
903 | ],
904 | "range": [
905 | 0,
906 | 16
907 | ],
908 | "raw": "(?:\\uD83D\\uDCA9)"
909 | },
910 | "\\u{110000}": {
911 | "type": "error",
912 | "name": "SyntaxError",
913 | "message": "Invalid escape sequence at position 1\n \\u{110000}\n ^",
914 | "input": "\\u{110000}"
915 | },
916 | "\\a": {
917 | "type": "error",
918 | "name": "SyntaxError",
919 | "message": "atomEscape at position 1\n \\a\n ^",
920 | "input": "\\a"
921 | },
922 | "\\-": {
923 | "type": "error",
924 | "name": "SyntaxError",
925 | "message": "atomEscape at position 1\n \\-\n ^",
926 | "input": "\\-"
927 | },
928 | "}": {
929 | "type": "error",
930 | "name": "SyntaxError",
931 | "message": "Expected atom at position 0\n }\n ^",
932 | "input": "}"
933 | },
934 | "]": {
935 | "type": "error",
936 | "name": "SyntaxError",
937 | "message": "Expected atom at position 0\n ]\n ^",
938 | "input": "]"
939 | },
940 | "[\\-]": {
941 | "type": "characterClass",
942 | "kind": "union",
943 | "body": [
944 | {
945 | "type": "value",
946 | "kind": "singleEscape",
947 | "codePoint": 45,
948 | "range": [
949 | 1,
950 | 3
951 | ],
952 | "raw": "\\-"
953 | }
954 | ],
955 | "negative": false,
956 | "range": [
957 | 0,
958 | 4
959 | ],
960 | "raw": "[\\-]"
961 | },
962 | "[}]": {
963 | "type": "characterClass",
964 | "kind": "union",
965 | "body": [
966 | {
967 | "type": "value",
968 | "kind": "symbol",
969 | "codePoint": 125,
970 | "range": [
971 | 1,
972 | 2
973 | ],
974 | "raw": "}"
975 | }
976 | ],
977 | "negative": false,
978 | "range": [
979 | 0,
980 | 3
981 | ],
982 | "raw": "[}]"
983 | },
984 | "[^}]": {
985 | "type": "characterClass",
986 | "kind": "union",
987 | "body": [
988 | {
989 | "type": "value",
990 | "kind": "symbol",
991 | "codePoint": 125,
992 | "range": [
993 | 2,
994 | 3
995 | ],
996 | "raw": "}"
997 | }
998 | ],
999 | "negative": true,
1000 | "range": [
1001 | 0,
1002 | 4
1003 | ],
1004 | "raw": "[^}]"
1005 | },
1006 | "[\\b-e]": {
1007 | "type": "characterClass",
1008 | "kind": "union",
1009 | "body": [
1010 | {
1011 | "type": "characterClassRange",
1012 | "min": {
1013 | "type": "value",
1014 | "kind": "singleEscape",
1015 | "codePoint": 8,
1016 | "range": [
1017 | 1,
1018 | 3
1019 | ],
1020 | "raw": "\\b"
1021 | },
1022 | "max": {
1023 | "type": "value",
1024 | "kind": "symbol",
1025 | "codePoint": 101,
1026 | "range": [
1027 | 4,
1028 | 5
1029 | ],
1030 | "raw": "e"
1031 | },
1032 | "range": [
1033 | 1,
1034 | 5
1035 | ],
1036 | "raw": "\\b-e"
1037 | }
1038 | ],
1039 | "negative": false,
1040 | "range": [
1041 | 0,
1042 | 6
1043 | ],
1044 | "raw": "[\\b-e]"
1045 | },
1046 | "[e-\\b]": {
1047 | "type": "error",
1048 | "name": "SyntaxError",
1049 | "message": "invalid range in character class at position 1: e-\\b\n [e-\\b]\n ^",
1050 | "input": "[e-\\b]"
1051 | },
1052 | "[\\w-e]": {
1053 | "type": "error",
1054 | "name": "SyntaxError",
1055 | "message": "invalid character class at position 5\n [\\w-e]\n ^",
1056 | "input": "[\\w-e]"
1057 | },
1058 | "[\\0-\\b]": {
1059 | "type": "characterClass",
1060 | "kind": "union",
1061 | "body": [
1062 | {
1063 | "type": "characterClassRange",
1064 | "min": {
1065 | "type": "value",
1066 | "kind": "null",
1067 | "codePoint": 0,
1068 | "range": [
1069 | 1,
1070 | 3
1071 | ],
1072 | "raw": "\\0"
1073 | },
1074 | "max": {
1075 | "type": "value",
1076 | "kind": "singleEscape",
1077 | "codePoint": 8,
1078 | "range": [
1079 | 4,
1080 | 6
1081 | ],
1082 | "raw": "\\b"
1083 | },
1084 | "range": [
1085 | 1,
1086 | 6
1087 | ],
1088 | "raw": "\\0-\\b"
1089 | }
1090 | ],
1091 | "negative": false,
1092 | "range": [
1093 | 0,
1094 | 7
1095 | ],
1096 | "raw": "[\\0-\\b]"
1097 | },
1098 | "{}": {
1099 | "type": "error",
1100 | "name": "SyntaxError",
1101 | "message": "Expected atom at position 0\n {}\n ^",
1102 | "input": "{}"
1103 | },
1104 | "([\\1])": {
1105 | "type": "error",
1106 | "name": "SyntaxError",
1107 | "message": "Invalid decimal escape in unicode mode at position 3\n ([\\1])\n ^",
1108 | "input": "([\\1])"
1109 | },
1110 | "\\10": {
1111 | "type": "error",
1112 | "name": "SyntaxError",
1113 | "message": "Invalid decimal escape in unicode mode at position 1\n \\10\n ^",
1114 | "input": "\\10"
1115 | },
1116 | "\\01": {
1117 | "type": "error",
1118 | "name": "SyntaxError",
1119 | "message": "Invalid decimal escape in unicode mode at position 1\n \\01\n ^",
1120 | "input": "\\01"
1121 | },
1122 | "\\00": {
1123 | "type": "error",
1124 | "name": "SyntaxError",
1125 | "message": "Invalid decimal escape in unicode mode at position 1\n \\00\n ^",
1126 | "input": "\\00"
1127 | },
1128 | "\\8": {
1129 | "type": "error",
1130 | "name": "SyntaxError",
1131 | "message": "Invalid decimal escape in unicode mode at position 1\n \\8\n ^",
1132 | "input": "\\8"
1133 | },
1134 | "\\0": {
1135 | "type": "value",
1136 | "kind": "null",
1137 | "codePoint": 0,
1138 | "range": [
1139 | 0,
1140 | 2
1141 | ],
1142 | "raw": "\\0"
1143 | },
1144 | "(.)\\1": {
1145 | "type": "alternative",
1146 | "body": [
1147 | {
1148 | "type": "group",
1149 | "behavior": "normal",
1150 | "body": [
1151 | {
1152 | "type": "dot",
1153 | "range": [
1154 | 1,
1155 | 2
1156 | ],
1157 | "raw": "."
1158 | }
1159 | ],
1160 | "range": [
1161 | 0,
1162 | 3
1163 | ],
1164 | "raw": "(.)"
1165 | },
1166 | {
1167 | "type": "reference",
1168 | "matchIndex": 1,
1169 | "range": [
1170 | 3,
1171 | 5
1172 | ],
1173 | "raw": "\\1"
1174 | }
1175 | ],
1176 | "range": [
1177 | 0,
1178 | 5
1179 | ],
1180 | "raw": "(.)\\1"
1181 | },
1182 | "\\1(.)": {
1183 | "type": "alternative",
1184 | "body": [
1185 | {
1186 | "type": "reference",
1187 | "matchIndex": 1,
1188 | "range": [
1189 | 0,
1190 | 2
1191 | ],
1192 | "raw": "\\1"
1193 | },
1194 | {
1195 | "type": "group",
1196 | "behavior": "normal",
1197 | "body": [
1198 | {
1199 | "type": "dot",
1200 | "range": [
1201 | 3,
1202 | 4
1203 | ],
1204 | "raw": "."
1205 | }
1206 | ],
1207 | "range": [
1208 | 2,
1209 | 5
1210 | ],
1211 | "raw": "(.)"
1212 | }
1213 | ],
1214 | "range": [
1215 | 0,
1216 | 5
1217 | ],
1218 | "raw": "\\1(.)"
1219 | },
1220 | "(.)\\2": {
1221 | "type": "error",
1222 | "name": "SyntaxError",
1223 | "message": "Invalid decimal escape in unicode mode at position 4\n (.)\\2\n ^",
1224 | "input": "(.)\\2"
1225 | },
1226 | "\\2(.)": {
1227 | "type": "error",
1228 | "name": "SyntaxError",
1229 | "message": "Invalid decimal escape in unicode mode at position 1\n \\2(.)\n ^",
1230 | "input": "\\2(.)"
1231 | },
1232 | ".(?=.){2,3}": {
1233 | "type": "error",
1234 | "name": "SyntaxError",
1235 | "message": "Expected atom at position 6\n .(?=.){2,3}\n ^",
1236 | "input": ".(?=.){2,3}"
1237 | },
1238 | ".(?!.){2,3}": {
1239 | "type": "error",
1240 | "name": "SyntaxError",
1241 | "message": "Expected atom at position 6\n .(?!.){2,3}\n ^",
1242 | "input": ".(?!.){2,3}"
1243 | },
1244 | "[&&]": {
1245 | "type": "characterClass",
1246 | "kind": "union",
1247 | "body": [
1248 | {
1249 | "type": "value",
1250 | "kind": "symbol",
1251 | "codePoint": 38,
1252 | "range": [
1253 | 1,
1254 | 2
1255 | ],
1256 | "raw": "&"
1257 | },
1258 | {
1259 | "type": "value",
1260 | "kind": "symbol",
1261 | "codePoint": 38,
1262 | "range": [
1263 | 2,
1264 | 3
1265 | ],
1266 | "raw": "&"
1267 | }
1268 | ],
1269 | "negative": false,
1270 | "range": [
1271 | 0,
1272 | 4
1273 | ],
1274 | "raw": "[&&]"
1275 | },
1276 | "[!!]": {
1277 | "type": "characterClass",
1278 | "kind": "union",
1279 | "body": [
1280 | {
1281 | "type": "value",
1282 | "kind": "symbol",
1283 | "codePoint": 33,
1284 | "range": [
1285 | 1,
1286 | 2
1287 | ],
1288 | "raw": "!"
1289 | },
1290 | {
1291 | "type": "value",
1292 | "kind": "symbol",
1293 | "codePoint": 33,
1294 | "range": [
1295 | 2,
1296 | 3
1297 | ],
1298 | "raw": "!"
1299 | }
1300 | ],
1301 | "negative": false,
1302 | "range": [
1303 | 0,
1304 | 4
1305 | ],
1306 | "raw": "[!!]"
1307 | },
1308 | "[##]": {
1309 | "type": "characterClass",
1310 | "kind": "union",
1311 | "body": [
1312 | {
1313 | "type": "value",
1314 | "kind": "symbol",
1315 | "codePoint": 35,
1316 | "range": [
1317 | 1,
1318 | 2
1319 | ],
1320 | "raw": "#"
1321 | },
1322 | {
1323 | "type": "value",
1324 | "kind": "symbol",
1325 | "codePoint": 35,
1326 | "range": [
1327 | 2,
1328 | 3
1329 | ],
1330 | "raw": "#"
1331 | }
1332 | ],
1333 | "negative": false,
1334 | "range": [
1335 | 0,
1336 | 4
1337 | ],
1338 | "raw": "[##]"
1339 | },
1340 | "[$$]": {
1341 | "type": "characterClass",
1342 | "kind": "union",
1343 | "body": [
1344 | {
1345 | "type": "value",
1346 | "kind": "symbol",
1347 | "codePoint": 36,
1348 | "range": [
1349 | 1,
1350 | 2
1351 | ],
1352 | "raw": "$"
1353 | },
1354 | {
1355 | "type": "value",
1356 | "kind": "symbol",
1357 | "codePoint": 36,
1358 | "range": [
1359 | 2,
1360 | 3
1361 | ],
1362 | "raw": "$"
1363 | }
1364 | ],
1365 | "negative": false,
1366 | "range": [
1367 | 0,
1368 | 4
1369 | ],
1370 | "raw": "[$$]"
1371 | },
1372 | "[%%]": {
1373 | "type": "characterClass",
1374 | "kind": "union",
1375 | "body": [
1376 | {
1377 | "type": "value",
1378 | "kind": "symbol",
1379 | "codePoint": 37,
1380 | "range": [
1381 | 1,
1382 | 2
1383 | ],
1384 | "raw": "%"
1385 | },
1386 | {
1387 | "type": "value",
1388 | "kind": "symbol",
1389 | "codePoint": 37,
1390 | "range": [
1391 | 2,
1392 | 3
1393 | ],
1394 | "raw": "%"
1395 | }
1396 | ],
1397 | "negative": false,
1398 | "range": [
1399 | 0,
1400 | 4
1401 | ],
1402 | "raw": "[%%]"
1403 | },
1404 | "[**]": {
1405 | "type": "characterClass",
1406 | "kind": "union",
1407 | "body": [
1408 | {
1409 | "type": "value",
1410 | "kind": "symbol",
1411 | "codePoint": 42,
1412 | "range": [
1413 | 1,
1414 | 2
1415 | ],
1416 | "raw": "*"
1417 | },
1418 | {
1419 | "type": "value",
1420 | "kind": "symbol",
1421 | "codePoint": 42,
1422 | "range": [
1423 | 2,
1424 | 3
1425 | ],
1426 | "raw": "*"
1427 | }
1428 | ],
1429 | "negative": false,
1430 | "range": [
1431 | 0,
1432 | 4
1433 | ],
1434 | "raw": "[**]"
1435 | },
1436 | "[++]": {
1437 | "type": "characterClass",
1438 | "kind": "union",
1439 | "body": [
1440 | {
1441 | "type": "value",
1442 | "kind": "symbol",
1443 | "codePoint": 43,
1444 | "range": [
1445 | 1,
1446 | 2
1447 | ],
1448 | "raw": "+"
1449 | },
1450 | {
1451 | "type": "value",
1452 | "kind": "symbol",
1453 | "codePoint": 43,
1454 | "range": [
1455 | 2,
1456 | 3
1457 | ],
1458 | "raw": "+"
1459 | }
1460 | ],
1461 | "negative": false,
1462 | "range": [
1463 | 0,
1464 | 4
1465 | ],
1466 | "raw": "[++]"
1467 | },
1468 | "[,,]": {
1469 | "type": "characterClass",
1470 | "kind": "union",
1471 | "body": [
1472 | {
1473 | "type": "value",
1474 | "kind": "symbol",
1475 | "codePoint": 44,
1476 | "range": [
1477 | 1,
1478 | 2
1479 | ],
1480 | "raw": ","
1481 | },
1482 | {
1483 | "type": "value",
1484 | "kind": "symbol",
1485 | "codePoint": 44,
1486 | "range": [
1487 | 2,
1488 | 3
1489 | ],
1490 | "raw": ","
1491 | }
1492 | ],
1493 | "negative": false,
1494 | "range": [
1495 | 0,
1496 | 4
1497 | ],
1498 | "raw": "[,,]"
1499 | },
1500 | "[..]": {
1501 | "type": "characterClass",
1502 | "kind": "union",
1503 | "body": [
1504 | {
1505 | "type": "value",
1506 | "kind": "symbol",
1507 | "codePoint": 46,
1508 | "range": [
1509 | 1,
1510 | 2
1511 | ],
1512 | "raw": "."
1513 | },
1514 | {
1515 | "type": "value",
1516 | "kind": "symbol",
1517 | "codePoint": 46,
1518 | "range": [
1519 | 2,
1520 | 3
1521 | ],
1522 | "raw": "."
1523 | }
1524 | ],
1525 | "negative": false,
1526 | "range": [
1527 | 0,
1528 | 4
1529 | ],
1530 | "raw": "[..]"
1531 | },
1532 | "[::]": {
1533 | "type": "characterClass",
1534 | "kind": "union",
1535 | "body": [
1536 | {
1537 | "type": "value",
1538 | "kind": "symbol",
1539 | "codePoint": 58,
1540 | "range": [
1541 | 1,
1542 | 2
1543 | ],
1544 | "raw": ":"
1545 | },
1546 | {
1547 | "type": "value",
1548 | "kind": "symbol",
1549 | "codePoint": 58,
1550 | "range": [
1551 | 2,
1552 | 3
1553 | ],
1554 | "raw": ":"
1555 | }
1556 | ],
1557 | "negative": false,
1558 | "range": [
1559 | 0,
1560 | 4
1561 | ],
1562 | "raw": "[::]"
1563 | },
1564 | "[;;]": {
1565 | "type": "characterClass",
1566 | "kind": "union",
1567 | "body": [
1568 | {
1569 | "type": "value",
1570 | "kind": "symbol",
1571 | "codePoint": 59,
1572 | "range": [
1573 | 1,
1574 | 2
1575 | ],
1576 | "raw": ";"
1577 | },
1578 | {
1579 | "type": "value",
1580 | "kind": "symbol",
1581 | "codePoint": 59,
1582 | "range": [
1583 | 2,
1584 | 3
1585 | ],
1586 | "raw": ";"
1587 | }
1588 | ],
1589 | "negative": false,
1590 | "range": [
1591 | 0,
1592 | 4
1593 | ],
1594 | "raw": "[;;]"
1595 | },
1596 | "[<<]": {
1597 | "type": "characterClass",
1598 | "kind": "union",
1599 | "body": [
1600 | {
1601 | "type": "value",
1602 | "kind": "symbol",
1603 | "codePoint": 60,
1604 | "range": [
1605 | 1,
1606 | 2
1607 | ],
1608 | "raw": "<"
1609 | },
1610 | {
1611 | "type": "value",
1612 | "kind": "symbol",
1613 | "codePoint": 60,
1614 | "range": [
1615 | 2,
1616 | 3
1617 | ],
1618 | "raw": "<"
1619 | }
1620 | ],
1621 | "negative": false,
1622 | "range": [
1623 | 0,
1624 | 4
1625 | ],
1626 | "raw": "[<<]"
1627 | },
1628 | "[==]": {
1629 | "type": "characterClass",
1630 | "kind": "union",
1631 | "body": [
1632 | {
1633 | "type": "value",
1634 | "kind": "symbol",
1635 | "codePoint": 61,
1636 | "range": [
1637 | 1,
1638 | 2
1639 | ],
1640 | "raw": "="
1641 | },
1642 | {
1643 | "type": "value",
1644 | "kind": "symbol",
1645 | "codePoint": 61,
1646 | "range": [
1647 | 2,
1648 | 3
1649 | ],
1650 | "raw": "="
1651 | }
1652 | ],
1653 | "negative": false,
1654 | "range": [
1655 | 0,
1656 | 4
1657 | ],
1658 | "raw": "[==]"
1659 | },
1660 | "[>>]": {
1661 | "type": "characterClass",
1662 | "kind": "union",
1663 | "body": [
1664 | {
1665 | "type": "value",
1666 | "kind": "symbol",
1667 | "codePoint": 62,
1668 | "range": [
1669 | 1,
1670 | 2
1671 | ],
1672 | "raw": ">"
1673 | },
1674 | {
1675 | "type": "value",
1676 | "kind": "symbol",
1677 | "codePoint": 62,
1678 | "range": [
1679 | 2,
1680 | 3
1681 | ],
1682 | "raw": ">"
1683 | }
1684 | ],
1685 | "negative": false,
1686 | "range": [
1687 | 0,
1688 | 4
1689 | ],
1690 | "raw": "[>>]"
1691 | },
1692 | "[??]": {
1693 | "type": "characterClass",
1694 | "kind": "union",
1695 | "body": [
1696 | {
1697 | "type": "value",
1698 | "kind": "symbol",
1699 | "codePoint": 63,
1700 | "range": [
1701 | 1,
1702 | 2
1703 | ],
1704 | "raw": "?"
1705 | },
1706 | {
1707 | "type": "value",
1708 | "kind": "symbol",
1709 | "codePoint": 63,
1710 | "range": [
1711 | 2,
1712 | 3
1713 | ],
1714 | "raw": "?"
1715 | }
1716 | ],
1717 | "negative": false,
1718 | "range": [
1719 | 0,
1720 | 4
1721 | ],
1722 | "raw": "[??]"
1723 | },
1724 | "[@@]": {
1725 | "type": "characterClass",
1726 | "kind": "union",
1727 | "body": [
1728 | {
1729 | "type": "value",
1730 | "kind": "symbol",
1731 | "codePoint": 64,
1732 | "range": [
1733 | 1,
1734 | 2
1735 | ],
1736 | "raw": "@"
1737 | },
1738 | {
1739 | "type": "value",
1740 | "kind": "symbol",
1741 | "codePoint": 64,
1742 | "range": [
1743 | 2,
1744 | 3
1745 | ],
1746 | "raw": "@"
1747 | }
1748 | ],
1749 | "negative": false,
1750 | "range": [
1751 | 0,
1752 | 4
1753 | ],
1754 | "raw": "[@@]"
1755 | },
1756 | "[^^^]": {
1757 | "type": "characterClass",
1758 | "kind": "union",
1759 | "body": [
1760 | {
1761 | "type": "value",
1762 | "kind": "symbol",
1763 | "codePoint": 94,
1764 | "range": [
1765 | 2,
1766 | 3
1767 | ],
1768 | "raw": "^"
1769 | },
1770 | {
1771 | "type": "value",
1772 | "kind": "symbol",
1773 | "codePoint": 94,
1774 | "range": [
1775 | 3,
1776 | 4
1777 | ],
1778 | "raw": "^"
1779 | }
1780 | ],
1781 | "negative": true,
1782 | "range": [
1783 | 0,
1784 | 5
1785 | ],
1786 | "raw": "[^^^]"
1787 | },
1788 | "[``]": {
1789 | "type": "characterClass",
1790 | "kind": "union",
1791 | "body": [
1792 | {
1793 | "type": "value",
1794 | "kind": "symbol",
1795 | "codePoint": 96,
1796 | "range": [
1797 | 1,
1798 | 2
1799 | ],
1800 | "raw": "`"
1801 | },
1802 | {
1803 | "type": "value",
1804 | "kind": "symbol",
1805 | "codePoint": 96,
1806 | "range": [
1807 | 2,
1808 | 3
1809 | ],
1810 | "raw": "`"
1811 | }
1812 | ],
1813 | "negative": false,
1814 | "range": [
1815 | 0,
1816 | 4
1817 | ],
1818 | "raw": "[``]"
1819 | },
1820 | "[~~]": {
1821 | "type": "characterClass",
1822 | "kind": "union",
1823 | "body": [
1824 | {
1825 | "type": "value",
1826 | "kind": "symbol",
1827 | "codePoint": 126,
1828 | "range": [
1829 | 1,
1830 | 2
1831 | ],
1832 | "raw": "~"
1833 | },
1834 | {
1835 | "type": "value",
1836 | "kind": "symbol",
1837 | "codePoint": 126,
1838 | "range": [
1839 | 2,
1840 | 3
1841 | ],
1842 | "raw": "~"
1843 | }
1844 | ],
1845 | "negative": false,
1846 | "range": [
1847 | 0,
1848 | 4
1849 | ],
1850 | "raw": "[~~]"
1851 | },
1852 | "^*": {
1853 | "type": "error",
1854 | "name": "SyntaxError",
1855 | "message": "Expected atom at position 1\n ^*\n ^",
1856 | "input": "^*"
1857 | },
1858 | "$+": {
1859 | "type": "error",
1860 | "name": "SyntaxError",
1861 | "message": "Expected atom at position 1\n $+\n ^",
1862 | "input": "$+"
1863 | },
1864 | "\\b?": {
1865 | "type": "error",
1866 | "name": "SyntaxError",
1867 | "message": "Expected atom at position 2\n \\b?\n ^",
1868 | "input": "\\b?"
1869 | },
1870 | "\\B{1}": {
1871 | "type": "error",
1872 | "name": "SyntaxError",
1873 | "message": "Expected atom at position 2\n \\B{1}\n ^",
1874 | "input": "\\B{1}"
1875 | },
1876 | "[\\c]": {
1877 | "type": "error",
1878 | "name": "SyntaxError",
1879 | "message": "classEscape at position 2\n [\\c]\n ^",
1880 | "input": "[\\c]"
1881 | }
1882 | }
1883 |
--------------------------------------------------------------------------------
/tests/tests.js:
--------------------------------------------------------------------------------
1 | var generate = require('../regjsgen').generate;
2 | var parse = require('regjsparser').parse;
3 | var astNodesAreEquivalent = require('./equiv');
4 |
5 | function runTests(data, options) {
6 | options || (options = {});
7 | var excused = options.excused || [],
8 | flags = options.flags || '',
9 | features = options.features || {};
10 |
11 | var keys = Object.keys(data).filter(function(name) {
12 | return data[name].type != 'error' && excused.indexOf(name) == -1;
13 | });
14 |
15 | keys.forEach(function(regex) {
16 | var node = data[regex],
17 | expected = JSON.stringify(regex),
18 | generated,
19 | passed,
20 | stack;
21 |
22 | // Ensure that the generated regex matches the original input.
23 | try {
24 | generated = JSON.stringify(generate(node));
25 | passed = generated == expected;
26 | } catch (error) {
27 | stack = error.stack;
28 | generated = JSON.stringify({
29 | 'name': error.name,
30 | 'message': error.message,
31 | 'input': regex
32 | });
33 | }
34 |
35 | if (passed) {
36 | console.log('PASSED TEST: %s', expected);
37 | return;
38 | }
39 |
40 | // If the generated regex does not match the original input, the output
41 | // could be identical to the original input in terms of the AST.
42 | // eg. `a{1,}` generates the same AST nodes as `a+`.
43 | // Compare the ASTs of the generated regex and the input regex.
44 | try {
45 | passed = astNodesAreEquivalent(
46 | parse(regex, flags, features),
47 | parse(generate(node), flags, features)
48 | );
49 | } catch (error) {
50 | stack = error.stack;
51 | generated = JSON.stringify({
52 | 'name': error.name,
53 | 'message': error.message,
54 | 'input': regex
55 | });
56 | }
57 |
58 | if (!passed) {
59 | console.error(
60 | [
61 | 'FAILED TEST: %s',
62 | 'Generated: %s',
63 | 'Input AST: %s'
64 | ].join('\n'),
65 | JSON.stringify(regex),
66 | generated,
67 | JSON.stringify(node)
68 | );
69 | if (stack) {
70 | console.error(stack);
71 | }
72 | process.exit(1);
73 | } else {
74 | console.log('PASSED TEST: %s', expected);
75 | }
76 | });
77 | };
78 |
79 | runTests(require('./test-data.json'));
80 | runTests(require('./test-data-nonstandard.json'));
81 | runTests(require('./test-data-unicode.json'), { 'flags': 'u' });
82 | runTests(require('./test-data-unicode-properties.json'), {
83 | 'flags': 'u',
84 | 'features': { 'unicodePropertyEscape': true }
85 | });
86 | runTests(require('./test-data-named-groups.json'), {
87 | 'features': { 'namedGroups': true }
88 | });
89 | runTests(require('./test-data-named-groups-unicode.json'), {
90 | 'flags': 'u',
91 | 'features': { 'namedGroups': true }
92 | });
93 | runTests(require('./test-data-named-groups-unicode-properties.json'), {
94 | 'flags': 'u',
95 | 'features': { 'namedGroups': true, 'unicodePropertyEscape': true }
96 | });
97 | runTests(require('./test-data-lookbehind.json'), {
98 | 'features': { 'lookbehind': true }
99 | });
100 | runTests(require('./test-data-unicode-set.json'), {
101 | 'flags': 'v',
102 | 'features': { 'unicodePropertyEscape': true, 'unicodeSet': true }
103 | });
104 | runTests(require('./test-data-modifiers-group.json'), {
105 | 'flags': '',
106 | 'features': { 'modifiers': true }
107 | });
108 |
--------------------------------------------------------------------------------
/tests/update-fixtures.js:
--------------------------------------------------------------------------------
1 | const { createWriteStream } = require('node:fs');
2 | const { join } = require('node:path');
3 | const { pipeline } = require('node:stream/promises');
4 |
5 | async function saveFile(url) {
6 | const name = url.slice(url.lastIndexOf('/') + 1);
7 |
8 | try {
9 | const { body } = await fetch(url);
10 |
11 | await pipeline(
12 | body,
13 | createWriteStream(join(__dirname, name)),
14 | );
15 | console.log('`%s` updated successfully.', name);
16 | } catch(err) {
17 | console.error('Error writing to file:', err);
18 | }
19 | }
20 |
21 | const FIXTURE_URLS = [
22 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data.json',
23 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-lookbehind.json',
24 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-nonstandard.json',
25 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-named-groups.json',
26 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-named-groups-unicode.json',
27 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-named-groups-unicode-properties.json',
28 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-unicode.json',
29 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-unicode-properties.json',
30 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-unicode-set.json',
31 | 'https://raw.githubusercontent.com/jviereck/regjsparser/gh-pages/test/test-data-modifiers-group.json',
32 | ];
33 |
34 | (async () => {
35 | await Promise.all(FIXTURE_URLS.map(saveFile));
36 | })();
37 |
--------------------------------------------------------------------------------