mirror of
https://github.com/kanaka/mal.git
synced 2024-11-10 12:47:45 +03:00
Expand quote, quasiquote, unquote and splice-unquote
This commit is contained in:
parent
3ccd8eaa68
commit
fa78d99b18
@ -10,9 +10,9 @@
|
|||||||
\\)\\|[^\"\\]\\)*\"$"
|
\\)\\|[^\"\\]\\)*\"$"
|
||||||
"RE string")
|
"RE string")
|
||||||
|
|
||||||
(defvar *tokenizer-re* "[[:space:],]*\\(~@\\|[][{}()`'^@]\\|\"\\(\\\\\\(.\\|
|
(defvar *tokenizer-re* "[[:space:],]*\\(~@\\|[][{}()~`'^@]\\|\"\\(\\\\\\(.\\|
|
||||||
\\)\\|[^\"\\]\\)*\"\\?\\|;[^
|
\\)\\|[^\"\\]\\)*\"\\?\\|;[^
|
||||||
]*\\|[^][[:space:]{}()`'\";]*\\)"
|
]*\\|[^][[:space:]~{}()`'\";]*\\)"
|
||||||
"RE")
|
"RE")
|
||||||
|
|
||||||
(define-condition eof (error)
|
(define-condition eof (error)
|
||||||
@ -89,8 +89,21 @@
|
|||||||
"]"
|
"]"
|
||||||
'vector)))
|
'vector)))
|
||||||
((string= token "{") (make-mal-hash-map (read-hash-map reader)))
|
((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)))))
|
(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))
|
(defun read-mal-sequence (reader &optional (delimiter ")") (constructor 'list))
|
||||||
;; Consume the opening brace
|
;; Consume the opening brace
|
||||||
(consume reader)
|
(consume reader)
|
||||||
|
Loading…
Reference in New Issue
Block a user