Last active
July 30, 2020 15:16
-
-
Save hyotang666/13ec68837c848024e9e4d80cfca1da25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun read-delimited-exps | |
(end-char &optional (stream *standard-input*) recursive-p) | |
(do ((char (peek-char t stream t t recursive-p) | |
(peek-char t stream t t recursive-p)) | |
(acc)) | |
((char= char end-char) | |
(read-char stream) ; discard close paren. | |
(nreverse acc)) | |
(case char | |
(#\. ; dot list. | |
(read-char stream) ; discard #\. character. | |
(let* ((elt (read stream t t recursive-p)) | |
(char (peek-char t stream t t recursive-p))) | |
(if (char= char end-char) | |
(progn (read-char stream) ; to discard #\). | |
(return (nreconc acc elt))) | |
(let ((macro-char (get-macro-character char))) | |
(if macro-char | |
(multiple-value-call | |
(lambda (&optional (return nil suppliedp)) | |
(when (or return suppliedp) | |
(error "More than one element follow . in list."))) | |
(funcall macro-char stream (read-char stream))) | |
(error "More than one element follow . in list.")))))) | |
(otherwise | |
(let ((macro-char (get-macro-character char))) | |
(if macro-char | |
(multiple-value-call | |
(lambda (&optional (return nil suppliedp)) | |
(when (or return suppliedp) | |
(push return acc))) | |
(funcall macro-char stream (read-char stream))) | |
(push (read stream t t recursive-p) acc))))))) | |
(let ((parens "[]{}⁅⁆⁽⁾₍₎⌈⌉⌊⌋〈〉⎛⎜⎝⎞⎟⎠⎡⎢⎣⎤⎥⎦⎧⎨⎩⎪⎫⎬⎭⎰⎱ ⎴⎵⎶⏜⏝⏞⏟⏠⏡❪❫❬❭❮❯❰❱❲❳❴❵⟦⟧⟨⟩⟪⟫⟮⟯⦃⦄⦅⦆⦇⦈⦉⦊⦋⦌⦍⦎⦏⦐⦑⦒⦗⦘⧼⧽⸨⸩ 〈〉《》「」『』【】〔〕〖〗〚〛﴾﴿︗︘︵︶︷︸︹︺︻︼︽︾︿﹀﹁﹂﹃﹄﹇﹈﹙﹚﹛﹜﹝﹞]{}⁅⁆⁽⁾₍₎⌈⌉⌊⌋〈〉⎛⎜⎝⎞⎟⎠⎡⎢⎣⎤⎥⎦⎧⎨⎩⎪⎫⎬⎭⎰⎱")) | |
(loop :for (open close) :on (coerce parens 'list) :by #'cddr | |
:do (set-macro-character open (lambda (stream character) | |
(declare (ignore character)) | |
(read-delimited-exps close stream t))) | |
(multiple-value-call #'set-macro-character | |
close | |
(get-macro-character #\))))) | |
{let [(a 1) | |
(b 2)] | |
「list a b <+ a b>」} | |
; -> (1 2 3) | |
(] | |
; -> Error. |
Now any parens above are supported!
🄜⒪⒮⒯ ⒝⒭⒤⒧⒧⒤⒜⒩⒯ 🄛⒤⒮⒫ ⒠⒱⒠⒭!
Thank you💛
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[]{}⁅⁆⁽⁾₍₎⌈⌉⌊⌋〈〉⎛⎜⎝⎞⎟⎠⎡⎢⎣⎤⎥⎦⎧⎨⎩⎪⎫⎬⎭⎰⎱
⎴⎵⎶⏜⏝⏞⏟⏠⏡❪❫❬❭❮❯❰❱❲❳❴❵⟦⟧⟨⟩⟪⟫⟮⟯⦃⦄⦅⦆⦇⦈⦉⦊⦋⦌⦍⦎⦏⦐⦑⦒⦗⦘⧼⧽⸨⸩
〈〉《》「」『』【】〔〕〖〗〚〛﴾﴿︗︘︵︶︷︸︹︺︻︼︽︾︿﹀﹁﹂﹃﹄﹇﹈﹙﹚﹛﹜﹝﹞