1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors assocs colors io io.styles kernel
4 make namespaces prettyprint.backend prettyprint.sections
5 prettyprint.stylesheet sequences sorting vocabs vocabs.parser ;
6 FROM: io.styles => inset ;
9 : pprint-vocab ( vocab -- )
10 [ vocab-name ] [ lookup-vocab vocab-style ] bi styled-text ;
12 : pprint-in ( vocab -- )
13 [ \ IN: pprint-word pprint-vocab ] with-pprint ;
17 : sort-vocabs ( seq -- seq' )
18 [ vocab-name ] sort-with ;
20 : pprint-using ( seq -- )
21 "syntax" lookup-vocab '[ _ = ] reject
28 GENERIC: pprint-qualified ( qualified -- )
30 M: qualified pprint-qualified
32 dup [ vocab>> vocab-name ] [ prefix>> ] bi = [
33 \ QUALIFIED: pprint-word
36 \ QUALIFIED-WITH: pprint-word
37 [ vocab>> pprint-vocab ] [ prefix>> text ] bi
41 M: from pprint-qualified
44 [ vocab>> pprint-vocab "=>" text ]
45 [ names>> [ text ] each ] bi
49 M: exclude pprint-qualified
51 \ EXCLUDE: pprint-word
52 [ vocab>> pprint-vocab "=>" text ]
53 [ names>> [ text ] each ] bi
57 M: rename pprint-qualified
61 [ vocab>> text "=>" text ]
62 [ words>> >alist first first text ]
66 : filter-interesting ( seq -- seq' )
67 [ [ vocab? ] [ extra-words? ] bi or ] reject ;
71 : (pprint-manifest ( manifest -- quots )
73 [ search-vocabs>> [ '[ _ pprint-using ] , ] unless-empty ]
74 [ qualified-vocabs>> filter-interesting [ '[ _ pprint-qualified ] , ] each ]
75 [ current-vocab>> [ '[ _ pprint-in ] , ] when* ]
79 : pprint-manifest) ( quots -- )
80 [ nl ] [ call( -- ) ] interleave ;
82 : pprint-manifest ( manifest -- )
83 (pprint-manifest pprint-manifest) ;
85 CONSTANT: manifest-style H{
86 { page-color COLOR: FactorLightTan }
87 { border-color COLOR: FactorDarkTan }
93 { { font-style bold } { font-name "sans-serif" } } [
94 "Restarts were invoked adding vocabularies to the search path." print
95 "To avoid doing this in the future, add the following forms" print
96 "at the top of the source file:" print nl
98 manifest-style [ manifest get pprint-manifest ] with-nesting
100 ] print-use-hook set-global