diff options
Diffstat (limited to 'stdlib/source/lux/compiler/default/phase/extension/bundle.lux')
-rw-r--r-- | stdlib/source/lux/compiler/default/phase/extension/bundle.lux | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/stdlib/source/lux/compiler/default/phase/extension/bundle.lux b/stdlib/source/lux/compiler/default/phase/extension/bundle.lux new file mode 100644 index 000000000..e2d36fa73 --- /dev/null +++ b/stdlib/source/lux/compiler/default/phase/extension/bundle.lux @@ -0,0 +1,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>))) |