@@ -115,6 +115,7 @@ pub(crate) fn pymatch(
115
115
has_matched : None ,
116
116
} ;
117
117
state. context_stack . push ( ctx) ;
118
+ let mut dispatcher = OpcodeDispatcher :: new ( ) ;
118
119
119
120
let mut has_matched = None ;
120
121
loop {
@@ -123,7 +124,6 @@ pub(crate) fn pymatch(
123
124
}
124
125
let ctx_id = state. context_stack . len ( ) - 1 ;
125
126
let mut drive = StackDrive :: drive ( ctx_id, state) ;
126
- let mut dispatcher = OpcodeDispatcher :: new ( ) ;
127
127
128
128
has_matched = dispatcher. pymatch ( & mut drive) ;
129
129
state = drive. take ( ) ;
@@ -132,11 +132,11 @@ pub(crate) fn pymatch(
132
132
}
133
133
}
134
134
135
- if has_matched == None || has_matched == Some ( false ) {
136
- return None ;
135
+ if has_matched != Some ( true ) {
136
+ None
137
+ } else {
138
+ Some ( Match :: new ( & state, pattern. clone ( ) , string. clone ( ) ) )
137
139
}
138
-
139
- Some ( Match :: new ( & state, pattern. clone ( ) , string. clone ( ) ) )
140
140
}
141
141
142
142
#[ derive( Debug , Copy , Clone ) ]
@@ -344,7 +344,9 @@ impl OpcodeDispatcher {
344
344
while drive. remaining_codes ( ) > 0 && drive. ctx ( ) . has_matched . is_none ( ) {
345
345
let code = drive. peek_code ( 0 ) ;
346
346
let opcode = SreOpcode :: try_from ( code) . unwrap ( ) ;
347
- self . dispatch ( opcode, drive) ;
347
+ if !self . dispatch ( opcode, drive) {
348
+ return None ;
349
+ }
348
350
}
349
351
match drive. ctx ( ) . has_matched {
350
352
Some ( matched) => Some ( matched) ,
@@ -469,7 +471,7 @@ impl OpcodeDispatcher {
469
471
SreOpcode :: MAX_UNTIL => Box :: new ( OpMaxUntil :: default ( ) ) ,
470
472
SreOpcode :: MIN_UNTIL => Box :: new ( OpMinUntil :: default ( ) ) ,
471
473
SreOpcode :: REPEAT => Box :: new ( OpRepeat :: default ( ) ) ,
472
- SreOpcode :: REPEAT_ONE => Box :: new ( OpMinRepeatOne :: default ( ) ) ,
474
+ SreOpcode :: REPEAT_ONE => Box :: new ( OpRepeatOne :: default ( ) ) ,
473
475
SreOpcode :: MIN_REPEAT_ONE => Box :: new ( OpMinRepeatOne :: default ( ) ) ,
474
476
SreOpcode :: GROUPREF => once ( |drive| general_op_groupref ( drive, |x| x) ) ,
475
477
SreOpcode :: GROUPREF_IGNORE => once ( |drive| general_op_groupref ( drive, lower_ascii) ) ,
@@ -1329,7 +1331,7 @@ struct OpRepeatOne {
1329
1331
child_ctx_id : usize ,
1330
1332
mincount : usize ,
1331
1333
maxcount : usize ,
1332
- count : usize ,
1334
+ count : isize ,
1333
1335
}
1334
1336
impl Default for OpRepeatOne {
1335
1337
fn default ( ) -> Self {
@@ -1354,9 +1356,9 @@ impl OpcodeExecutor for OpRepeatOne {
1354
1356
return None ;
1355
1357
}
1356
1358
drive. state . string_position = drive. ctx ( ) . string_position ;
1357
- self . count = count ( drive, self . maxcount ) ;
1358
- drive. skip_char ( self . count ) ;
1359
- if self . count < self . mincount {
1359
+ self . count = count ( drive, self . maxcount ) as isize ;
1360
+ drive. skip_char ( self . count as usize ) ;
1361
+ if self . count < self . mincount as isize {
1360
1362
drive. ctx_mut ( ) . has_matched = Some ( false ) ;
1361
1363
return None ;
1362
1364
}
@@ -1378,7 +1380,7 @@ impl OpcodeExecutor for OpRepeatOne {
1378
1380
}
1379
1381
1 => {
1380
1382
// General case: backtracking
1381
- if self . count >= self . mincount {
1383
+ if self . count >= self . mincount as isize {
1382
1384
drive. state . string_position = drive. ctx ( ) . string_position ;
1383
1385
self . child_ctx_id = drive. push_new_context ( drive. peek_code ( 1 ) as usize + 1 ) ;
1384
1386
self . jump_id = 2 ;
0 commit comments