use crate::bounded::Bounded;
#[path = "type_guard.rs"]
mod guard;
pub const TOKEN_PATH_DEPTH_LIMIT: usize = 32;
pub const CAPTURED_TOKEN_LIMIT: usize = 4096;
pub const CAPTURED_TREE_TOKEN_LIMIT: usize = CAPTURE_WORK_LIMIT - CAPTURED_TOKEN_LIMIT;
pub const CAPTURE_WORK_LIMIT: usize = 65_536;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct SpanHandle(u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CoordinateRole {
Byte,
SemanticOrigin,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct SourceCoordinate {
pub role: CoordinateRole,
pub position: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CapturedDelimiter {
Parenthesis,
Brace,
Bracket,
Bare,
}
crate::roster! {
#[must_use = "a bound refusal names which declared magnitude the capture would have passed"]
pub enum CaptureBound {
Depth = "depth",
Level = "level",
Tree = "tree",
Work = "work",
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TokenPath {
steps: Bounded<u32, TOKEN_PATH_DEPTH_LIMIT>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CaptureWalk {
remaining: usize,
taken: usize,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CapturedAtom {
Word(String),
Punct(char),
Text(String),
Number(String),
ByteText(Vec<u8>),
Character(char),
Byte(u8),
NulTerminatedText(Vec<u8>),
RawIdentifier(String),
JointPunct(char),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CapturedPayload {
Word(String),
Punct(char),
Text(String),
Number(String),
Group {
delimiter: CapturedDelimiter,
trees: Bounded<CapturedTokenTree, CAPTURED_TOKEN_LIMIT>,
},
ByteText(Vec<u8>),
Character(char),
Byte(u8),
NulTerminatedText(Vec<u8>),
RawIdentifier(String),
JointPunct(char),
}
crate::roster! {
#[must_use = "a literal refusal names why the spelling could not be read into a value"]
pub enum LiteralReadCause {
NotAKnownForm = "not-a-known-form",
NotReadable = "not-readable",
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CapturedTokenTree {
payload: CapturedPayload,
path: TokenPath,
span: SpanHandle,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CapturedInput {
trees: Bounded<CapturedTokenTree, CAPTURED_TOKEN_LIMIT>,
issued: usize,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct CapturedFragment<'tokens> {
pub(super) tokens: &'tokens [CapturedTokenTree],
pub(super) end: Option<SpanHandle>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum CaptureBuilderStanding {
Ready,
Refused { retained_before_capture: usize },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum CaptureLevelStanding {
Open,
Finished,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CaptureBuilder<Position> {
positions: Vec<Position>,
walk: CaptureWalk,
standing: CaptureBuilderStanding,
}
pub struct CaptureLevel<'capture, Position> {
positions: &'capture mut Vec<Position>,
walk: &'capture mut CaptureWalk,
builder_standing: &'capture mut CaptureBuilderStanding,
retained_before_capture: usize,
path: TokenPath,
trees: Bounded<CapturedTokenTree, CAPTURED_TOKEN_LIMIT>,
standing: CaptureLevelStanding,
}
#[must_use = "a capture refusal names whether a declared bound or the producer's own reading stopped construction"]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum CaptureBuildRefusal<Position, ProducerRefusal> {
Unbounded {
bound: CaptureBound,
at: Position,
},
ProducerRefused {
cause: ProducerRefusal,
path: TokenPath,
at: SpanHandle,
},
}
#[must_use = "a resolution refusal carries the handle and how far the table reaches"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct SpanResolutionRefusal {
pub handle: SpanHandle,
pub reaches: usize,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SpanTable {
ByteOffsets(Bounded<u64, CAPTURED_TREE_TOKEN_LIMIT>),
ProducerHeld,
}