aboutsummaryrefslogtreecommitdiff
path: root/temper.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'temper.lisp')
-rw-r--r--temper.lisp36
1 files changed, 25 insertions, 11 deletions
diff --git a/temper.lisp b/temper.lisp
index 6893071..2007a3b 100644
--- a/temper.lisp
+++ b/temper.lisp
@@ -21,25 +21,39 @@
(append (list (list 'string before) (list 'code code)) (lex input))))))
+(defun tokens-to-code-string (tokens)
+ (apply #'concatenate 'string
+ (map
+ 'list
+ #'(lambda (token)
+ (let ((token-type (first token))
+ (token-content (second token)))
+ (if (eql token-type 'string)
+ (format nil "~S"
+ `(setf buf (concatenate
+ 'string
+ buf
+ ,(string-trim '(#\linefeed #\space) token-content)
+ '(#\linefeed))))
+ token-content)))
+ tokens)))
+
(defun generate (tokens)
`(progn
(setq buf "")
(eval ,(read-from-string
(concatenate 'string
- (map
- 'string
- #'(lambda (token)
- (let ((token-type (first token))
- (token-content (second token)))
- (if (eql token-type 'string)
- (format nil "~A"
- `(setf buf (concatenate 'string buf ,token-content)))
- token-content)))
- tokens))))))
+ "(progn "
+ (tokens-to-code-string tokens)
+ ")")))))
+
(setq res (generate (lex (read-all))))
-(setq str (format t "~{~A~^ ~}" res))
+(format t "~A" (eval res))
+; (setq str (format t "~{~S~^ ~}" res))
+
+
; (princ str)