diff options
author | Eduardo Julian | 2019-04-17 19:24:47 -0400 |
---|---|---|
committer | Eduardo Julian | 2019-04-17 19:24:47 -0400 |
commit | a3389210ed2787c11a34fd1b587d6b120dddb29b (patch) | |
tree | 894b4e905b9ace40ab9476a8cdfdb4142de6930b /stdlib | |
parent | 84b5e5becced7eaad0f733f13d4c9f5064dd63ea (diff) |
Fixed an issue with weird spacing at the end of lines in "lux/time/duration".
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/control/exception.lux | 14 | ||||
-rw-r--r-- | stdlib/source/lux/time/duration.lux | 57 | ||||
-rw-r--r-- | stdlib/source/lux/tool/compiler/phase/macro.lux | 15 |
3 files changed, 48 insertions, 38 deletions
diff --git a/stdlib/source/lux/control/exception.lux b/stdlib/source/lux/control/exception.lux index cc8635b13..72cba8e54 100644 --- a/stdlib/source/lux/control/exception.lux +++ b/stdlib/source/lux/control/exception.lux @@ -1,6 +1,9 @@ (.module: {#.doc "Exception-handling functionality built on top of the Error type."} [lux #* [abstract + [monoid (#+)] + [fold (#+)] + [functor (#+)] [monad (#+ do)]] [control ["p" parser]] @@ -9,6 +12,8 @@ ["." maybe] ["." product] ["." text ("#@." monoid)] + [number + ["." nat ("#@." decimal)]] [collection ["." list ("#@." functor fold)]]] ["." macro @@ -163,3 +168,12 @@ success success)) + +(def: #export (enumerate %entry) + (All [a] + (-> (-> a Text) + (-> (List a) Text))) + (|>> list.enumerate + (list@map (function (_ [index entry]) + ($_ text@compose (nat@encode index) ": " (%entry entry)))) + (text.join-with text.new-line))) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 887a074f7..2ec2de13d 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -10,9 +10,9 @@ ["p" parser]] [data [number - ["." nat ("#;." decimal)] - ["." int ("#;." decimal number)]] - ["." text ("#;." monoid) + ["." nat ("#@." decimal)] + ["." int ("#@." decimal number)]] + ["." text ("#@." monoid) ["l" lexer]] ["e" error]] [type @@ -76,7 +76,7 @@ [>= i/>=] )))) - (open: "duration;." ..order) + (open: "duration@." ..order) (template [<name> <op>] [(def: #export (<name> left right) @@ -85,8 +85,8 @@ right left))] - [max duration;>] - [min duration;<] + [max duration@>] + [min duration@<] ) (template [<name> <op>] @@ -120,27 +120,26 @@ (def: identity ..empty) (def: compose ..merge)) -(def: #export (encode duration) - (-> Duration Text) - (if (:: ..equivalence = empty duration) - "+0ms" - (let [signed? (negative? duration) - [days time-left] [(query day duration) (frame day duration)] - days (if signed? - (int;abs days) - days) - time-left (if signed? - (..inverse time-left) - time-left) - [hours time-left] [(query hour time-left) (frame hour time-left)] - [minutes time-left] [(query minute time-left) (frame minute time-left)] - [seconds time-left] [(query second time-left) (frame second time-left)] - millis (to-millis time-left)] - ($_ text;compose - (if signed? "-" "+") - (if (i/= +0 days) "" (text;compose (nat;encode (.nat days)) "D")) - (if (i/= +0 hours) "" (text;compose (nat;encode (.nat hours)) "h")) - (if (i/= +0 minutes) "" (text;compose (nat;encode (.nat minutes)) "m")) - (if (i/= +0 seconds) "" (text;compose (nat;encode (.nat seconds)) "s")) - (if (i/= +0 millis) "" (text;compose (nat;encode (.nat millis)) "ms")) +(def: #export (encode duration) + (if (:: ..equivalence = empty duration) + "+0ms" + (let [signed? (negative? duration) + [days time-left] [(query day duration) (frame day duration)] + days (if signed? + (int@abs days) + days) + time-left (if signed? + (..inverse time-left) + time-left) + [hours time-left] [(query hour time-left) (frame hour time-left)] + [minutes time-left] [(query minute time-left) (frame minute time-left)] + [seconds time-left] [(query second time-left) (frame second time-left)] + millis (to-millis time-left)] + ($_ text@compose + (if signed? "-" "+") + (if (i/= +0 days) "" (text@compose (nat@encode (.nat days)) "D")) + (if (i/= +0 hours) "" (text@compose (nat@encode (.nat hours)) "h")) + (if (i/= +0 minutes) "" (text@compose (nat@encode (.nat minutes)) "m")) + (if (i/= +0 seconds) "" (text@compose (nat@encode (.nat seconds)) "s")) + (if (i/= +0 millis) "" (text@compose (nat@encode (.nat millis)) "ms")) )))) diff --git a/stdlib/source/lux/tool/compiler/phase/macro.lux b/stdlib/source/lux/tool/compiler/phase/macro.lux index ddbde68ad..9a94f9a4b 100644 --- a/stdlib/source/lux/tool/compiler/phase/macro.lux +++ b/stdlib/source/lux/tool/compiler/phase/macro.lux @@ -10,24 +10,21 @@ format] [collection [array (#+ Array)] - ["." list ("#;." functor)]]] + ["." list ("#@." functor)]]] ["." macro]] ["." //]) (exception: #export (expansion-failed {macro Name} {inputs (List Code)} {error Text}) (exception.report ["Macro" (%name macro)] - ["Inputs" (|> inputs - (list;map (|>> %code (format text.new-line text.tab))) - (text.join-with ""))] + ["Inputs" (exception.enumerate %code inputs)] ["Error" error])) -(exception: #export (must-have-single-expansion {macro Name} {inputs (List Code)}) +(exception: #export (must-have-single-expansion {macro Name} {inputs (List Code)} {outputs (List Code)}) (exception.report ["Macro" (%name macro)] - ["Inputs" (|> inputs - (list;map (|>> %code (format text.new-line text.tab))) - (text.join-with ""))])) + ["Inputs" (exception.enumerate %code inputs)] + ["Outputs" (exception.enumerate %code outputs)])) (type: #export Expander (-> Macro (List Code) Lux (Error (Error [Lux (List Code)])))) @@ -53,4 +50,4 @@ (wrap single) _ - (//.throw must-have-single-expansion [name inputs])))) + (//.throw must-have-single-expansion [name inputs expansion])))) |