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 = 16_384;
pub const CAPTURE_WORK_LIMIT: usize = 65_536;
pub const TEXT_SOURCE_BYTE_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,
}
#[must_use = "a bound refusal names which declared magnitude the capture would have passed"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CaptureBound {
Depth,
Level,
Tree,
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),
}
#[must_use = "a literal refusal names why the spelling could not be read into a value"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LiteralReadCause {
NotAKnownForm,
NotReadable,
}
#[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)]
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,
}
#[must_use = "a lexical refusal names the spelling distinction that could not be normalized"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TextLexicalCause {
BlockCommentNotTerminated,
InvalidIdentifier,
UnknownPrefix,
UnknownLifetimePrefix,
GuardedStringPrefix,
MalformedLiteral,
LifetimeStartsWithNumber,
Frontmatter,
UnknownToken,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TextReadCause {
NotTerminated,
NotEscapeFree,
NotBalanced,
NotOpened,
SourceBytesUnbounded,
Lexical(TextLexicalCause),
Unbounded(CaptureBound),
}
#[must_use = "a read refusal carries the established cause and the byte it sits at"]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TextReadRefusal {
pub cause: TextReadCause,
pub at: u64,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct TextCapture {
pub(super) input: CapturedInput,
pub(super) spans: SpanTable,
}