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>
impl<'a> Lexer<'a>
Sourcepub const fn new(data: &'a [u8], pos: usize) -> Self
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.
Sourcepub const fn with_limits(self, limits: &Limits) -> Self
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.
Sourcepub const fn set_pos(&mut self, pos: usize)
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.
Sourcepub const fn reached_end(&self) -> bool
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.
Sourcepub fn skip_whitespace(&mut self)
pub fn skip_whitespace(&mut self)
Skips white-space and % comments.
Added in 0.2.0.
Sourcepub fn next_token(&mut self) -> Result<Token<'a>>
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.