mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-26 03:31:12 +08:00
deps/vm: vendor regress 0.11.1 补 Script/Script_Extensions 的 Unknown(Zzzz) 取值——上游表缺未分配码点集取值,规范合法模式 \p{Script=Unknown} 编译期 SyntaxError;fork 纯增量(0 行改动上游行,仅补区间表与解析臂),回归钉四则(未分配匹配/已分配不匹配/sc·scx·Zzzz 别名/既有取值不扰动)
This commit is contained in:
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
//! Execution engine bits.
|
||||
|
||||
use crate::api::Match;
|
||||
use crate::insn::CompiledRegex;
|
||||
use crate::position::PositionType;
|
||||
|
||||
/// A trait for finding the next match in a regex.
|
||||
/// This is broken out from Executor to avoid needing to thread lifetimes
|
||||
/// around.
|
||||
pub trait MatchProducer: core::fmt::Debug {
|
||||
/// The position type of our indexer.
|
||||
type Position: PositionType;
|
||||
|
||||
/// \return an initial position for the given start offset.
|
||||
fn initial_position(&self, offset: usize) -> Option<Self::Position>;
|
||||
|
||||
/// Attempt to match at the given location.
|
||||
/// \return either the Match and the position to start looking for the next
|
||||
/// match, or None on failure.
|
||||
fn next_match(
|
||||
&mut self,
|
||||
pos: Self::Position,
|
||||
next_start: &mut Option<Self::Position>,
|
||||
) -> Option<Match>;
|
||||
}
|
||||
|
||||
/// A trait for executing a regex.
|
||||
pub trait Executor<'r, 't>: MatchProducer {
|
||||
/// The ASCII variant.
|
||||
type AsAscii: Executor<'r, 't>;
|
||||
|
||||
/// Construct a new Executor.
|
||||
fn new(re: &'r CompiledRegex, text: &'t str) -> Self;
|
||||
}
|
||||
|
||||
/// A struct which enables iteration over matches.
|
||||
#[derive(Debug)]
|
||||
pub struct Matches<Producer: MatchProducer> {
|
||||
mp: Producer,
|
||||
position: Option<Producer::Position>,
|
||||
}
|
||||
|
||||
impl<Producer: MatchProducer> Matches<Producer> {
|
||||
pub fn new(mp: Producer, start: usize) -> Self {
|
||||
let position = mp.initial_position(start);
|
||||
Matches { mp, position }
|
||||
}
|
||||
}
|
||||
|
||||
impl<Producer: MatchProducer> Iterator for Matches<Producer> {
|
||||
type Item = Match;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let pos = self.position?;
|
||||
self.mp.next_match(pos, &mut self.position)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user