]> gitweb.factorcode.org Git - factor.git/blob - basis/prettyprint/prettyprint.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / basis / prettyprint / prettyprint.factor
1 ! Copyright (C) 2003, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays accessors assocs colors combinators grouping io
4 io.streams.string io.styles kernel make math math.parser namespaces
5 parser prettyprint.backend prettyprint.config prettyprint.custom
6 prettyprint.sections quotations sequences sorting strings vocabs
7 vocabs.prettyprint words sets ;
8 IN: prettyprint
9
10 : with-use ( obj quot -- )
11     make-pprint (pprint-manifest
12     [ pprint-manifest) ] [ [ drop nl ] unless-empty ] bi
13     do-pprint ; inline
14
15 : with-in ( obj quot -- )
16     make-pprint current-vocab>> [ pprint-in bl ] when* do-pprint ; inline
17
18 : pprint ( obj -- ) [ pprint* ] with-pprint ;
19
20 : . ( obj -- ) pprint nl ;
21
22 : pprint-use ( obj -- ) [ pprint* ] with-use ;
23
24 : unparse ( obj -- str ) [ pprint ] with-string-writer ;
25
26 : unparse-use ( obj -- str ) [ pprint-use ] with-string-writer ;
27
28 : pprint-short ( obj -- )
29     H{
30        { line-limit 1 }
31        { length-limit 15 }
32        { nesting-limit 2 }
33        { string-limit? t }
34        { boa-tuples? t }
35     } clone [ pprint ] bind ;
36
37 : unparse-short ( obj -- str )
38     [ pprint-short ] with-string-writer ;
39
40 : short. ( obj -- ) pprint-short nl ;
41
42 : .b ( n -- ) >bin print ;
43 : .o ( n -- ) >oct print ;
44 : .h ( n -- ) >hex print ;
45
46 : stack. ( seq -- ) [ short. ] each ;
47
48 : .s ( -- ) datastack stack. ;
49 : .r ( -- ) retainstack stack. ;
50
51 <PRIVATE
52
53 SYMBOL: ->
54
55 \ ->
56 { { foreground T{ rgba f 1 1 1 1 } } { background T{ rgba f 0 0 0 1 } } }
57 "word-style" set-word-prop
58
59 : remove-step-into ( word -- )
60     building get [ nip pop wrapped>> ] unless-empty , ;
61
62 : (remove-breakpoints) ( quot -- newquot )
63     [
64         [
65             {
66                 { [ dup word? not ] [ , ] }
67                 { [ dup "break?" word-prop ] [ drop ] }
68                 { [ dup "step-into?" word-prop ] [ remove-step-into ] }
69                 [ , ]
70             } cond
71         ] each
72     ] [ ] make ;
73
74 : remove-breakpoints ( quot pos -- quot' )
75     over quotation? [
76         1 + cut [ (remove-breakpoints) ] bi@
77         [ -> ] glue 
78     ] [
79         drop
80     ] if ;
81
82 PRIVATE>
83
84 : callstack. ( callstack -- )
85     callstack>array 2 <groups> [
86         remove-breakpoints
87         [
88             3 nesting-limit set
89             100 length-limit set
90             .
91         ] with-scope
92     ] assoc-each ;
93
94 : .c ( -- ) callstack callstack. ;
95
96 : pprint-cell ( obj -- ) [ pprint-short ] with-cell ;
97
98 SYMBOL: pprint-string-cells?
99
100 : simple-table. ( values -- )
101     standard-table-style [
102         [
103             [
104                 [
105                     dup string? pprint-string-cells? get not and
106                     [ [ write ] with-cell ]
107                     [ pprint-cell ]
108                     if
109                 ] each
110             ] with-row
111         ] each
112     ] tabular-output nl ;