@ptolemy2002/rgx 11.0.0 → 11.1.1
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.
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rgxTaggedTemplateToArray = rgxTaggedTemplateToArray;
|
|
4
4
|
function rgxTaggedTemplateToArray(strings, tokens, multiline, verbatim) {
|
|
5
|
-
function isNullOrUndefined(value) {
|
|
6
|
-
return value === null || value === undefined;
|
|
7
|
-
}
|
|
8
5
|
const array = [];
|
|
9
6
|
for (let i = 0; i < Math.max(strings.length, tokens.length); i++) {
|
|
7
|
+
const isTokensEnd = i >= tokens.length;
|
|
10
8
|
const string = strings[i];
|
|
11
9
|
const token = tokens[i];
|
|
12
10
|
// Strings always come before tokens
|
|
13
|
-
if (
|
|
11
|
+
if (string !== undefined) {
|
|
14
12
|
if (!multiline) {
|
|
15
13
|
if (verbatim)
|
|
16
14
|
array.push(string);
|
|
@@ -33,10 +31,10 @@ function rgxTaggedTemplateToArray(strings, tokens, multiline, verbatim) {
|
|
|
33
31
|
resolves to "foo | bar |baz" instead of "foo | bar|baz"
|
|
34
32
|
*/
|
|
35
33
|
.map((line, i) => (i !== 0 || startsNewLine) ? line.trimStart() : line)
|
|
36
|
-
// Remove comments
|
|
34
|
+
// Remove comments from the start of the line.
|
|
37
35
|
.filter(line => !line.startsWith("//"))
|
|
38
36
|
.filter(line => line.length > 0)
|
|
39
|
-
// Remove comments
|
|
37
|
+
// Remove comments from the end of the line.
|
|
40
38
|
.map(line => {
|
|
41
39
|
const commentIndex = line.indexOf("//");
|
|
42
40
|
if (commentIndex !== -1) {
|
|
@@ -51,7 +49,7 @@ function rgxTaggedTemplateToArray(strings, tokens, multiline, verbatim) {
|
|
|
51
49
|
array.push({ rgxInterpolate: true, toRgx: () => lines });
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
if (!
|
|
52
|
+
if (!isTokensEnd)
|
|
55
53
|
array.push(token);
|
|
56
54
|
}
|
|
57
55
|
return array;
|
package/dist/walker/base.js
CHANGED
|
@@ -134,7 +134,16 @@ class RGXWalker {
|
|
|
134
134
|
}
|
|
135
135
|
catch (e) {
|
|
136
136
|
if (isPart && e instanceof errors_1.RGXRegexNotMatchedAtPositionError) {
|
|
137
|
-
token.afterFailure?.(e, { part: token, walker: this });
|
|
137
|
+
const control = token.afterFailure?.(e, { part: token, walker: this });
|
|
138
|
+
if (control === "stop") {
|
|
139
|
+
this._stopped = true;
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
if (control === "skip") {
|
|
143
|
+
this.tokenPosition++;
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
// Handling silent is pointless here since it won't add a capture in either case, so we don't check for it.
|
|
138
147
|
}
|
|
139
148
|
throw e;
|
|
140
149
|
}
|
|
@@ -144,7 +153,7 @@ class RGXWalker {
|
|
|
144
153
|
let branch = 0;
|
|
145
154
|
// Determine branch index for captureResult by finding the first index
|
|
146
155
|
// with non-undefined match group.
|
|
147
|
-
for (let i = 0; i < capture.length; i++) {
|
|
156
|
+
for (let i = 0; i < capture.length - 1; i++) {
|
|
148
157
|
const branchKey = `rgx_branch_${i}`;
|
|
149
158
|
if (capture.groups && capture.groups[branchKey] !== undefined) {
|
|
150
159
|
branch = i;
|
|
@@ -162,8 +171,18 @@ class RGXWalker {
|
|
|
162
171
|
token.validate(captureResult, { part: token, walker: this });
|
|
163
172
|
}
|
|
164
173
|
catch (e) {
|
|
174
|
+
this.sourcePosition = start; // Reset source position on validation failure
|
|
165
175
|
if (e instanceof errors_1.RGXPartValidationFailedError) {
|
|
166
|
-
token.afterValidationFailure?.(e, { part: token, walker: this });
|
|
176
|
+
const control = token.afterValidationFailure?.(e, { part: token, walker: this });
|
|
177
|
+
if (control === "stop") {
|
|
178
|
+
this._stopped = true;
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
if (control === "skip") {
|
|
182
|
+
this.tokenPosition++;
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
// Handling silent is pointless here since it won't add a capture in either case, so we don't check for it.
|
|
167
186
|
}
|
|
168
187
|
throw e;
|
|
169
188
|
}
|
package/dist/walker/part.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export type RGXPartOptions<R, S = unknown, T = string> = {
|
|
|
23
23
|
validate: (captured: RGXCapture<T>, context: RGXPartContext<R, S, T>) => boolean | string;
|
|
24
24
|
beforeCapture: ((context: RGXPartContext<R, S, T>) => RGXPartControl) | null;
|
|
25
25
|
afterCapture: ((capture: RGXCapture<T>, context: RGXPartContext<R, S, T>) => void) | null;
|
|
26
|
-
afterFailure: ((e: RGXRegexNotMatchedAtPositionError, context: RGXPartContext<R, S, T>) =>
|
|
27
|
-
afterValidationFailure: ((e: RGXPartValidationFailedError, context: RGXPartContext<R, S, T>) =>
|
|
26
|
+
afterFailure: ((e: RGXRegexNotMatchedAtPositionError, context: RGXPartContext<R, S, T>) => RGXPartControl) | null;
|
|
27
|
+
afterValidationFailure: ((e: RGXPartValidationFailedError, context: RGXPartContext<R, S, T>) => RGXPartControl) | null;
|
|
28
28
|
};
|
|
29
29
|
export declare class RGXPart<R, S = unknown, T = string> {
|
|
30
30
|
id: string | null;
|