@@ -412,44 +412,70 @@ impl MiniCore {
412412 }
413413
414414 let mut active_regions = Vec :: new ( ) ;
415+ let mut inactive_regions = Vec :: new ( ) ;
415416 let mut seen_regions = Vec :: new ( ) ;
416417 for line in lines {
417418 let trimmed = line. trim ( ) ;
418419 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+ }
421427 }
422428 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+ } ;
424434 assert_eq ! ( prev, region, "unbalanced region pairs" ) ;
425435 continue ;
426436 }
427437
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 ;
431445 active_regions. push ( & trimmed[ idx + "// :" . len ( ) ..] ) ;
432446 }
433447
434448 let mut keep = true ;
435- for & region in & active_regions {
449+ for & region in active_regions. iter ( ) {
436450 assert ! ( !region. starts_with( ' ' ) , "region marker starts with a space: {region:?}" ) ;
437451 self . assert_valid_flag ( region) ;
438452 seen_regions. push ( region) ;
439453 keep &= self . has_flag ( region) ;
440454 }
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+ }
441461
442462 if keep {
443463 buf. push_str ( line) ;
444464 }
445- if line_region {
465+ if active_line_region {
446466 active_regions. pop ( ) . unwrap ( ) ;
447467 }
468+ if inactive_line_region {
469+ inactive_regions. pop ( ) . unwrap ( ) ;
470+ }
448471 }
449472
450473 if !active_regions. is_empty ( ) {
451474 panic ! ( "unclosed regions: {active_regions:?} Add an `endregion` comment" ) ;
452475 }
476+ if !inactive_regions. is_empty ( ) {
477+ panic ! ( "unclosed regions: {inactive_regions:?} Add an `endregion` comment" ) ;
478+ }
453479
454480 for flag in & self . valid_flags {
455481 if !seen_regions. iter ( ) . any ( |it| it == flag) {
0 commit comments