Release coccinelle-0.2.0rc1
[bpt/coccinelle.git] / popl / pretty_print_popl.ml
1 open Format
2 module Past = Ast_popl
3
4 let start_block str =
5 force_newline(); print_string " "; open_box 0
6
7 let end_block str =
8 close_box(); force_newline ()
9
10 (* --------------------------------------------------------------------- *)
11
12 let rec print_sequence = function
13 Past.Seq(e,seq) -> print_element e; force_newline(); print_sequence seq
14 | Past.Empty -> ()
15 | Past.SExists((_,v),seq) -> print_string "exists "; print_string v;
16 print_string " ."; force_newline(); print_sequence seq
17
18 and print_element = function
19 Past.Term(term) -> Pretty_print_cocci.rule_elem "" term
20 | Past.Or(seq1,seq2) ->
21 force_newline(); print_string "("; force_newline(); print_sequence seq1;
22 print_string "|"; force_newline(); print_sequence seq2; print_string ")"
23 | Past.DInfo(dots,bef,aft) ->
24 start_block();
25 List.iter
26 (function b -> print_string ">>>"; print_element b; force_newline())
27 bef;
28 print_dots dots;
29 List.iter
30 (function b -> force_newline(); print_string "<<<"; print_element b)
31 aft;
32 end_block()
33 | Past.EExists((_,v),elem) -> print_string "exists "; print_string v;
34 print_string " ."; force_newline(); print_element elem
35
36 and print_dots = function
37 Past.Dots -> print_string "..."
38 | Past.Nest(seq)-> print_string "<..."; start_block(); print_sequence seq;
39 end_block(); print_string "...>"
40 | Past.When(dots,seq) -> print_dots dots; print_string " when != ";
41 open_box 0; print_sequence seq; close_box()
42 | Past.DExists((_,v),dots) -> print_string "exists "; print_string v;
43 print_string " ."; force_newline(); print_dots dots
44
45 (* --------------------------------------------------------------------- *)
46
47 let pretty_print_e e =
48 print_element e;
49 print_newline()
50
51 let pretty_print sl =
52 print_sequence sl;
53 print_newline()
54