Skip to content

Commit 61e979c

Browse files
authored
Merge pull request #508 from Azoy/fix-concat-printing
[Printer] Unconditionally print a regex block for concatenations
2 parents 6803dbf + 16a25f2 commit 61e979c

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Sources/_StringProcessing/PrintAsPattern.swift

+13-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,15 @@ extension PrettyPrinter {
7171
print("let \(namedCapture) = Reference(Substring.self)")
7272
}
7373

74-
printBlock("Regex") { printer in
75-
printer.printAsPattern(convertedFromAST: node)
74+
switch node {
75+
case .concatenation(_):
76+
printAsPattern(convertedFromAST: node)
77+
case .convertedRegexLiteral(.concatenation(_), _):
78+
printAsPattern(convertedFromAST: node)
79+
default:
80+
printBlock("Regex") { printer in
81+
printer.printAsPattern(convertedFromAST: node)
82+
}
7683
}
7784
}
7885

@@ -99,8 +106,10 @@ extension PrettyPrinter {
99106
}
100107

101108
case let .concatenation(c):
102-
c.forEach {
103-
printAsPattern(convertedFromAST: $0)
109+
printBlock("Regex") { printer in
110+
c.forEach {
111+
printer.printAsPattern(convertedFromAST: $0)
112+
}
104113
}
105114

106115
case let .nonCapturingGroup(kind, child):

Tests/RegexTests/RenderDSLTests.swift

+9-11
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,17 @@ extension RenderDSLTests {
9797
}
9898
""")
9999

100-
try XCTExpectFailure("Concatenations in alternations aren't grouped") {
101-
try testConversion(#"\da|b"#, """
102-
Regex {
103-
ChoiceOf {
104-
Regex {
105-
.digit
106-
"a"
107-
}
108-
"bc"
100+
try testConversion(#"\da|bc"#, """
101+
Regex {
102+
ChoiceOf {
103+
Regex {
104+
One(.digit)
105+
"a"
109106
}
107+
"bc"
110108
}
111-
""")
112-
}
109+
}
110+
""")
113111
}
114112

115113
func testQuoting() throws {

0 commit comments

Comments
 (0)