Skip to content

Commit 3c5ba0f

Browse files
authored
Rename 'greedy' to 'eager' and 'modern syntax' to 'experimental syntax' (swiftlang#89)
* Rename 'modern' to 'experimental' * Rename 'greedy' to 'eager'
1 parent 2244c53 commit 3c5ba0f

13 files changed

+109
-109
lines changed

Sources/_MatchingEngine/Regex/AST/Quantification.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extension AST {
2929
}
3030

3131
public enum Kind: String, Hashable {
32-
case greedy = ""
32+
case eager = ""
3333
case reluctant = "?"
3434
case possessive = "+"
3535
}
@@ -69,7 +69,7 @@ extension AST.Quantification.Kind: _ASTPrintable {
6969
public var _printBase: String { rawValue }
7070
public var _dumpBase: String {
7171
switch self {
72-
case .greedy: return "greedy"
72+
case .eager: return "eager"
7373
case .reluctant: return "reluctant"
7474
case .possessive: return "possessive"
7575
}

Sources/_MatchingEngine/Regex/Parse/LexicalAnalysis.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ extension Source {
281281
let kind: Located<Quant.Kind> = recordLoc { src in
282282
if src.tryEat("?") { return .reluctant }
283283
if src.tryEat("+") { return .possessive }
284-
return .greedy
284+
return .eager
285285
}
286286

287287
return (amt, kind)
@@ -290,8 +290,8 @@ extension Source {
290290
/// Consume a range
291291
///
292292
/// Range -> ',' <Int> | <Int> ',' <Int>? | <Int>
293-
/// | ModernRange
294-
/// ModernRange -> '..<' <Int> | '...' <Int>
293+
/// | ExpRange
294+
/// ExpRange -> '..<' <Int> | '...' <Int>
295295
/// | <Int> '..<' <Int> | <Int> '...' <Int>?
296296
mutating func expectRange() throws -> Located<Quant.Amount> {
297297
try recordLoc { src in
@@ -303,7 +303,7 @@ extension Source {
303303
let closedRange: Bool?
304304
if src.tryEat(",") {
305305
closedRange = true
306-
} else if src.modernRanges && src.tryEat(".") {
306+
} else if src.experimentalRanges && src.tryEat(".") {
307307
try src.expect(".")
308308
if src.tryEat(".") {
309309
closedRange = true
@@ -374,11 +374,11 @@ extension Source {
374374
///
375375
/// Quote -> '\Q' (!'\E' .)* '\E'
376376
///
377-
/// With `SyntaxOptions.modernQuotes`, also accepts
377+
/// With `SyntaxOptions.experimentalQuotes`, also accepts
378378
///
379-
/// ModernQuote -> '"' [^"]* '"'
379+
/// ExpQuote -> '"' [^"]* '"'
380380
///
381-
/// Future: Modern quotes are full fledged Swift string literals
381+
/// Future: Experimental quotes are full fledged Swift string literals
382382
///
383383
/// TODO: Need to support some escapes
384384
///
@@ -387,7 +387,7 @@ extension Source {
387387
if src.tryEat(sequence: #"\Q"#) {
388388
return try src.expectQuoted(endingWith: #"\E"#).value
389389
}
390-
if src.modernQuotes, src.tryEat("\"") {
390+
if src.experimentalQuotes, src.tryEat("\"") {
391391
// TODO: escaped `"`, etc...
392392
return try src.expectQuoted(endingWith: "\"").value
393393
}
@@ -399,9 +399,9 @@ extension Source {
399399
///
400400
/// Comment -> '(?#' [^')']* ')'
401401
///
402-
/// With `SyntaxOptions.modernComments`
402+
/// With `SyntaxOptions.experimentalComments`
403403
///
404-
/// ModernComment -> '/*' (!'*/' .)* '*/'
404+
/// ExpComment -> '/*' (!'*/' .)* '*/'
405405
///
406406
/// TODO: Swift-style nested comments, line-ending comments, etc
407407
///
@@ -410,7 +410,7 @@ extension Source {
410410
if src.tryEat(sequence: "(?#") {
411411
return try src.expectQuoted(endingWith: ")").value
412412
}
413-
if src.modernComments, src.tryEat(sequence: "/*") {
413+
if src.experimentalComments, src.tryEat(sequence: "/*") {
414414
return try src.expectQuoted(endingWith: "*/").value
415415
}
416416
return nil
@@ -439,9 +439,9 @@ extension Source {
439439
/// Named -> '<' [^'>']+ '>' | 'P<' [^'>']+ '>'
440440
/// | '\'' [^'\'']+ '\''
441441
///
442-
/// If `SyntaxOptions.modernGroups` is enabled, also accepts:
442+
/// If `SyntaxOptions.experimentalGroups` is enabled, also accepts:
443443
///
444-
/// ModernGroupStart -> '(_:'
444+
/// ExpGroupStart -> '(_:'
445445
///
446446
/// Future: Named groups of the form `(name: ...)`
447447
///
@@ -519,7 +519,7 @@ extension Source {
519519
}
520520

521521
// (_:)
522-
if src.modernCaptures && src.tryEat(sequence: "_:") {
522+
if src.experimentalCaptures && src.tryEat(sequence: "_:") {
523523
return .nonCapture
524524
}
525525
// TODO: (name:)
@@ -699,9 +699,9 @@ extension Source {
699699
/// SpecialCharacter -> '.' | '^' | '$'
700700
/// POSIXSet -> '[:' name ':]'
701701
///
702-
/// If `SyntaxOptions.nonSemanticWhitespace` is enabled, also accepts:
702+
/// If `SyntaxOptions.experimentalGroups` is enabled, also accepts:
703703
///
704-
/// ModernGroupStart -> '(_:'
704+
/// ExpGroupStart -> '(_:'
705705
///
706706
mutating func lexAtom(
707707
isInCustomCharacterClass customCC: Bool

Sources/_MatchingEngine/Regex/Parse/Mocking.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// TODO: mock up multi-line soon
33

44
enum Delimiter: Hashable, CaseIterable {
5-
case regular
6-
case modern
5+
case traditional
6+
case experimental
77

88
var openingAndClosing: (opening: String, closing: String) {
99
switch self {
10-
case .regular: return ("'/", "/'")
11-
case .modern: return ("'|", "|'")
10+
case .traditional: return ("'/", "/'")
11+
case .experimental: return ("'|", "|'")
1212
}
1313
}
1414
var opening: String { openingAndClosing.opening }
@@ -17,8 +17,8 @@ enum Delimiter: Hashable, CaseIterable {
1717
/// The default set of syntax options that the delimiter indicates.
1818
var defaultSyntaxOptions: SyntaxOptions {
1919
switch self {
20-
case .regular: return .traditional
21-
case .modern: return .modern
20+
case .traditional: return .traditional
21+
case .experimental: return .experimental
2222
}
2323
}
2424
}

Sources/_MatchingEngine/Regex/Parse/Source.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ extension Source {
3333
// MARK: - Syntax
3434

3535
extension Source {
36-
var modernRanges: Bool { syntax.contains(.modernRanges) }
37-
var modernCaptures: Bool { syntax.contains(.modernCaptures) }
38-
var modernQuotes: Bool { syntax.contains(.modernQuotes) }
39-
var modernComments: Bool { syntax.contains(.modernComments) }
36+
var experimentalRanges: Bool { syntax.contains(.experimentalRanges) }
37+
var experimentalCaptures: Bool { syntax.contains(.experimentalCaptures) }
38+
var experimentalQuotes: Bool { syntax.contains(.experimentalQuotes) }
39+
var experimentalComments: Bool { syntax.contains(.experimentalComments) }
4040
var nonSemanticWhitespace: Bool {
4141
syntax.contains(.nonSemanticWhitespace)
4242
}

Sources/_MatchingEngine/Regex/Parse/SyntaxOptions.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ public struct SyntaxOptions: OptionSet {
1616
///
1717
/// NOTE: Currently, this means we have raw quotes.
1818
/// Better would be to have real Swift string delimiter parsing logic.
19-
public static var modernQuotes: Self { Self(1 << 1) }
19+
public static var experimentalQuotes: Self { Self(1 << 1) }
2020

2121
/// `'a /* comment */ b' == '/a(?#. comment )b/'`
2222
///
2323
/// NOTE: traditional comments are not nested. Currently, we are neither.
2424
/// Traditional comments can't have `)`, not even escaped in them either, we
2525
/// can. Traditional comments can have `*/` in them, we can't without
2626
/// escaping. We don't currently do escaping.
27-
public static var modernComments: Self { Self(1 << 2) }
27+
public static var experimentalComments: Self { Self(1 << 2) }
2828

2929
/// ```
3030
/// 'a{n...m}' == '/a{n,m}/'
@@ -33,22 +33,22 @@ public struct SyntaxOptions: OptionSet {
3333
/// 'a{...m}' == '/a{,m}/'
3434
/// 'a{..<m}' == '/a{,m-1}/'
3535
/// ```
36-
public static var modernRanges: Self { Self(1 << 3) }
36+
public static var experimentalRanges: Self { Self(1 << 3) }
3737

3838
/// `(name: .*)` == `(?<name>.*)`
3939
/// `(_: .*)` == `(?:.*)`
40-
public static var modernCaptures: Self { Self(1 << 4) }
40+
public static var experimentalCaptures: Self { Self(1 << 4) }
4141

4242
/*
4343

4444
/// `<digit>*` == `[[:digit:]]*` == `\d*`
45-
public static var modernConsumers
45+
public static var experimentalConsumers
4646

4747
*/
4848

4949
public static var traditional: Self { Self(0) }
5050

51-
public static var modern: Self { Self(~0) }
51+
public static var experimental: Self { Self(~0) }
5252

5353
public var ignoreWhitespace: Bool {
5454
contains(.nonSemanticWhitespace)

Sources/_StringProcessing/ASTBuilder.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -88,53 +88,53 @@ public func atomicScriptRun(_ child: AST) -> AST {
8888

8989
func quant(
9090
_ amount: AST.Quantification.Amount,
91-
_ kind: AST.Quantification.Kind = .greedy,
91+
_ kind: AST.Quantification.Kind = .eager,
9292
_ child: AST
9393
) -> AST {
9494
.quantification(.init(
9595
.init(faking: amount), .init(faking: kind), child, .fake))
9696
}
9797
func zeroOrMore(
98-
_ kind: AST.Quantification.Kind = .greedy,
98+
_ kind: AST.Quantification.Kind = .eager,
9999
_ child: AST
100100
) -> AST {
101101
quant(.zeroOrMore, kind, child)
102102
}
103103
func zeroOrOne(
104-
_ kind: AST.Quantification.Kind = .greedy,
104+
_ kind: AST.Quantification.Kind = .eager,
105105
_ child: AST
106106
) -> AST {
107107
quant(.zeroOrOne, kind, child)
108108
}
109109
func oneOrMore(
110-
_ kind: AST.Quantification.Kind = .greedy,
110+
_ kind: AST.Quantification.Kind = .eager,
111111
_ child: AST
112112
) -> AST {
113113
quant(.oneOrMore, kind, child)
114114
}
115115
func exactly(
116-
_ kind: AST.Quantification.Kind = .greedy,
116+
_ kind: AST.Quantification.Kind = .eager,
117117
_ i: Int,
118118
_ child: AST
119119
) -> AST {
120120
quant(.exactly(.init(faking: i)), kind, child)
121121
}
122122
func nOrMore(
123-
_ kind: AST.Quantification.Kind = .greedy,
123+
_ kind: AST.Quantification.Kind = .eager,
124124
_ i: Int,
125125
_ child: AST
126126
) -> AST {
127127
quant(.nOrMore(.init(faking: i)), kind, child)
128128
}
129129
func upToN(
130-
_ kind: AST.Quantification.Kind = .greedy,
130+
_ kind: AST.Quantification.Kind = .eager,
131131
_ i: Int,
132132
_ child: AST
133133
) -> AST {
134134
quant(.upToN(.init(faking: i)), kind, child)
135135
}
136136
func quantRange(
137-
_ kind: AST.Quantification.Kind = .greedy,
137+
_ kind: AST.Quantification.Kind = .eager,
138138
_ r: ClosedRange<Int>,
139139
_ child: AST
140140
) -> AST {

Sources/_StringProcessing/Compiler.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class Compiler {
153153
// <code for component>
154154
// branch start
155155
// end:
156-
case (.zeroOrMore, .greedy):
156+
case (.zeroOrMore, .eager):
157157
let end = builder.makeAddress()
158158
let start = builder.makeAddress()
159159
builder.label(start)
@@ -168,7 +168,7 @@ class Compiler {
168168
// save end
169169
// branch element
170170
// end:
171-
case (.oneOrMore, .greedy):
171+
case (.oneOrMore, .eager):
172172
let element = builder.makeAddress()
173173
let end = builder.makeAddress()
174174
builder.label(element)
@@ -181,7 +181,7 @@ class Compiler {
181181
// save end
182182
// <code for component>
183183
// end:
184-
case (.zeroOrOne, .greedy):
184+
case (.zeroOrOne, .eager):
185185
let end = builder.makeAddress()
186186
builder.buildSave(end)
187187
try emit(child)

Sources/_StringProcessing/Legacy/LegacyCompile.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func compile(
8080
case .quantification(let quant):
8181
let child = quant.child
8282
switch (quant.amount.value, quant.kind.value) {
83-
case (.zeroOrMore, .greedy):
83+
case (.zeroOrMore, .eager):
8484
// a* ==> L_START, <split L_DONE>, a, goto L_START, L_DONE
8585
let childHasCaptures = child.hasCapture
8686
if childHasCaptures {
@@ -122,7 +122,7 @@ func compile(
122122
}
123123
return
124124

125-
case (.zeroOrOne, .greedy):
125+
case (.zeroOrOne, .eager):
126126
// a? ==> <split L_DONE> a, L_DONE
127127
if child.hasCapture {
128128
instructions.append(.beginGroup)
@@ -176,7 +176,7 @@ func compile(
176176
}
177177
return
178178

179-
case (.oneOrMore, .greedy):
179+
case (.oneOrMore, .eager):
180180
// a+ ==> L_START, a, <split L_DONE>, goto L_START, L_DONE
181181
let childHasCaptures = child.hasCapture
182182
if childHasCaptures {

Sources/_StringProcessing/RegexDSL/DSL.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public struct OneOrMore<Component: RegexProtocol>: RegexProtocol {
5353

5454
public init(_ component: Component) {
5555
self.regex = .init(ast:
56-
oneOrMore(.greedy, component.regex.ast)
56+
oneOrMore(.eager, component.regex.ast)
5757
)
5858
}
5959

@@ -75,7 +75,7 @@ public struct Repeat<Component: RegexProtocol>: RegexProtocol {
7575

7676
public init(_ component: Component) {
7777
self.regex = .init(ast:
78-
zeroOrMore(.greedy, component.regex.ast))
78+
zeroOrMore(.eager, component.regex.ast))
7979
}
8080

8181
public init(@RegexBuilder _ content: () -> Component) {
@@ -96,7 +96,7 @@ public struct Optionally<Component: RegexProtocol>: RegexProtocol {
9696

9797
public init(_ component: Component) {
9898
self.regex = .init(ast:
99-
zeroOrOne(.greedy, component.regex.ast))
99+
zeroOrOne(.eager, component.regex.ast))
100100
}
101101

102102
public init(@RegexBuilder _ content: () -> Component) {

Tests/RegexTests/LegacyTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ extension RegexTests {
377377
expectedCaptureType: (Substring, Substring).self,
378378
expecting: .init(captures: ("bb", "d"), capturesEqual: ==))
379379

380-
// Greedy vs lazy quantifiers
380+
// Eager vs reluctant quantifiers
381381
performTest(
382382
regex: "a(.*)(c+).*(e+)", input: "abbbbccccddddeeee",
383383
expectedCaptureType: (Substring, Substring, Substring).self,

Tests/RegexTests/LexTests.swift

+9-9
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,19 @@ extension RegexTests {
9292

9393
func testCompilerInterface() {
9494
let testCases: [(String, (String, Delimiter)?)] = [
95-
("'/abc/'", ("abc", .regular)),
96-
("'|abc|'", ("abc", .modern)),
95+
("'/abc/'", ("abc", .traditional)),
96+
("'|abc|'", ("abc", .experimental)),
9797

9898
// TODO: Null characters are lexically valid, similar to string literals,
9999
// but we ought to warn the user about them.
100-
("'|ab\0c|'", ("ab\0c", .modern)),
100+
("'|ab\0c|'", ("ab\0c", .experimental)),
101101
("'abc'", nil),
102-
("'/abc/def/'", ("abc/def", .regular)),
103-
("'|abc|def|'", ("abc|def", .modern)),
104-
("'/abc\\/'def/'", ("abc\\/'def", .regular)),
105-
("'|abc\\|'def|'", ("abc\\|'def", .modern)),
106-
("'/abc|'def/'", ("abc|'def", .regular)),
107-
("'|abc/'def|'", ("abc/'def", .modern)),
102+
("'/abc/def/'", ("abc/def", .traditional)),
103+
("'|abc|def|'", ("abc|def", .experimental)),
104+
("'/abc\\/'def/'", ("abc\\/'def", .traditional)),
105+
("'|abc\\|'def|'", ("abc\\|'def", .experimental)),
106+
("'/abc|'def/'", ("abc|'def", .traditional)),
107+
("'|abc/'def|'", ("abc/'def", .experimental)),
108108
("'/abc|'def/", nil),
109109
("'|abc/'def'", nil),
110110
("'/abc\n/'", nil),

0 commit comments

Comments
 (0)