]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/colors/constants/constants.factor
use reject instead of [ ... not ] filter.
[factor.git] / basis / colors / constants / constants.factor
index 98e7d434111339f9e4aea08892a2b45856842938..ad489a51a2d26a086e5364554c22d88d2a3c879a 100644 (file)
@@ -1,33 +1,33 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel assocs math math.parser memoize io.encodings.utf8
-io.files lexer parser colors sequences splitting
-combinators.smart ascii ;
+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" utf8 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 ;
 
-SYNTAX: COLOR: scan named-color parsed ;
\ No newline at end of file
+SYNTAX: COLOR: scan-token named-color suffix! ;