lex & parse paths

main
Matthew Butterick 8 years ago
parent 09963bf5a5
commit 5fe0ad25ae

@ -1,4 +1,5 @@
#lang pitfall/racket
(require brag/support sugar/list)
(provide parse-svg-path)
(define (parse-svg-path doc path)
@ -6,12 +7,14 @@
(apply-commands commands doc))
(define (parse path)
(let* ([path (string-replace path "," " ")] ; no commas
[path (string-replace path "-" " -")] ; at least one space before negative signs
[path (string-replace path #px"(?<=[A-Za-z])" " ")]) ; at least one space after letters
(for/list ([str (in-list (string-split path #px"(?=[A-Za-z])"))]
#:unless (zero? (string-length str)))
(read (open-input-string (format "(~a)" str))))))
(define lex-1
(lexer
[(eof) eof]
[alphabetic (string->symbol lexeme)]
[(:: (:? "-") (:+ numeric) (:? (:: "." (:+ numeric)))) (string->number lexeme)]
[(:or whitespace ",") (lex-1 input-port)]))
(slicef-at (for/list ([tok (in-port lex-1 (open-input-string path))])
tok) symbol?))
(module+ test
(require rackunit)

@ -24,4 +24,8 @@ make = (doc) ->
doc = new PDFDocument({compress: yes})
doc.pipe(fs.createWriteStream('test10c.pdf'))
make doc
doc = new PDFDocument({compress: no})
doc.pipe(fs.createWriteStream('test10.pdf'))
make doc

File diff suppressed because it is too large Load Diff

Binary file not shown.
Loading…
Cancel
Save