Skip to content

Commit 2c386ef

Browse files
committed
Add some comments
1 parent 12ef33b commit 2c386ef

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extension PrettyPrinter {
5858
// TODO: Handle global options...
5959
let node = ast.root.dslTreeNode
6060

61-
// If we have any named captures, create referencs to those above the regex.
61+
// If we have any named captures, create references to those above the regex.
6262
let namedCaptures = node.getNamedCaptures()
6363

6464
for namedCapture in namedCaptures {
@@ -226,6 +226,23 @@ extension PrettyPrinter {
226226

227227
var charMembers = ""
228228

229+
230+
// This iterates through all of the character class members collecting all
231+
// of the members who can be stuffed into a singular '.anyOf(...)' vs.
232+
// having multiple. This does alter the original representation, but the
233+
// result is the same. For example:
234+
//
235+
// Convert: '[abc\d\Qxyz\E[:space:]def]'
236+
//
237+
// CharacterClass(
238+
// .anyOf("abcxyzdef"),
239+
// .digit,
240+
// .whitespace
241+
// )
242+
//
243+
// This also allows us to determine if after collecting all of the members
244+
// and stuffing them if we can just emit a standalone '.anyOf' instead of
245+
// initializing a 'CharacterClass'.
229246
let nonCharMembers = ccc.members.filter {
230247
switch $0 {
231248
case let .atom(a):

0 commit comments

Comments
 (0)