1 ! Copyright (C) 2008, 2009 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: unicode.data kernel math sequences parser unicode.data.private
4 bit-arrays namespaces sequences.private arrays classes.parser
5 assocs classes.predicate sets fry splitting accessors ;
6 IN: unicode.categories.syntax
9 SYMBOLS: Cn Lu Ll Lt Lm Lo Mn Mc Me Nd Nl No Pc Pd Ps Pe Pi Pf Po Sm Sc Sk So Zs Zl Zp Cc Cf Cs Co | ;
13 : [category] ( categories code -- quot )
14 '[ integer>fixnum-strict dup category# _ member? [ drop t ] _ if ] ;
16 : integer-predicate-class ( word predicate -- )
17 integer swap define-predicate-class ;
19 : define-category ( word categories code -- )
20 [category] integer-predicate-class ;
22 : define-not-category ( word categories code -- )
23 [category] [ not ] compose integer-predicate-class ;
25 : parse-category ( -- word tokens quot )
26 scan-new-class \ ; parse-until { | } split1
27 [ [ name>> categories-map at ] B{ } map-as ]
28 [ [ [ ] like ] [ [ drop f ] ] if* ] bi* ;
32 SYNTAX: CATEGORY: parse-category define-category ;
34 SYNTAX: CATEGORY-NOT: parse-category define-not-category ;