]> gitweb.factorcode.org Git - factor.git/blob - core/prettyprint/core.factor
more sql changes
[factor.git] / core / prettyprint / core.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
7 ! Configuration
8 SYMBOL: tab-size
9 SYMBOL: margin
10 SYMBOL: nesting-limit
11 SYMBOL: length-limit
12 SYMBOL: line-limit
13 SYMBOL: string-limit
14
15 ! Special trick to highlight a word in a quotation
16 SYMBOL: hilite-quotation
17 SYMBOL: hilite-index
18 SYMBOL: hilite-next?
19
20 IN: prettyprint-internals
21
22 ! State
23 SYMBOL: position
24 SYMBOL: last-newline
25 SYMBOL: recursion-check
26 SYMBOL: line-count
27 SYMBOL: end-printing
28 SYMBOL: indent
29 SYMBOL: pprinter-stack
30
31 ! Utility words
32 : line-limit? ( -- ? )
33     line-limit get dup [ line-count get <= ] when ;
34
35 : do-indent ( -- ) indent get CHAR: \s <string> write ;
36
37 : fresh-line ( n -- )
38     dup last-newline get = [
39         drop
40     ] [
41         last-newline set
42         line-limit? [ "..." write end-printing get continue ] when
43         line-count inc
44         terpri do-indent
45     ] if ;
46
47 : text-fits? ( len -- ? )
48     indent get + margin get <= ;
49
50 global [
51     4 tab-size set
52     64 margin set
53     0 position set
54     0 indent set
55     0 last-newline set
56     1 line-count set
57     string-limit off
58 ] bind