aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/macro.lux
blob: 7c192cb2be58c7488876850a01daa3940543156a (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
##  Copyright (c) Eduardo Julian. All rights reserved.
##  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
##  If a copy of the MPL was not distributed with this file,
##  You can obtain one at http://mozilla.org/MPL/2.0/.

(;module:
  lux
  (lux (control monad)
       (data (struct [list "List/" Monad<List>])
             text/format)
       [compiler]
       (macro ["s" syntax #+ syntax: Syntax])))

(def: omit^
  (Syntax Bool)
  (s;tag? ["" "omit"]))

(do-template [<macro> <func>]
  [(syntax: #export (<macro> {? omit^} token)
     (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]
  )