]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/categories/syntax/syntax.factor
acb3fbd9bb123330fa6006cb382b47b0f3fd32c0
[factor.git] / basis / unicode / categories / syntax / syntax.factor
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
7
8 ! For use in CATEGORY:
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 | ;
10
11 <PRIVATE
12
13 : [category] ( categories code -- quot )
14     '[ integer>fixnum-strict dup category# _ member? [ drop t ] _ if ] ;
15
16 : integer-predicate-class ( word predicate -- )
17     integer swap define-predicate-class ;
18
19 : define-category ( word categories code -- )
20     [category] integer-predicate-class ;
21
22 : define-not-category ( word categories code -- )
23     [category] [ not ] compose integer-predicate-class ;
24
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* ;
29
30 PRIVATE>
31
32 SYNTAX: CATEGORY: parse-category define-category ;
33
34 SYNTAX: CATEGORY-NOT: parse-category define-not-category ;