11(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2- *
2+ *
33 * This program is free software: you can redistribute it and/or modify
44 * it under the terms of the GNU Lesser General Public License as published by
55 * the Free Software Foundation, either version 3 of the License, or
1717 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1818 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1919 * GNU Lesser General Public License for more details.
20- *
20+ *
2121 * You should have received a copy of the GNU Lesser General Public License
2222 * along with this program; if not, write to the Free Software
2323 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2929
3030
3131
32- module L = struct
32+ module L = struct
3333 let space = " "
3434 let indent_str = " "
3535end
3636
37- let indent_length = String. length L. indent_str
37+ let indent_length = String. length L. indent_str
3838
3939type t = {
4040 output_string : string -> unit ;
41- output_char : char -> unit ;
41+ output_char : char -> unit ;
4242 flush : unit -> unit ;
4343 mutable indent_level : int ;
44- mutable last_new_line : bool ;
44+ mutable last_new_line : bool ;
4545 (* only when we print newline, we print the indent *)
4646}
4747
48- let from_channel chan = {
49- output_string = (fun s -> output_string chan s);
48+ let from_channel chan = {
49+ output_string = (fun s -> output_string chan s);
5050 output_char = (fun c -> output_char chan c);
5151 flush = (fun _ -> flush chan);
5252 indent_level = 0 ;
@@ -62,105 +62,105 @@ let from_buffer buf = {
6262 last_new_line = false ;
6363}
6464
65- (* If we have [newline] in [s],
66- all indentations will be broken
65+ (* If we have [newline] in [s],
66+ all indentations will be broken
6767 in the future, we can detect this in [s]
6868*)
69- let string t s =
69+ let string t s =
7070 t.output_string s ;
7171 t.last_new_line < - false
7272
73- let newline t =
74- if not t.last_new_line then
73+ let newline t =
74+ if not t.last_new_line then
7575 begin
7676 t.output_char '\n' ;
77- for i = 0 to t.indent_level - 1 do
77+ for i = 0 to t.indent_level - 1 do
7878 t.output_string L. indent_str;
7979 done ;
8080 t.last_new_line < - true
8181 end
8282
83- let force_newline t =
83+ let force_newline t =
8484 t.output_char '\n' ;
85- for i = 0 to t.indent_level - 1 do
85+ for i = 0 to t.indent_level - 1 do
8686 t.output_string L. indent_str;
8787 done
8888
89- let space t =
89+ let space t =
9090 string t L. space
9191
92- let nspace t n =
92+ let nspace t n =
9393 string t (String. make n ' ' )
9494
95- let group t i action =
95+ let group t i action =
9696 if i = 0 then action ()
97- else
97+ else
9898 let old = t.indent_level in
9999 t.indent_level < - t.indent_level + i;
100- Ext_pervasives. finally () (fun _ -> t.indent_level < - old) action
100+ Ext_pervasives. finally () (fun _ -> t.indent_level < - old) action
101101
102102let vgroup = group
103103
104- let paren t action =
104+ let paren t action =
105105 string t " (" ;
106106 let v = action () in
107107 string t " )" ;
108- v
108+ v
109109
110- let brace fmt u =
110+ let brace fmt u =
111111 string fmt " {" ;
112112 (* break1 fmt ; *)
113113 let v = u () in
114114 string fmt " }" ;
115- v
115+ v
116116
117- let bracket fmt u =
117+ let bracket fmt u =
118118 string fmt " [" ;
119119 let v = u () in
120120 string fmt " ]" ;
121- v
121+ v
122122
123- let brace_vgroup st n action =
123+ let brace_vgroup st n action =
124124 string st " {" ;
125- let v = vgroup st n (fun _ ->
126- newline st;
125+ let v = vgroup st n (fun _ ->
126+ newline st;
127127 let v = action () in
128128 v
129129 ) in
130130 force_newline st;
131131 string st " }" ;
132132 v
133133
134- let bracket_vgroup st n action =
134+ let bracket_vgroup st n action =
135135 string st " [" ;
136- let v = vgroup st n (fun _ ->
137- newline st;
136+ let v = vgroup st n (fun _ ->
137+ newline st;
138138 let v = action () in
139139 v
140140 ) in
141141 force_newline st;
142142 string st " ]" ;
143143 v
144144
145- let bracket_group st n action =
145+ let bracket_group st n action =
146146 group st n (fun _ -> bracket st action)
147147
148- let paren_vgroup st n action =
148+ let paren_vgroup st n action =
149149 string st " (" ;
150- let v = group st n (fun _ ->
151- newline st;
150+ let v = group st n (fun _ ->
151+ newline st;
152152 let v = action () in
153153 v
154154 ) in
155155 newline st;
156156 string st " )" ;
157- v
157+ v
158158let paren_group st n action = group st n (fun _ -> paren st action)
159159
160- let brace_group st n action =
160+ let brace_group st n action =
161161 group st n (fun _ -> brace st action )
162162
163- let indent t n =
164- t.indent_level < - t.indent_level + n
163+ let indent t n =
164+ t.indent_level < - t.indent_level + n
165165
166166let flush t () = t.flush ()
0 commit comments