]> gitweb.factorcode.org Git - factor.git/blob - basis/unicode/syntax/syntax.factor
More docs for Unicode and simple-flat-file; moving more parsing code there
[factor.git] / basis / unicode / syntax / syntax.factor
1 ! Copyright (C) 2008 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: unicode.data kernel math sequences parser lexer
4 bit-arrays namespaces make sequences.private arrays quotations
5 assocs classes.predicate math.order strings.parser sets ;
6 IN: unicode.syntax
7
8 <PRIVATE
9
10 : >category-array ( categories -- bitarray )
11     categories [ swap member? ] with map >bit-array ;
12
13 : as-string ( strings -- bit-array )
14     concat unescape-string ;
15
16 : [category] ( categories -- quot )
17     [
18         [ [ categories member? not ] filter as-string ] keep 
19         [ categories member? ] filter >category-array
20         [ dup category# ] % , [ nth-unsafe [ drop t ] ] %
21         \ member? 2array >quotation ,
22         \ if ,
23     ] [ ] make ;
24
25 : define-category ( word categories -- )
26     [category] integer swap define-predicate-class ;
27
28 PRIVATE>
29
30 : CATEGORY:
31     CREATE ";" parse-tokens define-category ; parsing
32
33 : CATEGORY-NOT:
34     CREATE ";" parse-tokens
35     categories swap diff define-category ; parsing