1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs colors colors.constants fry io
4 io.styles kernel make math.order namespaces parser
5 prettyprint.backend prettyprint.sections prettyprint.stylesheet
6 sequences sets sorting vocabs vocabs.parser ;
9 : pprint-vocab ( vocab -- )
10 [ vocab-name ] [ 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" vocab = not ] filter
28 GENERIC: pprint-qualified ( qualified -- )
30 M: qualified pprint-qualified ( 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 ( from -- )
44 [ vocab>> pprint-vocab "=>" text ]
45 [ names>> [ text ] each ] bi
49 M: exclude pprint-qualified ( exclude -- )
51 \ EXCLUDE: pprint-word
52 [ vocab>> pprint-vocab "=>" text ]
53 [ names>> [ text ] each ] bi
57 M: rename pprint-qualified ( rename -- )
61 [ vocab>> text "=>" text ]
62 [ words>> >alist first first text ]
68 : (pprint-manifest ( manifest -- quots )
70 [ search-vocabs>> [ '[ _ pprint-using ] , ] unless-empty ]
71 [ qualified-vocabs>> [ extra-words? not ] filter [ '[ _ pprint-qualified ] , ] each ]
72 [ current-vocab>> [ '[ _ pprint-in ] , ] when* ]
76 : pprint-manifest) ( quots -- )
77 [ nl ] [ call( -- ) ] interleave ;
79 : pprint-manifest ( manifest -- )
80 (pprint-manifest pprint-manifest) ;
84 { { font-style bold } { font-name "sans-serif" } } [
85 "Restarts were invoked adding vocabularies to the search path." print
86 "To avoid doing this in the future, add the following forms" print
87 "at the top of the source file:" print nl
89 { { page-color COLOR: FactorLightTan } }
90 [ manifest get pprint-manifest ] with-nesting
92 ] print-use-hook set-global