@@ -412,44 +412,70 @@ impl MiniCore {
412
412
}
413
413
414
414
let mut active_regions = Vec :: new ( ) ;
415
+ let mut inactive_regions = Vec :: new ( ) ;
415
416
let mut seen_regions = Vec :: new ( ) ;
416
417
for line in lines {
417
418
let trimmed = line. trim ( ) ;
418
419
if let Some ( region) = trimmed. strip_prefix ( "// region:" ) {
419
- active_regions. push ( region) ;
420
- continue ;
420
+ if let Some ( region) = region. strip_prefix ( '!' ) {
421
+ inactive_regions. push ( region) ;
422
+ continue ;
423
+ } else {
424
+ active_regions. push ( region) ;
425
+ continue ;
426
+ }
421
427
}
422
428
if let Some ( region) = trimmed. strip_prefix ( "// endregion:" ) {
423
- let prev = active_regions. pop ( ) . unwrap ( ) ;
429
+ let ( prev, region) = if let Some ( region) = region. strip_prefix ( '!' ) {
430
+ ( inactive_regions. pop ( ) . unwrap ( ) , region)
431
+ } else {
432
+ ( active_regions. pop ( ) . unwrap ( ) , region)
433
+ } ;
424
434
assert_eq ! ( prev, region, "unbalanced region pairs" ) ;
425
435
continue ;
426
436
}
427
437
428
- let mut line_region = false ;
429
- if let Some ( idx) = trimmed. find ( "// :" ) {
430
- line_region = true ;
438
+ let mut active_line_region = false ;
439
+ let mut inactive_line_region = false ;
440
+ if let Some ( idx) = trimmed. find ( "// :!" ) {
441
+ inactive_line_region = true ;
442
+ inactive_regions. push ( & trimmed[ idx + "// :!" . len ( ) ..] ) ;
443
+ } else if let Some ( idx) = trimmed. find ( "// :" ) {
444
+ active_line_region = true ;
431
445
active_regions. push ( & trimmed[ idx + "// :" . len ( ) ..] ) ;
432
446
}
433
447
434
448
let mut keep = true ;
435
- for & region in & active_regions {
449
+ for & region in active_regions. iter ( ) {
436
450
assert ! ( !region. starts_with( ' ' ) , "region marker starts with a space: {region:?}" ) ;
437
451
self . assert_valid_flag ( region) ;
438
452
seen_regions. push ( region) ;
439
453
keep &= self . has_flag ( region) ;
440
454
}
455
+ for & region in inactive_regions. iter ( ) {
456
+ assert ! ( !region. starts_with( ' ' ) , "region marker starts with a space: {region:?}" ) ;
457
+ self . assert_valid_flag ( region) ;
458
+ seen_regions. push ( region) ;
459
+ keep &= !self . has_flag ( region) ;
460
+ }
441
461
442
462
if keep {
443
463
buf. push_str ( line) ;
444
464
}
445
- if line_region {
465
+ if active_line_region {
446
466
active_regions. pop ( ) . unwrap ( ) ;
447
467
}
468
+ if inactive_line_region {
469
+ inactive_regions. pop ( ) . unwrap ( ) ;
470
+ }
448
471
}
449
472
450
473
if !active_regions. is_empty ( ) {
451
474
panic ! ( "unclosed regions: {active_regions:?} Add an `endregion` comment" ) ;
452
475
}
476
+ if !inactive_regions. is_empty ( ) {
477
+ panic ! ( "unclosed regions: {inactive_regions:?} Add an `endregion` comment" ) ;
478
+ }
453
479
454
480
for flag in & self . valid_flags {
455
481
if !seen_regions. iter ( ) . any ( |it| it == flag) {
0 commit comments