Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions Sources/_StringProcessing/ByteCodeGen+DSLList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
internal import _RegexParser

extension Compiler.ByteCodeGen {
mutating func emitRoot(_ root: DSLList) throws -> MEProgram {
mutating func emitRoot(_ root: inout DSLList) throws -> MEProgram {
// If the whole regex is a matcher, then the whole-match value
// is the constructed value. Denote that the current value
// register is the processor's value output.
Expand All @@ -22,7 +22,11 @@ extension Compiler.ByteCodeGen {
default:
break
}


if optimizationsEnabled {
root.autoPossessify()
}

var list = root.nodes[...]
try emitNode(&list)

Expand Down Expand Up @@ -352,15 +356,7 @@ fileprivate extension Compiler.ByteCodeGen {
_ kind: DSLTree.QuantificationKind,
_ list: inout ArraySlice<DSLTree.Node>
) throws {
let updatedKind: AST.Quantification.Kind
switch kind {
case .explicit(let kind):
updatedKind = kind.ast
case .syntax(let kind):
updatedKind = kind.ast.applying(options)
case .default:
updatedKind = options.defaultQuantificationKind
}
let updatedKind = kind.applying(options: options)

let (low, high) = amount.bounds
guard let low = low else {
Expand Down
10 changes: 1 addition & 9 deletions Sources/_StringProcessing/ByteCodeGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -506,15 +506,7 @@ extension Compiler.ByteCodeGen {
_ kind: DSLTree.QuantificationKind,
_ child: DSLTree.Node
) throws {
let updatedKind: AST.Quantification.Kind
switch kind {
case .explicit(let kind):
updatedKind = kind.ast
case .syntax(let kind):
updatedKind = kind.ast.applying(options)
case .default:
updatedKind = options.defaultQuantificationKind
}
let updatedKind = kind.applying(options: options)

let (low, high) = amount.bounds
guard let low = low else {
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/Compiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ class Compiler {

__consuming func emitViaList() throws -> MEProgram {
// TODO: Handle global options
let dslList = DSLList(tree: tree)
var dslList = DSLList(tree: tree)
var codegen = ByteCodeGen(
options: options,
compileOptions:
compileOptions,
captureList: tree.captureList)
return try codegen.emitRoot(dslList)
return try codegen.emitRoot(&dslList)
}
}

Expand Down
15 changes: 9 additions & 6 deletions Sources/_StringProcessing/LiteralPrinter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,16 @@ extension LiteralPrinter {
}

mutating func outputQuantificationKind(_ kind: DSLTree.QuantificationKind) {
switch kind {
case .`default`:
guard let astKind = kind.quantificationKind?.ast else {
// We can treat this as if the current default had been given explicity.
outputQuantificationKind(
.explicit(.init(ast: options.defaultQuantificationKind)))
case let .explicit(kind):
switch kind.ast {
return
}

if kind.isExplicit {
// Explicitly provided modifiers need to match the current option state.
switch astKind {
case .eager:
output(options.isReluctantByDefault ? "?" : "")
case .reluctant:
Expand All @@ -242,9 +245,9 @@ extension LiteralPrinter {
fatalError()
#endif
}
case let .syntax(kind):
} else {
// Syntactically-specified quantification modifiers can stay as-is.
switch kind.ast {
switch astKind {
case .eager:
output("")
case .reluctant:
Expand Down
Loading