Skip to content

Commit d3a0469

Browse files
committed
Rename hasImplicitScope -> isIsolated
1 parent 9f11bce commit d3a0469

File tree

5 files changed

+38
-39
lines changed

5 files changed

+38
-39
lines changed

Sources/_MatchingEngine/Regex/AST/Group.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ extension AST {
5454
case atomicScriptRun
5555

5656
// (?iJmnsUxxxDPSWy{..}-iJmnsUxxxDPSW:)
57-
// If hasImplicitScope is true, it was written as e.g (?i), and implicitly
58-
// forms a group containing all the following elements of the current
59-
// group.
60-
case changeMatchingOptions(MatchingOptionSequence, hasImplicitScope: Bool)
57+
// Isolated options are written as e.g (?i), and implicitly form a group
58+
// containing all the following elements of the current group.
59+
case changeMatchingOptions(MatchingOptionSequence, isIsolated: Bool)
6160

6261
// NOTE: Comments appear to be groups, but are not parsed
6362
// the same. They parse more like quotes, so are not
@@ -74,16 +73,16 @@ extension AST.Group.Kind {
7473
}
7574
}
7675

77-
/// Whether this is a group with an implicit scope, e.g matching options
78-
/// written as (?i) implicitly become parent groups for the rest of the
79-
/// elements in the current group:
76+
/// Whether this is a group with an implicit scope, e.g isolated matching
77+
/// options implicitly become parent groups for the rest of the elements in
78+
/// the current group:
8079
///
8180
/// (a(?i)bc)de -> (a(?i:bc))de
8281
///
8382
public var hasImplicitScope: Bool {
8483
switch self {
85-
case .changeMatchingOptions(_, let hasImplicitScope):
86-
return hasImplicitScope
84+
case .changeMatchingOptions(_, let isIsolated):
85+
return isIsolated
8786
default:
8887
return false
8988
}

Sources/_MatchingEngine/Regex/Parse/LexicalAnalysis.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ extension Source {
602602
// Matching option changing group (?iJmnsUxxxDPSWy{..}-iJmnsUxxxDPSW:).
603603
if let seq = try src.lexMatchingOptionSequence() {
604604
if src.tryEat(":") {
605-
return .changeMatchingOptions(seq, hasImplicitScope: false)
605+
return .changeMatchingOptions(seq, isIsolated: false)
606606
}
607607
// If this isn't start of an explicit group, we should have an
608608
// implicit group that covers the remaining elements of the current
@@ -611,7 +611,7 @@ extension Source {
611611
// also does it across alternations, which will require additional
612612
// handling.
613613
try src.expect(")")
614-
return .changeMatchingOptions(seq, hasImplicitScope: true)
614+
return .changeMatchingOptions(seq, isIsolated: true)
615615
}
616616

617617
guard let next = src.peek() else {

Sources/_MatchingEngine/Regex/Printing/DumpAST.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ extension AST.Group.Kind: _ASTPrintable {
120120
case .nonAtomicLookbehind: return "nonAtomicLookbehind"
121121
case .scriptRun: return "scriptRun"
122122
case .atomicScriptRun: return "atomicScriptRun"
123-
case .changeMatchingOptions(let seq, let hasImplicitScope):
124-
return "changeMatchingOptions<\(seq), \(hasImplicitScope)>"
123+
case .changeMatchingOptions(let seq, let isIsolated):
124+
return "changeMatchingOptions<\(seq), \(isIsolated)>"
125125
}
126126
}
127127
}

Sources/_StringProcessing/ASTBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ public func atomicScriptRun(_ child: AST) -> AST {
9090
group(.atomicScriptRun, child)
9191
}
9292
func changeMatchingOptions(
93-
_ seq: AST.MatchingOptionSequence, hasImplicitScope: Bool, _ child: AST
93+
_ seq: AST.MatchingOptionSequence, isIsolated: Bool, _ child: AST
9494
) -> AST {
95-
group(.changeMatchingOptions(seq, hasImplicitScope: hasImplicitScope), child)
95+
group(.changeMatchingOptions(seq, isIsolated: isIsolated), child)
9696
}
9797

9898
func matchingOptions(

Tests/RegexTests/ParseTests.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -475,74 +475,74 @@ extension RegexTests {
475475

476476
// Matching option changing groups.
477477
parseTest("(?-)", changeMatchingOptions(
478-
matchingOptions(), hasImplicitScope: true, empty())
478+
matchingOptions(), isIsolated: true, empty())
479479
)
480480
parseTest("(?i)", changeMatchingOptions(
481481
matchingOptions(adding: .caseInsensitive),
482-
hasImplicitScope: true, empty())
482+
isIsolated: true, empty())
483483
)
484484
parseTest("(?m)", changeMatchingOptions(
485485
matchingOptions(adding: .multiline),
486-
hasImplicitScope: true, empty())
486+
isIsolated: true, empty())
487487
)
488488
parseTest("(?x)", changeMatchingOptions(
489489
matchingOptions(adding: .extended),
490-
hasImplicitScope: true, empty())
490+
isIsolated: true, empty())
491491
)
492492
parseTest("(?xx)", changeMatchingOptions(
493493
matchingOptions(adding: .extraExtended),
494-
hasImplicitScope: true, empty())
494+
isIsolated: true, empty())
495495
)
496496
parseTest("(?xxx)", changeMatchingOptions(
497497
matchingOptions(adding: .extraExtended, .extended),
498-
hasImplicitScope: true, empty())
498+
isIsolated: true, empty())
499499
)
500500
parseTest("(?-i)", changeMatchingOptions(
501501
matchingOptions(removing: .caseInsensitive),
502-
hasImplicitScope: true, empty())
502+
isIsolated: true, empty())
503503
)
504504
parseTest("(?i-s)", changeMatchingOptions(
505505
matchingOptions(adding: .caseInsensitive, removing: .singleLine),
506-
hasImplicitScope: true, empty())
506+
isIsolated: true, empty())
507507
)
508508
parseTest("(?i-is)", changeMatchingOptions(
509509
matchingOptions(adding: .caseInsensitive,
510510
removing: .caseInsensitive, .singleLine),
511-
hasImplicitScope: true, empty())
511+
isIsolated: true, empty())
512512
)
513513

