Skip to content

Remove the unsupported anyScalar case #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2023
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
3 changes: 0 additions & 3 deletions Sources/_StringProcessing/ByteCodeGen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,6 @@ fileprivate extension Compiler.ByteCodeGen {
case .characterClass(let cc):
// Custom character class that consumes a single grapheme
let model = cc.asRuntimeModel(options)
guard model.consumesSingleGrapheme else {
return false
}
builder.buildQuantify(
model: model,
kind,
Expand Down
8 changes: 0 additions & 8 deletions Sources/_StringProcessing/Engine/MEBuiltins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ extension String {
switch (isScalarSemantics, cc) {
case (_, .anyGrapheme):
next = index(after: currentPosition)
case (_, .anyScalar):
next = unicodeScalars.index(after: currentPosition)
case (true, _):
next = unicodeScalars.index(after: currentPosition)
case (false, _):
Expand All @@ -204,12 +202,6 @@ extension String {
switch cc {
case .any, .anyGrapheme:
matched = true
case .anyScalar:
if isScalarSemantics {
matched = true
} else {
matched = isOnGraphemeClusterBoundary(next)
}
case .digit:
if isScalarSemantics {
matched = scalar.properties.numericType != nil && asciiCheck
Expand Down
4 changes: 2 additions & 2 deletions Sources/_StringProcessing/PrintAsPattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,6 @@ extension DSLTree.Atom.CharacterClass {
switch self {
case .anyGrapheme:
return ".anyGraphemeCluster"
case .anyUnicodeScalar:
return ".anyUnicodeScalar"
case .digit:
return ".digit"
case .notDigit:
Expand All @@ -786,6 +784,8 @@ extension DSLTree.Atom.CharacterClass {
return ".whitespace"
case .notWhitespace:
return ".whitespace.inverted"
case .anyUnicodeScalar:
fatalError("Unsupported")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/_StringProcessing/Regex/ASTConversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ extension AST.Atom.EscapedBuiltin {
case .wordCharacter: return .word
case .notWordCharacter: return .notWord
case .graphemeCluster: return .anyGrapheme
case .trueAnychar: return .anyUnicodeScalar
default: return nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/_StringProcessing/Regex/DSLTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ extension DSLTree.Atom.CharacterClass {
public var inverted: DSLTree.Atom.CharacterClass? {
switch self {
case .anyGrapheme: return nil
case .anyUnicodeScalar: return nil
case .digit: return .notDigit
case .notDigit: return .digit
case .word: return .notWord
Expand All @@ -273,6 +272,8 @@ extension DSLTree.Atom.CharacterClass {
case .notVerticalWhitespace: return .verticalWhitespace
case .whitespace: return .notWhitespace
case .notWhitespace: return .whitespace
case .anyUnicodeScalar:
fatalError("Unsupported")
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/_StringProcessing/Unicode/ASCII.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ extension String {

// TODO: bitvectors
switch cc {
case .any, .anyGrapheme, .anyScalar:
// TODO: should any scalar not consume CR-LF in scalar semantic mode?
case .any, .anyGrapheme:
return (next, true)

case .digit:
Expand Down
14 changes: 1 addition & 13 deletions Sources/_StringProcessing/_CharacterClassModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ struct _CharacterClassModel: Hashable {
case any = 0
/// Any grapheme cluster
case anyGrapheme
/// Any Unicode scalar
case anyScalar
/// Character.isDigit
case digit
/// Horizontal whitespace: `[:blank:]`, i.e
Expand Down Expand Up @@ -90,15 +88,6 @@ struct _CharacterClassModel: Hashable {
}
}

extension _CharacterClassModel {
var consumesSingleGrapheme: Bool {
switch self.cc {
case .anyScalar: return false
default: return true
}
}
}

extension _CharacterClassModel.Representation {
/// Returns true if this CharacterClass should be matched by strict ascii under the given options
func isStrictAscii(options: MatchingOptions) -> Bool {
Expand All @@ -119,7 +108,6 @@ extension _CharacterClassModel.Representation: CustomStringConvertible {
switch self {
case .any: return "<any>"
case .anyGrapheme: return "<any grapheme>"
case .anyScalar: return "<any scalar>"
case .digit: return "<digit>"
case .horizontalWhitespace: return "<horizontal whitespace>"
case .newlineSequence: return "<newline sequence>"
Expand Down Expand Up @@ -185,7 +173,7 @@ extension DSLTree.Atom.CharacterClass {
case .anyGrapheme:
cc = .anyGrapheme
case .anyUnicodeScalar:
cc = .anyScalar
fatalError("Unsupported")
}
return _CharacterClassModel(cc: cc, options: options, isInverted: inverted)
}
Expand Down