aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/macro.lux
blob: 2a4f5b3c18c776659eff28502c39136f55ba7711 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(;module:
  lux
  (lux (control monad)
       (data (coll [list "List/" Monad<List>])
             text/format)
       [compiler]
       (macro ["s" syntax #+ syntax: Syntax])))

(def: omit^
  (Syntax Bool)
  (s;this? (' #omit)))

(do-template [<macro> <func>]
  [(syntax: #export (<macro> [? omit^] token)
     {#;doc (doc "Performs a macro-expansion and logs the resulting ASTs."
                 "You can either use the resulting ASTs, or omit them."
                 "By omitting them, this macro produces nothing (just like the lux;comment macro)."
                 (<macro> (def: (foo bar baz)
                            (-> Int Int Int)
                            (i.+ bar baz))))}
     (do @
       [output (<func> token)
        #let [_ (List/map (. log! %ast)
                          output)]]
       (if ?
         (wrap (list))
         (wrap output))))]

  [expand      compiler;macro-expand]
  [expand-all  compiler;macro-expand-all]
  [expand-once compiler;macro-expand-once]
  )