]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/cicNotationPt.ml
ocaml 3.09 transition
[helm.git] / helm / ocaml / cic_notation / cicNotationPt.ml
1 (* Copyright (C) 2005, 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 (** CIC Notation Parse Tree *)
27
28 type binder_kind = [ `Lambda | `Pi | `Exists | `Forall ]
29 type induction_kind = [ `Inductive | `CoInductive ]
30 type sort_kind = [ `Prop | `Set | `Type of CicUniv.universe | `CProp ]
31 type fold_kind = [ `Left | `Right ]
32
33 type location = Lexing.position * Lexing.position
34 (* cut and past from CicAst.loc_of_floc *)
35 let loc_of_floc = function
36   | { Lexing.pos_cnum = loc_begin }, { Lexing.pos_cnum = loc_end } ->
37       (loc_begin, loc_end)
38 let fail floc msg =
39   let (x, y) = loc_of_floc floc in
40   failwith (Printf.sprintf "Error at characters %d - %d: %s" x y msg)
41
42 type href = UriManager.uri
43
44 type child_pos = [ `Left | `Right | `Inner ]
45
46 type term_attribute =
47   [ `Loc of location                  (* source file location *)
48   | `IdRef of string                  (* ACic pointer *)
49   | `Level of int * Gramext.g_assoc   (* precedence, associativity *)
50   | `ChildPos of child_pos            (* position of l1 pattern variables *)
51   | `XmlAttrs of (string option * string * string) list
52       (* list of XML attributes: namespace, name, value *)
53   | `Raw of string                    (* unparsed version *)
54   ]
55
56 type literal =
57   [ `Symbol of string
58   | `Keyword of string
59   | `Number of string
60   ]
61
62 type case_indtype = string * href option
63
64 (** To be increased each time the term type below changes, used for "safe"
65  * marshalling *)
66 let magic = 1
67
68 type term =
69   (* CIC AST *)
70
71   | AttributedTerm of term_attribute * term
72
73   | Appl of term list
74   | Binder of binder_kind * capture_variable * term (* kind, name, body *)
75   | Case of term * case_indtype option * term option *
76       (case_pattern * term) list
77       (* what to match, inductive type, out type, <pattern,action> list *)
78   | Cast of term * term
79   | LetIn of capture_variable * term * term  (* name, body, where *)
80   | LetRec of induction_kind * (capture_variable * term * int) list * term
81       (* (name, body, decreasing argument) list, where *)
82   | Ident of string * subst list option
83       (* literal, substitutions.
84       * Some [] -> user has given an empty explicit substitution list 
85       * None -> user has given no explicit substitution list *)
86   | Implicit
87   | Meta of int * meta_subst list
88   | Num of string * int (* literal, instance *)
89   | Sort of sort_kind
90   | Symbol of string * int  (* canonical name, instance *)
91
92   | UserInput (* place holder for user input, used by MatitaConsole, not to be
93               used elsewhere *)
94   | Uri of string * subst list option (* as Ident, for long names *)
95
96   (* Syntax pattern extensions *)
97
98   | Literal of literal
99   | Layout of layout_pattern
100
101   | Magic of magic_term
102   | Variable of pattern_variable
103
104   (* name, type. First component must be Ident or Variable (FreshVar _) *)
105 and capture_variable = term * term option
106
107 and meta_subst = term option
108 and subst = string * term
109 and case_pattern = string * href option * capture_variable list
110
111 and box_kind = H | V | HV | HOV
112 and box_spec = box_kind * bool * bool (* kind, spacing, indent *)
113
114 and layout_pattern =
115   | Sub of term * term
116   | Sup of term * term
117   | Below of term * term
118   | Above of term * term
119   | Frac of term * term
120   | Over of term * term
121   | Atop of term * term
122 (*   | array of term * literal option * literal option
123       |+ column separator, row separator +| *)
124   | Sqrt of term
125   | Root of term * term (* argument, index *)
126   | Break
127   | Box of box_spec * term list
128   | Group of term list
129
130 and magic_term =
131   (* level 1 magics *)
132   | List0 of term * literal option (* pattern, separator *)
133   | List1 of term * literal option (* pattern, separator *)
134   | Opt of term
135
136   (* level 2 magics *)
137   | Fold of fold_kind * term * string list * term
138     (* base case pattern, recursive case bound names, recursive case pattern *)
139   | Default of term * term  (* "some" case pattern, "none" case pattern *)
140   | Fail
141   | If of term * term * term (* test, pattern if true, pattern if false *)
142
143 and pattern_variable =
144   (* level 1 and 2 variables *)
145   | NumVar of string
146   | IdentVar of string
147   | TermVar of string
148
149   (* level 1 variables *)
150   | Ascription of term * string
151
152   (* level 2 variables *)
153   | FreshVar of string
154
155 type argument_pattern =
156   | IdentArg of int * string (* eta-depth, name *)
157
158 type cic_appl_pattern =
159   | UriPattern of UriManager.uri
160   | VarPattern of string
161   | ImplicitPattern
162   | ApplPattern of cic_appl_pattern list
163
164 (** {2 Standard precedences} *)
165
166 let let_in_prec = 10
167 let binder_prec = 20
168 let apply_prec = 70
169 let simple_prec = 90
170
171 let let_in_assoc = Gramext.NonA
172 let binder_assoc = Gramext.RightA
173 let apply_assoc = Gramext.LeftA
174 let simple_assoc = Gramext.NonA
175