Paste: works now!
Author: | foo |
Mode: | factor |
Date: | Mon, 17 Nov 2008 22:32:32 |
Plain Text |
USING: arrays io io.files kernel math parser strings system
tools.test words namespaces make io.encodings.utf8
io.encodings.binary sequences splitting hashtables assocs peg peg.ebnf peg.search memoize ;
IN: indexes
: db-path ( -- path ) "resource:work/indexes/db" ;
: load-db ( -- contents ) db-path utf8 file-lines ;
: index-lines ( -- lines ) load-db harvest ;
: indices ( lines -- inds ) [ 6 head ] map ;
: names ( lines -- names ) [ 7 tail ] map ;
MEMO: i-n# ( -- hash ) index-lines [ indices ] [ names ] bi zip >hashtable ;
: src-path ( -- path ) "resource:work/indexes/kolo" ;
: load-src ( -- path ) src-path utf8 file-contents ;
: replaced ( -- string ) load-src
[EBNF index = ([0-9][0-9][0-9][0-9][0-9][0-9]) => [[ >string i-n# at ]]
non-index = (!(index).)+ => [[ >string ]]
text = (index | non-index)*
EBNF] concat ;
New Annotation