diff --git a/regex-syntax/src/hir/literal.rs b/regex-syntax/src/hir/literal.rs index 2fbcdcff2..121216ae5 100644 --- a/regex-syntax/src/hir/literal.rs +++ b/regex-syntax/src/hir/literal.rs @@ -186,7 +186,7 @@ impl Extractor { } Class(hir::Class::Bytes(ref cls)) => self.extract_class_bytes(cls), Repetition(ref rep) => self.extract_repetition(rep), - Capture(hir::Capture { ref hir, .. }) => self.extract(hir), + Capture(hir::Capture { ref sub, .. }) => self.extract(sub), Concat(ref hirs) => match self.kind { ExtractKind::Prefix => self.extract_concat(hirs.iter()), ExtractKind::Suffix => self.extract_concat(hirs.iter().rev()), @@ -448,7 +448,7 @@ impl Extractor { /// literals being extracted, which might actually be a better prefilter /// than just 'a'. fn extract_repetition(&self, rep: &hir::Repetition) -> Seq { - let mut subseq = self.extract(&rep.hir); + let mut subseq = self.extract(&rep.sub); match *rep { hir::Repetition { min: 0, max, greedy, .. } => { // When 'max=1', we can retain exactness, since 'a?' is diff --git a/regex-syntax/src/hir/mod.rs b/regex-syntax/src/hir/mod.rs index 7be604a66..a2465e98a 100644 --- a/regex-syntax/src/hir/mod.rs +++ b/regex-syntax/src/hir/mod.rs @@ -323,7 +323,7 @@ impl Hir { if rep.min == 0 && rep.max == Some(0) { return Hir::empty(); } else if rep.min == 1 && rep.max == Some(1) { - return *rep.hir; + return *rep.sub; } let props = Properties::repetition(&rep); Hir { kind: HirKind::Repetition(rep), props } @@ -1437,7 +1437,7 @@ pub struct Capture { /// The name of the capture, if it exists. pub name: Option>, /// The expression inside the capturing group, which may be empty. - pub hir: Box, + pub sub: Box, } /// The high-level intermediate representation of a repetition operator. @@ -1467,7 +1467,7 @@ pub struct Repetition { /// not. However, this can be inverted via the `U` "ungreedy" flag. pub greedy: bool, /// The expression being repeated. - pub hir: Box, + pub sub: Box, } impl Repetition { @@ -1523,8 +1523,8 @@ impl Drop for Hir { | HirKind::Literal(_) | HirKind::Class(_) | HirKind::Look(_) => return, - HirKind::Capture(ref x) if !x.hir.kind.has_subexprs() => return, - HirKind::Repetition(ref x) if !x.hir.kind.has_subexprs() => return, + HirKind::Capture(ref x) if !x.sub.kind.has_subexprs() => return, + HirKind::Repetition(ref x) if !x.sub.kind.has_subexprs() => return, HirKind::Concat(ref x) if x.is_empty() => return, HirKind::Alternation(ref x) if x.is_empty() => return, _ => {} @@ -1538,10 +1538,10 @@ impl Drop for Hir { | HirKind::Class(_) | HirKind::Look(_) => {} HirKind::Capture(ref mut x) => { - stack.push(mem::replace(&mut x.hir, Hir::empty())); + stack.push(mem::replace(&mut x.sub, Hir::empty())); } HirKind::Repetition(ref mut x) => { - stack.push(mem::replace(&mut x.hir, Hir::empty())); + stack.push(mem::replace(&mut x.sub, Hir::empty())); } HirKind::Concat(ref mut x) => { stack.extend(x.drain(..)); @@ -1926,7 +1926,7 @@ impl Properties { /// Create a new set of HIR properties for a repetition. fn repetition(rep: &Repetition) -> Properties { - let p = rep.hir.properties(); + let p = rep.sub.properties(); let minimum_len = p.minimum_len().map(|child_min| { let rep_min = usize::try_from(rep.min).unwrap_or(usize::MAX); child_min.saturating_mul(rep_min) @@ -1957,7 +1957,7 @@ impl Properties { /// Create a new set of HIR properties for a capture. fn capture(capture: &Capture) -> Properties { - let p = capture.hir.properties(); + let p = capture.sub.properties(); Properties(Box::new(PropertiesI { captures_len: p.captures_len().saturating_add(1), literal: false, @@ -3054,13 +3054,13 @@ mod tests { expr = Hir::capture(Capture { index: 1, name: None, - hir: Box::new(expr), + sub: Box::new(expr), }); expr = Hir::repetition(Repetition { min: 0, max: Some(1), greedy: true, - hir: Box::new(expr), + sub: Box::new(expr), }); expr = Hir { diff --git a/regex-syntax/src/hir/print.rs b/regex-syntax/src/hir/print.rs index ef654d40c..40f8905b7 100644 --- a/regex-syntax/src/hir/print.rs +++ b/regex-syntax/src/hir/print.rs @@ -478,7 +478,7 @@ mod tests { min: 1, max: None, greedy: true, - hir: Box::new(Hir::literal("ab".as_bytes())), + sub: Box::new(Hir::literal("ab".as_bytes())), }), Hir::literal("y".as_bytes()), ]); @@ -490,7 +490,7 @@ mod tests { min: 1, max: None, greedy: true, - hir: Box::new(Hir::concat(alloc::vec![ + sub: Box::new(Hir::concat(alloc::vec![ Hir::look(hir::Look::Start), Hir::look(hir::Look::End), ])), @@ -512,7 +512,7 @@ mod tests { min: 1, max: None, greedy: true, - hir: Box::new(Hir::alternation(alloc::vec![ + sub: Box::new(Hir::alternation(alloc::vec![ Hir::literal("cd".as_bytes()), Hir::literal("ef".as_bytes()), ])), @@ -527,7 +527,7 @@ mod tests { min: 1, max: None, greedy: true, - hir: Box::new(Hir::alternation(alloc::vec![ + sub: Box::new(Hir::alternation(alloc::vec![ Hir::look(hir::Look::Start), Hir::look(hir::Look::End), ])), diff --git a/regex-syntax/src/hir/translate.rs b/regex-syntax/src/hir/translate.rs index fcef47a1e..b1ebf7b17 100644 --- a/regex-syntax/src/hir/translate.rs +++ b/regex-syntax/src/hir/translate.rs @@ -912,7 +912,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> { // in which the data type is defined handles this automatically. ast::GroupKind::NonCapturing(_) => return expr, }; - Hir::capture(hir::Capture { index, name, hir: Box::new(expr) }) + Hir::capture(hir::Capture { index, name, sub: Box::new(expr) }) } fn hir_repetition(&self, rep: &ast::Repetition, expr: Hir) -> Hir { @@ -937,7 +937,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> { min, max, greedy, - hir: Box::new(expr), + sub: Box::new(expr), }) } @@ -1353,14 +1353,14 @@ mod tests { } fn hir_capture(index: u32, expr: Hir) -> Hir { - Hir::capture(hir::Capture { index, name: None, hir: Box::new(expr) }) + Hir::capture(hir::Capture { index, name: None, sub: Box::new(expr) }) } fn hir_capture_name(index: u32, name: &str, expr: Hir) -> Hir { Hir::capture(hir::Capture { index, name: Some(name.into()), - hir: Box::new(expr), + sub: Box::new(expr), }) } @@ -1369,7 +1369,7 @@ mod tests { min: 0, max: Some(1), greedy, - hir: Box::new(expr), + sub: Box::new(expr), }) } @@ -1378,7 +1378,7 @@ mod tests { min: 0, max: None, greedy, - hir: Box::new(expr), + sub: Box::new(expr), }) } @@ -1387,7 +1387,7 @@ mod tests { min: 1, max: None, greedy, - hir: Box::new(expr), + sub: Box::new(expr), }) } @@ -1396,7 +1396,7 @@ mod tests { min, max, greedy, - hir: Box::new(expr), + sub: Box::new(expr), }) } diff --git a/regex-syntax/src/hir/visitor.rs b/regex-syntax/src/hir/visitor.rs index ba1db238a..e5f15cf1c 100644 --- a/regex-syntax/src/hir/visitor.rs +++ b/regex-syntax/src/hir/visitor.rs @@ -195,8 +195,8 @@ impl<'a> Frame<'a> { /// child HIR node to visit. fn child(&self) -> &'a Hir { match *self { - Frame::Repetition(rep) => &rep.hir, - Frame::Capture(capture) => &capture.hir, + Frame::Repetition(rep) => &rep.sub, + Frame::Capture(capture) => &capture.sub, Frame::Concat { head, .. } => head, Frame::Alternation { head, .. } => head, } diff --git a/src/compile.rs b/src/compile.rs index 50ab78700..9ee52354d 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -368,7 +368,7 @@ impl Compiler { self.c_empty_look(prog::EmptyLook::NotWordBoundary) } }, - Capture(hir::Capture { index, ref name, ref hir }) => { + Capture(hir::Capture { index, ref name, ref sub }) => { if index as usize >= self.compiled.captures.len() { let name = match *name { None => None, @@ -379,7 +379,7 @@ impl Compiler { self.capture_name_idx.insert(name, index as usize); } } - self.c_capture(2 * index as usize, hir) + self.c_capture(2 * index as usize, sub) } Concat(ref es) => { if self.compiled.is_reverse { @@ -434,7 +434,7 @@ impl Compiler { min: 0, max: None, greedy: false, - hir: Box::new(hir), + sub: Box::new(hir), }))? .unwrap()) } @@ -644,14 +644,14 @@ impl Compiler { fn c_repeat(&mut self, rep: &hir::Repetition) -> ResultOrEmpty { match (rep.min, rep.max) { - (0, Some(1)) => self.c_repeat_zero_or_one(&rep.hir, rep.greedy), - (0, None) => self.c_repeat_zero_or_more(&rep.hir, rep.greedy), - (1, None) => self.c_repeat_one_or_more(&rep.hir, rep.greedy), + (0, Some(1)) => self.c_repeat_zero_or_one(&rep.sub, rep.greedy), + (0, None) => self.c_repeat_zero_or_more(&rep.sub, rep.greedy), + (1, None) => self.c_repeat_one_or_more(&rep.sub, rep.greedy), (min, None) => { - self.c_repeat_range_min_or_more(&rep.hir, rep.greedy, min) + self.c_repeat_range_min_or_more(&rep.sub, rep.greedy, min) } (min, Some(max)) => { - self.c_repeat_range(&rep.hir, rep.greedy, min, max) + self.c_repeat_range(&rep.sub, rep.greedy, min, max) } } }