Skip to main content

AtomStream

Struct AtomStream 

Source
pub struct AtomStream { /* private fields */ }
Expand description

A parse source over an eagerly lexed token vector, which remembers how far the parse ever got and stops it if it goes on too long.

Backtracking runs through syan’s Tape, which owns the pushback and the checkpoint scopes, so the forwarding half of this is a thin shim; the mark and the budget are the parts that are not.

Implementations§

Source§

impl AtomStream

Source

pub fn new(atoms: Vec<Atom>) -> Self

Wrap an eagerly lexed atom vector, with the budget Budget calibrates for its size.

Source

pub fn with_budget(atoms: Vec<Atom>, budget: Budget) -> Self

Self::new with the budget chosen by the caller.

Source

pub fn furthest(&self) -> usize

End byte of the furthest atom the parser ever consumed; 0 if it consumed nothing.

Consumed, not peeked: a lookahead that rejects a token has not made progress through it, and counting it would push every diagnostic one token to the right.

Source

pub fn furthest_span(&self) -> Option<Span>

The span of the atom that set Self::furthest — the token the parse stopped at.

It is the token ending at the mark, not the one starting after it: the generated leaf parsers are next() → match → push()-back-on- mismatch (see crate::leaf), so the offending token has already been pulled through the stream by the time the leaf rejects it. Reporting the token after it would put every diagnostic one token to the right.

Source

pub fn exhausted(&self) -> bool

Whether the parse hit its budget rather than reaching a real verdict.

When this is true, the failure the parser reported means only “the stream ended”, which is this type’s doing and not the source’s — so the caller must not dress it up as a claim about the source. crate::parse_error::locate does not.

Source

pub fn served(&self) -> u64

How many atoms have been served, counting every re-read. Exposed for calibrating Budget against a real corpus.

Trait Implementations§

Source§

impl ParseStream for AtomStream

Source§

type Atom = WithSpan<Token, Span>

The unit of input this stream serves.
Source§

type Error = Infallible

What the underlying source reports when it fails; see get_error.
Source§

fn next(&mut self) -> Option<Self::Atom>

Consume and return the next atom, or None at end of input.
Source§

fn peek(&mut self) -> Option<&Self::Atom>

The atom next would return, without consuming it.
Source§

fn push(&mut self, atom: Self::Atom)

Hand an atom back; it is served before anything still unread.
Source§

fn checkpoint_raw(&mut self) -> u64

Open a transaction; the returned token identifies it. Read more
Source§

fn rollback_raw(&mut self, raw: u64)

Undo everything consumed since raw was taken, and close that scope.
Source§

fn commit_raw(&mut self, raw: u64)

Keep everything consumed since raw was taken, and close that scope.
Source§

fn get_error(&mut self) -> Result<(), Self::Error>

Report an error the source has accumulated (a lexer that failed mid-stream, say), as opposed to a parse failure. Ok(()) for a source that cannot fail.
Source§

fn skip_sep(&mut self) -> bool

Skip the separator atoms if exists. Returns whether we skipped some separators. Read more
Source§

fn validate_spacing<S>(&mut self, is_joint: bool) -> Result<(), ParseError<S>>
where S: Span, Self: Sized, Self::Atom: Spanned<Span = S>,

Check the spacing before the next atom: is_joint demands no separator here, false demands one. Fails with ParseError::Spacing if the input disagrees.
Source§

fn dup<T, E, F>(&mut self, f: F) -> Result<T, E>
where F: FnOnce(&mut Self) -> Result<T, E>, Self: Sized,

Run a sub-parser as a transaction on this stream. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoParseStream for T
where T: ParseStream,

Source§

type Atom = <T as ParseStream>::Atom

The unit of input the resulting stream serves.
Source§

type Output = T

The stream this becomes.
Source§

fn into_parse_stream(self) -> <T as IntoParseStream>::Output

Build the stream.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.