@ac-kit/format-regex 0.3.3 → 0.4.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/CHANGELOG.md +52 -0
- package/README.md +47 -0
- package/dist/_unicode-category.d.ts +5 -0
- package/dist/_unicode-category.d.ts.map +1 -1
- package/dist/_unicode-category.js +5 -0
- package/dist/_unicode-category.js.map +1 -1
- package/dist/code-point-class.d.ts +46 -0
- package/dist/code-point-class.d.ts.map +1 -0
- package/dist/code-point-class.js +50 -0
- package/dist/code-point-class.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lexer.js +24 -24
- package/dist/lexer.js.map +1 -1
- package/dist/parser.js +32 -32
- package/dist/parser.js.map +1 -1
- package/dist/regex-tree.d.ts +167 -0
- package/dist/regex-tree.d.ts.map +1 -0
- package/dist/regex-tree.js +209 -0
- package/dist/regex-tree.js.map +1 -0
- package/dist/token.d.ts +20 -20
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +20 -21
- package/dist/token.js.map +1 -1
- package/dist/unicode-general-category.d.ts +39 -0
- package/dist/unicode-general-category.d.ts.map +1 -0
- package/dist/unicode-general-category.js +44 -0
- package/dist/unicode-general-category.js.map +1 -0
- package/dist/vm/_class-predicate.d.ts +23 -10
- package/dist/vm/_class-predicate.d.ts.map +1 -1
- package/dist/vm/_class-predicate.js +41 -26
- package/dist/vm/_class-predicate.js.map +1 -1
- package/dist/vm/pike-vm.d.ts +2 -1
- package/dist/vm/pike-vm.d.ts.map +1 -1
- package/dist/vm/pike-vm.js +45 -4
- package/dist/vm/pike-vm.js.map +1 -1
- package/dist/vm/program.d.ts +19 -0
- package/dist/vm/program.d.ts.map +1 -1
- package/dist/walk.d.ts +2 -1
- package/dist/walk.d.ts.map +1 -1
- package/dist/walk.js.map +1 -1
- package/package.json +5 -5
package/dist/parser.js
CHANGED
|
@@ -11,7 +11,7 @@ export class RegexParseError extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
function describeToken(token) {
|
|
14
|
-
return token.kind === TokenKind.
|
|
14
|
+
return token.kind === TokenKind.END_OF_PATTERN
|
|
15
15
|
? "end of pattern"
|
|
16
16
|
: `'${token.text}'`;
|
|
17
17
|
}
|
|
@@ -68,33 +68,33 @@ export function parseRegex(source, limits) {
|
|
|
68
68
|
let min;
|
|
69
69
|
let max;
|
|
70
70
|
let quantEnd = atom.span.end;
|
|
71
|
-
if (quantifierToken.kind === TokenKind.
|
|
71
|
+
if (quantifierToken.kind === TokenKind.STAR) {
|
|
72
72
|
min = 0;
|
|
73
73
|
max = undefined;
|
|
74
74
|
advance();
|
|
75
75
|
quantEnd = quantifierToken.span.end;
|
|
76
76
|
}
|
|
77
|
-
else if (quantifierToken.kind === TokenKind.
|
|
77
|
+
else if (quantifierToken.kind === TokenKind.PLUS) {
|
|
78
78
|
min = 1;
|
|
79
79
|
max = undefined;
|
|
80
80
|
advance();
|
|
81
81
|
quantEnd = quantifierToken.span.end;
|
|
82
82
|
}
|
|
83
|
-
else if (quantifierToken.kind === TokenKind.
|
|
83
|
+
else if (quantifierToken.kind === TokenKind.QUESTION) {
|
|
84
84
|
min = 0;
|
|
85
85
|
max = 1;
|
|
86
86
|
advance();
|
|
87
87
|
quantEnd = quantifierToken.span.end;
|
|
88
88
|
}
|
|
89
|
-
else if (quantifierToken.kind === TokenKind.
|
|
89
|
+
else if (quantifierToken.kind === TokenKind.LEFT_BRACE) {
|
|
90
90
|
advance();
|
|
91
|
-
const minText = expect(TokenKind.
|
|
91
|
+
const minText = expect(TokenKind.NUMBER, "a number").text;
|
|
92
92
|
let maxText = minText;
|
|
93
|
-
if (peek().kind === TokenKind.
|
|
93
|
+
if (peek().kind === TokenKind.COMMA) {
|
|
94
94
|
advance();
|
|
95
|
-
maxText = peek().kind === TokenKind.
|
|
95
|
+
maxText = peek().kind === TokenKind.NUMBER ? advance().text : undefined;
|
|
96
96
|
}
|
|
97
|
-
quantEnd = expect(TokenKind.
|
|
97
|
+
quantEnd = expect(TokenKind.RIGHT_BRACE, "'}'").span.end;
|
|
98
98
|
// Ordered on the digits, before any rounding to a number.
|
|
99
99
|
if (maxText !== undefined && compareDecimalDigits(maxText, minText) < 0) {
|
|
100
100
|
throw new RegexParseError(`Quantifier max (${maxText}) is less than min (${minText})`, { start: atom.span.start, end: quantEnd });
|
|
@@ -107,7 +107,7 @@ export function parseRegex(source, limits) {
|
|
|
107
107
|
return atom;
|
|
108
108
|
}
|
|
109
109
|
let lazy = false;
|
|
110
|
-
if (peek().kind === TokenKind.
|
|
110
|
+
if (peek().kind === TokenKind.QUESTION) {
|
|
111
111
|
lazy = true;
|
|
112
112
|
quantEnd = advance().span.end;
|
|
113
113
|
}
|
|
@@ -124,53 +124,53 @@ export function parseRegex(source, limits) {
|
|
|
124
124
|
function parseAtom() {
|
|
125
125
|
const token = peek();
|
|
126
126
|
switch (token.kind) {
|
|
127
|
-
case TokenKind.
|
|
127
|
+
case TokenKind.CHAR:
|
|
128
128
|
advance();
|
|
129
129
|
return { kind: "literal", char: token.text, span: token.span };
|
|
130
|
-
case TokenKind.
|
|
130
|
+
case TokenKind.DOT:
|
|
131
131
|
advance();
|
|
132
132
|
return { kind: "any", span: token.span };
|
|
133
|
-
case TokenKind.
|
|
133
|
+
case TokenKind.SHORTHAND:
|
|
134
134
|
advance();
|
|
135
135
|
return {
|
|
136
136
|
kind: "shorthand",
|
|
137
137
|
value: token.text,
|
|
138
138
|
span: token.span,
|
|
139
139
|
};
|
|
140
|
-
case TokenKind.
|
|
140
|
+
case TokenKind.CARET:
|
|
141
141
|
advance();
|
|
142
142
|
return { kind: "anchor", type: "start", span: token.span };
|
|
143
|
-
case TokenKind.
|
|
143
|
+
case TokenKind.DOLLAR:
|
|
144
144
|
advance();
|
|
145
145
|
return { kind: "anchor", type: "end", span: token.span };
|
|
146
|
-
case TokenKind.
|
|
146
|
+
case TokenKind.LEFT_BRACKET:
|
|
147
147
|
return parseCharClass();
|
|
148
148
|
default:
|
|
149
149
|
throw new RegexParseError(`Unexpected token ${describeToken(token)}`, token.span);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
function parseCharClass() {
|
|
153
|
-
const open = expect(TokenKind.
|
|
153
|
+
const open = expect(TokenKind.LEFT_BRACKET, "'['");
|
|
154
154
|
let negated = false;
|
|
155
|
-
if (peek().kind === TokenKind.
|
|
155
|
+
if (peek().kind === TokenKind.CARET) {
|
|
156
156
|
advance();
|
|
157
157
|
negated = true;
|
|
158
158
|
}
|
|
159
|
-
if (peek().kind === TokenKind.
|
|
159
|
+
if (peek().kind === TokenKind.RIGHT_BRACKET) {
|
|
160
160
|
throw new RegexParseError("Empty character class", {
|
|
161
161
|
start: open.span.start,
|
|
162
162
|
end: peek().span.end,
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
const items = [];
|
|
166
|
-
while (peek().kind !== TokenKind.
|
|
167
|
-
if (peek().kind === TokenKind.
|
|
166
|
+
while (peek().kind !== TokenKind.RIGHT_BRACKET) {
|
|
167
|
+
if (peek().kind === TokenKind.END_OF_PATTERN) {
|
|
168
168
|
throw new RegexParseError("Unterminated character class", {
|
|
169
169
|
start: open.span.start,
|
|
170
170
|
end: peek().span.end,
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
-
if (peek().kind === TokenKind.
|
|
173
|
+
if (peek().kind === TokenKind.SHORTHAND) {
|
|
174
174
|
const shorthandToken = advance();
|
|
175
175
|
items.push({
|
|
176
176
|
kind: "shorthand",
|
|
@@ -179,14 +179,14 @@ export function parseRegex(source, limits) {
|
|
|
179
179
|
continue;
|
|
180
180
|
}
|
|
181
181
|
const fromToken = advance();
|
|
182
|
-
if (fromToken.kind !== TokenKind.
|
|
183
|
-
fromToken.kind !== TokenKind.
|
|
182
|
+
if (fromToken.kind !== TokenKind.CHAR &&
|
|
183
|
+
fromToken.kind !== TokenKind.HYPHEN) {
|
|
184
184
|
throw new RegexParseError(`Unexpected token in character class ${describeToken(fromToken)}`, fromToken.span);
|
|
185
185
|
}
|
|
186
|
-
if (peek().kind === TokenKind.
|
|
186
|
+
if (peek().kind === TokenKind.HYPHEN) {
|
|
187
187
|
const savedIndex = index;
|
|
188
188
|
advance();
|
|
189
|
-
if (peek().kind === TokenKind.
|
|
189
|
+
if (peek().kind === TokenKind.CHAR) {
|
|
190
190
|
const toToken = advance();
|
|
191
191
|
items.push({ kind: "range", from: fromToken.text, to: toToken.text });
|
|
192
192
|
continue;
|
|
@@ -217,23 +217,23 @@ export function parseRegex(source, limits) {
|
|
|
217
217
|
const frame = frames[frames.length - 1];
|
|
218
218
|
const token = peek();
|
|
219
219
|
switch (token.kind) {
|
|
220
|
-
case TokenKind.
|
|
220
|
+
case TokenKind.PIPE:
|
|
221
221
|
advance();
|
|
222
222
|
frame.alternatives.push(closeConcat(frame));
|
|
223
223
|
frame.items = [];
|
|
224
224
|
frame.itemsStart = peek().span.start;
|
|
225
225
|
break;
|
|
226
|
-
case TokenKind.
|
|
227
|
-
case TokenKind.
|
|
226
|
+
case TokenKind.LEFT_PAREN:
|
|
227
|
+
case TokenKind.NON_CAPTURING_LEFT_PAREN: {
|
|
228
228
|
if (frames.length > maxNestingDepth) {
|
|
229
229
|
throw new RegexLimitExceededError("nestingDepth", maxNestingDepth);
|
|
230
230
|
}
|
|
231
|
-
const capturing = token.kind === TokenKind.
|
|
231
|
+
const capturing = token.kind === TokenKind.LEFT_PAREN;
|
|
232
232
|
advance();
|
|
233
233
|
frames.push(openFrame(token, capturing, capturing ? ++groupCount : undefined));
|
|
234
234
|
break;
|
|
235
235
|
}
|
|
236
|
-
case TokenKind.
|
|
236
|
+
case TokenKind.RIGHT_PAREN: {
|
|
237
237
|
if (frame.open === undefined) {
|
|
238
238
|
throw new RegexParseError(`Unexpected token ${describeToken(token)}`, token.span);
|
|
239
239
|
}
|
|
@@ -249,7 +249,7 @@ export function parseRegex(source, limits) {
|
|
|
249
249
|
frames[frames.length - 1].items.push(parseQuantifier(group));
|
|
250
250
|
break;
|
|
251
251
|
}
|
|
252
|
-
case TokenKind.
|
|
252
|
+
case TokenKind.END_OF_PATTERN:
|
|
253
253
|
if (frame.open !== undefined) {
|
|
254
254
|
throw new RegexParseError(`Expected ')', got ${describeToken(token)}`, token.span);
|
|
255
255
|
}
|
package/dist/parser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,yBAAyB,GAEzB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACN,oBAAoB,EAEpB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAS,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAChC,IAAI,CAAO;IACpB,YAAY,OAAe,EAAE,IAAU;QACtC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAClB,CAAC;CACD;AAED,SAAS,aAAa,CAAC,KAAY;IAClC,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,oBAAoB,EACpB,yBAAyB,GAEzB,MAAM,cAAc,CAAC;AAQtB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACN,oBAAoB,EAEpB,uBAAuB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAS,SAAS,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAChC,IAAI,CAAO;I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AC,IAAI,KAAK,SAAS,EAAE,CAAC;oBAC9B,MAAM,IAAI,eAAe,CACxB,qBAAqB,aAAa,CAAC,KAAK,CAAC,EAAE,EAC3C,KAAK,CAAC,IAAI,CACV,CAAC;gBACH,CAAC;gBACD,OAAO;oBACN,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,gBAAgB,CAAC,KAAK,CAAC;oBAC7B,UAAU;oBACV,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE;iBACtC,CAAC;YACH;gBACC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { type Predicate, type WorkBudget } from "@ac-kit/core";
|
|
2
|
+
import { type RegexLimits } from "./limits.js";
|
|
3
|
+
/**
|
|
4
|
+
* Matches `text` exactly, code point by code point; `""` matches the empty
|
|
5
|
+
* string.
|
|
6
|
+
*/
|
|
7
|
+
export interface RegexTreeLiteral {
|
|
8
|
+
readonly kind: "literal";
|
|
9
|
+
readonly text: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Matches one code point `test` accepts: a character class, a named set, a
|
|
13
|
+
* Unicode general category, anything a caller can decide one code point at a
|
|
14
|
+
* time.
|
|
15
|
+
*/
|
|
16
|
+
export interface RegexTreePredicate {
|
|
17
|
+
readonly kind: "predicate";
|
|
18
|
+
/**
|
|
19
|
+
* Receives a code point, or the code unit of a lone surrogate. Must not throw
|
|
20
|
+
* for a reason the caller wants to tell apart from the run's own: an error
|
|
21
|
+
* propagates out of the match unchanged.
|
|
22
|
+
*/
|
|
23
|
+
readonly test: Predicate<[codePoint: number]>;
|
|
24
|
+
/**
|
|
25
|
+
* Work units charged to the run each time `test` is called, beyond the one
|
|
26
|
+
* every thread step pays: for a test whose work grows with what it was built
|
|
27
|
+
* from (a large set), so the run's bound still bounds its time. A
|
|
28
|
+
* non-negative integer; `0` when absent.
|
|
29
|
+
*/
|
|
30
|
+
readonly cost?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Matches the empty string at a word boundary: where `isWord` answers
|
|
34
|
+
* differently for the code points on the two sides, the positions before the
|
|
35
|
+
* input and after it counting as not part of a word. With `negated`, matches
|
|
36
|
+
* where it answers the same.
|
|
37
|
+
*/
|
|
38
|
+
export interface RegexTreeWordBoundary {
|
|
39
|
+
readonly kind: "wordBoundary";
|
|
40
|
+
/** Whether a code point (or a lone surrogate's code unit) is part of a word. */
|
|
41
|
+
readonly isWord: Predicate<[codePoint: number]>;
|
|
42
|
+
/** `true` for a non-boundary (`\B`); `false` when absent. */
|
|
43
|
+
readonly negated?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Work units charged each time the assertion is evaluated, as
|
|
46
|
+
* {@link RegexTreePredicate.cost}. `0` when absent.
|
|
47
|
+
*/
|
|
48
|
+
readonly cost?: number;
|
|
49
|
+
}
|
|
50
|
+
/** Matches its items one after the other; no items matches the empty string. */
|
|
51
|
+
export interface RegexTreeSequence {
|
|
52
|
+
readonly kind: "sequence";
|
|
53
|
+
readonly items: readonly AnyRegexTreeNode[];
|
|
54
|
+
}
|
|
55
|
+
/** Matches any of its alternatives; no alternatives matches nothing at all. */
|
|
56
|
+
export interface RegexTreeChoice {
|
|
57
|
+
readonly kind: "choice";
|
|
58
|
+
readonly alternatives: readonly AnyRegexTreeNode[];
|
|
59
|
+
}
|
|
60
|
+
/** Matches `body` at least `min` and at most `max` times. */
|
|
61
|
+
export interface RegexTreeRepeat {
|
|
62
|
+
readonly kind: "repeat";
|
|
63
|
+
readonly body: AnyRegexTreeNode;
|
|
64
|
+
/** A non-negative safe integer. */
|
|
65
|
+
readonly min: number;
|
|
66
|
+
/**
|
|
67
|
+
* A safe integer no smaller than `min`; absent or `Infinity` for no upper
|
|
68
|
+
* bound.
|
|
69
|
+
*/
|
|
70
|
+
readonly max?: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A node of a caller-built expression tree for {@link compileRegexTree}: three
|
|
74
|
+
* atoms (a literal, a code-point predicate, a word-boundary assertion) and
|
|
75
|
+
* three operators (sequence, choice, repetition).
|
|
76
|
+
*
|
|
77
|
+
* Nodes may be shared: a subtree used in several places is lowered once per
|
|
78
|
+
* use.
|
|
79
|
+
*/
|
|
80
|
+
export type AnyRegexTreeNode = RegexTreeLiteral | RegexTreePredicate | RegexTreeWordBoundary | RegexTreeSequence | RegexTreeChoice | RegexTreeRepeat;
|
|
81
|
+
/** A compiled {@link AnyRegexTreeNode}, ready to test strings repeatedly. */
|
|
82
|
+
export interface CompiledRegexTree {
|
|
83
|
+
/**
|
|
84
|
+
* Whether the whole of `input` matches the tree. Unary and unbound, so
|
|
85
|
+
* `texts.filter(tree.match)` works.
|
|
86
|
+
*
|
|
87
|
+
* O(program size × input code points) time, O(program size) memory.
|
|
88
|
+
*
|
|
89
|
+
* @throws {RegexLimitExceededError} If the run outgrows
|
|
90
|
+
* {@link RegexLimits.maxSteps}.
|
|
91
|
+
* @throws Whatever a predicate of the tree throws.
|
|
92
|
+
*/
|
|
93
|
+
readonly match: (input: string) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* {@link CompiledRegexTree.match}, charged to `budget` instead of a fresh
|
|
96
|
+
* allowance of {@link RegexLimits.maxSteps}.
|
|
97
|
+
*
|
|
98
|
+
* @throws Whatever `budget.spend` or a predicate of the tree throws.
|
|
99
|
+
*/
|
|
100
|
+
readonly matchWithin: (input: string, budget: WorkBudget) => boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Compiles a caller-built expression tree onto this package's Pike VM, to test
|
|
104
|
+
* whether a whole string matches it.
|
|
105
|
+
*
|
|
106
|
+
* The entry point for a front end of another regular-expression notation: the
|
|
107
|
+
* front end parses its own syntax into an {@link AnyRegexTreeNode} and supplies
|
|
108
|
+
* whatever it means by a character class, a named set or a Unicode general
|
|
109
|
+
* category (`isInUnicodeGeneralCategory`) as a code-point predicate, and its
|
|
110
|
+
* own idea of a word as the word boundary's `isWord`. The tree is lowered by
|
|
111
|
+
* the same Thompson construction as {@link compileRegex} and
|
|
112
|
+
* {@link compileIRegexp}.
|
|
113
|
+
*
|
|
114
|
+
* Contract:
|
|
115
|
+
*
|
|
116
|
+
* - Matching is by code point: an astral character is one step and reaches a
|
|
117
|
+
* predicate whole; a lone surrogate in the input is one step of its own.
|
|
118
|
+
* - The match is anchored at both ends: the whole input must match, as if the
|
|
119
|
+
* tree were wrapped in `^(?:…)$`. Wrap it in a repetition of an always-true
|
|
120
|
+
* predicate on either side to search instead.
|
|
121
|
+
* - Linear and never backtracking, whatever the tree: every run is O(program size
|
|
122
|
+
* × input code points) time and O(program size) memory, where the program
|
|
123
|
+
* holds about one instruction per atom and two per operator, a counted
|
|
124
|
+
* repetition copying its body once per mandatory or optional copy.
|
|
125
|
+
* - Iterative: no depth of tree, width of choice or repetition count grows the
|
|
126
|
+
* JavaScript stack. A tree that contains itself is lowered until a limit
|
|
127
|
+
* stops it.
|
|
128
|
+
* - No captures and no laziness: only whether the input matches is answered.
|
|
129
|
+
*
|
|
130
|
+
* Limits: the program is bounded by {@link RegexLimits.maxProgramSize} (its
|
|
131
|
+
* states, checked as each is emitted), the work of compiling by
|
|
132
|
+
* {@link RegexLimits.maxSteps} or `budget` (one unit per node lowered and per
|
|
133
|
+
* jump patched, a literal by its length), and each run by
|
|
134
|
+
* {@link RegexLimits.maxSteps} or the budget given to `matchWithin`.
|
|
135
|
+
* `maxNestingDepth` does not apply: nothing walks the tree recursively. A run
|
|
136
|
+
* is synchronous, so it takes no `AbortSignal`; a caller needing a deadline
|
|
137
|
+
* passes `matchWithin` a `WorkBudget` whose `spend` checks the clock.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const digit = { kind: "predicate", test: (c: number) => c >= 0x30 && c <= 0x39 } as const;
|
|
142
|
+
* const phone = compileRegexTree({
|
|
143
|
+
* kind: "sequence",
|
|
144
|
+
* items: [
|
|
145
|
+
* { kind: "repeat", body: digit, min: 3, max: 3 },
|
|
146
|
+
* { kind: "literal", text: "-" },
|
|
147
|
+
* { kind: "repeat", body: digit, min: 4, max: 4 },
|
|
148
|
+
* ],
|
|
149
|
+
* });
|
|
150
|
+
* phone.match("555-1212"); // true
|
|
151
|
+
* phone.match("call 555-1212"); // false: the whole string must match
|
|
152
|
+
* ```;
|
|
153
|
+
*
|
|
154
|
+
* @param limits - Bounds on the program and on each run; see
|
|
155
|
+
* {@link RegexLimits}.
|
|
156
|
+
* @param budget - Charged for the compilation instead of a fresh allowance of
|
|
157
|
+
* {@link RegexLimits.maxSteps}.
|
|
158
|
+
* @throws {RegexLimitExceededError} If the program outgrows
|
|
159
|
+
* {@link RegexLimits.maxProgramSize}, or compiling outgrows
|
|
160
|
+
* {@link RegexLimits.maxSteps}.
|
|
161
|
+
* @throws {TypeError} If a node is not one of the tree's kinds, or a field has
|
|
162
|
+
* the wrong type.
|
|
163
|
+
* @throws {RangeError} If a repetition's bounds or a cost are not valid.
|
|
164
|
+
* @throws Whatever a caller's own `budget.spend` throws.
|
|
165
|
+
*/
|
|
166
|
+
export declare function compileRegexTree(tree: AnyRegexTreeNode, limits?: RegexLimits, budget?: WorkBudget): CompiledRegexTree;
|
|
167
|
+
//# sourceMappingURL=regex-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex-tree.d.ts","sourceRoot":"","sources":["../src/regex-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAkB,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAE,KAAK,WAAW,EAA+B,MAAM,aAAa,CAAC;AAS5E;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ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kBAAkB,GAClB,qBAAqB,GACrB,iBAAiB,GACjB,eAAe,GACf,eAAe,CAAC;AAEnB,6EAA6E;AAC7E,MAAM,WAAW,iBAAiB;IACjC;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAE3C;;;;;OAKG;IACH,QAAQ,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC;CACrE;AAwKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,gBAAgB,CAC/B,IAAI,EAAE,gBAAgB,EACtB,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,UAAU,GACjB,iBAAiB,CAWnB"}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { withWorkBudget } from "@ac-kit/core";
|
|
2
|
+
import { regexLimits, stepsExceeded_ } from "./limits.js";
|
|
3
|
+
import { emitThompson, ProgramBuilder, } from "./vm/_thompson.js";
|
|
4
|
+
import { testProgram } from "./vm/pike-vm.js";
|
|
5
|
+
/** Marks the nodes the lowering makes up, which no caller can build. */
|
|
6
|
+
const EMIT_ = Symbol("emit");
|
|
7
|
+
const emitNode_ = (instruction) => ({
|
|
8
|
+
kind: EMIT_,
|
|
9
|
+
shape: { kind: "emit", instruction },
|
|
10
|
+
});
|
|
11
|
+
/** What an empty choice lowers to: a step no unit passes. */
|
|
12
|
+
const NOTHING_ = {
|
|
13
|
+
kind: "emit",
|
|
14
|
+
instruction: { op: "predicate", test: () => false, label: "(?!)" },
|
|
15
|
+
};
|
|
16
|
+
function checkCost_(cost) {
|
|
17
|
+
if (cost !== undefined && !(Number.isSafeInteger(cost) && cost >= 0)) {
|
|
18
|
+
throw new RangeError("A cost must be a non-negative safe integer");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function checkNodes_(nodes, what) {
|
|
22
|
+
if (!Array.isArray(nodes)) {
|
|
23
|
+
throw new TypeError(`A regex tree ${what} must be an array`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function repeatShape_(node) {
|
|
27
|
+
const { min, max } = node;
|
|
28
|
+
if (!(Number.isSafeInteger(min) && min >= 0)) {
|
|
29
|
+
throw new RangeError("A repeat's min must be a non-negative safe integer");
|
|
30
|
+
}
|
|
31
|
+
if (max !== undefined &&
|
|
32
|
+
max !== Infinity &&
|
|
33
|
+
!(Number.isSafeInteger(max) && max >= min)) {
|
|
34
|
+
throw new RangeError("A repeat's max must be a safe integer no smaller than min, or Infinity");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
kind: "repeat",
|
|
38
|
+
body: node.body,
|
|
39
|
+
min,
|
|
40
|
+
max: max === Infinity ? undefined : max,
|
|
41
|
+
lazy: false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function atomShape_(node, budget) {
|
|
45
|
+
switch (node.kind) {
|
|
46
|
+
case "literal": {
|
|
47
|
+
if (typeof node.text !== "string") {
|
|
48
|
+
throw new TypeError("A regex tree literal's text must be a string");
|
|
49
|
+
}
|
|
50
|
+
// Charged before the code points are read.
|
|
51
|
+
budget.spend(node.text.length);
|
|
52
|
+
const items = [];
|
|
53
|
+
for (const character of node.text) {
|
|
54
|
+
items.push(emitNode_({ op: "char", char: character }));
|
|
55
|
+
}
|
|
56
|
+
return items.length === 1 ? items[0].shape : { kind: "sequence", items };
|
|
57
|
+
}
|
|
58
|
+
case "predicate": {
|
|
59
|
+
const { test, cost } = node;
|
|
60
|
+
if (typeof test !== "function") {
|
|
61
|
+
throw new TypeError("A regex tree predicate's test must be a function");
|
|
62
|
+
}
|
|
63
|
+
checkCost_(cost);
|
|
64
|
+
return {
|
|
65
|
+
kind: "emit",
|
|
66
|
+
instruction: {
|
|
67
|
+
op: "predicate",
|
|
68
|
+
test: (unit) => test(unit.codePointAt(0)),
|
|
69
|
+
label: "predicate",
|
|
70
|
+
cost: cost ?? 0,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
case "wordBoundary": {
|
|
75
|
+
if (typeof node.isWord !== "function") {
|
|
76
|
+
throw new TypeError("A regex tree word boundary's isWord must be a function");
|
|
77
|
+
}
|
|
78
|
+
checkCost_(node.cost);
|
|
79
|
+
return {
|
|
80
|
+
kind: "emit",
|
|
81
|
+
instruction: {
|
|
82
|
+
op: "assertWordBoundary",
|
|
83
|
+
isWord: node.isWord,
|
|
84
|
+
negated: node.negated === true,
|
|
85
|
+
cost: node.cost ?? 0,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The lowering of one compilation: an atom met again (a shared subtree, a
|
|
93
|
+
* counted repetition's copies) reuses its shape rather than rebuilding it.
|
|
94
|
+
*/
|
|
95
|
+
function shapeOfTreeNode_() {
|
|
96
|
+
const atoms = new Map();
|
|
97
|
+
return (node, budget) => {
|
|
98
|
+
switch (node.kind) {
|
|
99
|
+
case EMIT_:
|
|
100
|
+
return node.shape;
|
|
101
|
+
case "sequence":
|
|
102
|
+
checkNodes_(node.items, "sequence's items");
|
|
103
|
+
return { kind: "sequence", items: node.items };
|
|
104
|
+
case "choice":
|
|
105
|
+
checkNodes_(node.alternatives, "choice's alternatives");
|
|
106
|
+
return node.alternatives.length === 0
|
|
107
|
+
? NOTHING_
|
|
108
|
+
: { kind: "choice", alternatives: node.alternatives };
|
|
109
|
+
case "repeat":
|
|
110
|
+
return repeatShape_(node);
|
|
111
|
+
case "literal":
|
|
112
|
+
case "predicate":
|
|
113
|
+
case "wordBoundary": {
|
|
114
|
+
let shape = atoms.get(node);
|
|
115
|
+
if (shape === undefined) {
|
|
116
|
+
shape = atomShape_(node, budget);
|
|
117
|
+
atoms.set(node, shape);
|
|
118
|
+
}
|
|
119
|
+
return shape;
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
throw new TypeError(`Unknown regex tree node kind ${String(node.kind)}`);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function compileTreeProgram_(tree, maxProgramSize, budget) {
|
|
127
|
+
const builder = new ProgramBuilder(maxProgramSize);
|
|
128
|
+
emitThompson(builder, tree, shapeOfTreeNode_(), budget);
|
|
129
|
+
builder.emit({ op: "assertEnd" });
|
|
130
|
+
builder.emit({ op: "match" });
|
|
131
|
+
return {
|
|
132
|
+
instructions: builder.toInstructions(),
|
|
133
|
+
groupCount: 0,
|
|
134
|
+
unit: "codePoint",
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Compiles a caller-built expression tree onto this package's Pike VM, to test
|
|
139
|
+
* whether a whole string matches it.
|
|
140
|
+
*
|
|
141
|
+
* The entry point for a front end of another regular-expression notation: the
|
|
142
|
+
* front end parses its own syntax into an {@link AnyRegexTreeNode} and supplies
|
|
143
|
+
* whatever it means by a character class, a named set or a Unicode general
|
|
144
|
+
* category (`isInUnicodeGeneralCategory`) as a code-point predicate, and its
|
|
145
|
+
* own idea of a word as the word boundary's `isWord`. The tree is lowered by
|
|
146
|
+
* the same Thompson construction as {@link compileRegex} and
|
|
147
|
+
* {@link compileIRegexp}.
|
|
148
|
+
*
|
|
149
|
+
* Contract:
|
|
150
|
+
*
|
|
151
|
+
* - Matching is by code point: an astral character is one step and reaches a
|
|
152
|
+
* predicate whole; a lone surrogate in the input is one step of its own.
|
|
153
|
+
* - The match is anchored at both ends: the whole input must match, as if the
|
|
154
|
+
* tree were wrapped in `^(?:…)$`. Wrap it in a repetition of an always-true
|
|
155
|
+
* predicate on either side to search instead.
|
|
156
|
+
* - Linear and never backtracking, whatever the tree: every run is O(program size
|
|
157
|
+
* × input code points) time and O(program size) memory, where the program
|
|
158
|
+
* holds about one instruction per atom and two per operator, a counted
|
|
159
|
+
* repetition copying its body once per mandatory or optional copy.
|
|
160
|
+
* - Iterative: no depth of tree, width of choice or repetition count grows the
|
|
161
|
+
* JavaScript stack. A tree that contains itself is lowered until a limit
|
|
162
|
+
* stops it.
|
|
163
|
+
* - No captures and no laziness: only whether the input matches is answered.
|
|
164
|
+
*
|
|
165
|
+
* Limits: the program is bounded by {@link RegexLimits.maxProgramSize} (its
|
|
166
|
+
* states, checked as each is emitted), the work of compiling by
|
|
167
|
+
* {@link RegexLimits.maxSteps} or `budget` (one unit per node lowered and per
|
|
168
|
+
* jump patched, a literal by its length), and each run by
|
|
169
|
+
* {@link RegexLimits.maxSteps} or the budget given to `matchWithin`.
|
|
170
|
+
* `maxNestingDepth` does not apply: nothing walks the tree recursively. A run
|
|
171
|
+
* is synchronous, so it takes no `AbortSignal`; a caller needing a deadline
|
|
172
|
+
* passes `matchWithin` a `WorkBudget` whose `spend` checks the clock.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```ts
|
|
176
|
+
* const digit = { kind: "predicate", test: (c: number) => c >= 0x30 && c <= 0x39 } as const;
|
|
177
|
+
* const phone = compileRegexTree({
|
|
178
|
+
* kind: "sequence",
|
|
179
|
+
* items: [
|
|
180
|
+
* { kind: "repeat", body: digit, min: 3, max: 3 },
|
|
181
|
+
* { kind: "literal", text: "-" },
|
|
182
|
+
* { kind: "repeat", body: digit, min: 4, max: 4 },
|
|
183
|
+
* ],
|
|
184
|
+
* });
|
|
185
|
+
* phone.match("555-1212"); // true
|
|
186
|
+
* phone.match("call 555-1212"); // false: the whole string must match
|
|
187
|
+
* ```;
|
|
188
|
+
*
|
|
189
|
+
* @param limits - Bounds on the program and on each run; see
|
|
190
|
+
* {@link RegexLimits}.
|
|
191
|
+
* @param budget - Charged for the compilation instead of a fresh allowance of
|
|
192
|
+
* {@link RegexLimits.maxSteps}.
|
|
193
|
+
* @throws {RegexLimitExceededError} If the program outgrows
|
|
194
|
+
* {@link RegexLimits.maxProgramSize}, or compiling outgrows
|
|
195
|
+
* {@link RegexLimits.maxSteps}.
|
|
196
|
+
* @throws {TypeError} If a node is not one of the tree's kinds, or a field has
|
|
197
|
+
* the wrong type.
|
|
198
|
+
* @throws {RangeError} If a repetition's bounds or a cost are not valid.
|
|
199
|
+
* @throws Whatever a caller's own `budget.spend` throws.
|
|
200
|
+
*/
|
|
201
|
+
export function compileRegexTree(tree, limits, budget) {
|
|
202
|
+
const { maxProgramSize, maxSteps } = regexLimits(limits);
|
|
203
|
+
const program = withWorkBudget(budget ?? maxSteps, (work) => compileTreeProgram_(tree, maxProgramSize, work), stepsExceeded_);
|
|
204
|
+
return {
|
|
205
|
+
match: (input) => testProgram(program, input, maxSteps),
|
|
206
|
+
matchWithin: (input, runBudget) => testProgram(program, input, runBudget),
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=regex-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regex-tree.js","sourceRoot":"","sources":["../src/regex-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmC,cAAc,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAoB,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EACN,YAAY,EACZ,cAAc,GAEd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAqH9C,wEAAwE;AACxE,MAAM,KAAK,GAAkB,MAAM,CAAC,MAAM,CAAC,CAAC;AAS5C,MAAM,SAAS,GAAG,CAAC,WAAwB,EAAa,EAAE,CAAC,CAAC;IAC3D,IAAI,EAAE,KAAK;IACX,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE;CACpC,CAAC,CAAC;AAEH,6DAA6D;AAC7D,MAAM,QAAQ,GAAyB;IACtC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,KAA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ACzD,cAAc,CACd,CAAC;IACF,OAAO;QACN,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC;QACvD,WAAW,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC;KACzE,CAAC;AACH,CAAC"}
|
package/dist/token.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import type { Span } from "@ac-kit/core";
|
|
2
2
|
export declare enum TokenKind {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
3
|
+
CHAR = 0,
|
|
4
|
+
SHORTHAND = 1,
|
|
5
|
+
DOT = 2,
|
|
6
|
+
CARET = 3,
|
|
7
|
+
DOLLAR = 4,
|
|
8
|
+
STAR = 5,
|
|
9
|
+
PLUS = 6,
|
|
10
|
+
QUESTION = 7,
|
|
11
|
+
PIPE = 8,
|
|
12
|
+
LEFT_PAREN = 9,
|
|
13
|
+
NON_CAPTURING_LEFT_PAREN = 10,
|
|
14
|
+
RIGHT_PAREN = 11,
|
|
15
|
+
LEFT_BRACKET = 12,
|
|
16
|
+
RIGHT_BRACKET = 13,
|
|
17
|
+
HYPHEN = 14,
|
|
18
|
+
LEFT_BRACE = 15,
|
|
19
|
+
RIGHT_BRACE = 16,
|
|
20
|
+
COMMA = 17,
|
|
21
|
+
NUMBER = 18,
|
|
22
|
+
END_OF_PATTERN = 19
|
|
23
23
|
}
|
|
24
24
|
export interface Token {
|
|
25
25
|
readonly kind: TokenKind;
|