Skip to content

Commit d1cd5b4

Browse files
committed
Change position of canOnlyMatchAtStart property
The order of this property in MEProgram seems to determine whether or not it persists from the time it's stored to when it's accessed in RegexDSLTests. Clearly something else is going on here, but this works around the issue for now.
1 parent 12a8c9b commit d1cd5b4

File tree

4 files changed

+4
-25
lines changed

4 files changed

+4
-25
lines changed

Sources/_StringProcessing/Engine/MEBuilder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ extension MEProgram.Builder {
395395
regInfo.captures = nextCaptureRegister.rawValue
396396

397397
return MEProgram(
398+
canOnlyMatchAtStart: canOnlyMatchAtStart,
398399
instructions: InstructionList(instructions),
399400
staticElements: elements.stored,
400401
staticSequences: sequences.stored,
@@ -407,8 +408,7 @@ extension MEProgram.Builder {
407408
enableMetrics: enableMetrics,
408409
captureList: captureList,
409410
referencedCaptureOffsets: referencedCaptureOffsets,
410-
initialOptions: initialOptions,
411-
canOnlyMatchAtStart: canOnlyMatchAtStart)
411+
initialOptions: initialOptions)
412412
}
413413

414414
mutating func reset() { self = Self() }

Sources/_StringProcessing/Engine/MEProgram.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct MEProgram {
2020
typealias MatcherFunction =
2121
(Input, Input.Index, Range<Input.Index>) throws -> (Input.Index, Any)?
2222

23+
var canOnlyMatchAtStart: Bool
24+
2325
var instructions: InstructionList<Instruction>
2426

2527
var staticElements: [Input.Element]
@@ -38,7 +40,6 @@ struct MEProgram {
3840
let referencedCaptureOffsets: [ReferenceID: Int]
3941

4042
var initialOptions: MatchingOptions
41-
var canOnlyMatchAtStart: Bool
4243
}
4344

4445
extension MEProgram: CustomStringConvertible {

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ extension DSLTree.Node {
724724
/// In particular, non-required groups and option-setting groups are
725725
/// inconclusive about where they can match.
726726
private func _canOnlyMatchAtStartImpl(_ options: inout MatchingOptions) -> Bool? {
727-
print(self)
728727
switch self {
729728
// Defining cases
730729
case .atom(.assertion(.startOfSubject)):

Tests/RegexBuilderTests/RegexDSLTests.swift

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -985,28 +985,7 @@ class RegexDSLTests: XCTestCase {
985985
) {
986986
let regex = content().regex
987987
let result = regex.program.loweredProgram.canOnlyMatchAtStart
988-
print("""
989-
canOnlyMatchAtStart: \(result)
990-
expectation: \(expectation)
991-
equal? \(result == expectation)
992-
""")
993-
994-
XCTAssertEqual(result ? 1 : 0, expectation ? 1 : 0, file: file, line: line)
995-
996-
if expectation {
997-
XCTAssertTrue(result, file: file, line: line)
998-
} else {
999-
XCTAssertFalse(result, file: file, line: line)
1000-
}
1001-
1002-
XCTAssertTrue(expectation == result, file: file, line: line)
1003-
1004988
XCTAssertEqual(result, expectation, file: file, line: line)
1005-
XCTAssertEqual(
1006-
result.baseValue,
1007-
expectation.baseValue,
1008-
file: file, line: line)
1009-
fflush(stdout)
1010989
}
1011990

1012991
expectCanOnlyMatchAtStart(true) {

0 commit comments

Comments
 (0)