From e7f3412fc0ec598daf0042e80dc3b4c8dc45f34e Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 18 Jul 2022 12:32:51 -0700 Subject: [PATCH] Print Lookahead and NegativeLookahead --- .../_StringProcessing/PrintAsPattern.swift | 10 +++++++ Tests/RegexTests/RenderDSLTests.swift | 26 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/Sources/_StringProcessing/PrintAsPattern.swift b/Sources/_StringProcessing/PrintAsPattern.swift index 80f2e7697..54ce66d0d 100644 --- a/Sources/_StringProcessing/PrintAsPattern.swift +++ b/Sources/_StringProcessing/PrintAsPattern.swift @@ -119,6 +119,16 @@ extension PrettyPrinter { printer.printAsPattern(convertedFromAST: child) } + case .lookahead: + printBlock("Lookahead") { printer in + printer.printAsPattern(convertedFromAST: child) + } + + case .negativeLookahead: + printBlock("NegativeLookahead") { printer in + printer.printAsPattern(convertedFromAST: child) + } + default: printAsPattern(convertedFromAST: child) } diff --git a/Tests/RegexTests/RenderDSLTests.swift b/Tests/RegexTests/RenderDSLTests.swift index 3b0a8d5b3..52906d1ad 100644 --- a/Tests/RegexTests/RenderDSLTests.swift +++ b/Tests/RegexTests/RenderDSLTests.swift @@ -98,6 +98,32 @@ extension RenderDSLTests { /$/ } """#) + + try testConversion(#"foo(?=bar)"#, #""" + Regex { + "foo" + Lookahead { + "bar" + } + } + """#) + + try testConversion(#"abc(?=def(?!ghi)|xyz)"#, #""" + Regex { + "abc" + Lookahead { + ChoiceOf { + Regex { + "def" + NegativeLookahead { + "ghi" + } + } + "xyz" + } + } + } + """#) } func testOptions() throws {