Using racket serialization instead of simple reading of s-expressions.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
(require racket/string)
|
||||
(require racket/file)
|
||||
(require racket/port)
|
||||
(require racket/serialize)
|
||||
|
||||
(provide file->ini
|
||||
ini->file
|
||||
@@ -49,8 +50,8 @@
|
||||
(set! last-is-newline #f)
|
||||
(display (cadr line) out)
|
||||
(display "=" out)
|
||||
(display"VALUE:" out)
|
||||
(write (caddr line) out)
|
||||
(display"SER:" out)
|
||||
(write (serialize (caddr line)) out)
|
||||
(newline out))
|
||||
(error "Unknown line format")))))
|
||||
lines))))
|
||||
@@ -63,23 +64,29 @@
|
||||
(define re-num #px"^([+]|[-])?([0-9]+([.]([0-9]+))?)$")
|
||||
(define re-bool #px"^(#f|#t|true|false)$")
|
||||
(define re-value #px"^VALUE:(.*)$")
|
||||
(define re-serialize #px"^SER:(.*)$")
|
||||
|
||||
(define (interpret s)
|
||||
(let ((m (regexp-match re-value s)))
|
||||
(if (eq? m #f)
|
||||
(let ((ss (string-downcase (string-trim s))))
|
||||
(let ((m-num (regexp-match re-num ss)))
|
||||
(if (eq? m-num #f)
|
||||
(let ((m-b (regexp-match re-bool ss)))
|
||||
(if (eq? m-b #f)
|
||||
s
|
||||
(if (or (string=? ss "#t") (string=? ss "true"))
|
||||
#t
|
||||
#f)
|
||||
))
|
||||
(string->number (car m-num)))))
|
||||
(let* ((content (cadr m)))
|
||||
(with-input-from-string content read)))))
|
||||
(let ((sr (regexp-match re-serialize s)))
|
||||
(if (eq? sr #f)
|
||||
(let ((m (regexp-match re-value s)))
|
||||
(if (eq? m #f)
|
||||
(let ((ss (string-downcase (string-trim s))))
|
||||
(let ((m-num (regexp-match re-num ss)))
|
||||
(if (eq? m-num #f)
|
||||
(let ((m-b (regexp-match re-bool ss)))
|
||||
(if (eq? m-b #f)
|
||||
s
|
||||
(if (or (string=? ss "#t") (string=? ss "true"))
|
||||
#t
|
||||
#f)
|
||||
))
|
||||
(string->number (car m-num)))))
|
||||
(let* ((content (cadr m)))
|
||||
(with-handlers ([exn? (λ (e) content)])
|
||||
(with-input-from-string content read)))))
|
||||
(let ((content (cadr sr)))
|
||||
(deserialize (with-input-from-string content read))))))
|
||||
|
||||
(define (file->ini file*)
|
||||
(let* ((file (get-ini-file file*))
|
||||
|
||||
Reference in New Issue
Block a user