Skip to main content

Parser

Struct Parser 

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

Recursive-descent parser over a byte buffer.

Create positioned at an offset (Parser::at) and call one of the top-level entry points (Parser::parse_object, Parser::parse_indirect_object). The parser owns a lexer plus a two-token peek buffer (see module docs on the N G R lookahead).

Implementations§

Source§

impl<'a> Parser<'a>

Source

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

Parser over buf starting at absolute offset pos.

Source

pub const fn with_stream_length_policy(self, policy: StreamLengthPolicy) -> Self

Set the /Length-disagreement policy (builder form).

See StreamLengthPolicy for why the non-default value is restricted to the recovery path.

Source

pub const fn stream_lengths_recovered(&self) -> usize

How many stream extents this parser re-derived from endstream because the stored /Length was unusable.

Always 0 under StreamLengthPolicy::Strict (that policy errors instead of repairing), so a non-zero value is proof that the file disagreed with itself. Callers propagate it into the counted disclosure a front end shows the operator.

Source

pub const fn with_terminator_policy(self, policy: TerminatorPolicy) -> Self

Set the missing-endobj policy (builder form).

See TerminatorPolicy for why the non-default value is restricted to the recovery path.

Source

pub const fn missing_endobj_recovered(&self) -> usize

How many definitions this parser accepted with no endobj.

Always 0 under TerminatorPolicy::Strict, so a non-zero value is proof the file omitted a required keyword. Callers propagate it into the counted disclosure a front end shows the operator.

Source

pub const fn with_duplicate_key_policy(self, policy: DuplicateKeyPolicy) -> Self

Choose what happens when a dictionary names one key twice (§7.3.7).

DuplicateKeyPolicy::Refuse unless a caller asks otherwise — see that type for why the document loader opts in and the parser does not opt in for it.

Source

pub fn duplicate_keys_resolved(&self) -> usize

How many duplicate dictionary keys this parser resolved instead of refusing.

Always 0 under DuplicateKeyPolicy::Refuse, so a non-zero value is proof the file contradicted itself — which is why it is carried out to the operator rather than absorbed (R20, fuzzy-never-sneaky). The value pdfcer kept is the LAST one; the earlier one is gone from the loaded document and would not survive a save.

Source

pub fn duplicate_keys(&self) -> &[DuplicateKeyRecord]

Every duplicate key this parser resolved, with the value kept and the value discarded.

Empty under DuplicateKeyPolicy::Refuse. The caller tags each with the object it came from and carries it out as a crate::document::LoadAnomaly, which is what makes the operator’s choice offerable rather than theoretical.

Source

pub fn parse_object(&mut self) -> Result<Object, ParseError>

Parse one direct object (any §7.3 value, including N G R references). This is the entry point for trailer dictionaries and other bare-value positions.

§Errors

ParseError on malformed syntax — see ParseErrorKind.

Source

pub fn parse_indirect_object( &mut self, resolve_length: LengthResolver<'_>, ) -> Result<IndirectObject, ParseError>

Parse one complete indirect-object definition (N G obj <value> endobj, or the stream form) starting at this parser’s position — normally an offset taken from the xref table.

resolve_length is consulted only when a stream’s /Length is an indirect reference (§7.3.10 EXAMPLE 3); pass a closure over the xref/document (or &mut |_| None where indirect lengths are illegal, e.g. xref-stream bootstrap — §7.5.8.2’s directness rules).

§Errors

ParseError on malformed structure — see ParseErrorKind.

Trait Implementations§

Source§

impl<'a> Debug for Parser<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> RefUnwindSafe for Parser<'a>

§

impl<'a> Send for Parser<'a>

§

impl<'a> Sync for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

§

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

Source§

type Output = T

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