@ptolemy2002/rgx 6.2.0 → 7.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 +3 -2
- package/dist/walker/base.d.ts +1 -1
- package/dist/walker/base.js +4 -2
- package/dist/walker/part.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,6 +86,7 @@ type RGXCapture<T = unknown> = {
|
|
|
86
86
|
value: T;
|
|
87
87
|
start: number;
|
|
88
88
|
end: number;
|
|
89
|
+
ownerId: string | null;
|
|
89
90
|
};
|
|
90
91
|
|
|
91
92
|
type RGXPartOptions<R, T=string> = {
|
|
@@ -663,8 +664,8 @@ constructor(source: string, tokens: RGXTokenCollectionInput, options?: RGXWalker
|
|
|
663
664
|
- `tokens` (`RGXTokenCollection`): The internal collection of tokens in 'concat' mode (readonly).
|
|
664
665
|
- `tokenPosition` (`number`): The current index in the token collection. Setting this validates that the value is >= 0 and <= `tokens.length`, throwing `RGXOutOfBoundsError` if not.
|
|
665
666
|
- `reduced` (`R`): A user-defined accumulator value, typically updated by `RGXPart` callbacks during walking.
|
|
666
|
-
- `captures` (`RGXCapture[]`): An array of structured capture results recorded during walking. Each entry has a `raw` string
|
|
667
|
-
- `namedCaptures` (`Record<string, RGXCapture>`): An object mapping capture IDs to their corresponding `RGXCapture` results. Only Parts with non-null IDs are included.
|
|
667
|
+
- `captures` (`RGXCapture[]`): An array of structured capture results recorded during walking. Each entry has a `raw` string, a `value` (the transform result for Parts, or the raw string for plain tokens), `start` and `end` indices in the source string, and an `ownerId` that is the `id` of the Part that produced it (or `null` for captures from plain tokens or parts without ids).
|
|
668
|
+
- `namedCaptures` (`Record<string, RGXCapture[]>`): An object mapping capture IDs to their corresponding `RGXCapture` results. Only Parts with non-null IDs are included. The captures occur in the same order as they appear in the `captures` array.
|
|
668
669
|
- `stopped` (`boolean`, readonly): Whether the walker has been stopped, either by a Part's `beforeCapture` returning `"stop"` or by calling `stop()` in an `afterCapture` callback.
|
|
669
670
|
|
|
670
671
|
#### Methods
|
package/dist/walker/base.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class RGXWalker<R> implements RGXConvertibleToken {
|
|
|
13
13
|
_tokenPosition: number;
|
|
14
14
|
reduced: R;
|
|
15
15
|
captures: RGXCapture[];
|
|
16
|
-
namedCaptures: Record<string, RGXCapture>;
|
|
16
|
+
namedCaptures: Record<string, RGXCapture[]>;
|
|
17
17
|
private _stopped;
|
|
18
18
|
static check: (value: unknown) => value is RGXWalker<unknown>;
|
|
19
19
|
static assert: (value: unknown) => asserts value is RGXWalker<unknown>;
|
package/dist/walker/base.js
CHANGED
|
@@ -98,7 +98,7 @@ class RGXWalker {
|
|
|
98
98
|
const raw = this.capture(token);
|
|
99
99
|
const end = this.sourcePosition;
|
|
100
100
|
const value = isPart ? token.transform(raw) : raw;
|
|
101
|
-
const captureResult = { raw, value, start, end };
|
|
101
|
+
const captureResult = { raw, value, start, end, ownerId: isPart && token.hasId() ? token.id : null };
|
|
102
102
|
// Validate the part. If validation fails, it will throw an error, so nothing below will run.
|
|
103
103
|
if (isPart) {
|
|
104
104
|
token.validate(captureResult, this);
|
|
@@ -107,7 +107,9 @@ class RGXWalker {
|
|
|
107
107
|
if (!silent) {
|
|
108
108
|
this.captures.push(captureResult);
|
|
109
109
|
if (isPart && token.hasId()) {
|
|
110
|
-
|
|
110
|
+
if (!(token.id in this.namedCaptures))
|
|
111
|
+
this.namedCaptures[token.id] = [];
|
|
112
|
+
this.namedCaptures[token.id].push(captureResult);
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
// Notify Part after capture
|
package/dist/walker/part.d.ts
CHANGED