main
Matthew Butterick 7 years ago
parent e46714c6af
commit f3e6435ebc

@ -43,4 +43,9 @@ stream
endstream
endobj
trailer
<< /Root 1 0 R
/Size 5
>>
%%EOF

@ -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))

@ -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
pf-comment : COMMENT
;pf-xref-table :
pf-trailer : /"trailer" pf-dict

@ -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))]

@ -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)
(struct co-comment (text) #:transparent)
(struct co-trailer (dict) #:transparent)

@ -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)))

Loading…
Cancel
Save