@ptolemy2002/rgx 12.1.0 → 12.3.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/dist/class/base.d.ts +1 -0
- package/dist/class/base.js +4 -1
- package/dist/class/init.js +14 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +10 -1
- package/package.json +1 -1
package/dist/class/base.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export declare abstract class RGXClassToken implements RGXConvertibleToken {
|
|
|
12
12
|
rgxAcceptInsertion(tokens: RGXToken[], flags: ValidRegexFlags): string | boolean;
|
|
13
13
|
static check: (value: unknown) => value is RGXClassToken;
|
|
14
14
|
static assert: (value: unknown) => asserts value is RGXClassToken;
|
|
15
|
+
get rgxInterpolate(): boolean;
|
|
15
16
|
get rgxIsGroup(): boolean;
|
|
16
17
|
get rgxIsRepeatable(): boolean;
|
|
17
18
|
get rgxGroupWrap(): boolean;
|
package/dist/class/base.js
CHANGED
|
@@ -7,6 +7,9 @@ class RGXClassToken {
|
|
|
7
7
|
rgxAcceptInsertion(tokens, flags) {
|
|
8
8
|
return true;
|
|
9
9
|
}
|
|
10
|
+
get rgxInterpolate() {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
10
13
|
get rgxIsGroup() {
|
|
11
14
|
return false;
|
|
12
15
|
}
|
|
@@ -26,7 +29,7 @@ class RGXClassToken {
|
|
|
26
29
|
throw new errors_1.RGXNotImplementedError('RGXClassToken.repeat(min, max, lazy)', 'call rgxClassInit() first.');
|
|
27
30
|
}
|
|
28
31
|
optional(lazy = false) {
|
|
29
|
-
|
|
32
|
+
throw new errors_1.RGXNotImplementedError('RGXClassToken.optional(lazy)', 'call rgxClassInit() first.');
|
|
30
33
|
}
|
|
31
34
|
asLookahead(positive = true) {
|
|
32
35
|
throw new errors_1.RGXNotImplementedError('RGXClassToken.asLookahead(positive)', 'call rgxClassInit() first.');
|
package/dist/class/init.js
CHANGED
|
@@ -33,6 +33,20 @@ function rgxClassInit() {
|
|
|
33
33
|
throw new errors_1.RGXNotSupportedError("RGXLookaroundToken.repeat()", "Lookaround tokens cannot be repeated or made optional.");
|
|
34
34
|
return new repeat_1.RGXRepeatToken(this, min, max, lazy);
|
|
35
35
|
};
|
|
36
|
+
base_1.RGXClassToken.prototype.optional = function (lazy = false) {
|
|
37
|
+
if (repeat_1.RGXRepeatToken.check(this)) {
|
|
38
|
+
// Retun the self if already optional.
|
|
39
|
+
if (this.min === 0)
|
|
40
|
+
return this;
|
|
41
|
+
// Simply set min to 0 if it's currently 1,
|
|
42
|
+
// but not if it's any other number, since
|
|
43
|
+
// "either 0 or > 0" is not the same as "either 0 or >= n" for n > 1,
|
|
44
|
+
// but they are equivalent for n = 1, assuming n is an integer.
|
|
45
|
+
else if (this.min === 1)
|
|
46
|
+
return new repeat_1.RGXRepeatToken(this.token, 0, this.max, lazy);
|
|
47
|
+
}
|
|
48
|
+
return this.repeat(0, 1, lazy);
|
|
49
|
+
};
|
|
36
50
|
base_1.RGXClassToken.prototype.asLookahead = function (positive = true) {
|
|
37
51
|
if (lookahead_1.RGXLookaheadToken.check(this))
|
|
38
52
|
return this;
|
package/dist/constants.d.ts
CHANGED
|
@@ -120,6 +120,11 @@ export declare const RGX_PREDEFINED_CONSTANTS: {
|
|
|
120
120
|
readonly rgxGroupWrap: false;
|
|
121
121
|
readonly toRgx: () => RegExp;
|
|
122
122
|
};
|
|
123
|
+
readonly "escape-bound": {
|
|
124
|
+
readonly rgxGroupWrap: false;
|
|
125
|
+
readonly rgxIsRepeatable: false;
|
|
126
|
+
readonly toRgx: () => RegExp;
|
|
127
|
+
};
|
|
123
128
|
readonly "non-escape-bound": {
|
|
124
129
|
readonly rgxGroupWrap: false;
|
|
125
130
|
readonly rgxIsRepeatable: false;
|
package/dist/constants.js
CHANGED
|
@@ -144,12 +144,21 @@ exports.RGX_PREDEFINED_CONSTANTS = {
|
|
|
144
144
|
toRgx() { return /[\b]/; }
|
|
145
145
|
},
|
|
146
146
|
// Complex Constructs
|
|
147
|
+
"escape-bound": {
|
|
148
|
+
rgxGroupWrap: false,
|
|
149
|
+
rgxIsRepeatable: false,
|
|
150
|
+
toRgx() {
|
|
151
|
+
// Put this before any pattern to ensure that the pattern is escaped, i.e., preceded by an odd number of backslashes.
|
|
152
|
+
return /(?<=(?<!\\)\\(?:\\\\)*)/;
|
|
153
|
+
}
|
|
154
|
+
},
|
|
147
155
|
"non-escape-bound": {
|
|
148
156
|
rgxGroupWrap: false,
|
|
149
157
|
rgxIsRepeatable: false,
|
|
150
158
|
toRgx() {
|
|
151
159
|
// Put this before any pattern to ensure that the pattern is not escaped, i.e., not preceded by an odd number of backslashes.
|
|
152
|
-
|
|
160
|
+
// Essentially equivalent to escape-bound, but without the extra backslash between the negative lookbehind and the non-capturing group.
|
|
161
|
+
return /(?<=(?<!\\)(?:\\\\)*)/;
|
|
153
162
|
}
|
|
154
163
|
},
|
|
155
164
|
};
|