Skip to content

Commit 55ca29c

Browse files
committed
Base DSL on DSLTree
1 parent 8fb4647 commit 55ca29c

File tree

10 files changed

+2187
-2098
lines changed

10 files changed

+2187
-2098
lines changed

Sources/VariadicsGenerator/VariadicsGenerator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,13 @@ struct VariadicsGenerator: ParsableCommand {
251251
output(" init(")
252252
outputForEach(0..<arity, separator: ", ") { "_ x\($0): T\($0)" }
253253
output(") {\n")
254-
output(" \(patternProtocolRequirementName) = .init(ast: concat(\n ")
254+
output(" \(patternProtocolRequirementName) = .init(node: .concatenation([\n ")
255255
outputForEach(
256256
0..<arity, separator: ", ", lineTerminator: ""
257257
) { i in
258-
"x\(i).\(patternProtocolRequirementName).ast.root"
258+
"x\(i).\(patternProtocolRequirementName).root"
259259
}
260-
output("))\n")
260+
output("]))\n")
261261
output(" }\n}\n\n")
262262

263263
// Emit concatenation builders.

Sources/_StringProcessing/ByteCodeGen.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,13 @@ extension Compiler.ByteCodeGen {
287287
let (low, high) = amount.bounds
288288
switch (low, high) {
289289
case (_, 0):
290-
throw Unsupported(
291-
"TODO: Should error out earlier, maybe DSL and parser has validation logic?")
290+
// TODO: Should error out earlier, maybe DSL and parser
291+
// has validation logic?
292+
return
292293
case let (n, m?) where n > m:
293-
throw Unsupported(
294-
"TODO: Should error out earlier, maybe DSL and parser has validation logic?")
294+
// TODO: Should error out earlier, maybe DSL and parser
295+
// has validation logic?
296+
return
295297

296298
case let (n, m) where m == nil || n <= m!:
297299
// Ok
@@ -505,7 +507,7 @@ extension Compiler.ByteCodeGen {
505507
case let .atom(a):
506508
try emitAtom(a)
507509

508-
case let .stringLiteral(s):
510+
case let .quotedLiteral(s):
509511
// TODO: Should this incorporate options?
510512
builder.buildMatchSequence(s)
511513

Sources/_StringProcessing/Compiler.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ struct RegexProgram {
1717
}
1818

1919
class Compiler {
20-
let ast: AST
20+
let tree: DSLTree
21+
22+
// TODO: Or are these stored on the tree?
2123
var options = MatchingOptions()
2224

2325
init(ast: AST) {
24-
self.ast = ast
26+
self.tree = ast.dslTree
27+
}
28+
29+
init(tree: DSLTree) {
30+
self.tree = tree
2531
}
2632

2733
__consuming func emit() throws -> RegexProgram {
2834
// TODO: Handle global options
29-
let converted = ast.root.dslTreeNode
30-
3135
var codegen = ByteCodeGen(options: options)
32-
try codegen.emitNode(converted)
36+
try codegen.emitNode(tree.root)
3337
let program = codegen.finish()
3438
return RegexProgram(program: program)
3539
}

Sources/_StringProcessing/ConsumerInterface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extension DSLTree.Node {
5656
case .customCharacterClass(let ccc):
5757
return try ccc.generateConsumer(opts)
5858

59-
case .stringLiteral:
59+
case .quotedLiteral:
6060
// TODO: Should we handle this here?
6161
return nil
6262

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ extension PrettyPrinter {
133133
case .empty:
134134
print("")
135135

136-
case let .stringLiteral(v):
136+
case let .quotedLiteral(v):
137137
print(v._quoted)
138138

139139
case .regexLiteral:

0 commit comments

Comments
 (0)