Skip to content

Commit 55e1571

Browse files
authored
Merge pull request #587 from Azoy/lookahead-convert
Print Lookahead and NegativeLookahead
2 parents 96fb215 + e7f3412 commit 55e1571

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Sources/_StringProcessing/PrintAsPattern.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ extension PrettyPrinter {
119119
printer.printAsPattern(convertedFromAST: child)
120120
}
121121

122+
case .lookahead:
123+
printBlock("Lookahead") { printer in
124+
printer.printAsPattern(convertedFromAST: child)
125+
}
126+
127+
case .negativeLookahead:
128+
printBlock("NegativeLookahead") { printer in
129+
printer.printAsPattern(convertedFromAST: child)
130+
}
131+
122132
default:
123133
printAsPattern(convertedFromAST: child)
124134
}

Tests/RegexTests/RenderDSLTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ extension RenderDSLTests {
9898
/$/
9999
}
100100
"""#)
101+
102+
try testConversion(#"foo(?=bar)"#, #"""
103+
Regex {
104+
"foo"
105+
Lookahead {
106+
"bar"
107+
}
108+
}
109+
"""#)
110+
111+
try testConversion(#"abc(?=def(?!ghi)|xyz)"#, #"""
112+
Regex {
113+
"abc"
114+
Lookahead {
115+
ChoiceOf {
116+
Regex {
117+
"def"
118+
NegativeLookahead {
119+
"ghi"
120+
}
121+
}
122+
"xyz"
123+
}
124+
}
125+
}
126+
"""#)
101127
}
102128

103129
func testOptions() throws {

0 commit comments

Comments
 (0)