From f22b366d6464f9ac6415cc2a384a8461608dd304 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 17 Nov 2018 19:30:21 -0800 Subject: [PATCH] next: match recursive dicts --- pitfall/ptest/check-pdf.rkt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pitfall/ptest/check-pdf.rkt b/pitfall/ptest/check-pdf.rkt index 26ce01b9..4c90520f 100644 --- a/pitfall/ptest/check-pdf.rkt +++ b/pitfall/ptest/check-pdf.rkt @@ -1,6 +1,6 @@ #lang debug racket (require rackunit) -(provide check-pdfs-equal?) +(provide (all-defined-out)) (define (xref-offset bs) (match (regexp-match #px"(?<=startxref\n)\\d+" bs) @@ -21,7 +21,13 @@ (pat-lex x ["\\s+" (parse-1 x)] ; whitespace ["\\d+ 0 obj" (parse-1 x)] ;; obj name - ["stream\n(.*?)\nendstream" => cadr] ;; stream + ["(<<\n.*\n>>)\\s*stream\n" ; dict with stream + => (λ (m) + (define d (parse-1 (open-input-bytes (cadr m)))) + (define stream-length + (read (open-input-bytes (cdr (assoc #"/Length" d))))) + (define stream (read-bytes stream-length x)) + (append d (list (cons 'stream stream))))] ["<<\n(.*)\n>>" ;; dict => (λ (m) (define items (parse-pdf-bytes (cadr m)))