Skip to content

Commit 1d9ce15

Browse files
authored
api: add visit_concat_in method to the Visitor traits
This essentially copied the visit_alternation_in methods, but for concatenations. This is useful for some niche use cases where one wants to visit concatenations in reverse. PR #1017
1 parent 5a34a39 commit 1d9ce15

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

regex-syntax/src/ast/visitor.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ pub trait Visitor {
4848
Ok(())
4949
}
5050

51+
/// This method is called between child nodes of a concatenation.
52+
fn visit_concat_in(&mut self) -> Result<(), Self::Err> {
53+
Ok(())
54+
}
55+
5156
/// This method is called on every [`ClassSetItem`](ast::ClassSetItem)
5257
/// before descending into child nodes.
5358
fn visit_class_set_item_pre(
@@ -228,8 +233,14 @@ impl<'a> HeapVisitor<'a> {
228233
// If this is a concat/alternate, then we might have additional
229234
// inductive steps to process.
230235
if let Some(x) = self.pop(frame) {
231-
if let Frame::Alternation { .. } = x {
232-
visitor.visit_alternation_in()?;
236+
match x {
237+
Frame::Alternation { .. } => {
238+
visitor.visit_alternation_in()?;
239+
}
240+
Frame::Concat { .. } => {
241+
visitor.visit_concat_in()?;
242+
}
243+
_ => {}
233244
}
234245
ast = x.child();
235246
self.stack.push((post_ast, x));

regex-syntax/src/hir/visitor.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ pub trait Visitor {
4141
fn visit_alternation_in(&mut self) -> Result<(), Self::Err> {
4242
Ok(())
4343
}
44+
45+
/// This method is called between child nodes of a concatenation.
46+
fn visit_concat_in(&mut self) -> Result<(), Self::Err> {
47+
Ok(())
48+
}
4449
}
4550

4651
/// Executes an implementation of `Visitor` in constant stack space.
@@ -131,8 +136,14 @@ impl<'a> HeapVisitor<'a> {
131136
// If this is a concat/alternate, then we might have additional
132137
// inductive steps to process.
133138
if let Some(x) = self.pop(frame) {
134-
if let Frame::Alternation { .. } = x {
135-
visitor.visit_alternation_in()?;
139+
match x {
140+
Frame::Alternation { .. } => {
141+
visitor.visit_alternation_in()?;
142+
}
143+
Frame::Concat { .. } => {
144+
visitor.visit_concat_in()?;
145+
}
146+
_ => {}
136147
}
137148
hir = x.child();
138149
self.stack.push((post_hir, x));

0 commit comments

Comments
 (0)