aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux.lux
blob: a5c8c9167f90bfbd5e44e5bba9a250ba17cd6d38 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(.using
 [library
  [lux (.except)
   [control
    ["<>" parser (.only)
     ["<[0]>" binary (.only Parser)]]]
   [data
    [binary
     ["_" \\format (.only Writer)]]]
   [meta
    ["[0]" version]]]]
 ["[0]" /
  [analysis
   ["[0]" module]]
  [///
   [meta
    [archive
     ["[0]" signature]
     ["[0]" key (.only Key)]]]]])

... TODO: Remove #module_hash, #imports & #module_state ASAP.
... TODO: Not just from this parser, but from the lux.Module type.
(def: .public writer
  (Writer .Module)
  (let [definition (is (Writer Definition)
                       (all _.and _.bit _.type _.any))
        labels (is (Writer [Text (List Text)])
                   (_.and _.text (_.list _.text)))
        global_type (is (Writer [Bit Type (Either [Text (List Text)]
                                                  [Text (List Text)])])
                        (all _.and _.bit _.type (_.or labels labels)))
        global_label (is (Writer .Label)
                         (all _.and _.bit _.type (_.list _.text) _.nat))
        alias (is (Writer Alias)
                  (_.and _.text _.text))
        global (is (Writer Global)
                   (all _.or
                        definition
                        global_type
                        global_label
                        global_label
                        alias))]
    (all _.and
         ... #module_hash
         _.nat
         ... #module_aliases
         (_.list alias)
         ... #definitions
         (_.list (_.and _.text global))
         ... #imports
         (_.list _.text)
         ... #module_state
         _.any)))

(def: .public parser
  (Parser .Module)
  (let [definition (is (Parser Definition)
                       (all <>.and
                            <binary>.bit
                            <binary>.type
                            <binary>.any))
        labels (is (Parser [Text (List Text)])
                   (all <>.and
                        <binary>.text
                        (<binary>.list <binary>.text)))
        global_type (is (Parser [Bit Type (Either [Text (List Text)]
                                                  [Text (List Text)])])
                        (all <>.and
                             <binary>.bit
                             <binary>.type
                             (<binary>.or labels labels)))
        global_label (is (Parser .Label)
                         (all <>.and
                              <binary>.bit
                              <binary>.type
                              (<binary>.list <binary>.text)
                              <binary>.nat))
        alias (is (Parser Alias)
                  (all <>.and
                       <binary>.text
                       <binary>.text))
        global (is (Parser Global)
                   (all <binary>.or
                        definition
                        global_type
                        global_label
                        global_label
                        alias))]
    (all <>.and
         ... #module_hash
         <binary>.nat
         ... #module_aliases
         (<binary>.list alias)
         ... #definitions
         (<binary>.list (<>.and <binary>.text global))
         ... #imports
         (<binary>.list <binary>.text)
         ... #module_state
         (at <>.monad in {.#Cached}))))

(def: .public key
  (Key .Module)
  (key.key [signature.#name (symbol ..compiler)
            signature.#version version.latest]
           (module.empty 0)))