@@ -16,7 +16,7 @@ use std::cmp::Ordering;
16
16
use std:: error;
17
17
use std:: fmt;
18
18
19
- pub use ast:: visitor:: { Visitor , visit } ;
19
+ pub use ast:: visitor:: { visit , Visitor } ;
20
20
21
21
pub mod parse;
22
22
pub mod print;
@@ -202,11 +202,11 @@ impl error::Error for Error {
202
202
EscapeUnexpectedEof => "unexpected eof (escape sequence)" ,
203
203
EscapeUnrecognized => "unrecognized escape sequence" ,
204
204
FlagDanglingNegation => "dangling flag negation operator" ,
205
- FlagDuplicate { .. } => "duplicate flag" ,
206
- FlagRepeatedNegation { .. } => "repeated negation" ,
205
+ FlagDuplicate { .. } => "duplicate flag" ,
206
+ FlagRepeatedNegation { .. } => "repeated negation" ,
207
207
FlagUnexpectedEof => "unexpected eof (flag)" ,
208
208
FlagUnrecognized => "unrecognized flag" ,
209
- GroupNameDuplicate { .. } => "duplicate capture group name" ,
209
+ GroupNameDuplicate { .. } => "duplicate capture group name" ,
210
210
GroupNameEmpty => "empty capture group name" ,
211
211
GroupNameInvalid => "invalid capture group name" ,
212
212
GroupNameUnexpectedEof => "unclosed capture group name" ,
@@ -233,86 +233,67 @@ impl fmt::Display for ErrorKind {
233
233
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
234
234
use self :: ErrorKind :: * ;
235
235
match * self {
236
- CaptureLimitExceeded => {
237
- write ! ( f, "exceeded the maximum number of \
238
- capturing groups ({})", :: std:: u32 :: MAX )
239
- }
236
+ CaptureLimitExceeded => write ! (
237
+ f,
238
+ "exceeded the maximum number of \
239
+ capturing groups ({})",
240
+ :: std:: u32 :: MAX
241
+ ) ,
240
242
ClassEscapeInvalid => {
241
243
write ! ( f, "invalid escape sequence found in character class" )
242
244
}
243
- ClassRangeInvalid => {
244
- write ! ( f, "invalid character class range, \
245
- the start must be <= the end")
246
- }
245
+ ClassRangeInvalid => write ! (
246
+ f,
247
+ "invalid character class range, \
248
+ the start must be <= the end"
249
+ ) ,
247
250
ClassRangeLiteral => {
248
251
write ! ( f, "invalid range boundary, must be a literal" )
249
252
}
250
- ClassUnclosed => {
251
- write ! ( f, "unclosed character class" )
252
- }
253
- DecimalEmpty => {
254
- write ! ( f, "decimal literal empty" )
255
- }
256
- DecimalInvalid => {
257
- write ! ( f, "decimal literal invalid" )
258
- }
259
- EscapeHexEmpty => {
260
- write ! ( f, "hexadecimal literal empty" )
261
- }
253
+ ClassUnclosed => write ! ( f, "unclosed character class" ) ,
254
+ DecimalEmpty => write ! ( f, "decimal literal empty" ) ,
255
+ DecimalInvalid => write ! ( f, "decimal literal invalid" ) ,
256
+ EscapeHexEmpty => write ! ( f, "hexadecimal literal empty" ) ,
262
257
EscapeHexInvalid => {
263
258
write ! ( f, "hexadecimal literal is not a Unicode scalar value" )
264
259
}
265
- EscapeHexInvalidDigit => {
266
- write ! ( f, "invalid hexadecimal digit" )
267
- }
268
- EscapeUnexpectedEof => {
269
- write ! ( f, "incomplete escape sequence, \
270
- reached end of pattern prematurely")
271
- }
272
- EscapeUnrecognized => {
273
- write ! ( f, "unrecognized escape sequence" )
274
- }
260
+ EscapeHexInvalidDigit => write ! ( f, "invalid hexadecimal digit" ) ,
261
+ EscapeUnexpectedEof => write ! (
262
+ f,
263
+ "incomplete escape sequence, \
264
+ reached end of pattern prematurely"
265
+ ) ,
266
+ EscapeUnrecognized => write ! ( f, "unrecognized escape sequence" ) ,
275
267
FlagDanglingNegation => {
276
268
write ! ( f, "dangling flag negation operator" )
277
269
}
278
- FlagDuplicate { ..} => {
279
- write ! ( f, "duplicate flag" )
280
- }
281
- FlagRepeatedNegation { ..} => {
270
+ FlagDuplicate { .. } => write ! ( f, "duplicate flag" ) ,
271
+ FlagRepeatedNegation { .. } => {
282
272
write ! ( f, "flag negation operator repeated" )
283
273
}
284
274
FlagUnexpectedEof => {
285
275
write ! ( f, "expected flag but got end of regex" )
286
276
}
287
- FlagUnrecognized => {
288
- write ! ( f, "unrecognized flag" )
289
- }
290
- GroupNameDuplicate { ..} => {
277
+ FlagUnrecognized => write ! ( f, "unrecognized flag" ) ,
278
+ GroupNameDuplicate { .. } => {
291
279
write ! ( f, "duplicate capture group name" )
292
280
}
293
- GroupNameEmpty => {
294
- write ! ( f, "empty capture group name" )
295
- }
296
- GroupNameInvalid => {
297
- write ! ( f, "invalid capture group character" )
298
- }
299
- GroupNameUnexpectedEof => {
300
- write ! ( f, "unclosed capture group name" )
301
- }
302
- GroupUnclosed => {
303
- write ! ( f, "unclosed group" )
304
- }
305
- GroupUnopened => {
306
- write ! ( f, "unopened group" )
307
- }
308
- NestLimitExceeded ( limit) => {
309
- write ! ( f, "exceed the maximum number of \
310
- nested parentheses/brackets ({})", limit)
311
- }
312
- RepetitionCountInvalid => {
313
- write ! ( f, "invalid repetition count range, \
314
- the start must be <= the end")
315
- }
281
+ GroupNameEmpty => write ! ( f, "empty capture group name" ) ,
282
+ GroupNameInvalid => write ! ( f, "invalid capture group character" ) ,
283
+ GroupNameUnexpectedEof => write ! ( f, "unclosed capture group name" ) ,
284
+ GroupUnclosed => write ! ( f, "unclosed group" ) ,
285
+ GroupUnopened => write ! ( f, "unopened group" ) ,
286
+ NestLimitExceeded ( limit) => write ! (
287
+ f,
288
+ "exceed the maximum number of \
289
+ nested parentheses/brackets ({})",
290
+ limit
291
+ ) ,
292
+ RepetitionCountInvalid => write ! (
293
+ f,
294
+ "invalid repetition count range, \
295
+ the start must be <= the end"
296
+ ) ,
316
297
RepetitionCountDecimalEmpty => {
317
298
write ! ( f, "repetition quantifier expects a valid decimal" )
318
299
}
@@ -325,10 +306,11 @@ impl fmt::Display for ErrorKind {
325
306
UnsupportedBackreference => {
326
307
write ! ( f, "backreferences are not supported" )
327
308
}
328
- UnsupportedLookAround => {
329
- write ! ( f, "look-around, including look-ahead and look-behind, \
330
- is not supported")
331
- }
309
+ UnsupportedLookAround => write ! (
310
+ f,
311
+ "look-around, including look-ahead and look-behind, \
312
+ is not supported"
313
+ ) ,
332
314
_ => unreachable ! ( ) ,
333
315
}
334
316
}
@@ -384,7 +366,8 @@ impl fmt::Debug for Position {
384
366
write ! (
385
367
f,
386
368
"Position(o: {:?}, l: {:?}, c: {:?})" ,
387
- self . offset, self . line, self . column)
369
+ self . offset, self . line, self . column
370
+ )
388
371
}
389
372
}
390
373
@@ -868,7 +851,8 @@ impl ClassUnicode {
868
851
pub fn is_negated ( & self ) -> bool {
869
852
match self . kind {
870
853
ClassUnicodeKind :: NamedValue {
871
- op : ClassUnicodeOpKind :: NotEqual , ..
854
+ op : ClassUnicodeOpKind :: NotEqual ,
855
+ ..
872
856
} => !self . negated ,
873
857
_ => self . negated ,
874
858
}
@@ -910,7 +894,7 @@ impl ClassUnicodeOpKind {
910
894
/// Whether the op is an equality op or not.
911
895
pub fn is_equal ( & self ) -> bool {
912
896
match * self {
913
- ClassUnicodeOpKind :: Equal | ClassUnicodeOpKind :: Colon => true ,
897
+ ClassUnicodeOpKind :: Equal | ClassUnicodeOpKind :: Colon => true ,
914
898
_ => false ,
915
899
}
916
900
}
@@ -1428,26 +1412,24 @@ impl Drop for ClassSet {
1428
1412
use std:: mem;
1429
1413
1430
1414
match * self {
1431
- ClassSet :: Item ( ref item) => {
1432
- match * item {
1433
- ClassSetItem :: Empty ( _)
1434
- | ClassSetItem :: Literal ( _)
1435
- | ClassSetItem :: Range ( _)
1436
- | ClassSetItem :: Ascii ( _)
1437
- | ClassSetItem :: Unicode ( _)
1438
- | ClassSetItem :: Perl ( _) => return ,
1439
- ClassSetItem :: Bracketed ( ref x) => {
1440
- if x. kind . is_empty ( ) {
1441
- return ;
1442
- }
1415
+ ClassSet :: Item ( ref item) => match * item {
1416
+ ClassSetItem :: Empty ( _)
1417
+ | ClassSetItem :: Literal ( _)
1418
+ | ClassSetItem :: Range ( _)
1419
+ | ClassSetItem :: Ascii ( _)
1420
+ | ClassSetItem :: Unicode ( _)
1421
+ | ClassSetItem :: Perl ( _) => return ,
1422
+ ClassSetItem :: Bracketed ( ref x) => {
1423
+ if x. kind . is_empty ( ) {
1424
+ return ;
1443
1425
}
1444
- ClassSetItem :: Union ( ref x ) => {
1445
- if x . items . is_empty ( ) {
1446
- return ;
1447
- }
1426
+ }
1427
+ ClassSetItem :: Union ( ref x ) => {
1428
+ if x . items . is_empty ( ) {
1429
+ return ;
1448
1430
}
1449
1431
}
1450
- }
1432
+ } ,
1451
1433
ClassSet :: BinaryOp ( ref op) => {
1452
1434
if op. lhs . is_empty ( ) && op. rhs . is_empty ( ) {
1453
1435
return ;
@@ -1460,23 +1442,20 @@ impl Drop for ClassSet {
1460
1442
let mut stack = vec ! [ mem:: replace( self , empty_set( ) ) ] ;
1461
1443
while let Some ( mut set) = stack. pop ( ) {
1462
1444
match set {
1463
- ClassSet :: Item ( ref mut item) => {
1464
- match * item {
1465
- ClassSetItem :: Empty ( _)
1466
- | ClassSetItem :: Literal ( _)
1467
- | ClassSetItem :: Range ( _)
1468
- | ClassSetItem :: Ascii ( _)
1469
- | ClassSetItem :: Unicode ( _)
1470
- | ClassSetItem :: Perl ( _) => { }
1471
- ClassSetItem :: Bracketed ( ref mut x) => {
1472
- stack. push ( mem:: replace ( & mut x. kind , empty_set ( ) ) ) ;
1473
- }
1474
- ClassSetItem :: Union ( ref mut x) => {
1475
- stack. extend (
1476
- x. items . drain ( ..) . map ( ClassSet :: Item ) ) ;
1477
- }
1445
+ ClassSet :: Item ( ref mut item) => match * item {
1446
+ ClassSetItem :: Empty ( _)
1447
+ | ClassSetItem :: Literal ( _)
1448
+ | ClassSetItem :: Range ( _)
1449
+ | ClassSetItem :: Ascii ( _)
1450
+ | ClassSetItem :: Unicode ( _)
1451
+ | ClassSetItem :: Perl ( _) => { }
1452
+ ClassSetItem :: Bracketed ( ref mut x) => {
1453
+ stack. push ( mem:: replace ( & mut x. kind , empty_set ( ) ) ) ;
1478
1454
}
1479
- }
1455
+ ClassSetItem :: Union ( ref mut x) => {
1456
+ stack. extend ( x. items . drain ( ..) . map ( ClassSet :: Item ) ) ;
1457
+ }
1458
+ } ,
1480
1459
ClassSet :: BinaryOp ( ref mut op) => {
1481
1460
stack. push ( mem:: replace ( & mut op. lhs , empty_set ( ) ) ) ;
1482
1461
stack. push ( mem:: replace ( & mut op. rhs , empty_set ( ) ) ) ;
@@ -1515,7 +1494,7 @@ mod tests {
1515
1494
// We run our test on a thread with a small stack size so we can
1516
1495
// force the issue more easily.
1517
1496
thread:: Builder :: new ( )
1518
- . stack_size ( 1 << 10 )
1497
+ . stack_size ( 1 << 10 )
1519
1498
. spawn ( run)
1520
1499
. unwrap ( )
1521
1500
. join ( )
0 commit comments