Skip to content

Commit 446bfd4

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 d5010fb commit 446bfd4

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
emitCharacter(c)
@@ -320,7 +320,7 @@ fileprivate extension Compiler.ByteCodeGen {
320320
builder.buildMatch(c, isCaseInsensitive: false)
321321
}
322322

323-
mutating func emitAny() {
323+
mutating func emitDot() {
324324
switch (options.semanticLevel, options.dotMatchesNewline) {
325325
case (.graphemeCluster, true):
326326
builder.buildAdvance(1)
@@ -823,9 +823,9 @@ fileprivate extension Compiler.ByteCodeGen {
823823
try emitQuantification(amt.ast, kind, child)
824824

825825
case let .customCharacterClass(ccc):
826-
if ccc.containsAny {
826+
if ccc.containsDot {
827827
if !ccc.isInverted {
828-
emitAny()
828+
emitDot()
829829
} else {
830830
throw Unsupported("Inverted any")
831831
}

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ extension DSLTree.Atom {
128128
// can match a single scalar in scalar semantic mode.
129129
return try Character(s).generateConsumer(opts)
130130

131-
case .any:
131+
case .dot:
132132
// FIXME: Should this be a total ordering?
133133
if opts.semanticLevel == .graphemeCluster {
134134
return { input, bounds in
@@ -285,10 +285,10 @@ extension AST.Atom {
285285
case let .namedCharacter(name):
286286
return consumeName(name, opts: opts)
287287

288-
case .any:
288+
case .dot:
289289
assertionFailure(
290290
"Should have been handled by tree conversion")
291-
fatalError(".atom(.any) is handled in emitAny")
291+
fatalError(".atom(.dot) is handled in emitDot")
292292

293293
case .startOfLine, .endOfLine:
294294
// handled in emitAssertion

Sources/_StringProcessing/PrintAsPattern.swift

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

922-
case .any:
922+
case .dot:
923+
// FIXME: This is wrong, the DSL doesn't have an equivalent to .dot.
923924
return (".any", true)
924925

925926
case .startOfLine, .endOfLine:
@@ -974,7 +975,7 @@ extension AST.Atom {
974975
case .namedCharacter(let n):
975976
return "\\N{\(n)}"
976977

977-
case .any:
978+
case .dot:
978979
return "."
979980

980981
case .startOfLine, .endOfLine:
@@ -1123,7 +1124,8 @@ extension DSLTree.Atom {
11231124
_ printer: inout PrettyPrinter
11241125
) -> (String, canBeWrapped: Bool)? {
11251126
switch self {
1126-
case .any:
1127+
case .dot:
1128+
// FIXME: This is wrong, the DSL doesn't have an equivalent to .dot.
11271129
return (".any", true)
11281130

11291131
case let .char(c):
@@ -1165,7 +1167,7 @@ extension DSLTree.Atom {
11651167

11661168
var _regexBase: String {
11671169
switch self {
1168-
case .any:
1170+
case .dot:
11691171
return "."
11701172

11711173
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 .scalar(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
}
@@ -165,7 +165,10 @@ extension DSLTree {
165165
public enum Atom {
166166
case char(Character)
167167
case scalar(Unicode.Scalar)
168-
case any
168+
169+
/// The DSL representation of '.' in a regex literal. This does not match
170+
/// newlines unless single line mode is enabled.
171+
case dot
169172

170173
case assertion(_AST.AssertionKind)
171174
case backreference(_AST.Reference)
@@ -777,7 +780,7 @@ extension DSLTree.Atom {
777780
switch self {
778781
case .changeMatchingOptions, .assertion:
779782
return false
780-
case .char, .scalar, .any, .backreference, .symbolicReference, .unconverted:
783+
case .char, .scalar, .dot, .backreference, .symbolicReference, .unconverted:
781784
return true
782785
}
783786
}

0 commit comments

Comments
 (0)