Skip to main content

Lexer

Struct Lexer 

Source
pub struct Lexer<'a> { /* private fields */ }
Expand description

A cursor over PDF bytes that yields Tokens.

Added in 0.2.0.

Implementations§

Source§

impl<'a> Lexer<'a>

Source

pub const fn new(data: &'a [u8], pos: usize) -> Self

A lexer over data, starting at byte offset pos, with the default Limits.

Added in 0.2.0.

Source

pub const fn with_limits(self, limits: &Limits) -> Self

Applies limits (Limits::max_string_length bounds every string and name token).

Added in 0.2.0.

Source

pub const fn pos(&self) -> usize

The current byte offset.

Added in 0.2.0.

Source

pub const fn set_pos(&mut self, pos: usize)

Moves the cursor to byte offset pos (past the end is fine: the next token is Token::Eof).

Added in 0.2.0.

Source

pub const fn data(&self) -> &'a [u8] ⓘ

The whole input.

Added in 0.2.0.

Source

pub const fn reached_end(&self) -> bool

Whether lexing so far has looked for a byte past the end of the input (to finish a token, skip white-space or find out that there is no next token).

When it has not, every token read so far depends only on the bytes before the end, so lexing a window of a larger input gave the same tokens as lexing the whole input would. A caller reading a window (laminapdf-cos over a source without an in-memory slice) retries with a larger one when this is true and the window does not end the input.

Added in 0.2.0.

Source

pub fn skip_whitespace(&mut self)

Skips white-space and % comments.

Added in 0.2.0.

Source

pub fn next_token(&mut self) -> Result<Token<'a>>

Reads the next token, skipping leading white-space and comments.

§Errors

Error::UnexpectedEof for an unterminated string, Error::Syntax for an unbalanced ) or > or an invalid hex digit, Error::LimitExceeded for a string or name longer than Limits::max_string_length.

Added in 0.2.0.

Trait Implementations§

Source§

impl<'a> Clone for Lexer<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for Lexer<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Forget for Lexer<'a>

§

impl<'a> Freeze for Lexer<'a>

§

impl<'a> Move for Lexer<'a>

§

impl<'a> RefUnwindSafe for Lexer<'a>

§

impl<'a> Send for Lexer<'a>

§

impl<'a> Sync for Lexer<'a>

§

impl<'a> Unpin for Lexer<'a>

§

impl<'a> UnsafeUnpin for Lexer<'a>

§

impl<'a> UnwindSafe for Lexer<'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> 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> Same for T

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.