aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/meta/macro/syntax.lux
blob: 4b9710faa969a89abbf2de3c8c6eab129a962e6e (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(.require
 [library
  [lux (.except)
   ["$" documentation]
   [data
    [text (.only \n)
     ["%" \\format (.only format)]]
    [collection
     ["[0]" list (.use "[1]#[0]" monoid)]]]]]
 ["[0]" /
  ["[1][0]" check]
  ["[1][0]" declaration]
  ["[1][0]" definition]
  ["[1][0]" export]
  ["[1][0]" input]
  ["[1][0]" type
   ["[1]/[0]" variable]]]
 [\\library
  ["[0]" /]])

(def .public documentation
  (List $.Documentation)
  (list.partial ($.module /._
                          "")

                ($.definition /.syntax
                  (format \n "A more advanced way to define macros than 'macro'."
                          \n "The inputs to the macro can be parsed in complex ways through the use of syntax parsers."
                          \n "The macro body is also (implicitly) run in the Meta monad, to save some typing."
                          \n "Also, the compiler state can be accessed through a special binding.")
                  ($.example (def .public object
                               (syntax (_ lux_state [.let [imports (class_imports lux_state)]
                                                     .let [class_vars (list)]
                                                     super (opt (super_class_decl^ imports class_vars))
                                                     interfaces (tuple (some (super_class_decl^ imports class_vars)))
                                                     constructor_args (constructor_args^ imports class_vars)
                                                     methods (some (overriden_method_def^ imports))])
                                 (let [def_code (all text#composite "anon-class:"
                                                     (spaced (list (super_class_decl$ (maybe.else object_super_class super))
                                                                   (with_brackets (spaced (list#each super_class_decl$ interfaces)))
                                                                   (with_brackets (spaced (list#each constructor_arg$ constructor_args)))
                                                                   (with_brackets (spaced (list#each (method_def$ id) methods))))))]
                                   (in (list (` ((, (code.text def_code)))))))))))

                (all list#composite
                     /check.documentation
                     /declaration.documentation
                     /definition.documentation
                     /export.documentation
                     /input.documentation
                     /type/variable.documentation
                     )
                ))