- List.iter (function str -> print_string str; print_string "\n")
- info.Ast.strbef;
- if info.Ast.column > 0 && not(info.Ast.strbef = [])
- then print_string (String.make info.Ast.column ' ');
- fn s;
- (match info.Ast.straft with
- [] -> ()
- | aft ->
- List.iter (function str -> print_string "\n"; print_string str) aft;
- print_string "\n") (*XXX pr current_tabbing *)
+ let print_comments lb comments =
+ List.fold_left
+ (function line_before ->
+ function (str,line,col) ->
+ match line_before with
+ None ->
+ let str =
+ match str with
+ Ast.Noindent s -> unindent false; s
+ | Ast.Indent s -> s in
+ print_string str line col; Some line
+ | Some lb when line =|= lb ->
+ let str = match str with Ast.Noindent s | Ast.Indent s -> s in
+ print_string str line col; Some line
+ | _ ->
+ force_newline();
+ (* not super elegant to put side-effecting unindent in a let
+ expression... *)
+ let str =
+ match str with
+ Ast.Noindent s -> unindent false; s
+ | Ast.Indent s -> s in
+ print_string str line col; Some line)
+ lb comments in
+ let line_before = print_comments None info.Ast.strbef in
+ (match line_before with
+ None -> ()
+ | Some lb when lb =|= info.Ast.line -> ()
+ | _ -> force_newline());
+ fn s line lcol;
+ let _ = print_comments (Some info.Ast.line) info.Ast.straft in
+ (* newline after a pragma
+ should really store parsed versions of the strings, but make a cheap
+ effort here
+ print_comments takes care of interior newlines *)
+ ()