use crate::api;
use crate::bytesearch::{AsciiBitmap, ByteArraySet, ByteBitmap};
use crate::types::{BracketContents, CaptureGroupID};
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: u32,
pub min_iters: usize,
pub max_iters: usize,
pub greedy: bool,
pub exit: JumpTarget,
}
#[derive(Debug, Clone)]
pub enum Insn {
Goal,
Char(char),
CharICase(char),
StartOfLine,
EndOfLine,
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(BracketContents),
AsciiBracket(AsciiBitmap),
LookaheadInsn {
negate: bool,
start_group: CaptureGroupID,
end_group: CaptureGroupID,
continuation: JumpTarget,
},
LookbehindInsn {
negate: bool,
start_group: CaptureGroupID,
end_group: CaptureGroupID,
continuation: JumpTarget,
},
WordBoundary {
invert: bool,
},
CharSet([char; 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, Copy, Clone)]
pub enum StartPredicate {
Arbitrary,
ByteSeq1([u8; 1]),
ByteSeq2([u8; 2]),
ByteSeq3([u8; 3]),
ByteSeq4([u8; 4]),
ByteSet2([u8; 2]),
ByteBracket(ByteBitmap),
}
#[derive(Debug, Clone)]
pub struct CompiledRegex {
pub insns: Vec<Insn>,
pub start_pred: StartPredicate,
pub loops: u32,
pub groups: u32,
pub flags: api::Flags,
}