aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/format/context.lux
blob: c6ffbed82f9f0931a09a0d1177dacd4bf9431181 (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
(.module:
  lux
  (lux (control ["p" parser]
                ["ex" exception #+ exception:]
                [monad #+ do])
       (data ["E" error]
             (coll (dict ["dict" unordered #+ Dict])))))

(exception: #export (Unknown-Property {property Text})
  property)

(type: #export Context
  (Dict Text Text))

(type: #export (Property a)
  (p.Parser Context a))

(def: #export (property name)
  (-> Text (Property Text))
  (function (_ context)
    (case (dict.get name context)
      (#.Some value)
      (ex.return [context value])
      
      #.None
      (ex.throw Unknown-Property name))))

(def: #export (run context property)
  (All [a] (-> Context (Property a) (E.Error a)))
  (case (property context)
    (#E.Success [_ output])
    (#E.Success output)

    (#E.Error error)
    (#E.Error error)))