Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2022
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.57 KB | None | 0 0
  1. (defpackage :program (:use #:cl #:cl-who #:parenscript))
  2. (in-package :program)
  3.  
  4. (setq *js-string-delimiter* #\")
  5.  
  6. (defmacro emit (language file &body body)
  7.  `(with-open-file (str ,file
  8.             :direction :output
  9.             :if-exists :supersede)
  10.     (princ ,(cond (`(eq ',language 'html)
  11.              `(with-html-output-to-string (s nil :prologue t :indent t) ,@body))
  12.            (`(eq ',language 'javascript)
  13.              `(ps ,@body))
  14.            (`(eq ',language 'json)
  15.              `(remove #\; (ps ,@body))))
  16.         str)))
  17.  
  18. (emit json "~/file.json"
  19.  (create "name" "Wiki-Links"
  20.       "description" "Organize your Wikipedia reading history.")
  21.  (create "version" 1
  22.       "permissions" (array "storage")))
  23.  
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ;; macro-expansion form that the code produces:
  26. ;;
  27. ;; (WITH-OPEN-FILE (STR "~/file.json" :DIRECTION :OUTPUT :IF-EXISTS :SUPERSEDE)
  28. ;;   (PRINC
  29. ;;    (WITH-HTML-OUTPUT-TO-STRING (S NIL :PROLOGUE T :INDENT T)
  30. ;;      (CREATE "name" "Wiki-Links" "description"
  31. ;;       "Organize your Wikipedia reading history.")
  32. ;;      (CREATE "version" 1 "permissions" (ARRAY "storage")))
  33. ;;    STR))
  34.  
  35. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  36. ;; macro-expansion form that i'm trying to produce:
  37. ;;
  38. ;; (WITH-OPEN-FILE (STR "~/file.json" :DIRECTION :OUTPUT :IF-EXISTS :SUPERSEDE)
  39. ;;   (PRINC
  40. ;;    (REMOVE #\;
  41. ;;            (PS
  42. ;;              (CREATE "name" "Wiki-Links" "description"
  43. ;;           "Organize your Wikipedia reading history.")
  44. ;;              (CREATE "version" 1 "permissions" (ARRAY "storage"))))
  45. ;;    STR))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement