]> gitweb.factorcode.org Git - factor.git/blob - basis/vocabs/prettyprint/prettyprint.factor
vocabs.prettyprint: made the auto-use vocab box a little easier to read
[factor.git] / basis / vocabs / prettyprint / prettyprint.factor
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 ;
7 FROM: io.styles => inset ;
8 IN: vocabs.prettyprint
9
10 : pprint-vocab ( vocab -- )
11     [ vocab-name ] [ vocab vocab-style ] bi styled-text ;
12
13 : pprint-in ( vocab -- )
14     [ \ IN: pprint-word pprint-vocab ] with-pprint ;
15
16 <PRIVATE
17
18 : sort-vocabs ( seq -- seq' )
19     [ vocab-name ] sort-with ;
20
21 : pprint-using ( seq -- )
22     [ "syntax" vocab = not ] filter
23     sort-vocabs [
24         \ USING: pprint-word
25         [ pprint-vocab ] each
26         \ ; pprint-word
27     ] with-pprint ;
28
29 GENERIC: pprint-qualified ( qualified -- )
30
31 M: qualified pprint-qualified ( qualified -- )
32     [
33         dup [ vocab>> vocab-name ] [ prefix>> ] bi = [
34             \ QUALIFIED: pprint-word
35             vocab>> pprint-vocab
36         ] [
37             \ QUALIFIED-WITH: pprint-word
38             [ vocab>> pprint-vocab ] [ prefix>> text ] bi
39         ] if
40     ] with-pprint ;
41
42 M: from pprint-qualified ( from -- )
43     [
44         \ FROM: pprint-word
45         [ vocab>> pprint-vocab "=>" text ]
46         [ names>> [ text ] each ] bi
47         \ ; pprint-word
48     ] with-pprint ;
49
50 M: exclude pprint-qualified ( exclude -- )
51     [
52         \ EXCLUDE: pprint-word
53         [ vocab>> pprint-vocab "=>" text ]
54         [ names>> [ text ] each ] bi
55         \ ; pprint-word
56     ] with-pprint ;
57
58 M: rename pprint-qualified ( rename -- )
59     [
60         \ RENAME: pprint-word
61         [ word>> text ]
62         [ vocab>> text "=>" text ]
63         [ words>> >alist first first text ]
64         tri
65     ] with-pprint ;
66
67 PRIVATE>
68
69 : (pprint-manifest ( manifest -- quots )
70     [
71         [ search-vocabs>> [ '[ _ pprint-using ] , ] unless-empty ]
72         [ qualified-vocabs>> [ extra-words? not ] filter [ '[ _ pprint-qualified ] , ] each ]
73         [ current-vocab>> [ '[ _ pprint-in ] , ] when* ]
74         tri
75     ] { } make ;
76
77 : pprint-manifest) ( quots -- )
78     [ nl ] [ call( -- ) ] interleave ;
79
80 : pprint-manifest ( manifest -- )
81     (pprint-manifest pprint-manifest) ;
82
83 [
84     nl
85     { { font-style bold } { font-name "sans-serif" } } [
86         "Restarts were invoked adding vocabularies to the search path." print
87         "To avoid doing this in the future, add the following forms" print
88         "at the top of the source file:" print nl
89     ] with-style
90     { { page-color COLOR: FactorLightLightTan }
91       { border-color COLOR: FactorDarkTan }
92       { inset { 5 5 } } }
93     [ manifest get pprint-manifest ] with-nesting
94     nl nl
95 ] print-use-hook set-global