@ptolemy2002/rgx 11.0.0 → 11.1.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.
@@ -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
  }
@@ -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>) => void) | null;
27
- afterValidationFailure: ((e: RGXPartValidationFailedError, context: RGXPartContext<R, S, T>) => void) | null;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/rgx",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",