Skip to content

Commit 21cef5e

Browse files
Address review comments
Rename certain enums to be consistent with rest of codebase.
1 parent eafed1e commit 21cef5e

File tree

8 files changed

+72
-72
lines changed

8 files changed

+72
-72
lines changed

regex-automata/src/dfa/onepass.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ impl<'a> InternalBuilder<'a> {
638638
self.stack_push(nfa_id, Epsilons::empty())?;
639639
while let Some((id, epsilons)) = self.stack.pop() {
640640
match *self.nfa.state(id) {
641-
thompson::State::WriteLookaround { .. }
642-
| thompson::State::CheckLookaround { .. } => {
641+
thompson::State::WriteLookAround { .. }
642+
| thompson::State::CheckLookAround { .. } => {
643643
todo!("check how to handle")
644644
}
645645
thompson::State::ByteRange { ref trans } => {

regex-automata/src/nfa/thompson/backtrack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,8 +1519,8 @@ impl BoundedBacktracker {
15191519
}
15201520
sid = next;
15211521
}
1522-
State::WriteLookaround { .. }
1523-
| State::CheckLookaround { .. } => {
1522+
State::WriteLookAround { .. }
1523+
| State::CheckLookAround { .. } => {
15241524
todo!("check how to handle")
15251525
}
15261526
State::Union { ref alternates } => {

regex-automata/src/nfa/thompson/builder.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ enum State {
9393
},
9494
/// An empty state that behaves analogously to a `Match` state but for
9595
/// the look-around sub-expression with the given index.
96-
WriteLookaround { lookaround_index: SmallIndex },
96+
WriteLookAround { lookaround_index: SmallIndex },
9797
/// A conditional epsilon transition that will only be taken if the
9898
/// look-around sub-expression with the given index evaluates to `positive`
9999
/// at the current position in the haystack.
100-
CheckLookaround {
100+
CheckLookAround {
101101
lookaround_index: SmallIndex,
102102
positive: bool,
103103
next: StateID,
@@ -166,8 +166,8 @@ impl State {
166166
| State::CaptureEnd { .. }
167167
| State::Fail
168168
| State::Match { .. }
169-
| State::CheckLookaround { .. }
170-
| State::WriteLookaround { .. } => 0,
169+
| State::CheckLookAround { .. }
170+
| State::WriteLookAround { .. } => 0,
171171
State::Sparse { ref transitions } => {
172172
transitions.len() * mem::size_of::<Transition>()
173173
}
@@ -483,18 +483,18 @@ impl Builder {
483483
State::Look { look, next } => {
484484
remap[sid] = nfa.add(nfa::State::Look { look, next });
485485
}
486-
State::WriteLookaround { lookaround_index } => {
487-
remap[sid] = nfa.add(nfa::State::WriteLookaround {
488-
look_idx: lookaround_index,
486+
State::WriteLookAround { lookaround_index } => {
487+
remap[sid] = nfa.add(nfa::State::WriteLookAround {
488+
lookaround_idx: lookaround_index,
489489
});
490490
}
491-
State::CheckLookaround {
491+
State::CheckLookAround {
492492
lookaround_index,
493493
positive,
494494
next,
495495
} => {
496-
remap[sid] = nfa.add(nfa::State::CheckLookaround {
497-
look_idx: lookaround_index,
496+
remap[sid] = nfa.add(nfa::State::CheckLookAround {
497+
lookaround_idx: lookaround_index,
498498
positive,
499499
next,
500500
});
@@ -728,7 +728,7 @@ impl Builder {
728728
&mut self,
729729
index: SmallIndex,
730730
) -> Result<StateID, BuildError> {
731-
self.add(State::WriteLookaround { lookaround_index: index })
731+
self.add(State::WriteLookAround { lookaround_index: index })
732732
}
733733

734734
/// Add a state which will check whether the lookaround with the given
@@ -739,7 +739,7 @@ impl Builder {
739739
positive: bool,
740740
next: StateID,
741741
) -> Result<StateID, BuildError> {
742-
self.add(State::CheckLookaround {
742+
self.add(State::CheckLookAround {
743743
lookaround_index: index,
744744
positive,
745745
next,
@@ -1212,7 +1212,7 @@ impl Builder {
12121212
State::Look { ref mut next, .. } => {
12131213
*next = to;
12141214
}
1215-
State::CheckLookaround { ref mut next, .. } => {
1215+
State::CheckLookAround { ref mut next, .. } => {
12161216
*next = to;
12171217
}
12181218
State::Union { ref mut alternates } => {
@@ -1229,7 +1229,7 @@ impl Builder {
12291229
State::CaptureEnd { ref mut next, .. } => {
12301230
*next = to;
12311231
}
1232-
State::WriteLookaround { .. } => {}
1232+
State::WriteLookAround { .. } => {}
12331233
State::Fail => {}
12341234
State::Match { .. } => {}
12351235
}

regex-automata/src/nfa/thompson/compiler.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,7 @@ impl Compiler {
10451045
&self,
10461046
lookaround: &LookAround,
10471047
) -> Result<ThompsonRef, BuildError> {
1048-
let sub = match lookaround {
1049-
LookAround::NegativeLookBehind(ref sub)
1050-
| LookAround::PositiveLookBehind(ref sub) => self.c(sub)?,
1051-
};
1048+
let sub = self.c(lookaround.sub());
10521049
let pos = match lookaround {
10531050
LookAround::NegativeLookBehind(_) => false,
10541051
LookAround::PositiveLookBehind(_) => true,
@@ -1064,7 +1061,7 @@ impl Compiler {
10641061
self.patch(
10651062
self.lookaround_alt
10661063
.borrow()
1067-
.expect("Cannot compile lookaround outside pattern"),
1064+
.expect("Cannot compile look-around outside pattern"),
10681065
sub.start,
10691066
)?;
10701067
Ok(ThompsonRef { start: check, end: check })
@@ -2038,15 +2035,15 @@ mod tests {
20382035
}
20392036

20402037
fn s_write_lookaround(id: usize) -> State {
2041-
State::WriteLookaround {
2042-
look_idx: SmallIndex::new(id)
2038+
State::WriteLookAround {
2039+
lookaround_idx: SmallIndex::new(id)
20432040
.expect("look-around index too large"),
20442041
}
20452042
}
20462043

20472044
fn s_check_lookaround(id: usize, positive: bool, next: usize) -> State {
2048-
State::CheckLookaround {
2049-
look_idx: SmallIndex::new(id)
2045+
State::CheckLookAround {
2046+
lookaround_idx: SmallIndex::new(id)
20502047
.expect("look-around index too large"),
20512048
positive,
20522049
next: sid(next),

regex-automata/src/nfa/thompson/nfa.rs

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ impl NFA {
11001100
self.0.look_set_prefix_any
11011101
}
11021102

1103-
/// Returns how many lookaround sub-expressions this nfa contains
1103+
/// Returns how many look-around sub-expressions this nfa contains
11041104
#[inline]
11051105
pub fn lookaround_count(&self) -> SmallIndex {
11061106
self.0.lookaround_count
@@ -1299,8 +1299,8 @@ impl Inner {
12991299
State::ByteRange { .. }
13001300
| State::Dense { .. }
13011301
| State::Fail
1302-
| State::WriteLookaround { .. } => continue,
1303-
State::CheckLookaround { next, .. } => {
1302+
| State::WriteLookAround { .. } => continue,
1303+
State::CheckLookAround { next, .. } => {
13041304
stack.push(next);
13051305
}
13061306
State::Sparse(_) => {
@@ -1385,8 +1385,8 @@ impl Inner {
13851385
State::Capture { .. } => {
13861386
self.has_capture = true;
13871387
}
1388-
State::CheckLookaround { look_idx, .. }
1389-
| State::WriteLookaround { look_idx } => {
1388+
State::CheckLookAround { lookaround_idx: look_idx, .. }
1389+
| State::WriteLookAround { lookaround_idx: look_idx } => {
13901390
self.lookaround_count = self.lookaround_count.max(look_idx);
13911391
}
13921392
State::Union { .. }
@@ -1563,23 +1563,24 @@ pub enum State {
15631563
/// satisfied.
15641564
next: StateID,
15651565
},
1566-
/// This is like a match state but for a lookaround expression
1567-
/// executing this state will write a `true` into the lookaround oracle at
1568-
/// index `look_idx`
1569-
WriteLookaround {
1570-
/// The index of the lookaround expression that matches
1571-
look_idx: SmallIndex,
1566+
/// This is like a match state but for a look-around expression.
1567+
/// Executing this state will write the current haystack offset into the
1568+
/// look-around oracle at index `lookaround_idx`.
1569+
WriteLookAround {
1570+
/// The index of the look-around expression that matches.
1571+
lookaround_idx: SmallIndex,
15721572
},
15731573
/// This indicates that we need to check whether lookaround expression with
1574-
/// index `look_idx` holds at the current position in the haystack
1574+
/// index `lookaround_idx` holds at the current position in the haystack
15751575
/// If `positive` is false, then the lookaround expression is negative and
15761576
/// hence must NOT hold.
1577-
CheckLookaround {
1578-
/// The index of the lookaround expression that must be satisfied
1579-
look_idx: SmallIndex,
1580-
/// Whether this is a positive lookaround expression
1577+
CheckLookAround {
1578+
/// The index of the look-around expression that must be satisfied.
1579+
lookaround_idx: SmallIndex,
1580+
/// Whether this is a positive lookaround expression.
15811581
positive: bool,
1582-
/// The next state to transition if the lookaround assertion is satisfied
1582+
/// The next state to transition if the look-around assertion is
1583+
/// satisfied.
15831584
next: StateID,
15841585
},
15851586
/// An alternation such that there exists an epsilon transition to all
@@ -1696,12 +1697,12 @@ impl State {
16961697
| State::Dense { .. }
16971698
| State::Fail
16981699
| State::Match { .. }
1699-
| State::WriteLookaround { .. } => false,
1700+
| State::WriteLookAround { .. } => false,
17001701
State::Look { .. }
17011702
| State::Union { .. }
17021703
| State::BinaryUnion { .. }
17031704
| State::Capture { .. }
1704-
| State::CheckLookaround { .. } => true,
1705+
| State::CheckLookAround { .. } => true,
17051706
}
17061707
}
17071708

@@ -1714,8 +1715,8 @@ impl State {
17141715
| State::Capture { .. }
17151716
| State::Match { .. }
17161717
| State::Fail
1717-
| State::WriteLookaround { .. }
1718-
| State::CheckLookaround { .. } => 0,
1718+
| State::WriteLookAround { .. }
1719+
| State::CheckLookAround { .. } => 0,
17191720
State::Sparse(SparseTransitions { ref transitions }) => {
17201721
transitions.len() * mem::size_of::<Transition>()
17211722
}
@@ -1748,7 +1749,7 @@ impl State {
17481749
}
17491750
}
17501751
State::Look { ref mut next, .. } => *next = remap[*next],
1751-
State::CheckLookaround { ref mut next, .. } => {
1752+
State::CheckLookAround { ref mut next, .. } => {
17521753
*next = remap[*next]
17531754
}
17541755
State::Union { ref mut alternates } => {
@@ -1763,7 +1764,7 @@ impl State {
17631764
State::Capture { ref mut next, .. } => *next = remap[*next],
17641765
State::Fail
17651766
| State::Match { .. }
1766-
| State::WriteLookaround { .. } => {}
1767+
| State::WriteLookAround { .. } => {}
17671768
}
17681769
}
17691770
}
@@ -1793,15 +1794,19 @@ impl fmt::Debug for State {
17931794
State::Look { ref look, next } => {
17941795
write!(f, "{:?} => {:?}", look, next.as_usize())
17951796
}
1796-
State::WriteLookaround { look_idx } => {
1797-
write!(f, "Write Lookaround: {}", look_idx.as_u32())
1797+
State::WriteLookAround { lookaround_idx: look_idx } => {
1798+
write!(f, "write-look-around({})", look_idx.as_u32())
17981799
}
1799-
State::CheckLookaround { look_idx, positive, next } => {
1800+
State::CheckLookAround {
1801+
lookaround_idx: look_idx,
1802+
positive,
1803+
next,
1804+
} => {
18001805
write!(
18011806
f,
1802-
"Check Lookaround {} is {} => {}",
1807+
"check-look-around({} is {}) => {}",
18031808
look_idx.as_u32(),
1804-
positive,
1809+
if positive { "matched" } else { "not matched" },
18051810
next.as_usize()
18061811
)
18071812
}

regex-automata/src/nfa/thompson/pikevm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,8 @@ impl PikeVM {
15931593
| State::Union { .. }
15941594
| State::BinaryUnion { .. }
15951595
| State::Capture { .. }
1596-
| State::WriteLookaround { .. }
1597-
| State::CheckLookaround { .. } => None,
1596+
| State::WriteLookAround { .. }
1597+
| State::CheckLookAround { .. } => None,
15981598
State::ByteRange { ref trans } => {
15991599
if trans.matches(input.haystack(), at) {
16001600
let slots = curr_slot_table.for_state(sid);
@@ -1772,12 +1772,16 @@ impl PikeVM {
17721772
}
17731773
sid = next;
17741774
}
1775-
State::WriteLookaround { look_idx } => {
1775+
State::WriteLookAround { lookaround_idx: look_idx } => {
17761776
// This is ok since `at` is always less than `usize::MAX`.
17771777
lookarounds[look_idx] = NonMaxUsize::new(at);
17781778
return;
17791779
}
1780-
State::CheckLookaround { look_idx, positive, next } => {
1780+
State::CheckLookAround {
1781+
lookaround_idx: look_idx,
1782+
positive,
1783+
next,
1784+
} => {
17811785
let state = match lookarounds[look_idx] {
17821786
None => usize::MAX,
17831787
Some(pos) => pos.get(),
@@ -1988,11 +1992,7 @@ impl Cache {
19881992
stack: vec![],
19891993
curr: ActiveStates::new(re),
19901994
next: ActiveStates::new(re),
1991-
lookaround: {
1992-
let mut res = Vec::new();
1993-
res.resize(re.lookaround_count().as_usize(), None);
1994-
res
1995-
},
1995+
lookaround: vec![None; re.lookaround_count().as_usize()],
19961996
}
19971997
}
19981998

regex-automata/src/util/determinize/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ pub(crate) fn next(
251251
| thompson::State::Fail
252252
| thompson::State::Look { .. }
253253
| thompson::State::Capture { .. } => {}
254-
thompson::State::CheckLookaround { .. }
255-
| thompson::State::WriteLookaround { .. } => {
254+
thompson::State::CheckLookAround { .. }
255+
| thompson::State::WriteLookAround { .. } => {
256256
todo!("check how to handle")
257257
}
258258
thompson::State::Match { pattern_id } => {
@@ -403,8 +403,8 @@ pub(crate) fn epsilon_closure(
403403
| thompson::State::Dense { .. }
404404
| thompson::State::Fail
405405
| thompson::State::Match { .. } => break,
406-
thompson::State::WriteLookaround { .. }
407-
| thompson::State::CheckLookaround { .. } => {
406+
thompson::State::WriteLookAround { .. }
407+
| thompson::State::CheckLookAround { .. } => {
408408
todo!("check how to handle")
409409
}
410410
thompson::State::Look { look, next } => {
@@ -473,8 +473,8 @@ pub(crate) fn add_nfa_states(
473473
builder.add_nfa_state_id(nfa_id);
474474
builder.set_look_need(|need| need.insert(look));
475475
}
476-
thompson::State::CheckLookaround { .. }
477-
| thompson::State::WriteLookaround { .. } => {
476+
thompson::State::CheckLookAround { .. }
477+
| thompson::State::WriteLookAround { .. } => {
478478
todo!("check how to handle")
479479
}
480480
thompson::State::Union { .. }

regex-syntax/src/hir/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,8 +2139,6 @@ impl Properties {
21392139
///
21402140
/// Only returns true for [`HirKind::LookAround`] and not for
21412141
/// [`HirKind::Look`], which can be queried by [`look_set`] instead.
2142-
/// Currently, only lookbehind assertions without capture groups are
2143-
/// supported.
21442142
#[inline]
21452143
pub fn contains_lookaround_expr(&self) -> bool {
21462144
self.0.contains_lookaround_expr

0 commit comments

Comments
 (0)