Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit af1a53c

Browse files
committed
impl Match.groups()
1 parent 8fba935 commit af1a53c

File tree

1 file changed

+72
-177
lines changed

1 file changed

+72
-177
lines changed

interp.rs

Lines changed: 72 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ impl OpMinRepeatOne {
10701070
}
10711071
}
10721072

1073-
// Everything is stored in RepeatContext
10741073
struct OpMaxUntil {
10751074
jump_id: usize,
10761075
count: isize,
@@ -1088,189 +1087,85 @@ impl Default for OpMaxUntil {
10881087
impl OpcodeExecutor for OpMaxUntil {
10891088
fn next(&mut self, drive: &mut StackDrive) -> Option<()> {
10901089
match self.jump_id {
1091-
0 => self._0(drive),
1092-
1 => self._1(drive),
1093-
2 => self._2(drive),
1094-
3 => self._3(drive),
1095-
4 => self._4(drive),
1096-
_ => unreachable!(),
1097-
}
1098-
}
1099-
}
1100-
impl OpMaxUntil {
1101-
fn _0(&mut self, drive: &mut StackDrive) -> Option<()> {
1102-
let RepeatContext {
1103-
count,
1104-
code_position,
1105-
last_position,
1106-
} = *drive.repeat_ctx();
1107-
drive.ctx_mut().code_position = code_position;
1108-
let mincount = drive.peek_code(2) as usize;
1109-
let maxcount = drive.peek_code(3) as usize;
1110-
drive.state.string_position = drive.ctx().string_position;
1111-
self.count = count + 1;
1090+
0 => {
1091+
let RepeatContext {
1092+
count,
1093+
code_position,
1094+
last_position,
1095+
} = *drive.repeat_ctx();
1096+
drive.ctx_mut().code_position = code_position;
1097+
let mincount = drive.peek_code(2) as usize;
1098+
let maxcount = drive.peek_code(3) as usize;
1099+
drive.state.string_position = drive.ctx().string_position;
1100+
self.count = count + 1;
11121101

1113-
if (self.count as usize) < mincount {
1114-
// not enough matches
1115-
drive.repeat_ctx_mut().count = self.count;
1116-
drive.push_new_context(4);
1117-
self.jump_id = 1;
1118-
return Some(());
1119-
}
1102+
if (self.count as usize) < mincount {
1103+
// not enough matches
1104+
drive.repeat_ctx_mut().count = self.count;
1105+
drive.push_new_context(4);
1106+
self.jump_id = 1;
1107+
return Some(());
1108+
}
11201109

1121-
if ((count as usize) < maxcount || maxcount == MAXREPEAT)
1122-
&& drive.state.string_position != last_position
1123-
{
1124-
// we may have enough matches, if we can match another item, do so
1125-
drive.repeat_ctx_mut().count = self.count;
1126-
drive.state.marks_push();
1127-
self.save_last_position = last_position;
1128-
drive.repeat_ctx_mut().last_position = drive.state.string_position;
1129-
drive.push_new_context(4);
1130-
self.jump_id = 2;
1131-
return Some(());
1132-
}
1110+
if ((count as usize) < maxcount || maxcount == MAXREPEAT)
1111+
&& drive.state.string_position != last_position
1112+
{
1113+
// we may have enough matches, if we can match another item, do so
1114+
drive.repeat_ctx_mut().count = self.count;
1115+
drive.state.marks_push();
1116+
self.save_last_position = last_position;
1117+
drive.repeat_ctx_mut().last_position = drive.state.string_position;
1118+
drive.push_new_context(4);
1119+
self.jump_id = 2;
1120+
return Some(());
1121+
}
11331122

1134-
self.jump_id = 3;
1135-
self.next(drive)
1136-
}
1137-
fn _1(&mut self, drive: &mut StackDrive) -> Option<()> {
1138-
let child_ctx = drive.state.popped_context.unwrap();
1139-
drive.ctx_mut().has_matched = child_ctx.has_matched;
1140-
if drive.ctx().has_matched != Some(true) {
1141-
drive.repeat_ctx_mut().count = self.count - 1;
1142-
drive.state.string_position = drive.ctx().string_position;
1143-
}
1144-
None
1145-
}
1146-
fn _2(&mut self, drive: &mut StackDrive) -> Option<()> {
1147-
drive.repeat_ctx_mut().last_position = self.save_last_position;
1148-
let child_ctx = drive.state.popped_context.unwrap();
1149-
if child_ctx.has_matched == Some(true) {
1150-
drive.state.marks_pop_discard();
1151-
drive.ctx_mut().has_matched = Some(true);
1152-
return None;
1153-
}
1154-
drive.state.marks_pop();
1155-
drive.repeat_ctx_mut().count = self.count - 1;
1156-
drive.state.string_position = drive.ctx().string_position;
1157-
self.jump_id = 3;
1158-
self.next(drive)
1159-
}
1160-
fn _3(&mut self, drive: &mut StackDrive) -> Option<()> {
1161-
// cannot match more repeated items here. make sure the tail matches
1162-
drive.skip_code(drive.peek_code(1) as usize + 1);
1163-
drive.push_new_context(1);
1164-
self.jump_id = 4;
1165-
Some(())
1166-
}
1167-
fn _4(&mut self, drive: &mut StackDrive) -> Option<()> {
1168-
let child_ctx = drive.state.popped_context.unwrap();
1169-
drive.ctx_mut().has_matched = child_ctx.has_matched;
1170-
if drive.ctx().has_matched != Some(true) {
1171-
drive.state.string_position = drive.ctx().string_position;
1123+
self.jump_id = 3;
1124+
self.next(drive)
1125+
}
1126+
1 => {
1127+
let child_ctx = drive.state.popped_context.unwrap();
1128+
drive.ctx_mut().has_matched = child_ctx.has_matched;
1129+
if drive.ctx().has_matched != Some(true) {
1130+
drive.repeat_ctx_mut().count = self.count - 1;
1131+
drive.state.string_position = drive.ctx().string_position;
1132+
}
1133+
None
1134+
}
1135+
2 => {
1136+
drive.repeat_ctx_mut().last_position = self.save_last_position;
1137+
let child_ctx = drive.state.popped_context.unwrap();
1138+
if child_ctx.has_matched == Some(true) {
1139+
drive.state.marks_pop_discard();
1140+
drive.ctx_mut().has_matched = Some(true);
1141+
return None;
1142+
}
1143+
drive.state.marks_pop();
1144+
drive.repeat_ctx_mut().count = self.count - 1;
1145+
drive.state.string_position = drive.ctx().string_position;
1146+
self.jump_id = 3;
1147+
self.next(drive)
1148+
}
1149+
3 => {
1150+
// cannot match more repeated items here. make sure the tail matches
1151+
drive.skip_code(drive.peek_code(1) as usize + 1);
1152+
drive.push_new_context(1);
1153+
self.jump_id = 4;
1154+
Some(())
1155+
}
1156+
4 => {
1157+
let child_ctx = drive.state.popped_context.unwrap();
1158+
drive.ctx_mut().has_matched = child_ctx.has_matched;
1159+
if drive.ctx().has_matched != Some(true) {
1160+
drive.state.string_position = drive.ctx().string_position;
1161+
}
1162+
None
1163+
}
1164+
_ => unreachable!(),
11721165
}
1173-
None
11741166
}
11751167
}
11761168

1177-
// struct OpMaxUntil {
1178-
// jump_id: usize,
1179-
// count: isize,
1180-
// save_last_position: isize,
1181-
// }
1182-
// impl Default for OpMaxUntil {
1183-
// fn default() -> Self {
1184-
// Self {
1185-
// jump_id: 0,
1186-
// count: 0,
1187-
// save_last_position: -1,
1188-
// }
1189-
// }
1190-
// }
1191-
// impl OpcodeExecutor for OpMaxUntil {
1192-
// fn next(&mut self, drive: &mut StackDrive) -> Option<()> {
1193-
// match self.jump_id {
1194-
// 0 => {
1195-
// drive.state.string_position = drive.ctx().string_position;
1196-
// let repeat = match drive.state.repeat_stack.last_mut() {
1197-
// Some(repeat) => repeat,
1198-
// None => {
1199-
// panic!("Internal re error: MAX_UNTIL without REPEAT.");
1200-
// }
1201-
// };
1202-
// self.count = repeat.count + 1;
1203-
1204-
// if self.count < repeat.mincount as isize {
1205-
// // not enough matches
1206-
// repeat.count = self.count;
1207-
// drive.push_new_context(4);
1208-
// self.jump_id = 1;
1209-
// return Some(());
1210-
// }
1211-
1212-
// if (self.count < repeat.maxcount as isize || repeat.maxcount == MAXREPEAT)
1213-
// && (drive.state.string_position as isize != repeat.last_position)
1214-
// {
1215-
// // we may have enough matches, if we can match another item, do so
1216-
// repeat.count = self.count;
1217-
// self.save_last_position = repeat.last_position;
1218-
// repeat.last_position = drive.state.string_position as isize;
1219-
// drive.state.marks_push();
1220-
// drive.push_new_context(4);
1221-
// self.jump_id = 2;
1222-
// return Some(());
1223-
// }
1224-
1225-
// drive.push_new_context(1);
1226-
1227-
// self.jump_id = 3;
1228-
// Some(())
1229-
// }
1230-
// 1 => {
1231-
// let child_ctx = drive.state.popped_context.unwrap();
1232-
// drive.ctx_mut().has_matched = child_ctx.has_matched;
1233-
// if drive.ctx().has_matched != Some(true) {
1234-
// drive.state.string_position = drive.ctx().string_position;
1235-
// let repeat = drive.state.repeat_stack.last_mut().unwrap();
1236-
// repeat.count = self.count - 1;
1237-
// }
1238-
// None
1239-
// }
1240-
// 2 => {
1241-
// let repeat = drive.state.repeat_stack.last_mut().unwrap();
1242-
// repeat.last_position = drive.state.string_position as isize;
1243-
// let child_ctx = drive.state.popped_context.unwrap();
1244-
// if child_ctx.has_matched == Some(true) {
1245-
// drive.state.marks_pop_discard();
1246-
// drive.ctx_mut().has_matched = Some(true);
1247-
// return None;
1248-
// }
1249-
// repeat.count = self.count - 1;
1250-
// drive.state.marks_pop();
1251-
// drive.state.string_position = drive.ctx().string_position;
1252-
1253-
// drive.push_new_context(1);
1254-
1255-
// self.jump_id = 3;
1256-
// Some(())
1257-
// }
1258-
// 3 => {
1259-
// // cannot match more repeated items here. make sure the tail matches
1260-
// let child_ctx = drive.state.popped_context.unwrap();
1261-
// drive.ctx_mut().has_matched = child_ctx.has_matched;
1262-
// if drive.ctx().has_matched != Some(true) {
1263-
// drive.state.string_position = drive.ctx().string_position;
1264-
// } else {
1265-
// drive.state.repeat_stack.pop();
1266-
// }
1267-
// None
1268-
// }
1269-
// _ => unreachable!(),
1270-
// }
1271-
// }
1272-
// }
1273-
12741169
struct OpMinUntil {
12751170
jump_id: usize,
12761171
count: isize,

0 commit comments

Comments
 (0)