Struct InputTokenizer

Source
pub struct InputTokenizer<C: Character, S: TextLineSource<C>> {
    pub state: MouthState,
    pub source: S,
    /* private fields */
}
Expand description

Takes a TextLineSource and lazily turns it into Tokens, given a CategoryCodeScheme and an optional end-of-line Character. The primary use case is to process an input .tex file.

Example:

type T = StandardToken<u8,Ptr<str>>;
let mut cs_handler = ();
let cc = &DEFAULT_SCHEME_U8;

let string = "\\foo   \n  \n   {a}{!}";
let input: StringLineSource<u8> = string.into();
let mut tokenizer = InputTokenizer::new(input);
let eol = Some(b'\r');
let next = tokenizer.get_next(&mut cs_handler,cc,None); // \foo
assert!(matches!(next,Ok(Some(T::ControlSequence(s))) if &*s == "foo"));
let next = tokenizer.get_next(&mut cs_handler,cc,eol); // \par
assert!(matches!(next,Ok(Some(T::ControlSequence(s))) if &*s == "par"));
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // {
assert_eq!(next.command_code(), CommandCode::BeginGroup);
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // a
assert_eq!(next.command_code(), CommandCode::Letter);
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // }
assert_eq!(next.command_code(), CommandCode::EndGroup);
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // {
assert_eq!(next.command_code(), CommandCode::BeginGroup);
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // !
assert_eq!(next.command_code(), CommandCode::Other);
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // }
assert_eq!(next.command_code(), CommandCode::EndGroup);
let next : T = tokenizer.get_next(&mut cs_handler,cc,eol).unwrap().unwrap(); // end of line => space
assert_eq!(next.command_code(), CommandCode::Space);
assert!(tokenizer.get_next::<T>(&mut cs_handler,cc,eol).unwrap().is_none()); // EOF

Fields§

§state: MouthState§source: S

Implementations§

Source§

impl<C: Character, S: TextLineSource<C>> InputTokenizer<C, S>

Source

pub fn new(source: S) -> Self

Create a new InputTokenizer from a TextLineSource

Source

pub fn line(&self) -> usize

The current line

Source

pub fn column(&self) -> usize

The current column

Source

pub fn eof(&self) -> bool

whether the file end has been reached

Source

pub fn readline<T: Token<Char = C>, F: FnMut(T)>(&mut self, f: F)

\readline - read a line of input as Characters of CategoryCode::Other (except for , which has Space) and passing each token to the given function.

Source

pub fn read<T: Token<Char = C>, F: FnMut(T)>( &mut self, handler: &mut <<T as Token>::CS as CSName<<T as Token>::Char>>::Handler, cc: &CategoryCodeScheme<C>, endline: Option<C>, f: F, ) -> Result<(), InvalidCharacter<C>>

\read - read a line of input as Characters in the currenct CategoryCodeScheme, respecting braces (CategoryCode::BeginGroup and EndGroup) and passing each token to the given function.

Source

pub fn get_next<T: Token<Char = C>>( &mut self, handler: &mut <<T as Token>::CS as CSName<<T as Token>::Char>>::Handler, cc: &CategoryCodeScheme<C>, endline: Option<C>, ) -> Result<Option<T>, InvalidCharacter<C>>

Get the next Token from the InputTokenizer (if not empty). Throws InvalidCharacter on encountering a character of code CategoryCode::Invalid.

Source

pub fn preview<W: Write>(&self, len: &mut usize, f: W) -> Result

Only useful for debugging purposes: Print the next len Characters to the given Writer.

Trait Implementations§

Source§

impl<C: Clone + Character, S: Clone + TextLineSource<C>> Clone for InputTokenizer<C, S>

Source§

fn clone(&self) -> InputTokenizer<C, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + Character, S: Debug + TextLineSource<C>> Debug for InputTokenizer<C, S>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C, S> Freeze for InputTokenizer<C, S>
where S: Freeze,

§

impl<C, S> RefUnwindSafe for InputTokenizer<C, S>

§

impl<C, S> Send for InputTokenizer<C, S>
where S: Send, C: Send,

§

impl<C, S> Sync for InputTokenizer<C, S>
where S: Sync, C: Sync,

§

impl<C, S> Unpin for InputTokenizer<C, S>
where S: Unpin, C: Unpin,

§

impl<C, S> UnwindSafe for InputTokenizer<C, S>
where S: UnwindSafe, C: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<ET, Err, A> IntoErr<ET, Err> for A
where ET: EngineTypes, Err: From<A>,

Source§

fn into_err( self, _aux: &EngineAux<ET>, _state: &<ET as EngineTypes>::State, ) -> Err

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.