]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/cicAst.ml
added pp_location (pretty printer of ast location)
[helm.git] / helm / ocaml / cic_transformations / cicAst.ml
1 (* Copyright (C) 2004, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28 type location = Lexing.position * Lexing.position
29
30 let pp_location (loc_begin, loc_end) =
31   sprintf "(%d,%d)-(%d,%d)"
32     loc_begin.Lexing.pos_lnum
33     (loc_begin.Lexing.pos_cnum - loc_begin.Lexing.pos_bol)
34     loc_end.Lexing.pos_lnum
35     (loc_end.Lexing.pos_cnum - loc_end.Lexing.pos_bol)
36
37 let floc_of_loc (loc_begin, loc_end) =
38   let floc_begin =
39     { Lexing.pos_fname = ""; Lexing.pos_lnum = -1; Lexing.pos_bol = -1;
40       Lexing.pos_cnum = loc_begin }
41   in
42   let floc_end = { floc_begin with Lexing.pos_cnum = loc_end } in
43   (floc_begin, floc_end)
44
45 let loc_of_floc = function
46   | { Lexing.pos_cnum = loc_begin }, { Lexing.pos_cnum = loc_end } ->
47       (loc_begin, loc_end)
48
49 let dummy_floc = floc_of_loc (-1, -1)
50
51 type binder_kind = [ `Lambda | `Pi | `Exists | `Forall ]
52 type induction_kind = [ `Inductive | `CoInductive ]
53 type sort_kind = [ `Prop | `Set | `Type | `CProp ]
54
55 type term_attribute =
56   [ `Loc of location
57   | `IdRef of string
58   ]
59
60 type term =
61   | AttributedTerm of term_attribute * term
62
63   | Appl of term list
64   | Binder of binder_kind * capture_variable * term
65   | Case of term * string option * term option * (case_pattern * term) list
66   | LetIn of capture_variable * term * term
67   | LetRec of induction_kind * (capture_variable * term * int) list * term
68   | Ident of string * subst list option
69   | Implicit
70   | Meta of int * meta_subst list
71   | Num of string * int
72   | Sort of sort_kind
73   | Symbol of string * int
74
75   | UserInput
76   | Uri of string * subst list option
77
78 and capture_variable = Cic.name * term option
79 and meta_subst = term option
80 and subst = string * term
81 and case_pattern = string * capture_variable list
82
83 let pack asts =
84   List.fold_right
85     (fun ast acc -> Binder (`Forall, (Cic.Anonymous, Some ast), acc))
86     asts (Sort `Type)
87
88 let rec unpack = function
89   | Binder (`Forall, (Cic.Anonymous, Some ast), Sort `Type) -> [ast]
90   | Binder (`Forall, (Cic.Anonymous, Some ast), tgt) -> ast :: unpack tgt
91   | _ -> assert false
92