Skip to content

Internalize _CharacterClassModel #578

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 3 commits into from
Jul 14, 2022
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
21 changes: 9 additions & 12 deletions Sources/RegexBuilder/CharacterClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ public struct CharacterClass {
self.ccc = ccc
}

init(unconverted model: _CharacterClassModel) {
guard let ccc = model.makeDSLTreeCharacterClass() else {
fatalError("Unsupported character class")
}
self.ccc = ccc
init(unconverted atom: DSLTree._AST.Atom) {
self.ccc = .init(members: [.atom(.unconverted(atom))])
}
}

Expand All @@ -49,15 +46,15 @@ extension RegexComponent where Self == CharacterClass {
}

public static var anyGraphemeCluster: CharacterClass {
.init(unconverted: .anyGrapheme)
.init(unconverted: ._anyGrapheme)
}

public static var whitespace: CharacterClass {
.init(unconverted: .whitespace)
.init(unconverted: ._whitespace)
}

public static var digit: CharacterClass {
.init(unconverted: .digit)
.init(unconverted: ._digit)
}

public static var hexDigit: CharacterClass {
Expand All @@ -69,19 +66,19 @@ extension RegexComponent where Self == CharacterClass {
}

public static var horizontalWhitespace: CharacterClass {
.init(unconverted: .horizontalWhitespace)
.init(unconverted: ._horizontalWhitespace)
}

public static var newlineSequence: CharacterClass {
.init(unconverted: .newlineSequence)
.init(unconverted: ._newlineSequence)
}

public static var verticalWhitespace: CharacterClass {
.init(unconverted: .verticalWhitespace)
.init(unconverted: ._verticalWhitespace)
}

public static var word: CharacterClass {
.init(unconverted: .word)
.init(unconverted: ._word)
}
}

Expand Down
26 changes: 26 additions & 0 deletions Sources/_StringProcessing/Regex/DSLTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,32 @@ extension DSLTree {
@_spi(RegexBuilder)
public struct Atom {
internal var ast: AST.Atom

// FIXME: The below APIs should be removed once the DSL tree has been
// migrated to use proper DSL atoms for them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this entail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding them as dedicated cases to DSLTree.Atom (or splitting out a new BuiltinCharacterClass type perhaps), and then getting the consumer logic working with them. It's probably not too effort, but I'm going to leave it as a follow up for now. I can file an issue to track it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #579


public static var _anyGrapheme: Self {
.init(ast: .init(.escaped(.graphemeCluster), .fake))
}
public static var _whitespace: Self {
.init(ast: .init(.escaped(.whitespace), .fake))
}
public static var _digit: Self {
.init(ast: .init(.escaped(.decimalDigit), .fake))
}
public static var _horizontalWhitespace: Self {
.init(ast: .init(.escaped(.horizontalWhitespace), .fake))
}
public static var _newlineSequence: Self {
// FIXME: newline sequence is not same as \n
.init(ast: .init(.escaped(.newline), .fake))
}
public static var _verticalWhitespace: Self {
.init(ast: .init(.escaped(.verticalTab), .fake))
}
public static var _word: Self {
.init(ast: .init(.escaped(.wordCharacter), .fake))
}
}
}
}
Expand Down
Loading