1 ! Copyright (C) 2008 Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors values kernel sequences assocs io.files
4 io.encodings ascii math.ranges io splitting math.parser
5 namespaces make byte-arrays locals math sets io.encodings.ascii
6 words words.symbol compiler.units arrays interval-maps
14 : parse-script ( stream -- assoc )
15 ! assoc is code point/range => name
16 lines filter-comments [ split-; ] map ;
18 : range, ( value key -- )
20 [ name>> = ] with find nip 2array , ;
22 : expand-ranges ( assoc -- interval-map )
25 CHAR: . pick member? [
26 swap ".." split1 [ hex> ] bi@ 2array
27 ] [ swap hex> ] if range,
29 ] { } make <interval-map> ;
31 : >symbols ( strings -- symbols )
33 [ "unicode.script" create dup define-symbol ] map
34 ] with-compilation-unit ;
36 : process-script ( ranges -- )
37 dup values prune >symbols interned [
38 expand-ranges to: script-table
42 "resource:basis/unicode/script/Scripts.txt"
43 ascii <file-reader> parse-script process-script ;
50 : script-of ( char -- script )
51 script-table interval-at [ Unknown ] unless* ;