factor/basis/simple-flat-file/simple-flat-file.factor

33 lines
918 B
Factor
Raw Normal View History

! Copyright (C) 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: sequences splitting kernel math.parser io.files io.encodings.utf8
biassocs ascii ;
IN: simple-flat-file
: drop-comments ( seq -- newseq )
[ "#@" split first ] map harvest ;
: split-column ( line -- columns )
2009-03-07 21:55:55 -05:00
" \t" split harvest 2 short head 2 f pad-tail ;
: parse-hex ( s -- n )
2009-03-07 21:55:55 -05:00
dup [
"0x" ?head [ "U+" ?head [ "Missing 0x or U+" throw ] unless ] unless
hex>
] when ;
: parse-line ( line -- code-unicode )
split-column [ parse-hex ] map ;
: process-codetable-lines ( lines -- assoc )
drop-comments [ parse-line ] map ;
: flat-file>biassoc ( filename -- biassoc )
utf8 file-lines process-codetable-lines >biassoc ;
: split-; ( line -- array )
";" split [ [ blank? ] trim ] map ;
: data ( filename -- data )
ascii file-lines drop-comments [ split-; ] map ;