mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 03:01:12 +08:00
fix: 同名捕获组回引与 groups 字段改末次已定义语义
This commit is contained in:
Vendored
+3
-9
@@ -1689,15 +1689,9 @@ where
|
||||
ir::Node::BackRef(group_indices[0] + 1)
|
||||
}
|
||||
_ => {
|
||||
// Unusual case of multiple groups sharing a name: the backref should try each in turn.
|
||||
// Lower to alternations of backreferences. Reverse to keep it right-associative: a | (b | (c | d))...
|
||||
let backrefs = group_indices
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|group_index| ir::Node::BackRef(*group_index + 1));
|
||||
backrefs
|
||||
.reduce(|right, left| ir::Node::Alt(Box::new(left), Box::new(right)))
|
||||
.unwrap()
|
||||
// Multiple groups sharing a name: the backref reads the
|
||||
// last occurrence that is defined at match time.
|
||||
ir::Node::BackRefLastDefined(group_indices.iter().map(|i| i + 1).collect())
|
||||
}
|
||||
};
|
||||
Ok(node)
|
||||
|
||||
Reference in New Issue
Block a user