Created
June 7, 2013 07:12
-
-
Save mkamotsu/5727548 to your computer and use it in GitHub Desktop.
(expand t "${FOO} ${BAR}")を
(format t "~A ~A" FOO BAR)に変換するマクロ
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
(ql:quickload :cl-ppcre) | |
(defpackage :expand | |
(:use :cl :ppcre)) | |
(in-package :expand) | |
(defconstant +regex+ "\\$\\{(.*?)\\}") | |
(defun expand-string (string) | |
(regex-replace-all +regex+ string "~A")) | |
(defun expand-args (string) | |
(let ((args nil)) | |
(do-register-groups (arg) | |
(+regex+ string (nreverse args)) | |
(push (read-from-string arg) args)))) | |
(defmacro expand (stream string) | |
`(format ,stream ,(expand-string string) ,@(expand-args string))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment