Skip to content

Commit cb9c5fb

Browse files
committed
Rename startOfLine/endOfLine -> caretAnchor/dollarAnchor
1 parent fbe598c commit cb9c5fb

File tree

8 files changed

+30
-28
lines changed

8 files changed

+30
-28
lines changed

Sources/_RegexParser/Regex/AST/Atom.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ extension AST {
6363
case dot
6464

6565
/// ^
66-
case startOfLine
66+
case caretAnchor
6767

6868
/// $
69-
case endOfLine
69+
case dollarAnchor
7070

7171
// References
7272
case backreference(Reference)
@@ -105,8 +105,8 @@ extension AST.Atom {
105105
case .backtrackingDirective(let v): return v
106106
case .changeMatchingOptions(let v): return v
107107
case .dot: return nil
108-
case .startOfLine: return nil
109-
case .endOfLine: return nil
108+
case .caretAnchor: return nil
109+
case .dollarAnchor: return nil
110110
case .invalid: return nil
111111
}
112112
}
@@ -536,10 +536,10 @@ extension AST.Atom {
536536
case notTextSegment = #"\Y"#
537537

538538
/// ^
539-
case startOfLine = #"^"#
539+
case caretAnchor = #"^"#
540540

541541
/// $
542-
case endOfLine = #"$"#
542+
case dollarAnchor = #"$"#
543543

544544
/// \b (from outside a custom character class)
545545
case wordBoundary = #"\b"#
@@ -551,8 +551,8 @@ extension AST.Atom {
551551

552552
public var assertionKind: AssertionKind? {
553553
switch kind {
554-
case .startOfLine: return .startOfLine
555-
case .endOfLine: return .endOfLine
554+
case .caretAnchor: return .caretAnchor
555+
case .dollarAnchor: return .dollarAnchor
556556

557557
case .escaped(.wordBoundary): return .wordBoundary
558558
case .escaped(.notWordBoundary): return .notWordBoundary
@@ -806,9 +806,9 @@ extension AST.Atom {
806806
// the AST? Or defer for the matching engine?
807807
return nil
808808

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

861-
case .property, .escaped, .dot, .startOfLine, .endOfLine,
861+
case .property, .escaped, .dot, .caretAnchor, .dollarAnchor,
862862
.backreference, .subpattern, .namedCharacter, .callout,
863863
.backtrackingDirective, .changeMatchingOptions, .invalid:
864864
return nil
@@ -874,7 +874,7 @@ extension AST.Atom {
874874
// TODO: Are callouts quantifiable?
875875
case .escaped(let esc):
876876
return esc.isQuantifiable
877-
case .startOfLine, .endOfLine:
877+
case .caretAnchor, .dollarAnchor:
878878
return false
879879
default:
880880
return true

Sources/_RegexParser/Regex/Parse/LexicalAnalysis.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,8 +2074,8 @@ extension Parser {
20742074

20752075
// (sometimes) special metacharacters
20762076
case ".": return customCC ? .char(".") : .dot
2077-
case "^": return customCC ? .char("^") : .startOfLine
2078-
case "$": return customCC ? .char("$") : .endOfLine
2077+
case "^": return customCC ? .char("^") : .caretAnchor
2078+
case "$": return customCC ? .char("$") : .dollarAnchor
20792079

20802080
// Escaped
20812081
case "\\": return p.expectEscaped().value

Sources/_RegexParser/Regex/Parse/Sema.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ extension RegexValidator {
288288
at: atom.location)
289289
}
290290

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

294294
case .invalid:

Sources/_RegexParser/Regex/Printing/DumpAST.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ extension AST.Atom {
153153
case .keyboardControl, .keyboardMeta, .keyboardMetaControl:
154154
fatalError("TODO")
155155

156-
case .dot: return "."
157-
case .startOfLine: return "^"
158-
case .endOfLine: return "$"
156+
case .dot: return "."
157+
case .caretAnchor: return "^"
158+
case .dollarAnchor: return "$"
159159

160160
case .backreference(let r), .subpattern(let r):
161161
return "\(r._dumpBase)"

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fileprivate extension Compiler.ByteCodeGen {
170170
!input.isOnGraphemeClusterBoundary(pos)
171171
}
172172

173-
case .startOfLine:
173+
case .caretAnchor:
174174
// FIXME: Anchor.startOfLine must always use this first branch
175175
// The behavior of `^` should depend on `anchorsMatchNewlines`, but
176176
// the DSL-based `.startOfLine` anchor should always match the start
@@ -192,7 +192,7 @@ fileprivate extension Compiler.ByteCodeGen {
192192
}
193193
}
194194

195-
case .endOfLine:
195+
case .dollarAnchor:
196196
// FIXME: Anchor.endOfLine must always use this first branch
197197
// The behavior of `$` should depend on `anchorsMatchNewlines`, but
198198
// the DSL-based `.endOfLine` anchor should always match the end

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ extension AST.Atom {
272272
"Should have been handled by tree conversion")
273273
fatalError(".atom(.dot) is handled in emitDot")
274274

275-
case .startOfLine, .endOfLine:
275+
case .caretAnchor, .dollarAnchor:
276276
// handled in emitAssertion
277277
return nil
278278

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,11 @@ extension AST.Atom.AssertionKind {
627627
// TODO: Some way to integrate this with conversion...
628628
var _patternBase: String {
629629
switch self {
630-
case .startOfLine:
630+
case .caretAnchor:
631+
// FIXME: The DSL doesn't have a way of representing this.
631632
return "Anchor.startOfLine"
632-
case .endOfLine:
633+
case .dollarAnchor:
634+
// FIXME: The DSL doesn't have a way of representing this.
633635
return "Anchor.endOfLine"
634636
case .wordBoundary:
635637
return "Anchor.wordBoundary"
@@ -899,7 +901,7 @@ extension AST.Atom {
899901
// The DSL does not have an equivalent to '.', print as a regex.
900902
return ("/./", false)
901903

902-
case .startOfLine, .endOfLine:
904+
case .caretAnchor, .dollarAnchor:
903905
fatalError("unreachable")
904906

905907
case .backreference:
@@ -954,7 +956,7 @@ extension AST.Atom {
954956
case .dot:
955957
return "."
956958

957-
case .startOfLine, .endOfLine:
959+
case .caretAnchor, .dollarAnchor:
958960
fatalError("unreachable")
959961

960962
case .backreference:

Sources/_StringProcessing/Regex/DSLTree.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,10 @@ extension DSLTree {
801801
: .init(ast: .textSegment)
802802
}
803803
public static func startOfLine(_ inverted: Bool = false) -> Self {
804-
.init(ast: .startOfLine)
804+
.init(ast: .caretAnchor)
805805
}
806806
public static func endOfLine(_ inverted: Bool = false) -> Self {
807-
.init(ast: .endOfLine)
807+
.init(ast: .dollarAnchor)
808808
}
809809
public static func wordBoundary(_ inverted: Bool = false) -> Self {
810810
inverted

0 commit comments

Comments
 (0)