Skip to content

Commit 8e920c9

Browse files
committed
Rename any -> dot
Explicitly disambiguate the fact we're talking about `.`, which does not match newlines unless in single line mode.
1 parent b454390 commit 8e920c9

File tree

12 files changed

+40
-35
lines changed

12 files changed

+40
-35
lines changed

Sources/RegexBuilder/CharacterClass.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extension CharacterClass {
4242
@available(SwiftStdlib 5.7, *)
4343
extension RegexComponent where Self == CharacterClass {
4444
public static var any: CharacterClass {
45-
.init(DSLTree.CustomCharacterClass(members: [.atom(.any)]))
45+
.init(DSLTree.CustomCharacterClass(members: [.atom(.dot)]))
4646
}
4747

4848
public static var anyGraphemeCluster: CharacterClass {

Sources/_RegexParser/Regex/AST/Atom.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extension AST {
6060
case namedCharacter(String)
6161

6262
/// .
63-
case any
63+
case dot
6464

6565
/// ^
6666
case startOfLine
@@ -104,7 +104,7 @@ extension AST.Atom {
104104
case .callout(let v): return v
105105
case .backtrackingDirective(let v): return v
106106
case .changeMatchingOptions(let v): return v
107-
case .any: return nil
107+
case .dot: return nil
108108
case .startOfLine: return nil
109109
case .endOfLine: return nil
110110
case .invalid: return nil
@@ -806,7 +806,7 @@ extension AST.Atom {
806806
// the AST? Or defer for the matching engine?
807807
return nil
808808

809-
case .scalarSequence, .property, .any, .startOfLine, .endOfLine,
809+
case .scalarSequence, .property, .dot, .startOfLine, .endOfLine,
810810
.backreference, .subpattern, .callout, .backtrackingDirective,
811811
.changeMatchingOptions, .invalid:
812812
return nil
@@ -858,7 +858,7 @@ extension AST.Atom {
858858
case .keyboardMetaControl(let x):
859859
return "\\M-\\C-\(x)"
860860

861-
case .property, .escaped, .any, .startOfLine, .endOfLine,
861+
case .property, .escaped, .dot, .startOfLine, .endOfLine,
862862
.backreference, .subpattern, .namedCharacter, .callout,
863863
.backtrackingDirective, .changeMatchingOptions, .invalid:
864864
return nil

Sources/_RegexParser/Regex/Parse/LexicalAnalysis.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ extension Parser {
20732073
p.unreachable("Should have lexed a group or group-like atom")
20742074

20752075
// (sometimes) special metacharacters
2076-
case ".": return customCC ? .char(".") : .any
2076+
case ".": return customCC ? .char(".") : .dot
20772077
case "^": return customCC ? .char("^") : .startOfLine
20782078
case "$": return customCC ? .char("$") : .endOfLine
20792079

Sources/_RegexParser/Regex/Parse/Sema.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ extension RegexValidator {
221221
) {
222222
switch esc {
223223
case .resetStartOfMatch, .singleDataUnit, .trueAnychar,
224-
// '\N' needs to be emitted using 'emitAny'.
224+
// '\N' needs to be emitted using 'emitDot'.
225225
.notNewline:
226226
error(.unsupported("'\\\(esc.character)'"), at: loc)
227227

@@ -288,7 +288,7 @@ extension RegexValidator {
288288
at: atom.location)
289289
}
290290

291-
case .char, .scalar, .startOfLine, .endOfLine, .any:
291+
case .char, .scalar, .startOfLine, .endOfLine, .dot:
292292
break
293293

294294
case .invalid:

Sources/_RegexParser/Regex/Printing/DumpAST.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ extension AST.Atom {
153153
case .keyboardControl, .keyboardMeta, .keyboardMetaControl:
154154
fatalError("TODO")
155155

156-
case .any: return "."
156+
case .dot: return "."
157157
case .startOfLine: return "^"
158158
case .endOfLine: return "$"
159159

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ fileprivate extension Compiler.ByteCodeGen {
5555
}
5656
}
5757
switch a {
58-
case .any:
59-
emitAny()
58+
case .dot:
59+
emitDot()
6060

6161
case let .char(c):
6262
try emitCharacter(c)
@@ -282,7 +282,7 @@ fileprivate extension Compiler.ByteCodeGen {
282282
}
283283
}
284284

285-
mutating func emitAny() {
285+
mutating func emitDot() {
286286
switch (options.semanticLevel, options.dotMatchesNewline) {
287287
case (.graphemeCluster, true):
288288
builder.buildAdvance(1)
@@ -758,9 +758,9 @@ fileprivate extension Compiler.ByteCodeGen {
758758
try emitQuantification(amt.ast, kind, child)
759759

760760
case let .customCharacterClass(ccc):
761-
if ccc.containsAny {
761+
if ccc.containsDot {
762762
if !ccc.isInverted {
763-
emitAny()
763+
emitDot()
764764
} else {
765765
throw Unsupported("Inverted any")
766766
}

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ extension DSLTree.Atom {
111111
: $0 == s
112112
}
113113

114-
case .any:
114+
case .dot:
115115
// FIXME: Should this be a total ordering?
116116
if opts.semanticLevel == .graphemeCluster {
117117
return { input, bounds in
@@ -264,10 +264,10 @@ extension AST.Atom {
264264
case let .namedCharacter(name):
265265
return consumeName(name, opts: opts)
266266

267-
case .any:
267+
case .dot:
268268
assertionFailure(
269269
"Should have been handled by tree conversion")
270-
fatalError(".atom(.any) is handled in emitAny")
270+
fatalError(".atom(.dot) is handled in emitDot")
271271

272272
case .startOfLine, .endOfLine:
273273
// handled in emitAssertion

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ extension AST.Atom {
895895
case .namedCharacter:
896896
return (" /* TODO: named character */", false)
897897

898-
case .any:
898+
case .dot:
899+
// FIXME: This is wrong, the DSL doesn't have an equivalent to .dot.
899900
return (".any", true)
900901

901902
case .startOfLine, .endOfLine:
@@ -950,7 +951,7 @@ extension AST.Atom {
950951
case .namedCharacter(let n):
951952
return "\\N{\(n)}"
952953

953-
case .any:
954+
case .dot:
954955
return "."
955956

956957
case .startOfLine, .endOfLine:
@@ -1099,7 +1100,8 @@ extension DSLTree.Atom {
10991100
_ printer: inout PrettyPrinter
11001101
) -> (String, canBeWrapped: Bool)? {
11011102
switch self {
1102-
case .any:
1103+
case .dot:
1104+
// FIXME: This is wrong, the DSL doesn't have an equivalent to .dot.
11031105
return (".any", true)
11041106

11051107
case let .char(c):
@@ -1141,7 +1143,7 @@ extension DSLTree.Atom {
11411143

11421144
var _regexBase: String {
11431145
switch self {
1144-
case .any:
1146+
case .dot:
11451147
return "."
11461148

11471149
case let .char(c):

Sources/_StringProcessing/Regex/ASTConversion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ extension AST.Atom {
217217
switch self.kind {
218218
case let .char(c): return .char(c)
219219
case let .scalar(s): return .char(Character(s.value))
220-
case .any: return .any
220+
case .dot: return .dot
221221
case let .backreference(r): return .backreference(.init(ast: r))
222222
case let .changeMatchingOptions(seq): return .changeMatchingOptions(.init(ast: seq))
223223

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ extension DSLTree {
117117
var members: [Member]
118118
var isInverted: Bool
119119

120-
var containsAny: Bool {
120+
var containsDot: Bool {
121121
members.contains { member in
122122
switch member {
123-
case .atom(.any): return true
124-
case .custom(let ccc): return ccc.containsAny
123+
case .atom(.dot): return true
124+
case .custom(let ccc): return ccc.containsDot
125125
default:
126126
return false
127127
}
@@ -245,7 +245,10 @@ extension DSLTree {
245245
public enum Atom {
246246
case char(Character)
247247
case scalar(Unicode.Scalar)
248-
case any
248+
249+
/// The DSL representation of '.' in a regex literal. This does not match
250+
/// newlines unless single line mode is enabled.
251+
case dot
249252

250253
case assertion(_AST.AssertionKind)
251254
case backreference(_AST.Reference)
@@ -857,7 +860,7 @@ extension DSLTree.Atom {
857860
switch self {
858861
case .changeMatchingOptions, .assertion:
859862
return false
860-
case .char, .scalar, .any, .backreference, .symbolicReference, .unconverted:
863+
case .char, .scalar, .dot, .backreference, .symbolicReference, .unconverted:
861864
return true
862865
}
863866
}

0 commit comments

Comments
 (0)