aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/tool/compiler/language/lux.lux
blob: f237ebeaea24509078a7952760badc53b96d4763 (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 "*"
   [control
    ["<>" parser
     ["<[0]>" binary {"+" Parser}]]]
   [data
    [format
     ["_" binary {"+" Writer}]]]
   [meta
    ["[0]" version]]]]
 ["[0]" / "_"
  [analysis
   ["[0]" module]]
  [///
   [meta
    [archive
     ["[0]" signature]
     ["[0]" key {"+" 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)
                       ($_ _.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)])])
                        ($_ _.and _.bit _.type (_.or labels labels)))
        global_label (is (Writer .Label)
                         ($_ _.and _.bit _.type (_.list _.text) _.nat))
        alias (is (Writer Alias)
                  (_.and _.text _.text))
        global (is (Writer Global)
                   ($_ _.or
                       definition
                       global_type
                       global_label
                       global_label
                       alias))]
    ($_ _.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)
                       ($_ <>.and
                           <binary>.bit
                           <binary>.type
                           <binary>.any))
        labels (is (Parser [Text (List Text)])
                   ($_ <>.and
                       <binary>.text
                       (<binary>.list <binary>.text)))
        global_type (is (Parser [Bit Type (Either [Text (List Text)]
                                                  [Text (List Text)])])
                        ($_ <>.and
                            <binary>.bit
                            <binary>.type
                            (<binary>.or labels labels)))
        global_label (is (Parser .Label)
                         ($_ <>.and
                             <binary>.bit
                             <binary>.type
                             (<binary>.list <binary>.text)
                             <binary>.nat))
        alias (is (Parser Alias)
                  ($_ <>.and
                      <binary>.text
                      <binary>.text))
        global (is (Parser Global)
                   ($_ <binary>.or
                       definition
                       global_type
                       global_label
                       global_label
                       alias))]
    ($_ <>.and
        ... #module_hash
        <binary>.nat
        ... #module_aliases
        (<binary>.list alias)
        ... #definitions
        (<binary>.list (<>.and <binary>.text global))
        ... #imports
        (<binary>.list <binary>.text)
        ... #module_state
        (# <>.monad in {.#Cached}))))

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