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 Token
s, 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>
impl<C: Character, S: TextLineSource<C>> InputTokenizer<C, S>
Sourcepub fn new(source: S) -> Self
pub fn new(source: S) -> Self
Create a new InputTokenizer
from a TextLineSource
Sourcepub fn readline<T: Token<Char = C>, F: FnMut(T)>(&mut self, f: F)
pub fn readline<T: Token<Char = C>, F: FnMut(T)>(&mut self, f: F)
\readline
- read a line of input as Character
s of CategoryCode::Other
(except for
, which has
Space
) and passing each token to the given function.
Sourcepub 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>>
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 Character
s in the currenct CategoryCodeScheme
, respecting
braces (CategoryCode::BeginGroup
and EndGroup
) and passing each token to the
given function.
Sourcepub 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>>
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
.
Trait Implementations§
Source§impl<C: Clone + Character, S: Clone + TextLineSource<C>> Clone for InputTokenizer<C, S>
impl<C: Clone + Character, S: Clone + TextLineSource<C>> Clone for InputTokenizer<C, S>
Source§fn clone(&self) -> InputTokenizer<C, S>
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<C, S> Freeze for InputTokenizer<C, S>where
S: Freeze,
impl<C, S> RefUnwindSafe for InputTokenizer<C, S>where
S: RefUnwindSafe,
C: RefUnwindSafe,
impl<C, S> Send for InputTokenizer<C, S>
impl<C, S> Sync for InputTokenizer<C, S>
impl<C, S> Unpin for InputTokenizer<C, S>
impl<C, S> UnwindSafe for InputTokenizer<C, S>where
S: UnwindSafe,
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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