Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / popl / pretty_print_popl.ml
CommitLineData
5636bb2c
C
1(*
2 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
3 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
4 * This file is part of Coccinelle.
5 *
6 * Coccinelle is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, according to version 2 of the License.
9 *
10 * Coccinelle is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * The authors reserve the right to distribute this or future versions of
19 * Coccinelle under other licenses.
20 *)
21
22
9f8e26f4 23(*
ae4735db 24 * Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
9f8e26f4
C
25 * Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
26 * This file is part of Coccinelle.
27 *
28 * Coccinelle is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, according to version 2 of the License.
31 *
32 * Coccinelle is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License
38 * along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
39 *
40 * The authors reserve the right to distribute this or future versions of
41 * Coccinelle under other licenses.
42 *)
43
44
951c7801
C
45open Format
46module Past = Ast_popl
47
48let start_block str =
49 force_newline(); print_string " "; open_box 0
50
51let end_block str =
52 close_box(); force_newline ()
53
54(* --------------------------------------------------------------------- *)
55
56let rec print_sequence = function
57 Past.Seq(e,seq) -> print_element e; force_newline(); print_sequence seq
58 | Past.Empty -> ()
59 | Past.SExists((_,v),seq) -> print_string "exists "; print_string v;
60 print_string " ."; force_newline(); print_sequence seq
61
62and print_element = function
63 Past.Term(term) -> Pretty_print_cocci.rule_elem "" term
64 | Past.Or(seq1,seq2) ->
65 force_newline(); print_string "("; force_newline(); print_sequence seq1;
66 print_string "|"; force_newline(); print_sequence seq2; print_string ")"
67 | Past.DInfo(dots,bef,aft) ->
68 start_block();
69 List.iter
70 (function b -> print_string ">>>"; print_element b; force_newline())
71 bef;
72 print_dots dots;
73 List.iter
74 (function b -> force_newline(); print_string "<<<"; print_element b)
75 aft;
76 end_block()
77 | Past.EExists((_,v),elem) -> print_string "exists "; print_string v;
78 print_string " ."; force_newline(); print_element elem
79
80and print_dots = function
81 Past.Dots -> print_string "..."
82 | Past.Nest(seq)-> print_string "<..."; start_block(); print_sequence seq;
83 end_block(); print_string "...>"
84 | Past.When(dots,seq) -> print_dots dots; print_string " when != ";
85 open_box 0; print_sequence seq; close_box()
86 | Past.DExists((_,v),dots) -> print_string "exists "; print_string v;
87 print_string " ."; force_newline(); print_dots dots
88
89(* --------------------------------------------------------------------- *)
90
91let pretty_print_e e =
92 print_element e;
93 print_newline()
94
95let pretty_print sl =
96 print_sequence sl;
97 print_newline()
98