@@ -9,7 +9,7 @@ export type Node = BranchNode | LeafNode
9
9
export type BranchNode =
10
10
| RegExpLiteral
11
11
| Pattern
12
- | Disjunction
12
+ | Alternative
13
13
| Group
14
14
| CapturingGroup
15
15
| Quantifier
@@ -30,16 +30,20 @@ export type LeafNode =
30
30
/**
31
31
* The type which includes all atom nodes.
32
32
*/
33
- export type Element =
34
- | Disjunction
33
+ export type Element = Assertion | Quantifier | QuantifiableElement
34
+
35
+ /**
36
+ * The type which includes all atom nodes that Quantifier node can have as children.
37
+ */
38
+ export type QuantifiableElement =
35
39
| Group
36
40
| CapturingGroup
37
- | Quantifier
38
41
| CharacterClass
39
- | Assertion
40
42
| CharacterSet
41
43
| Character
42
44
| Backreference
45
+ // Lookahead assertions is quantifiable in Annex-B.
46
+ | LookaheadAssertion
43
47
44
48
/**
45
49
* The type which includes all character class atom nodes.
@@ -50,31 +54,6 @@ export type CharacterClassElement =
50
54
| Character
51
55
| CharacterClassRange
52
56
53
- /**
54
- * The type which includes all atom nodes that Alternative node can have as children.
55
- */
56
- export type AlternativeElement =
57
- | Group
58
- | CapturingGroup
59
- | Quantifier
60
- | CharacterClass
61
- | Assertion
62
- | CharacterSet
63
- | Character
64
- | Backreference
65
-
66
- /**
67
- * The type which includes all atom nodes that Quantifier node can have as children.
68
- */
69
- export type QuantifiableElement =
70
- | Group
71
- | CapturingGroup
72
- | CharacterClass
73
- | LookaheadAssertion
74
- | CharacterSet
75
- | Character
76
- | Backreference
77
-
78
57
/**
79
58
* The type which defines common properties for all node types.
80
59
*/
@@ -107,17 +86,17 @@ export interface RegExpLiteral extends NodeBase {
107
86
export interface Pattern extends NodeBase {
108
87
type : "Pattern"
109
88
parent : RegExpLiteral | null
110
- elements : Element [ ]
89
+ alternatives : Alternative [ ]
111
90
}
112
91
113
92
/**
114
- * The disjunction .
93
+ * The alternative .
115
94
* E.g. `a|b`
116
95
*/
117
- export interface Disjunction extends NodeBase {
118
- type : "Disjunction "
96
+ export interface Alternative extends NodeBase {
97
+ type : "Alternative "
119
98
parent : Pattern | Group | CapturingGroup | LookaroundAssertion
120
- alternatives : AlternativeElement [ ] [ ]
99
+ elements : Element [ ]
121
100
}
122
101
123
102
/**
@@ -126,14 +105,8 @@ export interface Disjunction extends NodeBase {
126
105
*/
127
106
export interface Group extends NodeBase {
128
107
type : "Group"
129
- parent :
130
- | Pattern
131
- | Disjunction
132
- | Group
133
- | CapturingGroup
134
- | Quantifier
135
- | LookaroundAssertion
136
- elements : Element [ ]
108
+ parent : Alternative | Quantifier
109
+ alternatives : Alternative [ ]
137
110
}
138
111
139
112
/**
@@ -142,15 +115,9 @@ export interface Group extends NodeBase {
142
115
*/
143
116
export interface CapturingGroup extends NodeBase {
144
117
type : "CapturingGroup"
145
- parent :
146
- | Pattern
147
- | Disjunction
148
- | Group
149
- | CapturingGroup
150
- | Quantifier
151
- | LookaroundAssertion
118
+ parent : Alternative | Quantifier
152
119
name : string | null
153
- elements : Element [ ]
120
+ alternatives : Alternative [ ]
154
121
references : Backreference [ ]
155
122
}
156
123
@@ -165,16 +132,10 @@ export type LookaroundAssertion = LookaheadAssertion | LookbehindAssertion
165
132
*/
166
133
export interface LookaheadAssertion extends NodeBase {
167
134
type : "Assertion"
168
- parent :
169
- | Pattern
170
- | Disjunction
171
- | Group
172
- | CapturingGroup
173
- | Quantifier
174
- | LookaroundAssertion
135
+ parent : Alternative | Quantifier
175
136
kind : "lookahead"
176
137
negate : boolean
177
- elements : Element [ ]
138
+ alternatives : Alternative [ ]
178
139
}
179
140
180
141
/**
@@ -183,10 +144,10 @@ export interface LookaheadAssertion extends NodeBase {
183
144
*/
184
145
export interface LookbehindAssertion extends NodeBase {
185
146
type : "Assertion"
186
- parent : Pattern | Disjunction | Group | CapturingGroup | LookaroundAssertion
147
+ parent : Alternative
187
148
kind : "lookbehind"
188
149
negate : boolean
189
- elements : Element [ ]
150
+ alternatives : Alternative [ ]
190
151
}
191
152
192
153
/**
@@ -195,7 +156,7 @@ export interface LookbehindAssertion extends NodeBase {
195
156
*/
196
157
export interface Quantifier extends NodeBase {
197
158
type : "Quantifier"
198
- parent : Pattern | Disjunction | Group | CapturingGroup | LookaroundAssertion
159
+ parent : Alternative
199
160
min : number
200
161
max : number // can be Number.POSITIVE_INFINITY
201
162
greedy : boolean
@@ -208,13 +169,7 @@ export interface Quantifier extends NodeBase {
208
169
*/
209
170
export interface CharacterClass extends NodeBase {
210
171
type : "CharacterClass"
211
- parent :
212
- | Pattern
213
- | Disjunction
214
- | Group
215
- | CapturingGroup
216
- | Quantifier
217
- | LookaroundAssertion
172
+ parent : Alternative | Quantifier
218
173
negate : boolean
219
174
elements : CharacterClassElement [ ]
220
175
}
@@ -246,13 +201,7 @@ export type BoundaryAssertion = EdgeAssertion | WordBoundaryAssertion
246
201
*/
247
202
export interface EdgeAssertion extends NodeBase {
248
203
type : "Assertion"
249
- parent :
250
- | Pattern
251
- | Disjunction
252
- | Group
253
- | CapturingGroup
254
- | Quantifier
255
- | LookaroundAssertion
204
+ parent : Alternative | Quantifier
256
205
kind : "start" | "end"
257
206
}
258
207
@@ -262,13 +211,7 @@ export interface EdgeAssertion extends NodeBase {
262
211
*/
263
212
export interface WordBoundaryAssertion extends NodeBase {
264
213
type : "Assertion"
265
- parent :
266
- | Pattern
267
- | Disjunction
268
- | Group
269
- | CapturingGroup
270
- | Quantifier
271
- | LookaroundAssertion
214
+ parent : Alternative | Quantifier
272
215
kind : "word"
273
216
negate : boolean
274
217
}
@@ -287,13 +230,7 @@ export type CharacterSet =
287
230
*/
288
231
export interface AnyCharacterSet extends NodeBase {
289
232
type : "CharacterSet"
290
- parent :
291
- | Pattern
292
- | Disjunction
293
- | Group
294
- | CapturingGroup
295
- | Quantifier
296
- | LookaroundAssertion
233
+ parent : Alternative | Quantifier
297
234
kind : "any"
298
235
}
299
236
@@ -303,14 +240,7 @@ export interface AnyCharacterSet extends NodeBase {
303
240
*/
304
241
export interface EscapeCharacterSet extends NodeBase {
305
242
type : "CharacterSet"
306
- parent :
307
- | Pattern
308
- | Disjunction
309
- | Group
310
- | CapturingGroup
311
- | Quantifier
312
- | CharacterClass
313
- | LookaroundAssertion
243
+ parent : Alternative | Quantifier | CharacterClass
314
244
kind : "digit" | "space" | "word"
315
245
negate : boolean
316
246
}
@@ -321,14 +251,7 @@ export interface EscapeCharacterSet extends NodeBase {
321
251
*/
322
252
export interface UnicodePropertyCharacterSet extends NodeBase {
323
253
type : "CharacterSet"
324
- parent :
325
- | Pattern
326
- | Disjunction
327
- | Group
328
- | CapturingGroup
329
- | Quantifier
330
- | CharacterClass
331
- | LookaroundAssertion
254
+ parent : Alternative | Quantifier | CharacterClass
332
255
kind : "property"
333
256
key : string
334
257
value : string | null
@@ -342,15 +265,7 @@ export interface UnicodePropertyCharacterSet extends NodeBase {
342
265
*/
343
266
export interface Character extends NodeBase {
344
267
type : "Character"
345
- parent :
346
- | Pattern
347
- | Disjunction
348
- | Group
349
- | CapturingGroup
350
- | Quantifier
351
- | CharacterClass
352
- | LookaroundAssertion
353
- | CharacterClassRange
268
+ parent : Alternative | Quantifier | CharacterClass | CharacterClassRange
354
269
value : number // a code point.
355
270
}
356
271
@@ -360,13 +275,7 @@ export interface Character extends NodeBase {
360
275
*/
361
276
export interface Backreference extends NodeBase {
362
277
type : "Backreference"
363
- parent :
364
- | Pattern
365
- | Disjunction
366
- | Group
367
- | CapturingGroup
368
- | Quantifier
369
- | LookaroundAssertion
278
+ parent : Alternative | Quantifier
370
279
ref : number | string
371
280
resolved : CapturingGroup
372
281
}
0 commit comments