1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs io.encodings.utf8 io.files
4 io.pathnames kernel make math.parser memoize sequences sets
5 sorting summary vocabs vocabs.loader ;
8 MEMO: vocab-file-contents ( vocab name -- seq )
10 [ dup exists? [ utf8 file-lines ] [ drop f ] if ] when ;
12 : set-vocab-file-contents ( seq vocab name -- )
13 dupd vocab-append-path [
15 \ vocab-file-contents reset-memoized
17 "The " swap vocab-name
18 " vocabulary was not loaded from the file system"
22 : vocab-windows-icon-path ( vocab -- string )
23 vocab-dir "icon.ico" append-path ;
25 : vocab-mac-icon-path ( vocab -- string )
26 vocab-dir "icon.icns" append-path ;
28 : vocab-resources-path ( vocab -- string )
29 vocab-dir "resources.txt" append-path ;
31 : vocab-resources ( vocab -- patterns )
32 dup vocab-resources-path vocab-file-contents harvest ;
34 : set-vocab-resources ( patterns vocab -- )
35 dup vocab-resources-path set-vocab-file-contents ;
37 : vocab-summary-path ( vocab -- string )
38 vocab-dir "summary.txt" append-path ;
40 : vocab-summary ( vocab -- summary )
41 dup dup vocab-summary-path vocab-file-contents
43 vocab-name " vocabulary" append
56 M: vocab-link summary vocab-summary ;
58 : set-vocab-summary ( string vocab -- )
60 dup vocab-summary-path
61 set-vocab-file-contents ;
63 : vocab-tags-path ( vocab -- string )
64 vocab-dir "tags.txt" append-path ;
66 : vocab-tags ( vocab -- tags )
67 dup vocab-tags-path vocab-file-contents harvest ;
69 : set-vocab-tags ( tags vocab -- )
70 dup vocab-tags-path set-vocab-file-contents ;
72 : add-vocab-tags ( tags vocab -- )
73 [ vocab-tags append prune ] keep set-vocab-tags ;
75 : vocab-authors-path ( vocab -- string )
76 vocab-dir "authors.txt" append-path ;
78 : vocab-authors ( vocab -- authors )
79 dup vocab-authors-path vocab-file-contents harvest ;
81 : set-vocab-authors ( authors vocab -- )
82 dup vocab-authors-path set-vocab-file-contents ;
84 : unportable? ( vocab -- ? )
85 vocab-tags "unportable" swap member? ;