colors.hex: adding an invalid-hex-color error.

master
John Benediktsson 2020-08-17 08:04:04 -07:00
parent ce871f99dd
commit 699ebc960b
1 changed files with 3 additions and 0 deletions

View File

@ -6,12 +6,15 @@ lexer math math.parser sequences ;
IN: colors.hex
ERROR: invalid-hex-color hex ;
: hex>rgba ( hex -- rgba )
dup length {
{ 6 [ 2 group [ hex> 255 /f ] map first3 1.0 ] }
{ 8 [ 2 group [ hex> 255 /f ] map first4 ] }
{ 3 [ [ digit> 15 /f ] { } map-as first3 1.0 ] }
{ 4 [ [ digit> 15 /f ] { } map-as first4 ] }
[ drop invalid-hex-color ]
} case <rgba> ;
: rgba>hex ( rgba -- hex )