Skip to content
Merged
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
68 changes: 32 additions & 36 deletions Sources/_StringProcessing/ByteCodeGen+DSLList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ fileprivate extension Compiler.ByteCodeGen {
return nil

// In an alternation, all of its children must match only at start.
case .orderedChoice(let children):
for _ in 0..<children.count {
case .orderedChoice(let count):
for _ in 0..<count {
guard _canOnlyMatchAtStartImpl(&list) == true else {
return false
}
}
return true
case .concatenation(let children):

case .concatenation(let count):
// In a concatenation, the first definitive child provides the answer.
var i = 0
var found = false
while i < children.count {
while i < count {
i += 1
if let result = _canOnlyMatchAtStartImpl(&list) {
found = result
Expand All @@ -94,14 +94,14 @@ fileprivate extension Compiler.ByteCodeGen {
}
// Once a definitive answer has been found, skip the rest of the nodes
// in the concatenation.
while i < children.count {
while i < count {
i += 1
try? skipNode(&list, preservingCaptures: false)
}
return found

// Groups (and other parent nodes) defer to the child.
case .nonCapturingGroup(let kind, _):
case .nonCapturingGroup(let kind):
// Don't let a negative lookahead affect this - need to continue to next sibling
if kind.isNegativeLookahead {
try? skipNode(&list, preservingCaptures: false)
Expand All @@ -122,7 +122,7 @@ fileprivate extension Compiler.ByteCodeGen {

// A quantification that doesn't require its child to exist can still
// allow a start-only match. (e.g. `/(foo)?^bar/`)
case .quantification(let amount, _, _):
case .quantification(let amount, _):
if amount.requiresAtLeastOne {
return _canOnlyMatchAtStartImpl(&list)
} else {
Expand Down Expand Up @@ -356,17 +356,17 @@ fileprivate extension Compiler.ByteCodeGen {
let node = list[position]
position += 1
switch node {
case .orderedChoice(let children):
return (0..<children.count).allSatisfy { _ in
case .orderedChoice(let count):
return (0..<count).allSatisfy { _ in
_guaranteesForwardProgressImpl(list, position: &position)
}
case .concatenation(let children):
return (0..<children.count).contains { _ in
case .concatenation(let count):
return (0..<count).contains { _ in
_guaranteesForwardProgressImpl(list, position: &position)
}
case .capture(_, _, _, _):
case .capture(_, _, _):
return _guaranteesForwardProgressImpl(list, position: &position)
case .nonCapturingGroup(let kind, _):
case .nonCapturingGroup(let kind):
switch kind.ast {
case .lookahead, .negativeLookahead, .lookbehind, .negativeLookbehind:
return false
Expand All @@ -382,14 +382,14 @@ fileprivate extension Compiler.ByteCodeGen {
}
case .trivia, .empty:
return false
case .quotedLiteral(let string):
case .quotedLiteral(let string, _):
return !string.isEmpty
case .consumer, .matcher:
// Allow zero width consumers and matchers
return false
case .customCharacterClass(let ccc):
return ccc.guaranteesForwardProgress
case .quantification(let amount, _, _):
case .quantification(let amount, _):
let (atLeast, _) = amount.ast.bounds
if let atLeast, atLeast > 0 {
return _guaranteesForwardProgressImpl(list, position: &position)
Expand Down Expand Up @@ -719,7 +719,7 @@ fileprivate extension Compiler.ByteCodeGen {
} else {
return false
}
case .nonCapturingGroup(let groupKind, _):
case .nonCapturingGroup(let groupKind):
// .nonCapture nonCapturingGroups are ignored during compilation
guard groupKind.ast == .nonCapture else {
return false
Expand Down Expand Up @@ -751,15 +751,13 @@ fileprivate extension Compiler.ByteCodeGen {
guard let node = list.popFirst() else { return nil }
switch node {

case let .orderedChoice(children):
let n = children.count
case let .orderedChoice(n):
try emitAlternation(&list, alternationCount: n)

case let .concatenation(children):
let n = children.count

case let .concatenation(n):
try emitConcatenation(&list, componentCount: n)

case let .capture(name, refId, _, transform):
case let .capture(name, refId, transform):
options.beginScope()
defer { options.endScope() }

Expand Down Expand Up @@ -793,19 +791,19 @@ fileprivate extension Compiler.ByteCodeGen {
builder.buildTransformCapture(cap, fn)
}

case let .nonCapturingGroup(kind, _):
case let .nonCapturingGroup(kind):
try emitNoncapturingGroup(kind.ast, &list)

case .ignoreCapturesInTypedOutput(_):
case .ignoreCapturesInTypedOutput:
try emitNode(&list)

case .limitCaptureNesting(_):
case .limitCaptureNesting:
return try emitNode(&list)

case .conditional:
throw Unsupported("Conditionals")

case let .quantification(amt, kind, _):
case let .quantification(amt, kind):
try emitQuantification(amt.ast, kind, &list)

case let .customCharacterClass(ccc):
Expand All @@ -822,7 +820,7 @@ fileprivate extension Compiler.ByteCodeGen {
case let .atom(a):
try emitAtom(a)

case let .quotedLiteral(s):
case let .quotedLiteral(s, _):
emitQuotedLiteral(s)

case .absentFunction:
Expand Down Expand Up @@ -852,19 +850,17 @@ extension Compiler.ByteCodeGen {
) throws {
guard let node = list.popFirst() else { return }
switch node {
case let .orderedChoice(children):
let n = children.count
case let .orderedChoice(n):
for _ in 0..<n {
try skipNode(&list, preservingCaptures: preservingCaptures)
}

case let .concatenation(children):
let n = children.count

case let .concatenation(n):
for _ in 0..<n {
try skipNode(&list, preservingCaptures: preservingCaptures)
}

case let .capture(name, refId, _, _):
case let .capture(name, refId, _):
options.beginScope()
defer { options.endScope() }

Expand All @@ -877,7 +873,7 @@ extension Compiler.ByteCodeGen {
try skipNode(&list, preservingCaptures: preservingCaptures)
}

case .nonCapturingGroup(_, _):
case .nonCapturingGroup:
try skipNode(&list, preservingCaptures: preservingCaptures)

case .ignoreCapturesInTypedOutput:
Expand All @@ -886,7 +882,7 @@ extension Compiler.ByteCodeGen {
case .limitCaptureNesting:
try skipNode(&list, preservingCaptures: preservingCaptures)

case .quantification(_, _, _):
case .quantification:
try skipNode(&list, preservingCaptures: preservingCaptures)

case .customCharacterClass, .atom, .quotedLiteral, .matcher:
Expand Down
Loading
Loading