Skip to main content

Tokenizer

Struct Tokenizer 

Source
pub struct Tokenizer<'a> { /* private fields */ }
Available on crate feature text only.
Expand description

Stateful textproto tokenizer.

Holds a cursor into the input string and a small stack of open delimiters. peek caches its result so it is cheap to call repeatedly before read.

Implementations§

Source§

impl<'a> Tokenizer<'a>

Source

pub fn new(input: &'a str) -> Self

Create a tokenizer positioned at the start of input.

A leading UTF-8 byte-order mark (U+FEFF) is silently skipped — some editors prepend one when saving, and it is not a valid identifier start character.

Source

pub fn peek(&mut self) -> Result<Token<'a>, ParseError>

Look at the next token without consuming it.

The result is cached: repeated peek() calls do not re-parse.

§Errors

Any tokenization error at the upcoming position.

Source

pub fn read(&mut self) -> Result<Token<'a>, ParseError>

Consume and return the next token.

§Errors

Any tokenization error at the current position.

Source

pub fn line_col(&self, pos: usize) -> (u32, u32)

Convert a byte offset into the input into a 1-based (line, column).

Column counts Unicode scalar values, not bytes. pos past the end of input clamps to the final position.

Line and column use u32: inputs larger than ~4 GiB would wrap, but that is not a realistic textproto size and this is error-reporting only.

Auto Trait Implementations§

§

impl<'a> Freeze for Tokenizer<'a>

§

impl<'a> RefUnwindSafe for Tokenizer<'a>

§

impl<'a> Send for Tokenizer<'a>

§

impl<'a> Sync for Tokenizer<'a>

§

impl<'a> Unpin for Tokenizer<'a>

§

impl<'a> UnsafeUnpin for Tokenizer<'a>

§

impl<'a> UnwindSafe for Tokenizer<'a>

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.