Skip to content

Remove the last SPI use of _RegexParser symbols #416

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
May 15, 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
3 changes: 2 additions & 1 deletion Sources/PatternConverter/PatternConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ struct PatternConverter: ParsableCommand {

print()
if !skipDSL {
let render = ast.renderAsBuilderDSL(
let render = renderAsBuilderDSL(
ast: ast,
maxTopDownLevels: topDownConversionLimit,
minBottomUpLevels: bottomUpConversionLimit
)
Expand Down
32 changes: 19 additions & 13 deletions Sources/_StringProcessing/PrintAsPattern.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@
// incremental conversion, such that leaves remain
// as canonical regex literals.

/// Renders an AST tree as a Pattern DSL.
///
/// - Parameters:
/// - ast: A `_RegexParser.AST` instance.
/// - maxTopDownLevels: The number of levels down from the root of the tree
/// to perform conversion. `nil` means no limit.
/// - minBottomUpLevels: The number of levels up from the leaves of the tree
/// to perform conversion. `nil` means no limit.
/// - Returns: A string representation of `ast` in the `RegexBuilder` syntax.
@_spi(PatternConverter)
extension AST {
/// Renders as a Pattern DSL.
@_spi(PatternConverter)
public func renderAsBuilderDSL(
maxTopDownLevels: Int? = nil,
minBottomUpLevels: Int? = nil
) -> String {
var printer = PrettyPrinter(
maxTopDownLevels: maxTopDownLevels,
minBottomUpLevels: minBottomUpLevels)
printer.printAsPattern(self)
return printer.finish()
}
public func renderAsBuilderDSL(
ast: Any,
maxTopDownLevels: Int? = nil,
minBottomUpLevels: Int? = nil
) -> String {
var printer = PrettyPrinter(
maxTopDownLevels: maxTopDownLevels,
minBottomUpLevels: minBottomUpLevels)
printer.printAsPattern(ast as! AST)
return printer.finish()
}

extension PrettyPrinter {
Expand Down