1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel assocs math math.parser memoize io.encodings.utf8
4 io.files lexer parser colors sequences splitting ascii ;
9 : parse-color ( line -- name color )
11 [ [ string>number 255 /f ] tri@ 1.0 <rgba> ] dip
12 [ blank? ] trim-head H{ { CHAR: \s CHAR: - } } substitute swap ;
14 : parse-colors ( lines -- assoc )
16 [ 11 cut [ " \t" split harvest ] dip suffix ] map
17 [ parse-color ] H{ } map>assoc ;
19 MEMO: colors ( -- assoc )
20 "resource:basis/colors/constants/rgb.txt"
21 "resource:basis/colors/constants/factor-colors.txt"
22 [ utf8 file-lines parse-colors ] bi@ assoc-union ;
26 : named-colors ( -- keys ) colors keys ;
28 ERROR: no-such-color name ;
30 : named-color ( name -- color )
31 dup colors at [ ] [ throw-no-such-color ] ?if ;
33 SYNTAX: COLOR: scan-token named-color suffix! ;