1 ! Copyright (C) 2009, 2010 Slava Pestov, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs classes.algebra combinators
4 combinators.short-circuit continuations io.directories
5 io.encodings.utf8 io.files io.pathnames kernel make math.parser
6 memoize namespaces sequences splitting summary system vocabs
10 : check-vocab ( vocab -- vocab )
11 dup find-vocab-root [ no-vocab ] unless ;
13 : vocab-file-path ( vocab name -- path/f )
14 [ dup vocab-dir ] [ append-path ] bi* vocab-append-path ;
16 MEMO: vocab-file-lines ( vocab name -- lines/f )
19 utf8 file-lines harvest
25 : set-vocab-file-lines ( lines vocab name -- )
26 dupd vocab-file-path [
27 swap [ ?delete-file ] [ swap utf8 set-file-lines ] if-empty
28 \ vocab-file-lines reset-memoized
29 ] [ vocab-name no-vocab ] ?if ;
31 : vocab-resources-path ( vocab -- path/f )
32 "resources.txt" vocab-file-path ;
34 : vocab-resources ( vocab -- patterns )
35 "resources.txt" vocab-file-lines ;
37 : vocab-summary-path ( vocab -- path/f )
38 "summary.txt" vocab-file-path ;
40 : vocab-summary ( vocab -- summary )
41 "summary.txt" vocab-file-lines [ first ] [ f ] if* ;
43 : vocab-in-root-summary ( vocab -- string )
46 ".private" ?tail drop find-vocab-root
47 [ "`" "'" surround " in " glue ] when*
48 ] bi over [ ", " glue ] [ nip ] if ;
52 dup vocab-in-root-summary %
58 M: vocab-link summary vocab-in-root-summary ;
60 : vocab-tags-path ( vocab -- path/f )
61 "tags.txt" vocab-file-path ;
63 : vocab-tags ( vocab -- tags )
64 "tags.txt" vocab-file-lines ;
66 : vocab-authors-path ( vocab -- path/f )
67 "authors.txt" vocab-file-path ;
69 : vocab-authors ( vocab -- authors )
70 "authors.txt" vocab-file-lines ;
72 : vocab-platforms-path ( vocab -- path/f )
73 "platforms.txt" vocab-file-path ;
75 ERROR: bad-platform name ;
77 : vocab-platforms ( vocab -- platforms )
78 "platforms.txt" vocab-file-lines
79 [ dup "system" lookup-word [ ] [ bad-platform ] ?if ] map ;
81 : supported-platform? ( platforms -- ? )
82 [ t ] [ [ os swap class<= ] any? ] if-empty ;
84 : don't-load? ( vocab -- ? )
86 [ vocab-tags "not loaded" swap member? ]
87 [ vocab-platforms supported-platform? not ]
90 : don't-test? ( vocab -- ? )
91 vocab-tags "not tested" swap member? ;
93 TUPLE: unsupported-platform vocab requires ;
95 : throw-unsupported-platform ( vocab requires -- )
96 unsupported-platform boa throw-continue ;
98 M: unsupported-platform summary
99 drop "Current operating system not supported by this vocabulary" ;
101 : file-exists?, ( path -- )
102 [ dup file-exists? [ , ] [ drop ] if ] when* ;
104 : vocab-metadata-files ( vocab -- paths )
107 [ vocab-summary-path file-exists?, ]
108 [ vocab-authors-path file-exists?, ]
109 [ vocab-tags-path file-exists?, ]
110 [ vocab-platforms-path file-exists?, ]
111 [ vocab-resources-path file-exists?, ]
116 dup vocab-platforms dup supported-platform?
117 [ 2drop ] [ [ vocab-name ] dip throw-unsupported-platform ] if
118 ] check-vocab-hook set-global