diff options
author | rekado <rekado@elephly.net> | 2015-08-16 05:11:20 +0200 |
---|---|---|
committer | rekado <rekado@elephly.net> | 2015-08-17 22:56:02 +0200 |
commit | 69b4e3db8cac30029fb94640f30354ac7c338b5b (patch) | |
tree | 36c75f637672ec664094cb535760198a5c215342 | |
parent | 2bef983c813bcdaeb35acf68992534e5d9a5a79c (diff) |
Add reader for skribe format.
-rw-r--r-- | skribe.scm | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/skribe.scm b/skribe.scm new file mode 100644 index 0000000..c7d8380 --- /dev/null +++ b/skribe.scm @@ -0,0 +1,58 @@ +(define-module (skribe) + #:use-module ((system reader) #:renamer (symbol-prefix-proc 'r:)) + #:export (%skribe-reader)) + +;; Taken from Skribilo +(define (make-colon-free-token-reader tr) + ;; Stolen from `guile-reader' 0.3. + "If token reader @var{tr} handles the @code{:} (colon) character, remove it +from its specification and return the new token reader." + (let* ((spec (r:token-reader-specification tr)) + (proc (r:token-reader-procedure tr))) + (r:make-token-reader (filter (lambda (chr) + (not (char=? chr #\:))) + spec) + proc))) + +(define &sharp-reader + ;; The reader for what comes after a `#' character. + (let* ((dsssl-keyword-reader ;; keywords à la `#!key' + (r:make-token-reader #\! + (r:token-reader-procedure + (r:standard-token-reader 'keyword))))) + (r:make-reader (cons dsssl-keyword-reader + (map r:standard-token-reader + '(character srfi-4 vector + number+radix boolean + srfi30-block-comment + srfi62-sexp-comment))) + #f ;; use default fault handler + 'reader/record-positions))) + +(define (make-skribe-reader) + (let ((colon-keywords ;; keywords à la `:key' fashion + (r:make-token-reader #\: + (r:token-reader-procedure + (r:standard-token-reader 'keyword)))) + (symbol-misc-chars-tr + ;; Make sure `:' is handled only by the keyword token reader. + (make-colon-free-token-reader + (r:standard-token-reader 'r6rs-symbol-misc-chars)))) + + ;; Note: we use the `r6rs-symbol-*' and `r6rs-number' token readers since + ;; they consider square brackets as delimiters. + (r:make-reader (cons* (r:make-token-reader #\# &sharp-reader) + colon-keywords + symbol-misc-chars-tr + (map r:standard-token-reader + `(whitespace + sexp string r6rs-number + r6rs-symbol-lower-case + r6rs-symbol-upper-case + quote-quasiquote-unquote + semicolon-comment + skribe-exp))) + #f ;; use the default fault handler + 'reader/record-positions))) + +(define %skribe-reader (make-skribe-reader)) |