diff options
author | Eduardo Julian | 2022-08-11 16:50:42 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-08-11 16:50:42 -0400 |
commit | e5625dd840a8b8adc76987f649da254335d3d93a (patch) | |
tree | fb672669383525d90d462edf8c141f98bc953894 /licentia/source/program | |
parent | 065e8a4d8122d4616b570496915d2c0e2c78cd6b (diff) |
Improved exception-definition macro.
Diffstat (limited to 'licentia/source/program')
-rw-r--r-- | licentia/source/program/licentia/input.lux | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/licentia/source/program/licentia/input.lux b/licentia/source/program/licentia/input.lux index afc723656..f1166d865 100644 --- a/licentia/source/program/licentia/input.lux +++ b/licentia/source/program/licentia/input.lux @@ -4,7 +4,7 @@ [abstract [monad (.only do)]] [control - ["[0]" exception (.only exception)] + ["[0]" exception (.only Exception)] ["<>" parser]] [data [text @@ -38,13 +38,15 @@ (<json>.field "name" <json>.string) (<json>.field "version" <json>.string)))) -(exception .public (cannot_use_fractional_amount [amount Frac]) - (exception.report - (list ["Amount" (%.frac amount)]))) +(with_template [<name> <type> <format>] + (exception.def .public (cannot_use_fractional_amount it) + (Exception <type>) + (exception.report + (list ["Amount" (<format> it)]))) -(exception .public (cannot_use_negative_amount [amount Int]) - (exception.report - (list ["Amount" (%.int amount)]))) + [cannot_use_fractional_amount Frac %.frac] + [cannot_use_negative_amount Int %.int] + ) (def amount (Parser Nat) @@ -58,7 +60,8 @@ (i.> +0 amountI))] (wrap (.nat amountI)))) -(exception .public (invalid_period [period (Period Nat)]) +(exception.def .public (invalid_period period) + (Exception (Period Nat)) (exception.report (list ["Start" (%.nat (the time.#start period))] ["End" (%.nat (the time.#end period))]))) |