@@ -636,37 +636,20 @@ extension Parser {
636636 }
637637}
638638
639- public enum ASTStage {
640- /// The regex is parsed, and a syntactically valid AST is returned. Otherwise
641- /// an error is thrown. This is useful for e.g syntax coloring.
642- case syntactic
643-
644- /// The regex is parsed, and a syntactically and semantically valid AST is
645- /// returned. Otherwise an error is thrown. A semantically valid AST has been
646- /// checked for e.g unsupported constructs and invalid backreferences.
647- case semantic
648- }
649-
650639public func parseWithRecovery< S: StringProtocol > (
651- _ regex: S , _ syntax: SyntaxOptions , stage : ASTStage = . semantic
640+ _ regex: S , _ syntax: SyntaxOptions
652641) -> AST where S. SubSequence == Substring
653642{
654643 let source = Source ( String ( regex) )
655644 var parser = Parser ( source, syntax: syntax)
656- let ast = parser. parse ( )
657- switch stage {
658- case . syntactic:
659- return ast
660- case . semantic:
661- return validate ( ast)
662- }
645+ return validate ( parser. parse ( ) )
663646}
664647
665648public func parse< S: StringProtocol > (
666- _ regex: S , _ stage : ASTStage , _ syntax: SyntaxOptions
649+ _ regex: S , _ syntax: SyntaxOptions
667650) throws -> AST where S. SubSequence == Substring
668651{
669- try parseWithRecovery ( regex, syntax, stage : stage ) . ensureValid ( )
652+ try parseWithRecovery ( regex, syntax) . ensureValid ( )
670653}
671654
672655extension StringProtocol {
@@ -709,12 +692,12 @@ public func parseWithDelimitersWithRecovery<S: StringProtocol>(
709692/// Parses a given regex string with delimiters, inferring the syntax options
710693/// from the delimiters used.
711694public func parseWithDelimiters< S: StringProtocol > (
712- _ regex: S , _ stage : ASTStage
695+ _ regex: S
713696) throws -> AST where S. SubSequence == Substring {
714697 let ( contents, delim) = droppingRegexDelimiters ( String ( regex) )
715698 let syntax = defaultSyntaxOptions ( delim, contents: contents)
716699 do {
717- return try parseWithRecovery ( contents, syntax, stage : stage ) . ensureValid ( )
700+ return try parseWithRecovery ( contents, syntax) . ensureValid ( )
718701 } catch let error as LocatedErrorProtocol {
719702 // Convert the range in 'contents' to the range in 'regex'.
720703 let delimCount = delim. opening. count
0 commit comments