@ptolemy2002/rgx 7.5.0 → 7.7.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 +29 -17
- package/dist/constants.d.ts +131 -6
- package/dist/constants.js +141 -173
- package/dist/walker/base.d.ts +4 -4
- package/dist/walker/base.js +9 -2
- package/dist/walker/part.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -110,6 +110,10 @@ type RGXWalkerOptions<R> = {
|
|
|
110
110
|
type RGXWOptions<R = unknown> = Omit<RGXWalkerOptions<R>, "startingSourcePosition"> & {
|
|
111
111
|
multiline?: boolean;
|
|
112
112
|
};
|
|
113
|
+
|
|
114
|
+
// See src/constants.ts for the actual mapping of predefined constant names to their token values
|
|
115
|
+
type RGXPredefinedConstant = keyof typeof RGX_PREDEFINED_CONSTANTS;
|
|
116
|
+
type RGXConstantName = RGXPredefinedConstant | (string & {});
|
|
113
117
|
```
|
|
114
118
|
|
|
115
119
|
## Classes
|
|
@@ -680,7 +684,7 @@ constructor(source: string, tokens: RGXTokenCollectionInput, options?: RGXWalker
|
|
|
680
684
|
- `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.
|
|
681
685
|
|
|
682
686
|
#### Methods
|
|
683
|
-
- `stop() =>
|
|
687
|
+
- `stop() => this`: Sets `stopped` to `true`, causing any active `stepToToken`, `stepToPart`, or `walk` loop to halt after the current iteration. Typically called from an `afterCapture` callback to stop walking after the current capture.
|
|
684
688
|
- `atTokenEnd() => boolean`: Returns `true` if the token position is at or past the end of the token collection.
|
|
685
689
|
- `hasNextToken(predicate?: (token: RGXToken) => boolean) => boolean`: Returns `true` if there is a current token and it satisfies the optional predicate (defaults to `() => true`).
|
|
686
690
|
- `atSourceEnd() => boolean`: Returns `true` if the source has been fully consumed (`sourcePosition >= source.length`).
|
|
@@ -691,9 +695,9 @@ constructor(source: string, tokens: RGXTokenCollectionInput, options?: RGXWalker
|
|
|
691
695
|
- `capture(token: RGXToken, includeMatch?: false) => string`: Resolves the token to a regex, asserts that it matches at the current source position (throwing `RGXRegexNotMatchedAtPositionError` if not), and advances the source position by the match length. Returns the matched string.
|
|
692
696
|
- `capture(token: RGXToken, includeMatch: true) => RegExpExecArray`: Same as above, but returns the full `RegExpExecArray` from the match instead of just the matched string.
|
|
693
697
|
- `step() => RGXCapture | null`: Steps through the next token in the collection. If the token is an `RGXPart`, calls `beforeCapture` first — if it returns `"stop"`, sets `stopped` and returns `null` without advancing; if `"skip"`, advances the token position and returns `null` without capturing; if `"silent"`, captures but does not add to `captures` or `namedCaptures`. After capturing, validates. After validating, calls `afterCapture` if present. Returns the `RGXCapture` result, or `null` if there are no more tokens (or no more source in `infinite`/`looping` mode), the step was skipped, or the walker was stopped.
|
|
694
|
-
- `stepToToken(predicate: (token: RGXToken) => boolean) =>
|
|
695
|
-
- `stepToPart(predicate?: (part: RGXPart<R>) => boolean) =>
|
|
696
|
-
- `walk() =>
|
|
698
|
+
- `stepToToken(predicate: (token: RGXToken) => boolean) => this`: Steps through tokens until the predicate returns `true` for the current token or the walker is stopped. The matching token is not consumed.
|
|
699
|
+
- `stepToPart(predicate?: (part: RGXPart<R>) => boolean) => this`: Steps through tokens until the next `RGXPart` satisfying the predicate is reached. If already at a Part, steps once first to move past it. The matching Part is not consumed.
|
|
700
|
+
- `walk() => this`: Steps through all remaining tokens until the end of the token collection (or until the source is consumed in `infinite`/`looping` mode) or the walker is stopped.
|
|
697
701
|
- `toRgx() => RGXToken`: Returns the internal `RGXTokenCollection`, allowing the walker to be used as a convertible token.
|
|
698
702
|
- `clone(depth: CloneDepth = "max") => RGXWalker`: Creates a clone of the walker. When `depth` is `0`, returns `this`; otherwise, creates a new `RGXWalker` with cloned tokens, source position, reduced value, captures, stopped state, and the `infinite`/`looping` flags.
|
|
699
703
|
|
|
@@ -1551,6 +1555,13 @@ Creates a clone of the given RGX token to the given depth, provided that the tok
|
|
|
1551
1555
|
#### Returns
|
|
1552
1556
|
- `T`: The cloned token.
|
|
1553
1557
|
|
|
1558
|
+
### RGX_PREDEFINED_CONSTANTS
|
|
1559
|
+
```typescript
|
|
1560
|
+
const RGX_PREDEFINED_CONSTANTS: Record<RGXPredefinedConstant, RGXToken>
|
|
1561
|
+
```
|
|
1562
|
+
|
|
1563
|
+
A read-only object containing all of the library's built-in constant definitions, keyed by their `RGXPredefinedConstant` name. This is the source from which the predefined constants are registered at module load time. It can be used to inspect available constant names at compile time (via `keyof typeof RGX_PREDEFINED_CONSTANTS`) or to iterate over the predefined set without calling `listRGXConstants`.
|
|
1564
|
+
|
|
1554
1565
|
### listRGXConstants
|
|
1555
1566
|
```typescript
|
|
1556
1567
|
function listRGXConstants(): string[]
|
|
@@ -1563,52 +1574,52 @@ Returns the names of all currently defined RGX constants.
|
|
|
1563
1574
|
|
|
1564
1575
|
### hasRGXConstant
|
|
1565
1576
|
```typescript
|
|
1566
|
-
function hasRGXConstant(name:
|
|
1577
|
+
function hasRGXConstant(name: RGXConstantName): boolean
|
|
1567
1578
|
```
|
|
1568
1579
|
|
|
1569
1580
|
Checks if an RGX constant with the given name exists.
|
|
1570
1581
|
|
|
1571
1582
|
#### Parameters
|
|
1572
|
-
- `name` (`
|
|
1583
|
+
- `name` (`RGXConstantName`): The constant name to check.
|
|
1573
1584
|
|
|
1574
1585
|
#### Returns
|
|
1575
1586
|
- `boolean`: `true` if the constant exists, otherwise `false`.
|
|
1576
1587
|
|
|
1577
1588
|
### assertHasRGXConstant
|
|
1578
1589
|
```typescript
|
|
1579
|
-
function assertHasRGXConstant(name:
|
|
1590
|
+
function assertHasRGXConstant(name: RGXConstantName): void
|
|
1580
1591
|
```
|
|
1581
1592
|
|
|
1582
1593
|
Asserts that an RGX constant with the given name exists. If the assertion fails, an `RGXInvalidConstantKeyError` will be thrown.
|
|
1583
1594
|
|
|
1584
1595
|
#### Parameters
|
|
1585
|
-
- `name` (`
|
|
1596
|
+
- `name` (`RGXConstantName`): The constant name to assert.
|
|
1586
1597
|
|
|
1587
1598
|
#### Returns
|
|
1588
1599
|
- `void`: This function does not return a value, but will throw an error if the assertion fails.
|
|
1589
1600
|
|
|
1590
1601
|
### assertNotHasRGXConstant
|
|
1591
1602
|
```typescript
|
|
1592
|
-
function assertNotHasRGXConstant(name:
|
|
1603
|
+
function assertNotHasRGXConstant(name: RGXConstantName): void
|
|
1593
1604
|
```
|
|
1594
1605
|
|
|
1595
1606
|
Asserts that an RGX constant with the given name does not exist. If the assertion fails, an `RGXConstantConflictError` will be thrown.
|
|
1596
1607
|
|
|
1597
1608
|
#### Parameters
|
|
1598
|
-
- `name` (`
|
|
1609
|
+
- `name` (`RGXConstantName`): The constant name to assert.
|
|
1599
1610
|
|
|
1600
1611
|
#### Returns
|
|
1601
1612
|
- `void`: This function does not return a value, but will throw an error if the assertion fails.
|
|
1602
1613
|
|
|
1603
1614
|
### defineRGXConstant
|
|
1604
1615
|
```typescript
|
|
1605
|
-
function defineRGXConstant(name:
|
|
1616
|
+
function defineRGXConstant(name: RGXConstantName, value: RGXToken): RGXToken
|
|
1606
1617
|
```
|
|
1607
1618
|
|
|
1608
1619
|
Defines a new RGX constant with the given name and value. If the value is a native token (string, number, boolean, or no-op), it is automatically wrapped in an `RGXClassWrapperToken` before being stored. This ensures that native-valued constants are not stripped by multiline template processing in `rgx`, since only the literal string parts of the template are affected by multiline mode. Throws an `RGXConstantConflictError` if a constant with the same name already exists.
|
|
1609
1620
|
|
|
1610
1621
|
#### Parameters
|
|
1611
|
-
- `name` (`
|
|
1622
|
+
- `name` (`RGXConstantName`): The name for the constant.
|
|
1612
1623
|
- `value` (`RGXToken`): The token value to associate with the name. Native tokens are automatically wrapped in `RGXClassWrapperToken`.
|
|
1613
1624
|
|
|
1614
1625
|
#### Returns
|
|
@@ -1616,26 +1627,26 @@ Defines a new RGX constant with the given name and value. If the value is a nati
|
|
|
1616
1627
|
|
|
1617
1628
|
### rgxConstant
|
|
1618
1629
|
```typescript
|
|
1619
|
-
function rgxConstant(name:
|
|
1630
|
+
function rgxConstant(name: RGXConstantName): RGXToken
|
|
1620
1631
|
```
|
|
1621
1632
|
|
|
1622
1633
|
Retrieves the value of an RGX constant by name. Throws an `RGXInvalidConstantKeyError` if no constant with the given name exists.
|
|
1623
1634
|
|
|
1624
1635
|
#### Parameters
|
|
1625
|
-
- `name` (`
|
|
1636
|
+
- `name` (`RGXConstantName`): The constant name to retrieve.
|
|
1626
1637
|
|
|
1627
1638
|
#### Returns
|
|
1628
1639
|
- `RGXToken`: The token value associated with the constant name.
|
|
1629
1640
|
|
|
1630
1641
|
### deleteRGXConstant
|
|
1631
1642
|
```typescript
|
|
1632
|
-
function deleteRGXConstant(name:
|
|
1643
|
+
function deleteRGXConstant(name: RGXConstantName): void
|
|
1633
1644
|
```
|
|
1634
1645
|
|
|
1635
1646
|
Deletes an existing RGX constant by name. Throws an `RGXInvalidConstantKeyError` if no constant with the given name exists.
|
|
1636
1647
|
|
|
1637
1648
|
#### Parameters
|
|
1638
|
-
- `name` (`
|
|
1649
|
+
- `name` (`RGXConstantName`): The constant name to delete.
|
|
1639
1650
|
|
|
1640
1651
|
#### Returns
|
|
1641
1652
|
- `void`: This function does not return a value, but will throw an error if the constant does not exist.
|
|
@@ -1657,7 +1668,8 @@ Since these are defined as native tokens (strings), they are automatically wrapp
|
|
|
1657
1668
|
### Special Characters
|
|
1658
1669
|
| Name | Resolves To | Description |
|
|
1659
1670
|
| --- | --- | --- |
|
|
1660
|
-
| `"any"` |
|
|
1671
|
+
| `"any"` | `(?s:.)` | Matches any single character, including newlines |
|
|
1672
|
+
| `"non-newline"` | `.` | Matches any single character except newlines |
|
|
1661
1673
|
| `"start"` | `^` | Start of string anchor |
|
|
1662
1674
|
| `"line-start"` | `^` (with `m` flag) | Start of line anchor |
|
|
1663
1675
|
| `"end"` | `$` | End of string anchor |
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,8 +1,133 @@
|
|
|
1
1
|
import { RGXToken } from "./types";
|
|
2
|
+
export declare const RGX_PREDEFINED_CONSTANTS: {
|
|
3
|
+
readonly newline: "\n";
|
|
4
|
+
readonly "carriage-return": "\r";
|
|
5
|
+
readonly tab: "\t";
|
|
6
|
+
readonly null: "\0";
|
|
7
|
+
readonly "form-feed": "\f";
|
|
8
|
+
readonly any: {
|
|
9
|
+
readonly rgxGroupWrap: false;
|
|
10
|
+
readonly toRgx: () => RegExp;
|
|
11
|
+
};
|
|
12
|
+
readonly "non-newline": {
|
|
13
|
+
readonly rgxGroupWrap: false;
|
|
14
|
+
readonly toRgx: () => RegExp;
|
|
15
|
+
};
|
|
16
|
+
readonly start: {
|
|
17
|
+
readonly rgxGroupWrap: false;
|
|
18
|
+
readonly rgxIsRepeatable: false;
|
|
19
|
+
readonly toRgx: () => RegExp;
|
|
20
|
+
};
|
|
21
|
+
readonly "line-start": {
|
|
22
|
+
readonly rgxGroupWrap: false;
|
|
23
|
+
readonly rgxIsRepeatable: false;
|
|
24
|
+
readonly toRgx: () => RegExp;
|
|
25
|
+
};
|
|
26
|
+
readonly end: {
|
|
27
|
+
readonly rgxGroupWrap: false;
|
|
28
|
+
readonly rgxIsRepeatable: false;
|
|
29
|
+
readonly toRgx: () => RegExp;
|
|
30
|
+
};
|
|
31
|
+
readonly "line-end": {
|
|
32
|
+
readonly rgxGroupWrap: false;
|
|
33
|
+
readonly rgxIsRepeatable: false;
|
|
34
|
+
readonly toRgx: () => RegExp;
|
|
35
|
+
};
|
|
36
|
+
readonly "word-bound": {
|
|
37
|
+
readonly rgxGroupWrap: false;
|
|
38
|
+
readonly rgxIsRepeatable: false;
|
|
39
|
+
readonly toRgx: () => RegExp;
|
|
40
|
+
};
|
|
41
|
+
readonly "non-word-bound": {
|
|
42
|
+
readonly rgxGroupWrap: false;
|
|
43
|
+
readonly rgxIsRepeatable: false;
|
|
44
|
+
readonly toRgx: () => RegExp;
|
|
45
|
+
};
|
|
46
|
+
readonly "word-bound-start": {
|
|
47
|
+
readonly rgxGroupWrap: false;
|
|
48
|
+
readonly rgxIsRepeatable: false;
|
|
49
|
+
readonly toRgx: () => RegExp;
|
|
50
|
+
};
|
|
51
|
+
readonly "word-bound-end": {
|
|
52
|
+
readonly rgxGroupWrap: false;
|
|
53
|
+
readonly rgxIsRepeatable: false;
|
|
54
|
+
readonly toRgx: () => RegExp;
|
|
55
|
+
};
|
|
56
|
+
readonly letter: {
|
|
57
|
+
readonly rgxIsGroup: true;
|
|
58
|
+
readonly rgxGroupWrap: false;
|
|
59
|
+
readonly toRgx: () => RegExp;
|
|
60
|
+
};
|
|
61
|
+
readonly "lowercase-letter": {
|
|
62
|
+
readonly rgxIsGroup: true;
|
|
63
|
+
readonly rgxGroupWrap: false;
|
|
64
|
+
readonly toRgx: () => RegExp;
|
|
65
|
+
};
|
|
66
|
+
readonly "uppercase-letter": {
|
|
67
|
+
readonly rgxIsGroup: true;
|
|
68
|
+
readonly rgxGroupWrap: false;
|
|
69
|
+
readonly toRgx: () => RegExp;
|
|
70
|
+
};
|
|
71
|
+
readonly "non-letter": {
|
|
72
|
+
readonly rgxIsGroup: true;
|
|
73
|
+
readonly rgxGroupWrap: false;
|
|
74
|
+
readonly toRgx: () => RegExp;
|
|
75
|
+
};
|
|
76
|
+
readonly alphanumeric: {
|
|
77
|
+
readonly rgxIsGroup: true;
|
|
78
|
+
readonly rgxGroupWrap: false;
|
|
79
|
+
readonly toRgx: () => RegExp;
|
|
80
|
+
};
|
|
81
|
+
readonly "non-alphanumeric": {
|
|
82
|
+
readonly rgxIsGroup: true;
|
|
83
|
+
readonly rgxGroupWrap: false;
|
|
84
|
+
readonly toRgx: () => RegExp;
|
|
85
|
+
};
|
|
86
|
+
readonly digit: {
|
|
87
|
+
readonly rgxGroupWrap: false;
|
|
88
|
+
readonly toRgx: () => RegExp;
|
|
89
|
+
};
|
|
90
|
+
readonly "non-digit": {
|
|
91
|
+
readonly rgxGroupWrap: false;
|
|
92
|
+
readonly toRgx: () => RegExp;
|
|
93
|
+
};
|
|
94
|
+
readonly whitespace: {
|
|
95
|
+
readonly rgxGroupWrap: false;
|
|
96
|
+
readonly toRgx: () => RegExp;
|
|
97
|
+
};
|
|
98
|
+
readonly "non-whitespace": {
|
|
99
|
+
readonly rgxGroupWrap: false;
|
|
100
|
+
readonly toRgx: () => RegExp;
|
|
101
|
+
};
|
|
102
|
+
readonly "vertical-whitespace": {
|
|
103
|
+
readonly rgxGroupWrap: false;
|
|
104
|
+
readonly toRgx: () => RegExp;
|
|
105
|
+
};
|
|
106
|
+
readonly "word-char": {
|
|
107
|
+
readonly rgxGroupWrap: false;
|
|
108
|
+
readonly toRgx: () => RegExp;
|
|
109
|
+
};
|
|
110
|
+
readonly "non-word-char": {
|
|
111
|
+
readonly rgxGroupWrap: false;
|
|
112
|
+
readonly toRgx: () => RegExp;
|
|
113
|
+
};
|
|
114
|
+
readonly backspace: {
|
|
115
|
+
readonly rgxIsGroup: true;
|
|
116
|
+
readonly rgxGroupWrap: false;
|
|
117
|
+
readonly toRgx: () => RegExp;
|
|
118
|
+
};
|
|
119
|
+
readonly "non-escape-bound": {
|
|
120
|
+
readonly rgxGroupWrap: false;
|
|
121
|
+
readonly rgxIsRepeatable: false;
|
|
122
|
+
readonly toRgx: () => RegExp;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
export type RGXPredefinedConstant = keyof typeof RGX_PREDEFINED_CONSTANTS;
|
|
126
|
+
export type RGXConstantName = RGXPredefinedConstant | (string & {});
|
|
2
127
|
export declare function listRGXConstants(): string[];
|
|
3
|
-
export declare function hasRGXConstant(name:
|
|
4
|
-
export declare function assertHasRGXConstant(name:
|
|
5
|
-
export declare function assertNotHasRGXConstant(name:
|
|
6
|
-
export declare function defineRGXConstant(name:
|
|
7
|
-
export declare function rgxConstant(name:
|
|
8
|
-
export declare function deleteRGXConstant(name:
|
|
128
|
+
export declare function hasRGXConstant(name: RGXConstantName): boolean;
|
|
129
|
+
export declare function assertHasRGXConstant(name: RGXConstantName): void;
|
|
130
|
+
export declare function assertNotHasRGXConstant(name: RGXConstantName): void;
|
|
131
|
+
export declare function defineRGXConstant(name: RGXConstantName, value: RGXToken): RegExp | import("./types").RGXConvertibleToken | RGXToken[];
|
|
132
|
+
export declare function rgxConstant(name: RGXConstantName): RGXToken;
|
|
133
|
+
export declare function deleteRGXConstant(name: RGXConstantName): void;
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RGX_PREDEFINED_CONSTANTS = void 0;
|
|
3
4
|
exports.listRGXConstants = listRGXConstants;
|
|
4
5
|
exports.hasRGXConstant = hasRGXConstant;
|
|
5
6
|
exports.assertHasRGXConstant = assertHasRGXConstant;
|
|
@@ -11,6 +12,143 @@ const class_1 = require("./class");
|
|
|
11
12
|
const errors_1 = require("./errors");
|
|
12
13
|
const typeGuards_1 = require("./typeGuards");
|
|
13
14
|
const rgxConstants = {};
|
|
15
|
+
exports.RGX_PREDEFINED_CONSTANTS = {
|
|
16
|
+
// Control Characters
|
|
17
|
+
"newline": "\n",
|
|
18
|
+
"carriage-return": "\r",
|
|
19
|
+
"tab": "\t",
|
|
20
|
+
"null": "\0",
|
|
21
|
+
"form-feed": "\f",
|
|
22
|
+
// Special Characters
|
|
23
|
+
"any": {
|
|
24
|
+
rgxGroupWrap: false,
|
|
25
|
+
toRgx() { return /./s; }
|
|
26
|
+
},
|
|
27
|
+
"non-newline": {
|
|
28
|
+
rgxGroupWrap: false,
|
|
29
|
+
toRgx() { return /./; }
|
|
30
|
+
},
|
|
31
|
+
"start": {
|
|
32
|
+
rgxGroupWrap: false,
|
|
33
|
+
rgxIsRepeatable: false,
|
|
34
|
+
toRgx() { return /^/; }
|
|
35
|
+
},
|
|
36
|
+
"line-start": {
|
|
37
|
+
rgxGroupWrap: false,
|
|
38
|
+
rgxIsRepeatable: false,
|
|
39
|
+
toRgx() { return /^/m; }
|
|
40
|
+
},
|
|
41
|
+
"end": {
|
|
42
|
+
rgxGroupWrap: false,
|
|
43
|
+
rgxIsRepeatable: false,
|
|
44
|
+
toRgx() { return /$/; }
|
|
45
|
+
},
|
|
46
|
+
"line-end": {
|
|
47
|
+
rgxGroupWrap: false,
|
|
48
|
+
rgxIsRepeatable: false,
|
|
49
|
+
toRgx() { return /$/m; }
|
|
50
|
+
},
|
|
51
|
+
"word-bound": {
|
|
52
|
+
rgxGroupWrap: false,
|
|
53
|
+
rgxIsRepeatable: false,
|
|
54
|
+
toRgx() { return /\b/; }
|
|
55
|
+
},
|
|
56
|
+
"non-word-bound": {
|
|
57
|
+
rgxGroupWrap: false,
|
|
58
|
+
rgxIsRepeatable: false,
|
|
59
|
+
toRgx() { return /\B/; }
|
|
60
|
+
},
|
|
61
|
+
"word-bound-start": {
|
|
62
|
+
rgxGroupWrap: false,
|
|
63
|
+
rgxIsRepeatable: false,
|
|
64
|
+
toRgx() {
|
|
65
|
+
// Make sure there is a non-word character before and a word character after
|
|
66
|
+
return /(?<=\W)(?=\w)/;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"word-bound-end": {
|
|
70
|
+
rgxGroupWrap: false,
|
|
71
|
+
rgxIsRepeatable: false,
|
|
72
|
+
toRgx() {
|
|
73
|
+
// Make sure there is a word character before and a non-word character after
|
|
74
|
+
return /(?<=\w)(?=\W)/;
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
// Character Sets
|
|
78
|
+
"letter": {
|
|
79
|
+
rgxIsGroup: true,
|
|
80
|
+
rgxGroupWrap: false,
|
|
81
|
+
toRgx() { return /[a-zA-Z]/; }
|
|
82
|
+
},
|
|
83
|
+
"lowercase-letter": {
|
|
84
|
+
rgxIsGroup: true,
|
|
85
|
+
rgxGroupWrap: false,
|
|
86
|
+
toRgx() { return /[a-z]/; }
|
|
87
|
+
},
|
|
88
|
+
"uppercase-letter": {
|
|
89
|
+
rgxIsGroup: true,
|
|
90
|
+
rgxGroupWrap: false,
|
|
91
|
+
toRgx() { return /[A-Z]/; }
|
|
92
|
+
},
|
|
93
|
+
"non-letter": {
|
|
94
|
+
rgxIsGroup: true,
|
|
95
|
+
rgxGroupWrap: false,
|
|
96
|
+
toRgx() { return /[^a-zA-Z]/; }
|
|
97
|
+
},
|
|
98
|
+
"alphanumeric": {
|
|
99
|
+
rgxIsGroup: true,
|
|
100
|
+
rgxGroupWrap: false,
|
|
101
|
+
toRgx() { return /[a-zA-Z0-9]/; }
|
|
102
|
+
},
|
|
103
|
+
"non-alphanumeric": {
|
|
104
|
+
rgxIsGroup: true,
|
|
105
|
+
rgxGroupWrap: false,
|
|
106
|
+
toRgx() { return /[^a-zA-Z0-9]/; }
|
|
107
|
+
},
|
|
108
|
+
// Predefined Character Sets
|
|
109
|
+
"digit": {
|
|
110
|
+
rgxGroupWrap: false,
|
|
111
|
+
toRgx() { return /\d/; }
|
|
112
|
+
},
|
|
113
|
+
"non-digit": {
|
|
114
|
+
rgxGroupWrap: false,
|
|
115
|
+
toRgx() { return /\D/; }
|
|
116
|
+
},
|
|
117
|
+
"whitespace": {
|
|
118
|
+
rgxGroupWrap: false,
|
|
119
|
+
toRgx() { return /\s/; }
|
|
120
|
+
},
|
|
121
|
+
"non-whitespace": {
|
|
122
|
+
rgxGroupWrap: false,
|
|
123
|
+
toRgx() { return /\S/; }
|
|
124
|
+
},
|
|
125
|
+
"vertical-whitespace": {
|
|
126
|
+
rgxGroupWrap: false,
|
|
127
|
+
toRgx() { return /\v/; }
|
|
128
|
+
},
|
|
129
|
+
"word-char": {
|
|
130
|
+
rgxGroupWrap: false,
|
|
131
|
+
toRgx() { return /\w/; }
|
|
132
|
+
},
|
|
133
|
+
"non-word-char": {
|
|
134
|
+
rgxGroupWrap: false,
|
|
135
|
+
toRgx() { return /\W/; }
|
|
136
|
+
},
|
|
137
|
+
"backspace": {
|
|
138
|
+
rgxIsGroup: true,
|
|
139
|
+
rgxGroupWrap: false,
|
|
140
|
+
toRgx() { return /[\b]/; }
|
|
141
|
+
},
|
|
142
|
+
// Complex Constructs
|
|
143
|
+
"non-escape-bound": {
|
|
144
|
+
rgxGroupWrap: false,
|
|
145
|
+
rgxIsRepeatable: false,
|
|
146
|
+
toRgx() {
|
|
147
|
+
// Put this before any pattern to ensure that the pattern is not escaped, i.e., not preceded by an odd number of backslashes.
|
|
148
|
+
return /(?<=(?<!\\)(?:\\\\)*)(?=[^\\]|$)/;
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
};
|
|
14
152
|
function listRGXConstants() {
|
|
15
153
|
return Object.keys(rgxConstants);
|
|
16
154
|
}
|
|
@@ -41,176 +179,6 @@ function deleteRGXConstant(name) {
|
|
|
41
179
|
assertHasRGXConstant(name);
|
|
42
180
|
delete rgxConstants[name];
|
|
43
181
|
}
|
|
44
|
-
|
|
45
|
-
defineRGXConstant(
|
|
46
|
-
|
|
47
|
-
defineRGXConstant("tab", "\t");
|
|
48
|
-
defineRGXConstant("null", "\0");
|
|
49
|
-
defineRGXConstant("form-feed", "\f");
|
|
50
|
-
// Special Characters
|
|
51
|
-
defineRGXConstant("any", {
|
|
52
|
-
rgxGroupWrap: false,
|
|
53
|
-
toRgx() {
|
|
54
|
-
return /./;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
defineRGXConstant("start", {
|
|
58
|
-
rgxGroupWrap: false,
|
|
59
|
-
rgxIsRepeatable: false,
|
|
60
|
-
toRgx() {
|
|
61
|
-
return /^/;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
defineRGXConstant("line-start", {
|
|
65
|
-
rgxGroupWrap: false,
|
|
66
|
-
rgxIsRepeatable: false,
|
|
67
|
-
toRgx() {
|
|
68
|
-
return /^/m;
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
defineRGXConstant("end", {
|
|
72
|
-
rgxGroupWrap: false,
|
|
73
|
-
rgxIsRepeatable: false,
|
|
74
|
-
toRgx() {
|
|
75
|
-
return /$/;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
defineRGXConstant("line-end", {
|
|
79
|
-
rgxGroupWrap: false,
|
|
80
|
-
rgxIsRepeatable: false,
|
|
81
|
-
toRgx() {
|
|
82
|
-
return /$/m;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
defineRGXConstant("word-bound", {
|
|
86
|
-
rgxGroupWrap: false,
|
|
87
|
-
rgxIsRepeatable: false,
|
|
88
|
-
toRgx() {
|
|
89
|
-
return /\b/;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
defineRGXConstant("non-word-bound", {
|
|
93
|
-
rgxGroupWrap: false,
|
|
94
|
-
rgxIsRepeatable: false,
|
|
95
|
-
toRgx() {
|
|
96
|
-
return /\B/;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
defineRGXConstant("word-bound-start", {
|
|
100
|
-
rgxGroupWrap: false,
|
|
101
|
-
rgxIsRepeatable: false,
|
|
102
|
-
toRgx() {
|
|
103
|
-
// Make sure there is a non-word character before and a word character after
|
|
104
|
-
return /(?<=\W)(?=\w)/;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
defineRGXConstant("word-bound-end", {
|
|
108
|
-
rgxGroupWrap: false,
|
|
109
|
-
rgxIsRepeatable: false,
|
|
110
|
-
toRgx() {
|
|
111
|
-
// Make sure there is a word character before and a non-word character after
|
|
112
|
-
return /(?<=\w)(?=\W)/;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
// Character Sets
|
|
116
|
-
defineRGXConstant("letter", {
|
|
117
|
-
rgxIsGroup: true,
|
|
118
|
-
rgxGroupWrap: false,
|
|
119
|
-
toRgx() {
|
|
120
|
-
return /[a-zA-Z]/;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
defineRGXConstant("lowercase-letter", {
|
|
124
|
-
rgxIsGroup: true,
|
|
125
|
-
rgxGroupWrap: false,
|
|
126
|
-
toRgx() {
|
|
127
|
-
return /[a-z]/;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
defineRGXConstant("uppercase-letter", {
|
|
131
|
-
rgxIsGroup: true,
|
|
132
|
-
rgxGroupWrap: false,
|
|
133
|
-
toRgx() {
|
|
134
|
-
return /[A-Z]/;
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
defineRGXConstant("non-letter", {
|
|
138
|
-
rgxIsGroup: true,
|
|
139
|
-
rgxGroupWrap: false,
|
|
140
|
-
toRgx() {
|
|
141
|
-
return /[^a-zA-Z]/;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
defineRGXConstant("alphanumeric", {
|
|
145
|
-
rgxIsGroup: true,
|
|
146
|
-
rgxGroupWrap: false,
|
|
147
|
-
toRgx() {
|
|
148
|
-
return /[a-zA-Z0-9]/;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
defineRGXConstant("non-alphanumeric", {
|
|
152
|
-
rgxIsGroup: true,
|
|
153
|
-
rgxGroupWrap: false,
|
|
154
|
-
toRgx() {
|
|
155
|
-
return /[^a-zA-Z0-9]/;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
// Predefined Character Sets
|
|
159
|
-
defineRGXConstant("digit", {
|
|
160
|
-
rgxGroupWrap: false,
|
|
161
|
-
toRgx() {
|
|
162
|
-
return /\d/;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
defineRGXConstant("non-digit", {
|
|
166
|
-
rgxGroupWrap: false,
|
|
167
|
-
toRgx() {
|
|
168
|
-
return /\D/;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
defineRGXConstant("whitespace", {
|
|
172
|
-
rgxGroupWrap: false,
|
|
173
|
-
toRgx() {
|
|
174
|
-
return /\s/;
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
defineRGXConstant("non-whitespace", {
|
|
178
|
-
rgxGroupWrap: false,
|
|
179
|
-
toRgx() {
|
|
180
|
-
return /\S/;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
defineRGXConstant("vertical-whitespace", {
|
|
184
|
-
rgxGroupWrap: false,
|
|
185
|
-
toRgx() {
|
|
186
|
-
return /\v/;
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
defineRGXConstant("word-char", {
|
|
190
|
-
rgxGroupWrap: false,
|
|
191
|
-
toRgx() {
|
|
192
|
-
return /\w/;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
defineRGXConstant("non-word-char", {
|
|
196
|
-
rgxGroupWrap: false,
|
|
197
|
-
toRgx() {
|
|
198
|
-
return /\W/;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
defineRGXConstant("backspace", {
|
|
202
|
-
rgxIsGroup: true,
|
|
203
|
-
rgxGroupWrap: false,
|
|
204
|
-
toRgx() {
|
|
205
|
-
return /[\b]/;
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
// Complex Constructs
|
|
209
|
-
// Put this before any pattern to ensure that the pattern is not escaped, i.e., not preceded by an odd number of backslashes.
|
|
210
|
-
defineRGXConstant("non-escape-bound", {
|
|
211
|
-
rgxGroupWrap: false,
|
|
212
|
-
rgxIsRepeatable: false,
|
|
213
|
-
toRgx() {
|
|
214
|
-
return /(?<=(?<!\\)(?:\\\\)*)(?=[^\\]|$)/;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
182
|
+
for (const [name, value] of Object.entries(exports.RGX_PREDEFINED_CONSTANTS)) {
|
|
183
|
+
defineRGXConstant(name, value);
|
|
184
|
+
}
|
package/dist/walker/base.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare class RGXWalker<R> implements RGXConvertibleToken {
|
|
|
27
27
|
set tokenPosition(value: number);
|
|
28
28
|
get stopped(): boolean;
|
|
29
29
|
constructor(source: string, tokens: RGXTokenCollectionInput, options?: RGXWalkerOptions<R>);
|
|
30
|
-
stop():
|
|
30
|
+
stop(): this;
|
|
31
31
|
atTokenEnd(): boolean;
|
|
32
32
|
hasNextToken(predicate?: (token: RGXToken) => boolean): boolean;
|
|
33
33
|
atSourceEnd(): boolean;
|
|
@@ -38,9 +38,9 @@ export declare class RGXWalker<R> implements RGXConvertibleToken {
|
|
|
38
38
|
capture(token: RGXToken, includeMatch: true): RegExpExecArray;
|
|
39
39
|
capture(token: RGXToken, includeMatch?: false): string;
|
|
40
40
|
step(): RGXCapture | null;
|
|
41
|
-
stepToToken(predicate: (token: RGXToken) => boolean):
|
|
42
|
-
stepToPart(predicate?: (part: RGXPart<R>) => boolean):
|
|
43
|
-
walk():
|
|
41
|
+
stepToToken(predicate: (token: RGXToken) => boolean): this;
|
|
42
|
+
stepToPart(predicate?: (part: RGXPart<R>) => boolean): this;
|
|
43
|
+
walk(): this;
|
|
44
44
|
toRgx(): RGXTokenCollection;
|
|
45
45
|
clone(depth?: CloneDepth): RGXWalker<R>;
|
|
46
46
|
}
|
package/dist/walker/base.js
CHANGED
|
@@ -54,6 +54,7 @@ class RGXWalker {
|
|
|
54
54
|
}
|
|
55
55
|
stop() {
|
|
56
56
|
this._stopped = true;
|
|
57
|
+
return this;
|
|
57
58
|
}
|
|
58
59
|
atTokenEnd() {
|
|
59
60
|
return this.tokenPosition >= this.tokens.length;
|
|
@@ -137,7 +138,11 @@ class RGXWalker {
|
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
|
-
const captureResult = {
|
|
141
|
+
const captureResult = {
|
|
142
|
+
raw, value, start, end, branch,
|
|
143
|
+
ownerId: isPart && token.hasId() ? token.id : null,
|
|
144
|
+
groups: isPart ? capture.groups ?? null : null
|
|
145
|
+
};
|
|
141
146
|
// Validate the part. If validation fails, it will throw an error, so nothing below will run.
|
|
142
147
|
if (isPart) {
|
|
143
148
|
token.validate(captureResult, this);
|
|
@@ -172,6 +177,7 @@ class RGXWalker {
|
|
|
172
177
|
if (this._stopped)
|
|
173
178
|
break;
|
|
174
179
|
}
|
|
180
|
+
return this;
|
|
175
181
|
}
|
|
176
182
|
stepToPart(predicate = () => true) {
|
|
177
183
|
// If currently at a Part, step past it first so repeated
|
|
@@ -180,9 +186,10 @@ class RGXWalker {
|
|
|
180
186
|
this._stopped = false;
|
|
181
187
|
this.step();
|
|
182
188
|
if (this._stopped)
|
|
183
|
-
return;
|
|
189
|
+
return this;
|
|
184
190
|
}
|
|
185
191
|
this.stepToToken(token => token instanceof part_1.RGXPart && predicate(token));
|
|
192
|
+
return this;
|
|
186
193
|
}
|
|
187
194
|
walk() {
|
|
188
195
|
return this.stepToToken(() => false);
|
package/dist/walker/part.d.ts
CHANGED