]> gitweb.factorcode.org Git - factor.git/blob - core/prettyprint/frontend.factor
more sql changes
[factor.git] / core / prettyprint / frontend.factor
1 ! Copyright (C) 2003, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: prettyprint
4 USING: alien arrays generic hashtables io kernel math
5 namespaces parser sequences strings styles vectors words
6 prettyprint-internals ;
7
8 : with-pprint ( quot -- )
9     [
10         V{ } clone recursion-check set
11         H{ } <flow> f ?push pprinter-stack set
12         call end-blocks do-pprint
13     ] with-scope ; inline
14
15 : pprint ( obj -- ) [ pprint* ] with-pprint ;
16
17 : . ( obj -- )
18     H{
19        { length-limit 1000 }
20        { nesting-limit 10 }
21     } clone [ pprint ] bind terpri ;
22
23 : unparse ( obj -- str ) [ pprint ] string-out ;
24
25 : pprint-short ( obj -- )
26     H{
27        { line-limit 1 }
28        { length-limit 15 }
29        { nesting-limit 2 }
30        { string-limit t }
31     } clone [ pprint ] bind ;
32
33 : short. ( obj -- ) pprint-short terpri ;
34
35 : unparse-short ( obj -- str ) [ pprint-short ] string-out ;
36
37 : .b ( n -- ) >bin print ;
38 : .o ( n -- ) >oct print ;
39 : .h ( n -- ) >hex print ;
40
41 GENERIC: summary ( object -- string )
42
43 M: object summary
44     "an instance of the " swap class word-name " class" 3append ;
45
46 M: input summary
47     "Input: " swap input-string dup string?
48     [ "\n" split1 "..." "" ? append ] [ unparse-short ] if
49     append ;
50
51 M: vocab-link summary
52     [
53         vocab-link-name dup %
54         " vocabulary (" %
55         words length #
56         " words)" %
57     ] "" make ;