! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel assocs math math.parser memoize
-io.encodings.ascii io.files lexer parser
-colors sequences splitting combinators.smart ascii ;
+USING: kernel assocs math math.parser memoize io.encodings.utf8
+io.files lexer parser colors sequences splitting ascii ;
IN: colors.constants
<PRIVATE
: parse-color ( line -- name color )
- [
- [ [ string>number 255 /f ] tri@ 1.0 <rgba> ] dip
- [ blank? ] trim-head { { CHAR: \s CHAR: - } } substitute swap
- ] input<sequence ;
+ first4
+ [ [ string>number 255 /f ] tri@ 1.0 <rgba> ] dip
+ [ blank? ] trim-head H{ { CHAR: \s CHAR: - } } substitute swap ;
-: parse-rgb.txt ( lines -- assoc )
- [ "!" head? not ] filter
+: parse-colors ( lines -- assoc )
+ [ "!" head? ] reject
[ 11 cut [ " \t" split harvest ] dip suffix ] map
[ parse-color ] H{ } map>assoc ;
-MEMO: rgb.txt ( -- assoc )
- "resource:basis/colors/constants/rgb.txt" ascii file-lines parse-rgb.txt ;
+MEMO: colors ( -- assoc )
+ "resource:basis/colors/constants/rgb.txt"
+ "resource:basis/colors/constants/factor-colors.txt"
+ [ utf8 file-lines parse-colors ] bi@ assoc-union ;
PRIVATE>
-: named-colors ( -- keys ) rgb.txt keys ;
+: named-colors ( -- keys ) colors keys ;
ERROR: no-such-color name ;
: named-color ( name -- color )
- dup rgb.txt at [ ] [ no-such-color ] ?if ;
+ dup colors at [ ] [ no-such-color ] ?if ;
-: COLOR: scan named-color parsed ; parsing
\ No newline at end of file
+SYNTAX: COLOR: scan-token named-color suffix! ;