514514
parseTest("(?:)", nonCapture(empty()))
515515
parseTest("(?-:)", changeMatchingOptions(
516-
matchingOptions(), hasImplicitScope: false, empty())
516+
matchingOptions(), isIsolated: false, empty())
517517
)
518518
parseTest("(?i:)", changeMatchingOptions(
519519
matchingOptions(adding: .caseInsensitive),
520-
hasImplicitScope: false, empty())
520+
isIsolated: false, empty())
521521
)
522522
parseTest("(?-i:)", changeMatchingOptions(
523523
matchingOptions(removing: .caseInsensitive),
524-
hasImplicitScope: false, empty())
524+
isIsolated: false, empty())
525525
)
526526

527527
parseTest("(?^)", changeMatchingOptions(
528528
unsetMatchingOptions(),
529-
hasImplicitScope: true, empty())
529+
isIsolated: true, empty())
530530
)
531531
parseTest("(?^:)", changeMatchingOptions(
532532
unsetMatchingOptions(),
533-
hasImplicitScope: false, empty())
533+
isIsolated: false, empty())
534534
)
535535
parseTest("(?^ims:)", changeMatchingOptions(
536536
unsetMatchingOptions(adding: .caseInsensitive, .multiline, .singleLine),
537-
hasImplicitScope: false, empty())
537+
isIsolated: false, empty())
538538
)
539539
parseTest("(?^J:)", changeMatchingOptions(
540540
unsetMatchingOptions(adding: .allowDuplicateGroupNames),
541-
hasImplicitScope: false, empty())
541+
isIsolated: false, empty())
542542
)
543543
parseTest("(?^y{w}:)", changeMatchingOptions(
544544
unsetMatchingOptions(adding: .textSegmentWordMode),
545-
hasImplicitScope: false, empty())
545+
isIsolated: false, empty())
546546
)
547547

548548
let allOptions: [AST.MatchingOption.Kind] = [
@@ -557,44 +557,44 @@ extension RegexTests {
557557
adding: allOptions,
558558
removing: allOptions.dropLast(2)
559559
),
560-
hasImplicitScope: true, empty())
560+
isIsolated: true, empty())
561561
)
562562
parseTest("(?iJmnsUxxxwDPSWy{g}y{w}-iJmnsUxxxwDPSW:)", changeMatchingOptions(
563563
matchingOptions(
564564
adding: allOptions,
565565
removing: allOptions.dropLast(2)
566566
),
567-
hasImplicitScope: false, empty())
567+
isIsolated: false, empty())
568568
)
569569

570570
parseTest(
571571
"a(b(?i)c)d", concat("a", capture(concat("b", changeMatchingOptions(
572572
matchingOptions(adding: .caseInsensitive),
573-
hasImplicitScope: true, "c"))), "d"),
573+
isIsolated: true, "c"))), "d"),
574574
captures: .atom()
575575
)
576576
parseTest(
577577
"(a(?i)b(c)d)", capture(concat("a", changeMatchingOptions(
578578
matchingOptions(adding: .caseInsensitive),
579-
hasImplicitScope: true, concat("b", capture("c"), "d")))),
579+
isIsolated: true, concat("b", capture("c"), "d")))),
580580
captures: .tuple(.atom(), .atom())
581581
)
582582
parseTest(
583583
"(a(?i)b(?#hello)c)", capture(concat("a", changeMatchingOptions(
584584
matchingOptions(adding: .caseInsensitive),
585-
hasImplicitScope: true, concat("b", "c")))),
585+
isIsolated: true, concat("b", "c")))),
586586
captures: .atom()
587587
)
588588

589589
// TODO: This is Oniguruma's behavior, but PCRE treats it as:
590590
// ab(?i:c)|(?i:def)|(?i:gh)
591591
// instead. We ought to have a mode to emulate that.
592592
parseTest("ab(?i)c|def|gh", concat("a", "b", changeMatchingOptions(
593-
matchingOptions(adding: .caseInsensitive), hasImplicitScope: true,
593+
matchingOptions(adding: .caseInsensitive), isIsolated: true,
594594
alt("c", concat("d", "e", "f"), concat("g", "h")))))
595595

596596
parseTest("(a|b(?i)c|d)", capture(alt("a", concat("b", changeMatchingOptions(
597-
matchingOptions(adding: .caseInsensitive), hasImplicitScope: true,
597+
matchingOptions(adding: .caseInsensitive), isIsolated: true,
598598
alt("c", "d"))))),
599599
captures: .atom())
600600

0 commit comments

Comments
 (0)