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
4 combinators.short-circuit continuations io.directories
5 io.encodings.utf8 io.files io.pathnames kernel make math.parser
6 memoize namespaces sequences summary system vocabs vocabs.loader
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 dup "summary.txt" vocab-file-lines [
42 vocab-name " vocabulary" append
55 M: vocab-link summary vocab-summary ;
57 : vocab-tags-path ( vocab -- path/f )
58 "tags.txt" vocab-file-path ;
60 : vocab-tags ( vocab -- tags )
61 "tags.txt" vocab-file-lines ;
63 : vocab-authors-path ( vocab -- path/f )
64 "authors.txt" vocab-file-path ;
66 : vocab-authors ( vocab -- authors )
67 "authors.txt" vocab-file-lines ;
69 : vocab-platforms-path ( vocab -- path/f )
70 "platforms.txt" vocab-file-path ;
72 ERROR: bad-platform name ;
74 : vocab-platforms ( vocab -- platforms )
75 "platforms.txt" vocab-file-lines
76 [ dup "system" lookup-word [ ] [ bad-platform ] ?if ] map ;
78 : supported-platform? ( platforms -- ? )
79 [ t ] [ [ os swap class<= ] any? ] if-empty ;
81 : don't-load? ( vocab -- ? )
83 [ vocab-tags "not loaded" swap member? ]
84 [ vocab-platforms supported-platform? not ]
87 : don't-test? ( vocab -- ? )
88 vocab-tags "not tested" swap member? ;
90 TUPLE: unsupported-platform vocab requires ;
92 : throw-unsupported-platform ( vocab requires -- )
93 unsupported-platform boa throw-continue ;
95 M: unsupported-platform summary
96 drop "Current operating system not supported by this vocabulary" ;
99 dup vocab-platforms dup supported-platform?
100 [ 2drop ] [ [ vocab-name ] dip throw-unsupported-platform ] if
101 ] check-vocab-hook set-global