trilean-regex 0.0.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -0
- package/dist/ast-D8HLFxxv.d.cts +75 -0
- package/dist/ast-D8HLFxxv.d.ts +75 -0
- package/dist/ast.cjs +14 -0
- package/dist/ast.d.cts +2 -0
- package/dist/ast.d.ts +2 -0
- package/dist/ast.js +12 -0
- package/dist/errors.cjs +19 -0
- package/dist/errors.d.cts +13 -0
- package/dist/errors.d.ts +13 -0
- package/dist/errors.js +18 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/matcher.cjs +89 -0
- package/dist/matcher.d.cts +31 -0
- package/dist/matcher.d.ts +31 -0
- package/dist/matcher.js +86 -0
- package/dist/nfa.cjs +246 -0
- package/dist/nfa.d.cts +34 -0
- package/dist/nfa.d.ts +34 -0
- package/dist/nfa.js +245 -0
- package/dist/parser.cjs +329 -0
- package/dist/parser.d.cts +12 -0
- package/dist/parser.d.ts +12 -0
- package/dist/parser.js +328 -0
- package/dist/shorthand-classes.cjs +74 -0
- package/dist/shorthand-classes.d.cts +8 -0
- package/dist/shorthand-classes.d.ts +8 -0
- package/dist/shorthand-classes.js +73 -0
- package/package.json +89 -2
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/shorthand-classes.ts
|
|
3
|
+
function codeOf(char) {
|
|
4
|
+
return char.charCodeAt(0);
|
|
5
|
+
}
|
|
6
|
+
function range(fromChar, toChar) {
|
|
7
|
+
return {
|
|
8
|
+
from: codeOf(fromChar),
|
|
9
|
+
to: codeOf(toChar)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function single(char) {
|
|
13
|
+
const codeUnit = codeOf(char);
|
|
14
|
+
return {
|
|
15
|
+
from: codeUnit,
|
|
16
|
+
to: codeUnit
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** `\d` -- the ASCII digits `0`-`9`. Fixed, not locale- or engine-dependent: a shorthand's whole purpose here is to expand to the same ranges regardless of which dialect a `trilean-sql` compiler is targeting, so its expansion is a constant this package owns rather than a delegation to the host's own `RegExp` notion of "digit". */
|
|
20
|
+
const DIGIT_RANGES = [range("0", "9")];
|
|
21
|
+
/** `\w` -- ASCII letters, digits, and underscore. The ECMAScript definition of "word character" without the `u`/`unicode` flag, which is the one this grammar's non-Unicode-scalar code-unit model corresponds to. */
|
|
22
|
+
const WORD_RANGES = [
|
|
23
|
+
range("A", "Z"),
|
|
24
|
+
range("a", "z"),
|
|
25
|
+
range("0", "9"),
|
|
26
|
+
single("_")
|
|
27
|
+
];
|
|
28
|
+
/** `\s` -- the ASCII whitespace characters ECMAScript's `\s` matches outside the `u` flag's extra Unicode space separators: space, tab, newline, carriage return, form feed, vertical tab. */
|
|
29
|
+
const SPACE_RANGES = [
|
|
30
|
+
single(" "),
|
|
31
|
+
single(" "),
|
|
32
|
+
single("\n"),
|
|
33
|
+
single("\r"),
|
|
34
|
+
single("\f"),
|
|
35
|
+
single("\v")
|
|
36
|
+
];
|
|
37
|
+
/** Expands a shorthand class letter (`d`/`D`/`w`/`W`/`s`/`S`) to the `CharClassNode` it stands for. Uppercase negates the corresponding lowercase letter's ranges rather than owning a separate range table, since a shorthand class and its negation are the same set by definition. */
|
|
38
|
+
function expandShorthandClass(letter) {
|
|
39
|
+
switch (letter) {
|
|
40
|
+
case "d": return {
|
|
41
|
+
kind: "charClass",
|
|
42
|
+
negated: false,
|
|
43
|
+
ranges: DIGIT_RANGES
|
|
44
|
+
};
|
|
45
|
+
case "D": return {
|
|
46
|
+
kind: "charClass",
|
|
47
|
+
negated: true,
|
|
48
|
+
ranges: DIGIT_RANGES
|
|
49
|
+
};
|
|
50
|
+
case "w": return {
|
|
51
|
+
kind: "charClass",
|
|
52
|
+
negated: false,
|
|
53
|
+
ranges: WORD_RANGES
|
|
54
|
+
};
|
|
55
|
+
case "W": return {
|
|
56
|
+
kind: "charClass",
|
|
57
|
+
negated: true,
|
|
58
|
+
ranges: WORD_RANGES
|
|
59
|
+
};
|
|
60
|
+
case "s": return {
|
|
61
|
+
kind: "charClass",
|
|
62
|
+
negated: false,
|
|
63
|
+
ranges: SPACE_RANGES
|
|
64
|
+
};
|
|
65
|
+
case "S": return {
|
|
66
|
+
kind: "charClass",
|
|
67
|
+
negated: true,
|
|
68
|
+
ranges: SPACE_RANGES
|
|
69
|
+
};
|
|
70
|
+
default: throw new Error("unreachable shorthand class letter");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.expandShorthandClass = expandShorthandClass;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { a as CharClassNode } from "./ast-D8HLFxxv.cjs";
|
|
2
|
+
//#region src/shorthand-classes.d.ts
|
|
3
|
+
/** The letter each shorthand class is written with, case distinguishing the positive form (`d`, `w`, `s`) from its negation (`D`, `W`, `S`). */
|
|
4
|
+
type ShorthandClassLetter = "d" | "D" | "w" | "W" | "s" | "S";
|
|
5
|
+
/** Expands a shorthand class letter (`d`/`D`/`w`/`W`/`s`/`S`) to the `CharClassNode` it stands for. Uppercase negates the corresponding lowercase letter's ranges rather than owning a separate range table, since a shorthand class and its negation are the same set by definition. */
|
|
6
|
+
declare function expandShorthandClass(letter: ShorthandClassLetter): CharClassNode;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ShorthandClassLetter, expandShorthandClass };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { a as CharClassNode } from "./ast-D8HLFxxv.js";
|
|
2
|
+
//#region src/shorthand-classes.d.ts
|
|
3
|
+
/** The letter each shorthand class is written with, case distinguishing the positive form (`d`, `w`, `s`) from its negation (`D`, `W`, `S`). */
|
|
4
|
+
type ShorthandClassLetter = "d" | "D" | "w" | "W" | "s" | "S";
|
|
5
|
+
/** Expands a shorthand class letter (`d`/`D`/`w`/`W`/`s`/`S`) to the `CharClassNode` it stands for. Uppercase negates the corresponding lowercase letter's ranges rather than owning a separate range table, since a shorthand class and its negation are the same set by definition. */
|
|
6
|
+
declare function expandShorthandClass(letter: ShorthandClassLetter): CharClassNode;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ShorthandClassLetter, expandShorthandClass };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region src/shorthand-classes.ts
|
|
2
|
+
function codeOf(char) {
|
|
3
|
+
return char.charCodeAt(0);
|
|
4
|
+
}
|
|
5
|
+
function range(fromChar, toChar) {
|
|
6
|
+
return {
|
|
7
|
+
from: codeOf(fromChar),
|
|
8
|
+
to: codeOf(toChar)
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function single(char) {
|
|
12
|
+
const codeUnit = codeOf(char);
|
|
13
|
+
return {
|
|
14
|
+
from: codeUnit,
|
|
15
|
+
to: codeUnit
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** `\d` -- the ASCII digits `0`-`9`. Fixed, not locale- or engine-dependent: a shorthand's whole purpose here is to expand to the same ranges regardless of which dialect a `trilean-sql` compiler is targeting, so its expansion is a constant this package owns rather than a delegation to the host's own `RegExp` notion of "digit". */
|
|
19
|
+
const DIGIT_RANGES = [range("0", "9")];
|
|
20
|
+
/** `\w` -- ASCII letters, digits, and underscore. The ECMAScript definition of "word character" without the `u`/`unicode` flag, which is the one this grammar's non-Unicode-scalar code-unit model corresponds to. */
|
|
21
|
+
const WORD_RANGES = [
|
|
22
|
+
range("A", "Z"),
|
|
23
|
+
range("a", "z"),
|
|
24
|
+
range("0", "9"),
|
|
25
|
+
single("_")
|
|
26
|
+
];
|
|
27
|
+
/** `\s` -- the ASCII whitespace characters ECMAScript's `\s` matches outside the `u` flag's extra Unicode space separators: space, tab, newline, carriage return, form feed, vertical tab. */
|
|
28
|
+
const SPACE_RANGES = [
|
|
29
|
+
single(" "),
|
|
30
|
+
single(" "),
|
|
31
|
+
single("\n"),
|
|
32
|
+
single("\r"),
|
|
33
|
+
single("\f"),
|
|
34
|
+
single("\v")
|
|
35
|
+
];
|
|
36
|
+
/** Expands a shorthand class letter (`d`/`D`/`w`/`W`/`s`/`S`) to the `CharClassNode` it stands for. Uppercase negates the corresponding lowercase letter's ranges rather than owning a separate range table, since a shorthand class and its negation are the same set by definition. */
|
|
37
|
+
function expandShorthandClass(letter) {
|
|
38
|
+
switch (letter) {
|
|
39
|
+
case "d": return {
|
|
40
|
+
kind: "charClass",
|
|
41
|
+
negated: false,
|
|
42
|
+
ranges: DIGIT_RANGES
|
|
43
|
+
};
|
|
44
|
+
case "D": return {
|
|
45
|
+
kind: "charClass",
|
|
46
|
+
negated: true,
|
|
47
|
+
ranges: DIGIT_RANGES
|
|
48
|
+
};
|
|
49
|
+
case "w": return {
|
|
50
|
+
kind: "charClass",
|
|
51
|
+
negated: false,
|
|
52
|
+
ranges: WORD_RANGES
|
|
53
|
+
};
|
|
54
|
+
case "W": return {
|
|
55
|
+
kind: "charClass",
|
|
56
|
+
negated: true,
|
|
57
|
+
ranges: WORD_RANGES
|
|
58
|
+
};
|
|
59
|
+
case "s": return {
|
|
60
|
+
kind: "charClass",
|
|
61
|
+
negated: false,
|
|
62
|
+
ranges: SPACE_RANGES
|
|
63
|
+
};
|
|
64
|
+
case "S": return {
|
|
65
|
+
kind: "charClass",
|
|
66
|
+
negated: true,
|
|
67
|
+
ranges: SPACE_RANGES
|
|
68
|
+
};
|
|
69
|
+
default: throw new Error("unreachable shorthand class letter");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { expandShorthandClass };
|
package/package.json
CHANGED
|
@@ -1,5 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trilean-regex",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A portable regular-expression grammar -- a true regular language, with a Thompson-construction reference matcher -- so a pattern means the same thing in process and wherever trilean-sql can push it down to a database's own engine.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ExaDev/trilean.git",
|
|
9
|
+
"directory": "packages/trilean-regex"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/ExaDev/trilean/tree/main/packages/trilean-regex",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ExaDev/trilean/issues"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": {
|
|
18
|
+
"import": "./dist/index.d.ts",
|
|
19
|
+
"require": "./dist/index.d.cts"
|
|
20
|
+
},
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./*": {
|
|
25
|
+
"types": {
|
|
26
|
+
"import": "./dist/*.d.ts",
|
|
27
|
+
"require": "./dist/*.d.cts"
|
|
28
|
+
},
|
|
29
|
+
"import": "./dist/*.js",
|
|
30
|
+
"require": "./dist/*.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.cjs",
|
|
34
|
+
"module": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true,
|
|
42
|
+
"registry": "https://registry.npmjs.org/"
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": false,
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "turbo run _build",
|
|
51
|
+
"_build": "tsdown",
|
|
52
|
+
"lint": "turbo run _lint",
|
|
53
|
+
"_lint": "eslint . --fix --cache --max-warnings 0",
|
|
54
|
+
"typecheck": "turbo run _typecheck _typecheck:attw",
|
|
55
|
+
"_typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.node.json",
|
|
56
|
+
"_typecheck:attw": "attw --pack",
|
|
57
|
+
"test": "turbo run _test",
|
|
58
|
+
"_test": "vitest run --project unit",
|
|
59
|
+
"test:coverage": "turbo run _test:coverage",
|
|
60
|
+
"_test:coverage": "vitest run --project unit --coverage",
|
|
61
|
+
"prepush": "turbo run _prepush",
|
|
62
|
+
"_prepush": "true",
|
|
63
|
+
"prepublishOnly": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build && publint && attw --pack"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"regex",
|
|
67
|
+
"regular-expression",
|
|
68
|
+
"regular-language",
|
|
69
|
+
"finite-automaton",
|
|
70
|
+
"nfa",
|
|
71
|
+
"parser",
|
|
72
|
+
"trilean",
|
|
73
|
+
"isomorphic"
|
|
74
|
+
],
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
77
|
+
"@exadev/eslint-config": "^2.10.2",
|
|
78
|
+
"@types/node": "^26.4.0",
|
|
79
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
80
|
+
"eslint": "^10.9.1",
|
|
81
|
+
"eslint-config-prettier": "^10.1.8",
|
|
82
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
83
|
+
"globals": "^17.11.0",
|
|
84
|
+
"prettier": "^3.9.6",
|
|
85
|
+
"publint": "^0.3.24",
|
|
86
|
+
"tsdown": "^0.22.14",
|
|
87
|
+
"turbo": "^2.10.12",
|
|
88
|
+
"typescript": "^6.0.3",
|
|
89
|
+
"typescript-eslint": "^8.68.0",
|
|
90
|
+
"vitest": "^4.1.11"
|
|
91
|
+
}
|
|
5
92
|
}
|