Skip to content

Commit 5ca5c4f

Browse files
committed
works, we just back off a little early
1 parent c8c4dc8 commit 5ca5c4f

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

Sources/_MatchingEngine/Regex/DSLTree.swift

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ extension DSLTree {
2121
AST.Quantification.Kind,
2222
Node)
2323

24+
case customCharacterClass(CustomCharacterClass)
25+
2426
/// Comments, non-semantic whitespace, etc
2527
// TODO: Do we want this? Could be interesting
2628
case trivia(String)
@@ -34,11 +36,16 @@ extension DSLTree {
3436
/// An embedded literal
3537
case regexLiteral(AST)
3638

39+
// MARK: - Tree conversions
40+
3741
/// The target of AST conversion.
3842
///
3943
/// Keeps original AST around for rich syntatic and source information
4044
case convertedRegexLiteral(Node, AST)
4145

46+
// Fall-back for when conversion fails
47+
case unconvertedRegexLiteral(AST)
48+
4249
// MARK: - Extensibility points
4350

4451
/// A capturing group (TODO: is it?) with a transformation function
@@ -51,7 +58,19 @@ extension DSLTree {
5158

5259
case consumerValidator(_ConsumerValidatorInterface)
5360

54-
case customCharacterClass(_CharacterPredicateInterface)
61+
// TODO: Would this just boil down to a consumer?
62+
case characterPredicate(_CharacterPredicateInterface)
63+
}
64+
}
65+
66+
extension DSLTree {
67+
enum CustomCharacterClass {
68+
// TODO: Still need to convert atoms
69+
case members([AST.Atom])
70+
71+
indirect case intersection(Self, Self)
72+
indirect case subtraction(Self, Self)
73+
indirect case symmetricDifference(Self, Self)
5574
}
5675
}
5776

@@ -99,8 +118,8 @@ extension DSLTree.Node {
99118
case let .conditional(_, t, f): return [t,f]
100119

101120
case .trivia, .empty, .stringLiteral, .regexLiteral,
102-
.consumer, .consumerValidator,
103-
.customCharacterClass:
121+
.consumer, .consumerValidator, .characterPredicate,
122+
.customCharacterClass, .unconvertedRegexLiteral:
104123
return []
105124
}
106125
}
@@ -109,7 +128,8 @@ extension DSLTree.Node {
109128
extension DSLTree.Node {
110129
var ast: AST? {
111130
switch self {
112-
case let .regexLiteral(ast): return ast
131+
case let .regexLiteral(ast): return ast
132+
case let .unconvertedRegexLiteral(ast): return ast
113133
case let .convertedRegexLiteral(_, ast): return ast
114134
default: return nil
115135
}
@@ -180,6 +200,7 @@ extension AST {
180200
children.append(.stringLiteral(str))
181201
} else {
182202
children.append(astChildren[curIdx].dslTreeNode)
203+
children.formIndex(after: &curIdx)
183204
}
184205
}
185206
return .concatenation(children)
@@ -210,15 +231,13 @@ extension AST {
210231
return .stringLiteral(str)
211232
}
212233

213-
// TODO: Should we bottom out here or do something
214-
// else? We probably want to rewrite built-in
215-
// character classes, etc
234+
// TODO: More conversions
235+
return .unconvertedRegexLiteral(self)
216236

217-
return .regexLiteral(self)
237+
case .customCharacterClass(_):
218238

219-
case let .customCharacterClass(v):
220-
// FIXME: What should we do here?
221-
fatalError("TODO \(v)")
239+
// TODO: More conversions
240+
return .unconvertedRegexLiteral(self)
222241

223242
case .empty(_):
224243
return .empty

Sources/_MatchingEngine/Regex/Printing/PrintAsPattern.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ extension PrettyPrinter {
102102

103103
case let .stringLiteral(v):
104104
print(v._quoted)
105+
105106
case let .regexLiteral(v):
106107
printAsCanonical(v, delimiters: true)
108+
case let .unconvertedRegexLiteral(v):
109+
printAsCanonical(v, delimiters: true)
107110

108111
case let .convertedRegexLiteral(n, _):
109112
// FIXME: This recursion coordinates with back-off
@@ -112,14 +115,18 @@ extension PrettyPrinter {
112115
// label is a lie.
113116
printAsPattern(convertedFromAST: n)
114117

118+
case .customCharacterClass:
119+
print("/* TODO: custom character class */")
120+
115121
case .groupTransform:
116122
print("/* TODO: group transforms */")
117123
case .consumer:
118124
print("/* TODO: consumers */")
119125
case .consumerValidator:
120126
print("/* TODO: consumer validators */")
121-
case .customCharacterClass:
122-
print("/* TODO: custom character class */")
127+
case .characterPredicate:
128+
print("/* TODO: character predicates */")
129+
123130
}
124131
}
125132

0 commit comments

Comments
 (0)