main
Matthew Butterick 8 years ago
parent 418ae36414
commit 9462039de7

@ -1,7 +1,6 @@
#lang s-exp pitfall/render
(co-version 1.1)
(co-comment "%¥±ë")
(co-header "%PDF-1.1\n%¥±ë")
(co-io
1
0

@ -7,7 +7,8 @@
(module+ reader (provide read-syntax))
(define (read-syntax src port)
(define parse-tree (parse (make-tokenizer port src)))
;; use latin-1 reencoding to make one char = one byte
(define parse-tree (parse (make-tokenizer (open-input-string (bytes->string/latin-1 (port->bytes port))) src)))
(strip-bindings
#`(module pitfall-parse-mod pitfall/parse
#,parse-tree)))
@ -84,6 +85,6 @@
(define-macro (pf-indirect-object-ref (OBJ GEN _))
#'(co-io-ref OBJ GEN))
(define (pf-version num) (co-version num))
(define (pf-header num) (co-header num))
(define (pf-comment text) (co-comment text))

@ -1,7 +1,7 @@
#lang brag
pf-program : 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-version | pf-comment
@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-header | pf-comment
@pf-null : NULL
pf-name : NAME
pf-string : STRING-TOK | /"<" HEX-DIGIT-PAIR* /">"
@ -12,5 +12,5 @@ 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-version : PDF-VERSION
pf-header : PDF-HEADER
pf-comment : COMMENT

@ -21,6 +21,7 @@
(cond
[(co-version? x)
@string-append{%%PDF-@(number->string (co-version-num x))}]
[(co-header? x) (co-header-string x)]
[(co-array? x)
@string-append{[ @(string-join (map loop (co-array-items x)) " ") ]}]
[(co-io? x)

@ -5,6 +5,7 @@
(struct co-array (items) #:transparent)
(struct co-stream (dict data) #:transparent)
(struct co-version (num) #:transparent)
(struct co-header (string) #:transparent)
(struct co-io (idx rev thing) #:transparent)
(struct co-io-ref (idx rev) #:transparent)
(struct co-comment (text) #:transparent)

@ -12,8 +12,8 @@
(define-lex-abbrev blackspace (:~ pdf-whitespace))
(define-lex-abbrev not-right-paren (:~ ")"))
(define-lex-abbrev substring (:seq "(" (:* not-right-paren) ")"))
(define-lex-abbrev nonreg-char (:seq "#" hex-digit hex-digit))
(define-lex-abbrev pdf-eol (:or #\return #\newline (:: #\return #\newline)))
(define (make-tokenizer port [src #f])
(port-count-lines! port)
@ -24,7 +24,8 @@
[(:seq "%%EOF" any-string) eof]
[(:seq digits (:+ pdf-whitespace) digits (:+ pdf-whitespace) "R")
(token 'INDIRECT-OBJECT-REF-TOK (map string->number (string-split lexeme)))]
[(:seq "%PDF-" digits "." digits) (token 'PDF-VERSION (string->number (trim-ends "%PDF-" lexeme "")))]
[(: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)]
[(:or "true" "false") (token 'BOOLEAN (equal? lexeme "true"))]

Loading…
Cancel
Save