Skip to content

Commit c0202a9

Browse files
committed
Handle atoms as things to be wrapped
oops
1 parent 9cf3cfc commit c0202a9

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Sources/_StringProcessing/PrintAsPattern.swift

+18-12
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ extension PrettyPrinter {
193193
}
194194

195195
if let pattern = a._patternBase(&self) {
196-
print(pattern)
196+
if pattern.canBeWrapped {
197+
print("One(\(pattern.0))")
198+
} else {
199+
print(pattern.0)
200+
}
197201
}
198202

199203
case .trivia:
@@ -387,9 +391,9 @@ extension PrettyPrinter {
387391
if let lhs = lhs._patternBase(&self), let rhs = rhs._patternBase(&self) {
388392
indent()
389393
output("(")
390-
output(lhs)
394+
output(lhs.0)
391395
output("...")
392-
output(rhs)
396+
output(rhs.0)
393397
output(")")
394398
}
395399

@@ -1029,33 +1033,35 @@ extension DSLTree.CustomCharacterClass {
10291033
}
10301034

10311035
extension DSLTree.Atom {
1032-
func _patternBase(_ printer: inout PrettyPrinter) -> String? {
1036+
func _patternBase(
1037+
_ printer: inout PrettyPrinter
1038+
) -> (String, canBeWrapped: Bool)? {
10331039
switch self {
10341040
case .any:
1035-
return ".any"
1041+
return (".any", true)
10361042

10371043
case let .char(c):
1038-
return String(c)._quoted
1044+
return (String(c)._quoted, false)
10391045

10401046
case let .scalar(s):
10411047
let hex = String(s.value, radix: 16, uppercase: true)
1042-
return "\\u{\(hex)}"._quoted
1048+
return ("\\u{\(hex)}"._quoted, false)
10431049

10441050
case let .unconverted(a):
10451051
if a.ast.isUnprintableAtom {
1046-
return "#/\(a.ast._regexBase)/#"
1052+
return ("#/\(a.ast._regexBase)/#", false)
10471053
} else {
1048-
return a.ast._dslBase.0
1054+
return a.ast._dslBase
10491055
}
10501056

10511057
case .assertion(let a):
1052-
return a.ast._patternBase
1058+
return (a.ast._patternBase, false)
10531059

10541060
case .backreference(_):
1055-
return "/* TOOD: backreferences */"
1061+
return ("/* TOOD: backreferences */", false)
10561062

10571063
case .symbolicReference:
1058-
return "/* TOOD: symbolic references */"
1064+
return ("/* TOOD: symbolic references */", false)
10591065

10601066
case .changeMatchingOptions(let matchingOptions):
10611067
for add in matchingOptions.ast.adding {

0 commit comments

Comments
 (0)