@@ -207,6 +207,15 @@ impl State {
207207 return true ;
208208 }
209209
210+ if ctx. try_peek_code_as :: < SreOpcode , _ > ( & req, 1 ) . unwrap ( ) == SreOpcode :: AT
211+ && ( ctx. try_peek_code_as :: < SreAtCode , _ > ( & req, 2 ) . unwrap ( ) == SreAtCode :: BEGINNING
212+ || ctx. try_peek_code_as :: < SreAtCode , _ > ( & req, 2 ) . unwrap ( )
213+ == SreAtCode :: BEGINNING_STRING )
214+ {
215+ self . reset ( req. end ) ;
216+ return false ;
217+ }
218+
210219 req. must_advance = false ;
211220 ctx. toplevel = false ;
212221 while req. start < end {
@@ -272,15 +281,11 @@ enum Jump {
272281 PossessiveRepeat4 ,
273282}
274283
275- fn _match < S : StrDrive > ( req : & Request < S > , state : & mut State , ctx : MatchContext ) -> bool {
276- let mut context_stack = vec ! [ ctx ] ;
284+ fn _match < S : StrDrive > ( req : & Request < S > , state : & mut State , mut ctx : MatchContext ) -> bool {
285+ let mut context_stack = vec ! [ ] ;
277286 let mut popped_result = false ;
278287
279288 ' coro: loop {
280- let Some ( mut ctx) = context_stack. pop ( ) else {
281- break ;
282- } ;
283-
284289 popped_result = ' result: loop {
285290 let yielded = ' context: loop {
286291 match ctx. jump {
@@ -864,9 +869,14 @@ fn _match<S: StrDrive>(req: &Request<S>, state: &mut State, ctx: MatchContext) -
864869 }
865870 } ;
866871 context_stack. push ( ctx) ;
867- context_stack . push ( yielded) ;
872+ ctx = yielded;
868873 continue ' coro;
869874 } ;
875+ if let Some ( popped_ctx) = context_stack. pop ( ) {
876+ ctx = popped_ctx;
877+ } else {
878+ break ;
879+ }
870880 }
871881 popped_result
872882}
@@ -1148,6 +1158,13 @@ impl MatchContext {
11481158 req. pattern_codes [ self . code_position + peek]
11491159 }
11501160
1161+ fn try_peek_code_as < T , S > ( & self , req : & Request < S > , peek : usize ) -> Result < T , T :: Error >
1162+ where
1163+ T : TryFrom < u32 > ,
1164+ {
1165+ self . peek_code ( req, peek) . try_into ( )
1166+ }
1167+
11511168 fn skip_code ( & mut self , skip : usize ) {
11521169 self . code_position += skip;
11531170 }
0 commit comments