aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/language/compiler/extension/bundle.lux
blob: e2d36fa73f7d5637865c30fdb79d0418d5e381bf (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
(.module:
  [lux #*
   [control
    [monad (#+ do)]
    ["ex" exception (#+ exception:)]]
   [data
    ["." text
     format]
    [collection
     [list ("list/." Functor<List>)]
     ["dict" dictionary (#+ Dictionary)]]]]
  [// (#+ Handler Bundle)])

(exception: #export (incorrect-arity {name Text} {arity Nat} {args Nat})
  (ex.report ["Extension" (%t name)]
             ["Expected arity" (|> arity .int %i)]
             ["Actual arity" (|> args .int %i)]))

(exception: #export (invalid-syntax {name Text})
  (ex.report ["Extension" name]))

## [Utils]
(def: #export empty
  Bundle
  (dict.new text.Hash<Text>))

(def: #export (install name anonymous)
  (All [s i o]
    (-> Text (Handler s i o)
        (-> (Bundle s i o) (Bundle s i o))))
  (dict.put name anonymous))

(def: #export (prefix prefix)
  (All [s i o]
    (-> Text (-> (Bundle s i o) (Bundle s i o))))
  (|>> dict.entries
       (list/map (function (_ [key val]) [(format prefix " " key) val]))
       (dict.from-list text.Hash<Text>)))