Skip to content

Commit fb53d30

Browse files
committed
Rebasing on main
1 parent 42f1a66 commit fb53d30

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

Sources/_MatchingEngine/Regex/DSLTree.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ extension DSLTree {
3636
case stringLiteral(String)
3737

3838
/// An embedded literal
39-
case regexLiteral(AST)
39+
case regexLiteral(AST.Node)
4040

4141
// MARK: - Tree conversions
4242

4343
/// The target of AST conversion.
4444
///
4545
/// Keeps original AST around for rich syntatic and source information
46-
case convertedRegexLiteral(Node, AST)
46+
case convertedRegexLiteral(Node, AST.Node)
4747

4848
// Fall-back for when conversion fails
49-
case unconvertedRegexLiteral(AST)
49+
case unconvertedRegexLiteral(AST.Node)
5050

5151
// MARK: - Extensibility points
5252

@@ -142,7 +142,7 @@ extension DSLTree.Node {
142142
}
143143

144144
extension DSLTree.Node {
145-
var ast: AST? {
145+
var astNode: AST.Node? {
146146
switch self {
147147
case let .regexLiteral(ast): return ast
148148
case let .unconvertedRegexLiteral(ast): return ast
@@ -152,7 +152,7 @@ extension DSLTree.Node {
152152
}
153153
}
154154

155-
extension AST {
155+
extension AST.Node {
156156
/// Converts an AST node to a `convertedRegexLiteral` node.
157157
var dslTreeNode: DSLTree.Node {
158158
func wrap(_ node: DSLTree.Node) -> DSLTree.Node {
@@ -258,6 +258,10 @@ extension AST {
258258
let child = v.child.dslTreeNode
259259
return .groupTransform(
260260
v.kind.value, child, transform)
261+
262+
case .absentFunction:
263+
// TODO: What should this map to?
264+
return .unconvertedRegexLiteral(self)
261265
}
262266
}
263267

Sources/_MatchingEngine/Regex/Printing/PrintAsPattern.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ extension PrettyPrinter {
4343
return false
4444
}
4545

46+
mutating func printBackoff(_ node: DSLTree.Node) {
47+
precondition(node.astNode != nil, "unconverted node")
48+
printAsCanonical(
49+
.init(node.astNode!, globalOptions: nil),
50+
delimiters: true)
51+
}
52+
4653
mutating func printAsPattern(_ ast: AST) {
4754
// TODO: Handle global options...
4855
let node = ast.root.dslTreeNode
@@ -58,8 +65,7 @@ extension PrettyPrinter {
5865
convertedFromAST node: DSLTree.Node
5966
) {
6067
if patternBackoff(node) {
61-
precondition(node.ast != nil, "unconverted node")
62-
printAsCanonical(node.ast!, delimiters: true)
68+
printBackoff(node)
6369
return
6470
}
6571

@@ -80,6 +86,7 @@ extension PrettyPrinter {
8086
}
8187

8288
case let .group(kind, child):
89+
let kind = kind._patternBase
8390
printBlock("Group(\(kind))") { printer in
8491
printer.printAsPattern(convertedFromAST: child)
8592
}
@@ -119,10 +126,8 @@ extension PrettyPrinter {
119126
case let .stringLiteral(v):
120127
print(v._quoted)
121128

122-
case let .regexLiteral(v):
123-
printAsCanonical(v, delimiters: true)
124-
case let .unconvertedRegexLiteral(v):
125-
printAsCanonical(v, delimiters: true)
129+
case .regexLiteral, .unconvertedRegexLiteral:
130+
printBackoff(node)
126131

127132
case let .convertedRegexLiteral(n, _):
128133
// FIXME: This recursion coordinates with back-off

0 commit comments

Comments
 (0)