1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 10:07:45 +03:00

Expand quote, quasiquote, unquote and splice-unquote

This commit is contained in:
Iqbal Ansari 2016-08-15 23:10:58 +05:30
parent 3ccd8eaa68
commit fa78d99b18

View File

@ -10,9 +10,9 @@
\\)\\|[^\"\\]\\)*\"$"
"RE string")
(defvar *tokenizer-re* "[[:space:],]*\\(~@\\|[][{}()`'^@]\\|\"\\(\\\\\\(.\\|
(defvar *tokenizer-re* "[[:space:],]*\\(~@\\|[][{}()~`'^@]\\|\"\\(\\\\\\(.\\|
\\)\\|[^\"\\]\\)*\"\\?\\|;[^
]*\\|[^][[:space:]{}()`'\";]*\\)"
]*\\|[^][[:space:]~{}()`'\";]*\\)"
"RE")
(define-condition eof (error)
@ -89,8 +89,21 @@
"]"
'vector)))
((string= token "{") (make-mal-hash-map (read-hash-map reader)))
((string= token "'") (expand-quote reader))
((string= token "`") (expand-quote reader))
((string= token "~") (expand-quote reader))
((string= token "~@") (expand-quote reader))
(t (read-atom reader)))))
(defun expand-quote (reader)
(let ((quote (next reader)))
(make-mal-list (list (make-mal-symbol (cond
((string= quote "'") "quote")
((string= quote "`") "quasiquote")
((string= quote "~") "unquote")
((string= quote "~@") "splice-unquote")))
(read-form reader)))))
(defun read-mal-sequence (reader &optional (delimiter ")") (constructor 'list))
;; Consume the opening brace
(consume reader)