Skip to content

Commit df63ffa

Browse files
committed
Rename DSLTree.alternation to DSLTree.orderedChoice
1 parent cd3ad6d commit df63ffa

File tree

6 files changed

+34
-24
lines changed

6 files changed

+34
-24
lines changed

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ extension Compiler.ByteCodeGen {
557557
mutating func emitNode(_ node: DSLTree.Node) throws {
558558
switch node {
559559

560-
case let .alternation(children):
560+
case let .orderedChoice(children):
561561
try emitAlternation(children)
562562

563563
case let .concatenation(children):

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extension DSLTree.Node {
3636
case let .convertedRegexLiteral(n, _):
3737
return try n.generateConsumer(opts)
3838

39-
case .alternation, .conditional, .concatenation, .group,
39+
case .orderedChoice, .conditional, .concatenation, .group,
4040
.quantification, .trivia, .empty,
4141
.groupTransform, .absentFunction: return nil
4242

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension PrettyPrinter {
7373

7474
switch node {
7575

76-
case let .alternation(a):
76+
case let .orderedChoice(a):
7777
printBlock("Alternation") { printer in
7878
a.forEach {
7979
printer.printAsPattern(convertedFromAST: $0)

Sources/_StringProcessing/RegexDSL/ASTConversion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension AST.Node {
4848
switch self {
4949
case let .alternation(v):
5050
let children = v.children.map(\.dslTreeNode)
51-
return .alternation(children)
51+
return .orderedChoice(children)
5252

5353
case let .concatenation(v):
5454
// Coalesce adjacent children who can produce a

Sources/_StringProcessing/RegexDSL/DSLTree.swift

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,28 @@ struct DSLTree {
2323

2424
extension DSLTree {
2525
indirect enum Node: _TreeNode {
26-
/// ... | ... | ...
27-
case alternation([Node])
26+
/// Try to match each node in order
27+
///
28+
/// ... | ... | ...
29+
case orderedChoice([Node])
2830

29-
/// ... ...
31+
/// Match each node in sequence
32+
///
33+
/// ... ...
3034
case concatenation([Node])
3135

32-
/// (...)
36+
/// Match a subpattern / group
37+
///
38+
/// (...)
3339
case group(AST.Group.Kind, Node, ReferenceID? = nil)
3440

35-
/// (?(cond) true-branch | false-branch)
41+
// TODO: Consider splitting off grouped conditions, or have
42+
// our own kind
43+
44+
/// Match a choice of two nodes based on a condition
45+
///
46+
/// (?(cond) true-branch | false-branch)
3647
///
37-
/// TODO: Consider splitting off grouped conditions, or have our own kind
3848
case conditional(
3949
AST.Conditional.Condition.Kind, Node, Node)
4050

@@ -157,7 +167,7 @@ extension DSLTree.Node {
157167
var children: [DSLTree.Node]? {
158168
switch self {
159169

160-
case let .alternation(v): return v
170+
case let .orderedChoice(v): return v
161171
case let .concatenation(v): return v
162172

163173
case let .convertedRegexLiteral(n, _):
@@ -253,7 +263,7 @@ extension DSLTree.Node {
253263
_ constructor: inout CaptureStructure.Constructor
254264
) -> CaptureStructure {
255265
switch self {
256-
case let .alternation(children):
266+
case let .orderedChoice(children):
257267
return constructor.alternating(children)
258268

259269
case let .concatenation(children):
@@ -319,10 +329,10 @@ extension DSLTree.Node {
319329
}
320330

321331
func appendingAlternationCase(_ newNode: DSLTree.Node) -> DSLTree.Node {
322-
if case .alternation(let components) = self {
323-
return .alternation(components + [newNode])
332+
if case .orderedChoice(let components) = self {
333+
return .orderedChoice(components + [newNode])
324334
}
325-
return .alternation([self, newNode])
335+
return .orderedChoice([self, newNode])
326336
}
327337
}
328338

Sources/_StringProcessing/RegexDSL/Variadics.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,47 +2220,47 @@ public func | <R0, W0, C0, C1, C2, C3, C4, C5, C6, C7, C8, R1, W1, C9>(lhs: R0,
22202220
}
22212221
extension AlternationBuilder {
22222222
public static func buildBlock<R, W, C0>(_ regex: R) -> Regex<(W, C0?)> where R: RegexComponent, R.Match == (W, C0) {
2223-
.init(node: .alternation([regex.regex.root]))
2223+
.init(node: .orderedChoice([regex.regex.root]))
22242224
}
22252225
}
22262226
extension AlternationBuilder {
22272227
public static func buildBlock<R, W, C0, C1>(_ regex: R) -> Regex<(W, C0?, C1?)> where R: RegexComponent, R.Match == (W, C0, C1) {
2228-
.init(node: .alternation([regex.regex.root]))
2228+
.init(node: .orderedChoice([regex.regex.root]))
22292229
}
22302230
}
22312231
extension AlternationBuilder {
22322232
public static func buildBlock<R, W, C0, C1, C2>(_ regex: R) -> Regex<(W, C0?, C1?, C2?)> where R: RegexComponent, R.Match == (W, C0, C1, C2) {
2233-
.init(node: .alternation([regex.regex.root]))
2233+
.init(node: .orderedChoice([regex.regex.root]))
22342234
}
22352235
}
22362236
extension AlternationBuilder {
22372237
public static func buildBlock<R, W, C0, C1, C2, C3>(_ regex: R) -> Regex<(W, C0?, C1?, C2?, C3?)> where R: RegexComponent, R.Match == (W, C0, C1, C2, C3) {
2238-
.init(node: .alternation([regex.regex.root]))
2238+
.init(node: .orderedChoice([regex.regex.root]))
22392239
}
22402240
}
22412241
extension AlternationBuilder {
22422242
public static func buildBlock<R, W, C0, C1, C2, C3, C4>(_ regex: R) -> Regex<(W, C0?, C1?, C2?, C3?, C4?)> where R: RegexComponent, R.Match == (W, C0, C1, C2, C3, C4) {
2243-
.init(node: .alternation([regex.regex.root]))
2243+
.init(node: .orderedChoice([regex.regex.root]))
22442244
}
22452245
}
22462246
extension AlternationBuilder {
22472247
public static func buildBlock<R, W, C0, C1, C2, C3, C4, C5>(_ regex: R) -> Regex<(W, C0?, C1?, C2?, C3?, C4?, C5?)> where R: RegexComponent, R.Match == (W, C0, C1, C2, C3, C4, C5) {
2248-
.init(node: .alternation([regex.regex.root]))
2248+
.init(node: .orderedChoice([regex.regex.root]))
22492249
}
22502250
}
22512251
extension AlternationBuilder {
22522252
public static func buildBlock<R, W, C0, C1, C2, C3, C4, C5, C6>(_ regex: R) -> Regex<(W, C0?, C1?, C2?, C3?, C4?, C5?, C6?)> where R: RegexComponent, R.Match == (W, C0, C1, C2, C3, C4, C5, C6) {
2253-
.init(node: .alternation([regex.regex.root]))
2253+
.init(node: .orderedChoice([regex.regex.root]))
22542254
}
22552255
}
22562256
extension AlternationBuilder {
22572257
public static func buildBlock<R, W, C0, C1, C2, C3, C4, C5, C6, C7>(_ regex: R) -> Regex<(W, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?)> where R: RegexComponent, R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7) {
2258-
.init(node: .alternation([regex.regex.root]))
2258+
.init(node: .orderedChoice([regex.regex.root]))
22592259
}
22602260
}
22612261
extension AlternationBuilder {
22622262
public static func buildBlock<R, W, C0, C1, C2, C3, C4, C5, C6, C7, C8>(_ regex: R) -> Regex<(W, C0?, C1?, C2?, C3?, C4?, C5?, C6?, C7?, C8?)> where R: RegexComponent, R.Match == (W, C0, C1, C2, C3, C4, C5, C6, C7, C8) {
2263-
.init(node: .alternation([regex.regex.root]))
2263+
.init(node: .orderedChoice([regex.regex.root]))
22642264
}
22652265
}
22662266
// MARK: - Non-builder capture arity 0

0 commit comments

Comments
 (0)