/** * One COS lexical token (ISO 32000-1 §7.2/§7.3): a number, name, string (literal * or hex), an array/dictionary delimiter, a bare keyword (`obj` / `R` / `stream` * / `true` / …), or end-of-input. */ export type Token = { readonly kind: 'num'; readonly value: number; } | { readonly kind: 'name'; readonly value: string; } | { readonly kind: 'str'; readonly value: string; } | { readonly kind: 'hexstr'; readonly bytes: Uint8Array; } | { readonly kind: 'arrayOpen'; } | { readonly kind: 'arrayClose'; } | { readonly kind: 'dictOpen'; } | { readonly kind: 'dictClose'; } | { readonly kind: 'keyword'; readonly value: string; } | { readonly kind: 'eof'; }; /** * COS lexer (ISO 32000-1 §7.2/§7.3): scans a PDF byte buffer into a stream of * {@link Token}s. The parser drives it with look-ahead to recover the object * grammar. `pos` is the public cursor; callers (and the parser's rewind logic) * read and assign it directly. */ export declare class Lexer { private readonly buf; pos: number; /** * @param buf The PDF byte buffer to tokenize. * @param pos The starting byte offset (defaults to the start of the buffer). */ constructor(buf: Uint8Array, pos?: number); /** The length of the underlying byte buffer. */ get length(): number; /** The bytes between two offsets, as a view onto the buffer. */ slice(from: number, to: number): Uint8Array; /** The byte at index `i`, or −1 when out of range. */ byteAt(i: number): number; /** §7.2.3 — skip whitespace and `%`-to-end-of-line comments. */ skipWhitespace(): void; /** Read and consume the next {@link Token} from the current position. */ nextToken(): Token; /** Read a numeric token (optional sign, digits and a decimal point). */ private readNumber; /** Read a `/Name` token, decoding `#XX` hex escapes (§7.3.5). */ private readName; /** Read a bare keyword token: a run of regular bytes (`obj`, `R`, `true`, …). */ private readKeyword; /** Read a `<…>` hex string (§7.3.4.3); an odd trailing digit takes a low nibble of 0. */ private readHexString; /** * Read a `(…)` literal string (§7.3.4.2): handles nested parentheses, backslash * escapes and octal codes. The bytes are decoded latin1. */ private readLiteralString; /** * First index of an ASCII `needle` at or after `from` (−1 if none). Used to find * `endstream` when a stream's `/Length` is missing or an unresolved reference. */ indexOfAscii(needle: string, from: number): number; /** * §7.3.8.1 — read a stream's raw bytes. `pos` must sit right after the `stream` * keyword. The keyword is followed by CRLF (or a lone LF); the data then runs * for `length` bytes, or — when the length is unknown — up to `endstream`. * Leaves `pos` at the `endstream` keyword. */ readStreamBody(length: number | undefined): Uint8Array; } /** * Bytes → a Latin-1 (ISO-8859-1) string: each byte becomes the code point of the * same value, so the string round-trips back to the exact bytes. PDF text in * strings is decoded to Unicode later (via the font's `/ToUnicode`); at the COS * layer a string is just bytes. */ export declare function latin1(bytes: Uint8Array): string;