@@ -711,7 +711,13 @@ pub struct Compiler {
711711 /// State used for caching common suffixes when compiling reverse UTF-8
712712 /// automata (for Unicode character classes).
713713 utf8_suffix : RefCell < Utf8SuffixMap > ,
714+ /// Top level alternation state which is used to run all look-around
715+ /// assertion checks in lockstep with the main expression. Each look-around
716+ /// expression is compiled to a set of states that is patched into this
717+ /// state, and this state is updated on each new pattern being compiled.
714718 lookaround_alt : RefCell < Option < StateID > > ,
719+ /// The next index to use for a look-around expression.
720+ lookaround_index : RefCell < SmallIndex > ,
715721}
716722
717723impl Compiler {
@@ -725,6 +731,7 @@ impl Compiler {
725731 trie_state : RefCell :: new ( RangeTrie :: new ( ) ) ,
726732 utf8_suffix : RefCell :: new ( Utf8SuffixMap :: new ( 1000 ) ) ,
727733 lookaround_alt : RefCell :: new ( None ) ,
734+ lookaround_index : RefCell :: new ( SmallIndex :: ZERO ) ,
728735 }
729736 }
730737
@@ -1046,7 +1053,11 @@ impl Compiler {
10461053 LookAround :: NegativeLookBehind ( _) => false ,
10471054 LookAround :: PositiveLookBehind ( _) => true ,
10481055 } ;
1049- let idx = todo ! ( "get index" ) ;
1056+ let idx = * self . lookaround_index . borrow ( ) ;
1057+ * self . lookaround_index . borrow_mut ( ) = SmallIndex :: new ( idx. one_more ( ) )
1058+ . map_err ( |e| {
1059+ BuildError :: too_many_lookarounds ( e. attempted ( ) as usize )
1060+ } ) ?;
10501061 let check = self . add_check_lookaround ( idx, pos) ?;
10511062 let write = self . add_write_lookaround ( idx) ?;
10521063 self . patch ( sub. end , write) ?;
0 commit comments