diff --git a/pitfall/pitfall/minimal-pdf.rkt b/pitfall/pitfall/minimal-pdf.rkt index e6e0080c..8e0c0763 100644 --- a/pitfall/pitfall/minimal-pdf.rkt +++ b/pitfall/pitfall/minimal-pdf.rkt @@ -43,4 +43,9 @@ stream endstream endobj +trailer + << /Root 1 0 R + /Size 5 + >> + %%EOF \ No newline at end of file diff --git a/pitfall/pitfall/parse.rkt b/pitfall/pitfall/parse.rkt index d1e7cb40..78bb3851 100644 --- a/pitfall/pitfall/parse.rkt +++ b/pitfall/pitfall/parse.rkt @@ -88,3 +88,11 @@ (define (pf-header num) (co-header num)) (define (pf-comment text) (co-comment text)) + +(define (pf-trailer dict) + (let ([h (co-dict-dict dict)]) + (unless (and (hash-has-key? h 'Size) (hash-has-key? h 'Root)) + (raise-argument-error 'pf-trailer + "Size and Root keys are required for trailer" + (hash-keys h)))) + (co-trailer dict)) diff --git a/pitfall/pitfall/parser.rkt b/pitfall/pitfall/parser.rkt index 5cb1e395..bf019b21 100644 --- a/pitfall/pitfall/parser.rkt +++ b/pitfall/pitfall/parser.rkt @@ -1,7 +1,8 @@ #lang brag -pf-program : [pf-header] pf-object* +pf-program : pf-header pf-body pf-trailer pf-header : PDF-HEADER +@pf-body : pf-object* @pf-object : pf-null | CHAR | BOOLEAN | INT | REAL | pf-name | pf-string | pf-array | pf-dict | pf-stream | pf-indirect-object | pf-indirect-object-ref | pf-comment @pf-null : NULL pf-name : NAME @@ -13,4 +14,8 @@ pf-dict : /"<" /"<" (pf-dict-key pf-dict-value)* /">" /">" pf-stream : pf-dict STREAM-DATA pf-indirect-object : INT INT /"obj" pf-object /"endobj" pf-indirect-object-ref : INDIRECT-OBJECT-REF-TOK -pf-comment : COMMENT \ No newline at end of file +pf-comment : COMMENT + +;pf-xref-table : + +pf-trailer : /"trailer" pf-dict \ No newline at end of file diff --git a/pitfall/pitfall/render.rkt b/pitfall/pitfall/render.rkt index 655e368c..efc84cfe 100644 --- a/pitfall/pitfall/render.rkt +++ b/pitfall/pitfall/render.rkt @@ -44,7 +44,11 @@ stream @(loop (co-stream-data x)) endstream}] - [(co-comment? x) (co-comment-text x)] + #;[(co-comment? x) (co-comment-text x)] + [(co-trailer? x) @string-append{ + trailer + @(loop (co-trailer-dict x)) + }] [(symbol? x) @string-append{/@(symbol->string x)}] [(number? x) @number->string{@x}] [(string? x) (bytes->string/utf-8 (string->bytes/latin-1 x))] diff --git a/pitfall/pitfall/struct.rkt b/pitfall/pitfall/struct.rkt index 93266fe5..9b141a9c 100644 --- a/pitfall/pitfall/struct.rkt +++ b/pitfall/pitfall/struct.rkt @@ -8,4 +8,5 @@ (struct co-header (string) #:transparent) (struct co-io (idx rev thing) #:transparent) (struct co-io-ref (idx rev) #:transparent) -(struct co-comment (text) #:transparent) \ No newline at end of file +(struct co-comment (text) #:transparent) +(struct co-trailer (dict) #:transparent) \ No newline at end of file diff --git a/pitfall/pitfall/tokenizer.rkt b/pitfall/pitfall/tokenizer.rkt index 79100951..3927a25e 100644 --- a/pitfall/pitfall/tokenizer.rkt +++ b/pitfall/pitfall/tokenizer.rkt @@ -27,7 +27,7 @@ [(:seq "%PDF-" digits "." digits (:? (:: pdf-eol "%" (:>= 4 (:~ (union #\return #\newline)))))) (token 'PDF-HEADER lexeme)] [pdf-whitespace (token 'IGNORE lexeme #:skip? #t)] - [(from/stop-before "%" #\newline) (token 'COMMENT lexeme)] + [(from/stop-before "%" #\newline) (token 'COMMENT lexeme #:skip? #t)] [(:or "true" "false") (token 'BOOLEAN (equal? lexeme "true"))] [(:seq optional-sign digits) (token 'INT (string->number lexeme))] [(:seq optional-sign (:or (:seq digits "." (:? digits)) @@ -37,7 +37,7 @@ ["null" (token 'NULL 'null)] [(:seq "(" (:* (:or not-right-paren substring)) ")") (token 'STRING-TOK lexeme)] [(:seq hex-digit hex-digit) (token 'HEX-DIGIT-PAIR (string->number lexeme 16))] - [(:or "<" ">" "[" "]" "obj" "endobj") (token lexeme lexeme)] + [(:or "<" ">" "[" "]" "obj" "endobj" "trailer") (token lexeme lexeme)] [(from/to "stream" "endstream") (token 'STREAM-DATA (string-trim (trim-ends "stream" lexeme "endstream") "\n"))] [any-char (token 'CHAR lexeme)])) (λ () (lex-one-token port)))