Skip to content

Commit

Permalink
syntax: rename 'hir' to 'sub'
Browse files Browse the repository at this point in the history
Where 'sub' is short for 'sub-expression.'
  • Loading branch information
BurntSushi committed Mar 1, 2023
1 parent 2c3409f commit c52e226
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions regex-syntax/src/hir/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions regex-syntax/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -1437,7 +1437,7 @@ pub struct Capture {
/// The name of the capture, if it exists.
pub name: Option<Box<str>>,
/// The expression inside the capturing group, which may be empty.
pub hir: Box<Hir>,
pub sub: Box<Hir>,
}

/// The high-level intermediate representation of a repetition operator.
Expand Down Expand Up @@ -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<Hir>,
pub sub: Box<Hir>,
}

impl Repetition {
Expand Down Expand Up @@ -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,
_ => {}
Expand All @@ -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(..));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions regex-syntax/src/hir/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
]);
Expand All @@ -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),
])),
Expand All @@ -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()),
])),
Expand All @@ -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),
])),
Expand Down
16 changes: 8 additions & 8 deletions regex-syntax/src/hir/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -937,7 +937,7 @@ impl<'t, 'p> TranslatorI<'t, 'p> {
min,
max,
greedy,
hir: Box::new(expr),
sub: Box::new(expr),
})
}

Expand Down Expand Up @@ -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),
})
}

Expand All @@ -1369,7 +1369,7 @@ mod tests {
min: 0,
max: Some(1),
greedy,
hir: Box::new(expr),
sub: Box::new(expr),
})
}

Expand All @@ -1378,7 +1378,7 @@ mod tests {
min: 0,
max: None,
greedy,
hir: Box::new(expr),
sub: Box::new(expr),
})
}

Expand All @@ -1387,7 +1387,7 @@ mod tests {
min: 1,
max: None,
greedy,
hir: Box::new(expr),
sub: Box::new(expr),
})
}

Expand All @@ -1396,7 +1396,7 @@ mod tests {
min,
max,
greedy,
hir: Box::new(expr),
sub: Box::new(expr),
})
}

Expand Down
4 changes: 2 additions & 2 deletions regex-syntax/src/hir/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
16 changes: 8 additions & 8 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -434,7 +434,7 @@ impl Compiler {
min: 0,
max: None,
greedy: false,
hir: Box::new(hir),
sub: Box::new(hir),
}))?
.unwrap())
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit c52e226

Please sign in to comment.