@@ -74,7 +74,7 @@ export default class ExpressionLexer {
74
74
brgroups . pop ( ) ;
75
75
}
76
76
} else {
77
- token . err = "groupclose" ;
77
+ token . error = { id : "groupclose" } ;
78
78
}
79
79
} else if ( c === "[" ) {
80
80
charset = this . parseSquareBracket ( str , token , charset ) ;
@@ -120,18 +120,12 @@ export default class ExpressionLexer {
120
120
// quantifier:
121
121
if ( token . clss === "quant" ) {
122
122
if ( ! prv || prv . close !== undefined || unquantifiable [ prv . type ] || ( prv . open && unquantifiable [ prv . open . type ] ) ) {
123
- token . err = "quanttarg" ;
123
+ token . error = { id : "quanttarg" } ;
124
124
} else {
125
125
token . related = [ prv . open || prv ] ;
126
126
}
127
127
}
128
128
129
- // js warnings:
130
- // TODO: this isn't ideal, but I'm hesitant to write a more robust solution for a couple of edge cases.
131
- if ( profile . id === "js" && ( token . type === "neglookbehind" || token . type === "poslookbehind" ) ) {
132
- token . err = "jsfuture" ;
133
- }
134
-
135
129
// reference:
136
130
if ( token . group === true ) {
137
131
refs . push ( token ) ;
@@ -141,7 +135,7 @@ export default class ExpressionLexer {
141
135
let curGroup = groups . length ? groups [ groups . length - 1 ] : null ;
142
136
if ( curGroup && ( curGroup . type === "conditional" || curGroup . type === "conditionalgroup" ) && token . type === "alt" ) {
143
137
if ( ! curGroup . alt ) { curGroup . alt = token ; }
144
- else { token . err = "extraelse" ; }
138
+ else { token . error = { id : "extraelse" } ; }
145
139
token . related = [ curGroup ] ;
146
140
token . type = "conditionalelse" ;
147
141
token . clss = "special" ;
@@ -154,13 +148,17 @@ export default class ExpressionLexer {
154
148
if ( prv && prv . type === "range" && prv . l === 1 ) {
155
149
this . validateRange ( str , token ) ;
156
150
}
151
+
152
+ // js warnings:
153
+ // TODO: this isn't ideal, but I'm hesitant to write a more robust solution for a couple of edge cases.
154
+ if ( profile . id === "js" ) { this . addJSWarnings ( token ) ; }
157
155
158
156
// general:
159
157
if ( token . open && ! token . clss ) {
160
158
token . clss = token . open . clss ;
161
159
}
162
- if ( token . err ) {
163
- this . errors . push ( token . err ) ;
160
+ if ( token . error ) {
161
+ this . addError ( token ) ;
164
162
}
165
163
i += token . l ;
166
164
prev = token ;
@@ -169,16 +167,28 @@ export default class ExpressionLexer {
169
167
170
168
// post processing:
171
169
while ( groups . length ) {
172
- this . errors . push ( groups . pop ( ) . err = "groupopen" ) ;
170
+ this . addError ( groups . pop ( ) , { id : "groupopen" } ) ;
173
171
}
174
172
this . matchRefs ( refs , capgroups , namedgroups ) ;
175
173
if ( charset ) {
176
- this . errors . push ( charset . err = "setopen" ) ;
174
+ this . addError ( charset , { id : "setopen" } ) ;
177
175
}
178
176
179
177
return this . token ;
180
178
}
181
179
180
+ addError ( token , error = token . error ) {
181
+ token . error = error ;
182
+ this . errors . push ( token ) ;
183
+ }
184
+
185
+ addJSWarnings ( token ) {
186
+ if ( ( token . type === "neglookbehind" || token . type === "poslookbehind" ) ||
187
+ ( token . type === "sticky" || token . type === "unicode" ) ) {
188
+ token . error = { id : "jsfuture" , warning :true } ;
189
+ }
190
+ }
191
+
182
192
addCaptureGroup ( token , groups ) {
183
193
// it would be nice to make branch reset groups actually highlight all of the groups that share the same number
184
194
// that would require switching to arrays of groups for each group num - requires rearchitecture throughout the app.
@@ -191,10 +201,10 @@ export default class ExpressionLexer {
191
201
token . num = capgroups . length + 1 ;
192
202
}
193
203
if ( ! capgroups [ token . num - 1 ] ) { capgroups . push ( token ) ; }
194
- if ( token . name && ! token . err ) {
195
- if ( / \d / . test ( token . name [ 0 ] ) ) { token . err = "badname" ; }
204
+ if ( token . name && ! token . error ) {
205
+ if ( / \d / . test ( token . name [ 0 ] ) ) { token . error = { id : "badname" } ; }
196
206
else if ( namedgroups [ token . name ] ) {
197
- token . err = "dupname" ;
207
+ token . error = { id : "dupname" } ;
198
208
token . related = [ namedgroups [ token . name ] ] ;
199
209
} else { namedgroups [ token . name ] = token ; }
200
210
}
@@ -224,7 +234,7 @@ export default class ExpressionLexer {
224
234
delete token . group ;
225
235
delete token . relIndex ;
226
236
this . refToOctal ( token ) ;
227
- if ( token . err ) { this . errors . push ( token . err ) ; }
237
+ if ( token . error ) { this . errors . push ( token . error ) ; }
228
238
}
229
239
}
230
240
} ;
@@ -241,7 +251,7 @@ export default class ExpressionLexer {
241
251
let name = token . name , profile = this . _profile ;
242
252
if ( token . type !== "numref" ) {
243
253
// not a simple \4 style reference, so can't decompose into an octal.
244
- token . err = "unmatchedref" ;
254
+ token . error = { id : "unmatchedref" } ;
245
255
} else if ( / ^ [ 0 - 7 ] { 2 } $ / . test ( name ) || ( profile . config . reftooctalalways && / ^ [ 0 - 7 ] $ / . test ( name ) ) ) { // octal
246
256
let next = token . next , char = String . fromCharCode ( next . code ) ;
247
257
if ( next . type === "char" && char >= "0" && char <= "7" && parseInt ( name + char , 8 ) <= 255 ) {
@@ -256,7 +266,7 @@ export default class ExpressionLexer {
256
266
this . parseEscChar ( token , name ) ;
257
267
delete token . name ;
258
268
} else {
259
- token . err = "unmatchedref" ;
269
+ token . error = { id : "unmatchedref" } ;
260
270
}
261
271
} ;
262
272
@@ -279,14 +289,14 @@ export default class ExpressionLexer {
279
289
} else {
280
290
token . type = this . _profile . flags [ c ] ;
281
291
}
282
- token . clear = true ;
292
+ // token.clear = true;
283
293
} ;
284
294
285
295
parseChar ( str , token , charset ) {
286
296
let c = str [ token . i ] ;
287
297
token . type = ( ! charset && this . _profile . charTypes [ c ] ) || "char" ;
288
298
if ( ! charset && c === "/" ) {
289
- token . err = "fwdslash" ;
299
+ token . error = { id : "fwdslash" } ;
290
300
}
291
301
if ( token . type === "char" ) {
292
302
token . code = c . charCodeAt ( 0 ) ;
@@ -310,12 +320,12 @@ export default class ExpressionLexer {
310
320
token . clss = "charclass" ;
311
321
if ( match [ 1 ] === ":" ) {
312
322
token . type = "posixcharclass" ;
313
- if ( ! this . _profile . posixCharClasses [ match [ 2 ] ] ) { token . err = "posixcharclassbad" ; }
314
- else if ( ! charset ) { token . err = "posixcharclassnoset" ; }
323
+ if ( ! this . _profile . posixCharClasses [ match [ 2 ] ] ) { token . error = { id : "posixcharclassbad" } ; }
324
+ else if ( ! charset ) { token . error = { id : "posixcharclassnoset" } ; }
315
325
} else {
316
326
token . type = "posixcollseq" ;
317
327
// TODO: can this be generalized? Right now, no, because we assign ids that aren't in the profile.
318
- token . err = "notsupported" ;
328
+ token . error = { id : "notsupported" } ;
319
329
}
320
330
} else if ( ! charset ) {
321
331
// set [a-z] [aeiou]
@@ -449,7 +459,7 @@ export default class ExpressionLexer {
449
459
token . capture = true ;
450
460
}
451
461
452
- if ( ! this . _profile . tokens [ token . type ] ) { token . err = "notsupported" ; }
462
+ if ( ! this . _profile . tokens [ token . type ] ) { token . error = { id : "notsupported" } ; }
453
463
454
464
return token ;
455
465
} ;
@@ -459,7 +469,7 @@ export default class ExpressionLexer {
459
469
let i = token . i , match , profile = this . _profile ;
460
470
let sub = str . substr ( i + 1 ) , c = sub [ 0 ] , val ;
461
471
if ( i + 1 === ( closeIndex || str . length ) ) {
462
- token . err = "esccharopen" ;
472
+ token . error = { id : "esccharopen" } ;
463
473
return ;
464
474
}
465
475
@@ -502,7 +512,7 @@ export default class ExpressionLexer {
502
512
token . l += match [ 0 ] . length ;
503
513
val = parseInt ( match [ 1 ] , 16 ) ;
504
514
// PCRE errors on more than 2 digits (>255). In theory it should allow 4?
505
- if ( isNaN ( val ) || val > 255 || / [ ^ \d a - f ] / i. test ( match [ 1 ] ) ) { token . err = "esccharbad" ; }
515
+ if ( isNaN ( val ) || val > 255 || / [ ^ \d a - f ] / i. test ( match [ 1 ] ) ) { token . error = { id : "esccharbad" } ; }
506
516
else { token . code = val ; }
507
517
} else if ( match = sub . match ( / ^ x ( [ \d a - f A - F ] { 0 , 2 } ) / ) ) {
508
518
// hex ascii: \xFF
@@ -519,7 +529,7 @@ export default class ExpressionLexer {
519
529
token . l += 2 ;
520
530
} else if ( profile . config . ctrlcodeerr ) {
521
531
token . l ++ ;
522
- token . err = "esccharbad" ;
532
+ token . error = { id : "esccharbad" } ;
523
533
} else {
524
534
return this . parseChar ( str , token , charset ) ; // this builds the "/" token
525
535
}
@@ -537,7 +547,7 @@ export default class ExpressionLexer {
537
547
token . type = "escoctal" ;
538
548
token . l += match [ 0 ] . length ;
539
549
val = parseInt ( match [ 1 ] , 8 ) ;
540
- if ( isNaN ( val ) || val > 255 || / [ ^ 0 - 7 ] / . test ( match [ 1 ] ) ) { token . err = "esccharbad" ; }
550
+ if ( isNaN ( val ) || val > 255 || / [ ^ 0 - 7 ] / . test ( match [ 1 ] ) ) { token . error = { id : "esccharbad" } ; }
541
551
else { token . code = val ; }
542
552
} else {
543
553
// single char
@@ -572,7 +582,7 @@ export default class ExpressionLexer {
572
582
token . code = c . charCodeAt ( 0 ) ;
573
583
token . clss = "esc" ;
574
584
} else {
575
- token . err = "esccharbad" ;
585
+ token . error = { id : "esccharbad" } ;
576
586
}
577
587
}
578
588
@@ -616,7 +626,7 @@ export default class ExpressionLexer {
616
626
val = null ;
617
627
}
618
628
if ( not ) { token . type = "not" + token . type ; }
619
- if ( ! val ) { token . err = "unicodebad" ; }
629
+ if ( ! val ) { token . error = { id : "unicodebad" } ; }
620
630
token . value = val ;
621
631
token . clss = "charclass"
622
632
return token ;
@@ -651,7 +661,7 @@ export default class ExpressionLexer {
651
661
token . l = match [ 0 ] . length + 2 ;
652
662
653
663
if ( bad ) {
654
- token . err = "modebad" ;
664
+ token . error = { id : "modebad" } ;
655
665
token . errmode = c ;
656
666
} else {
657
667
this . _modes = modes ;
@@ -669,7 +679,7 @@ export default class ExpressionLexer {
669
679
token . min = parseInt ( arr [ 0 ] ) ;
670
680
token . max = ( arr [ 1 ] === undefined ) ? token . min : ( arr [ 1 ] === "" ) ? - 1 : parseInt ( arr [ 1 ] ) ;
671
681
if ( token . max !== - 1 && token . min > token . max ) {
672
- token . err = "quantrev" ;
682
+ token . error = { id : "quantrev" } ;
673
683
}
674
684
return token ;
675
685
} ;
@@ -684,7 +694,7 @@ export default class ExpressionLexer {
684
694
token . clss = "set" ;
685
695
if ( prv . code > next . code ) {
686
696
// this gets added here because parse has already moved to the next token:
687
- this . errors . push ( token . err = "rangerev" ) ;
697
+ this . errors . push ( token . error = { id : "rangerev" } ) ;
688
698
}
689
699
// preserve as separate tokens, but treat as one in the UI:
690
700
next . proxy = prv . proxy = token ;
0 commit comments