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