Skip to main content

Tokenizer

Struct Tokenizer 

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

Stateful, reusable line classifier. Buffer text with feed, flush the remainder with end, and reset with reset before reuse.

Implementations§

Source§

impl Tokenizer

Source

pub fn new() -> Self

Construct a fresh tokenizer at line 1.

Source

pub fn feed(&mut self, chunk: &str) -> Vec<Token>

Feed a chunk and return all complete-line tokens. A partial trailing line (no trailing \n) is buffered until the next Self::feed or Self::end. No-op once Self::end has been called; call Self::reset to reuse.

Source

pub fn end(&mut self) -> Vec<Token>

Flush any buffered partial line as a final token.

Source

pub fn reset(&mut self)

Return to a fresh state for reuse.

Source

pub fn tokenize_all(&mut self, text: &str) -> Vec<Token>

Tokenize an entire input in one shot.

Source

pub fn tokenize(&self, line: &str, line_num: u32) -> Token

Classify a single line (no state).

Source

pub fn is_op(&self, line: &str) -> bool

True when line parses as a hunk header verb.

Source

pub fn is_header(&self, line: &str) -> bool

True when line parses as a [PATH(#HASH)?] header.

Source

pub fn is_envelope_marker(&self, line: &str) -> bool

True when line is an envelope begin/end/abort marker.

Trait Implementations§

Source§

impl Debug for Tokenizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tokenizer

Source§

fn default() -> Self

Returns the “default value” for a type. 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, 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.