#[cfg(not(feature = "std"))]
use {
alloc::{string::String, vec::Vec},
hashbrown::HashMap,
};
use crate::api;
use crate::bytesearch::{AsciiBitmap, ByteArraySet, ByteBitmap};
use crate::types::{BracketContents, CaptureGroupID, LoopID};
extern crate memchr;
use memchr::memmem;
type JumpTarget = u32;
pub const MAX_BYTE_SEQ_LENGTH: usize = 16;
pub const MAX_BYTE_SET_LENGTH: usize = 4;
pub const MAX_CHAR_SET_LENGTH: usize = 4;
#[derive(Debug, Clone)]
pub struct LoopFields {
pub loop_id: LoopID,
pub min_iters: usize,
pub max_iters: usize,
pub greedy: bool,
pub exit: JumpTarget,
}
#[derive(Debug, Clone)]
pub enum Insn {
Goal,
Char(u32),
CharICase(u32),
StartOfLine {
multiline: bool,
},
EndOfLine {
multiline: bool,
},
MatchAny,
MatchAnyExceptLineTerminator,
EnterLoop(LoopFields),
LoopAgain {
begin: JumpTarget,
},
Loop1CharBody {
min_iters: usize,
max_iters: usize,
greedy: bool,
},
Jump {
target: JumpTarget,
},
Alt {
secondary: JumpTarget,
},
BeginCaptureGroup(CaptureGroupID),
EndCaptureGroup(CaptureGroupID),
ResetCaptureGroup(CaptureGroupID),
BackRef(u32),
Bracket(usize),
AsciiBracket(AsciiBitmap),
Lookahead {
negate: bool,
start_group: CaptureGroupID,
end_group: CaptureGroupID,
continuation: JumpTarget,
},
Lookbehind {
negate: bool,
start_group: CaptureGroupID,
end_group: CaptureGroupID,
continuation: JumpTarget,
},
WordBoundary {
invert: bool,
},
WordBoundaryUnicodeICase {
invert: bool,
},
CharSet([u32; MAX_CHAR_SET_LENGTH]),
ByteSet2(ByteArraySet<[u8; 2]>),
ByteSet3(ByteArraySet<[u8; 3]>),
ByteSet4(ByteArraySet<[u8; 4]>),
ByteSeq1([u8; 1]),
ByteSeq2([u8; 2]),
ByteSeq3([u8; 3]),
ByteSeq4([u8; 4]),
ByteSeq5([u8; 5]),
ByteSeq6([u8; 6]),
ByteSeq7([u8; 7]),
ByteSeq8([u8; 8]),
ByteSeq9([u8; 9]),
ByteSeq10([u8; 10]),
ByteSeq11([u8; 11]),
ByteSeq12([u8; 12]),
ByteSeq13([u8; 13]),
ByteSeq14([u8; 14]),
ByteSeq15([u8; 15]),
ByteSeq16([u8; 16]),
JustFail,
}
#[derive(Debug, Clone)]
pub enum StartPredicate {
Arbitrary,
ByteSet1([u8; 1]),
ByteSet2([u8; 2]),
ByteSet3([u8; 3]),
ByteSeq(Box<memmem::Finder<'static>>),
ByteBracket(ByteBitmap),
StartAnchored,
}
#[derive(Debug, Clone)]
pub struct CompiledRegex {
pub insns: Vec<Insn>,
pub brackets: Vec<BracketContents>,
pub start_pred: StartPredicate,
pub loops: u32,
pub groups: u32,
pub group_names: Box<[Box<str>]>,
pub flags: api::Flags,
}