diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-08 23:56:40 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-08 23:56:40 +0100 |
| commit | 21437030c5610a11c5d0664e114fe41b0896735c (patch) | |
| tree | 7c62cb1292a804e7770e534eb139ee45006d3a60 | |
| parent | d85e44552a1d59ad2f8a5539d8e7c0a42a3c56b8 (diff) | |
| download | temper-21437030c5610a11c5d0664e114fe41b0896735c.tar.gz temper-21437030c5610a11c5d0664e114fe41b0896735c.tar.bz2 temper-21437030c5610a11c5d0664e114fe41b0896735c.zip | |
Fixing generate, working with basic test
| -rw-r--r-- | temper.lisp | 36 |
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) |
