aboutsummaryrefslogtreecommitdiff
path: root/licentia/source/program/licentia/input.lux
blob: ff14a78d67a7199e6078969a55314d03e13edab8 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
(.using
  [library
   [lux "*"
    [abstract
     [monad {"+" do}]]
    [control
     ["[0]" exception {"+" exception:}]
     ["<>" parser
      ["<[0]>" json {"+" Parser}]]]
    [data
     [text
      ["%" format {"+" format}]]]
    [math
     [number
      ["n" nat]
      ["i" int]
      ["f" frac]]]]]
  ["[0]" // "_"
   ["[1]" license {"+" Identification
                   Termination
                   Liability
                   Distribution
                   Commercial
                   Extension
                   Entity Black_List
                   URL Attribution
                   Addendum
                   License}
    ["[0]" time {"+" Period}]
    ["[0]" copyright]]])

(def: identification
  (Parser Identification)
  (<json>.object
    ($_ <>.and
        (<json>.field "name" <json>.string)
        (<json>.field "version" <json>.string))))

(exception: .public (cannot_use_fractional_amount [amount Frac])
  (exception.report
   ["Amount" (%.frac amount)]))

(exception: .public (cannot_use_negative_amount [amount Int])
  (exception.report
   ["Amount" (%.int amount)]))

(def: amount
  (Parser Nat)
  (do <>.monad
    [amountF <json>.number
     #let [amountI (f.int amountF)]
     _ (<>.assert (exception.construct ..cannot_use_fractional_amount [amountF])
                  (f.= amountF
                       (i.frac amountI)))
     _ (<>.assert (exception.construct ..cannot_use_negative_amount [amountI])
                  (i.> +0 amountI))]
    (wrap (.nat amountI))))

(exception: .public (invalid_period [period (Period Nat)])
  (exception.report
   ["Start" (%.nat (value@ time.#start period))]
   ["End" (%.nat (value@ time.#end period))]))

(def: period
  (Parser (Period Nat))
  (<json>.object
    (do <>.monad
      [start (<json>.field "start" ..amount)
       end (<json>.field "end" ..amount)
       #let [period [time.#start start
                     time.#end end]]
       _ (<>.assert (exception.construct ..invalid_period [period])
                    (n.<= end start))]
      (wrap period))))

(def: copyright_holder
  (Parser copyright.Holder)
  (<json>.object
    ($_ <>.and
        (<json>.field "name" <json>.string)
        (<json>.field "period" ..period))))

(def: termination
  (Parser Termination)
  (<json>.object
    ($_ <>.and
        (<json>.field "patent retaliation?" <json>.boolean)
        (<json>.field "termination period" ..amount)
        (<json>.field "grace period" ..amount))))

(def: liability
  (Parser Liability)
  (<json>.object
    ($_ <>.and
        (<json>.field "can accept?" <json>.boolean)
        (<json>.field "disclaim high risk?" <json>.boolean))))

(def: distribution
  (Parser Distribution)
  (<json>.object
    ($_ <>.and
        (<json>.field "can re-license?" <json>.boolean)
        (<json>.field "can multi-license?" <json>.boolean))))

(def: commercial
  (Parser Commercial)
  (<json>.object
    ($_ <>.and
        (<json>.field "can sell?" <json>.boolean)
        (<json>.field "require contributor credit?" <json>.boolean)
        (<json>.field "allow contributor endorsement?" <json>.boolean))))

(def: extension
  (Parser Extension)
  (<json>.object
    ($_ <>.and
        (<json>.field "same license?" <json>.boolean)
        (<json>.field "must be distinguishable?" <json>.boolean)
        (<json>.field "notification period" (<json>.nullable ..period))
        (<json>.field "must describe modifications?" <json>.boolean))))

(def: entity
  (Parser Entity)
  <json>.string)

(def: black_list
  (Parser Black_List)
  (<json>.object
    ($_ <>.and
        (<json>.field "justification" (<json>.nullable <json>.string))
        (<json>.field "entities" (<json>.array (<>.many ..entity))))))

(def: url
  (Parser URL)
  <json>.string)

(def: attribution
  (Parser Attribution)
  (<json>.object
    ($_ <>.and
        (<json>.field "copyright-notice" <json>.string)
        (<json>.field "phrase" (<json>.nullable <json>.string))
        (<json>.field "url" ..url)
        (<json>.field "image" (<json>.nullable ..url)))))

(def: addendum
  (Parser Addendum)
  (<json>.object
    ($_ <>.and
        (<json>.field "commons clause?" <json>.boolean)
        )))

(def: .public license
  (Parser License)
  (<json>.object
    ($_ <>.and
        (<json>.field "copyright-holders" (<json>.array (<>.many ..copyright_holder)))
        (<json>.field "identification" (<json>.nullable ..identification))
        (<json>.field "termination" ..termination)
        (<json>.field "liability" ..liability)
        (<json>.field "distribution" ..distribution)
        (<json>.field "commercial" ..commercial)
        (<json>.field "extension" ..extension)
        (<json>.field "black-lists" (<json>.array (<>.some ..black_list)))
        (<json>.field "attribution" (<json>.nullable ..attribution))
        (<>.default [//.#commons_clause? false]
                    (<json>.field "addendum" ..addendum))
        )))