]> matita.cs.unibo.it Git - helm.git/blob - matita/components/content/notationPt.ml
- new syntax for let rec/corec with flavor specifier (tested on lambdadelta/ground_2/)
[helm.git] / matita / components / content / notationPt.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 (* $Id$ *)
27
28 (** CIC Notation Parse Tree *)
29
30 type binder_kind = [ `Lambda | `Pi | `Exists | `Forall ]
31 type induction_kind = [ `Inductive | `CoInductive ]
32 type sort_kind = [ `Prop | `Set | `NType of string |`NCProp of string]
33 type fold_kind = [ `Left | `Right ]
34
35 type location = Stdpp.location
36 let fail floc msg =
37   let (x, y) = HExtlib.loc_of_floc floc in
38   failwith (Printf.sprintf "Error at characters %d - %d: %s" x y msg)
39
40 type href = NReference.reference
41
42 type child_pos = [ `Left | `Right | `Inner ]
43
44 type term_attribute =
45   [ `Loc of location                  (* source file location *)
46   | `IdRef of string                  (* ACic pointer *)
47   | `Level of int
48   | `XmlAttrs of (string option * string * string) list
49       (* list of XML attributes: namespace, name, value *)
50   | `Raw of string                    (* unparsed version *)
51   ]
52
53 type literal =
54   [ `Symbol of string
55   | `Keyword of string
56   | `Number of string
57   ]
58
59 type case_indtype = string * href option
60
61 type 'term capture_variable = 'term * 'term option
62
63 (** To be increased each time the term type below changes, used for "safe"
64  * marshalling *)
65 let magic = 8
66
67 type term =
68   (* CIC AST *)
69
70   | AttributedTerm of term_attribute * term
71
72   | Appl of term list
73   | Binder of binder_kind * term capture_variable * term (* kind, name, body *)
74   | Case of term * case_indtype option * term option *
75       (case_pattern * term) list
76       (* what to match, inductive type, out type, <pattern,action> list *)
77   | Cast of term * term
78   | LetIn of term capture_variable * term * term  (* name, body, where *)
79   | Ident of string * subst list option
80       (* literal, substitutions.
81       * Some [] -> user has given an empty explicit substitution list 
82       * None -> user has given no explicit substitution list *)
83   | Implicit of [`Vector | `JustOne | `Tagged of string]
84   | Meta of int * meta_subst list
85   | Num of string * int (* literal, instance *)
86   | Sort of sort_kind
87   | Symbol of string * int  (* canonical name, instance *)
88
89   | UserInput (* place holder for user input, used by MatitaConsole, not to be
90               used elsewhere *)
91   | Uri of string * subst list option (* as Ident, for long names *)
92   | NRef of NReference.reference
93
94   | NCic of NCic.term
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
106 and meta_subst = term option
107 and subst = string * term
108 and case_pattern =
109    Pattern of string * href option * term capture_variable list
110  | Wildcard
111
112 and box_kind = H | V | HV | HOV
113 and box_spec = box_kind * bool * bool (* kind, spacing, indent *)
114
115 and layout_pattern =
116   | Sub of term * term
117   | Sup of term * term
118   | Below of term * term
119   | Above of term * term
120   | Frac of term * term
121   | Over of term * term
122   | Atop of term * term
123   | InfRule of term * term * term
124 (*   | array of term * literal option * literal option
125       |+ column separator, row separator +| *)
126   | Maction of term list
127   | Sqrt of term
128   | Root of term * term (* argument, index *)
129   | Break
130   | Box of box_spec * term list
131   | Group of term list
132   | Mstyle of (string * string) list * term list
133   | Mpadded of (string * string) list * term list
134
135 and magic_term =
136   (* level 1 magics *)
137   | List0 of term * literal option (* pattern, separator *)
138   | List1 of term * literal option (* pattern, separator *)
139   | Opt of term
140
141   (* level 2 magics *)
142   | Fold of fold_kind * term * string list * term
143     (* base case pattern, recursive case bound names, recursive case pattern *)
144   | Default of term * term  (* "some" case pattern, "none" case pattern *)
145   | Fail
146   | If of term * term * term (* test, pattern if true, pattern if false *)
147
148 and term_level = Self of int | Level of int
149
150 and pattern_variable =
151   (* level 1 and 2 variables *)
152   | NumVar of string
153   | IdentVar of string
154   | TermVar of string * term_level
155
156   (* level 1 variables *)
157   | Ascription of term * string
158
159   (* level 2 variables *)
160   | FreshVar of string
161
162 type argument_pattern =
163   | IdentArg of int * string (* eta-depth, name *)
164
165 type cic_appl_pattern =
166   | NRefPattern of NReference.reference
167   | VarPattern of string
168   | ImplicitPattern
169   | ApplPattern of cic_appl_pattern list
170
171   (** <name, inductive/coinductive, type, constructor list>
172   * true means inductive, false coinductive *)
173 type 'term inductive_type = string * bool * 'term * (string * 'term) list
174
175 type 'term obj =
176   | Inductive of 'term capture_variable list * 'term inductive_type list * NCic.source
177       (** parameters, list of loc * mutual inductive types *)
178   | Theorem of string * 'term * 'term option * NCic.c_attr
179       (** name, type, body, attributes
180        * - name is absent when an unnamed theorem is being proved, tipically in
181        *   interactive usage
182        * - body is present when its given along with the command, otherwise it
183        *   will be given in proof editing mode using the tactical language,
184        *   unless the flavour is an Axiom
185        *)
186   | Record of 'term capture_variable list * string * 'term * (string * 'term * bool * int) list * NCic.source
187       (** left parameters, name, type, fields *)
188   | LetRec of induction_kind * ('term capture_variable list * 'term capture_variable * 'term * int) list * NCic.f_attr
189       (* (params, name, body, decreasing arg) list, attributes *)
190
191 (** {2 Standard precedences} *)
192
193 let let_in_prec = 10
194 let binder_prec = 20
195 let apply_prec = 70
196 let simple_prec = 90