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>
impl<'a> Parser<'a>
Sourcepub const fn at(buf: &'a [u8], pos: usize) -> Self
pub const fn at(buf: &'a [u8], pos: usize) -> Self
Parser over buf starting at absolute offset pos.
Sourcepub const fn with_stream_length_policy(self, policy: StreamLengthPolicy) -> Self
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.
Sourcepub const fn stream_lengths_recovered(&self) -> usize
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.
Sourcepub const fn with_terminator_policy(self, policy: TerminatorPolicy) -> Self
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.
Sourcepub const fn missing_endobj_recovered(&self) -> usize
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.
Sourcepub const fn with_duplicate_key_policy(self, policy: DuplicateKeyPolicy) -> Self
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.
Sourcepub fn duplicate_keys_resolved(&self) -> usize
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.
Sourcepub fn duplicate_keys(&self) -> &[DuplicateKeyRecord]
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.
Sourcepub fn parse_object(&mut self) -> Result<Object, ParseError>
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.
Sourcepub fn parse_indirect_object(
&mut self,
resolve_length: LengthResolver<'_>,
) -> Result<IndirectObject, ParseError>
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.