]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/cicNotationPt.ml
handled difference associativity for the same level of the extensible grammar
[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 | `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 term_attribute =
43   [ `Loc of location                  (* source file location *)
44   | `IdRef of string                  (* ACic pointer *)
45   | `Href of UriManager.uri list      (* hyperlinks for literals *)
46   | `Level of int * Gramext.g_assoc   (* precedence, associativity *)
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 term =
59   (* CIC AST *)
60
61   | AttributedTerm of term_attribute * term
62
63   | Appl of term list
64   | Binder of binder_kind * capture_variable * term (* kind, name, body *)
65   | Case of term * string option * term option * (case_pattern * term) list
66       (* what to match, inductive type, out type, <pattern,action> list *)
67   | Cast of term * term
68   | LetIn of capture_variable * term * term  (* name, body, where *)
69   | LetRec of induction_kind * (capture_variable * term * int) list * term
70       (* (name, body, decreasing argument) list, where *)
71   | Ident of string * subst list option
72       (* literal, substitutions.
73       * Some [] -> user has given an empty explicit substitution list 
74       * None -> user has given no explicit substitution list *)
75   | Implicit
76   | Meta of int * meta_subst list
77   | Num of string * int (* literal, instance *)
78   | Sort of sort_kind
79   | Symbol of string * int  (* canonical name, instance *)
80
81   | UserInput (* place holder for user input, used by MatitaConsole, not to be
82               used elsewhere *)
83   | Uri of string * subst list option (* as Ident, for long names *)
84
85   (* Syntax pattern extensions *)
86
87   | Literal of literal
88   | Layout of layout_pattern
89
90   | Magic of magic_term
91   | Variable of pattern_variable
92
93   (* name, type. First component must be Ident or Variable (FreshVar _) *)
94 and capture_variable = term * term option
95
96 and meta_subst = term option
97 and subst = string * term
98 and case_pattern = string * capture_variable list
99
100 and box_kind = H | V | HV | HOV
101 and box_spec = box_kind * bool * bool (* kind, spacing, indent *)
102
103 and layout_pattern =
104   | Sub of term * term
105   | Sup of term * term
106   | Below of term * term
107   | Above of term * term
108   | Frac of term * term
109   | Over of term * term
110   | Atop of term * term
111 (*   | array of term * literal option * literal option
112       |+ column separator, row separator +| *)
113   | Sqrt of term
114   | Root of term * term (* argument, index *)
115   | Break
116   | Box of box_spec * term list
117   | Group of term list
118
119 and magic_term =
120   (* level 1 magics *)
121   | List0 of term * literal option (* pattern, separator *)
122   | List1 of term * literal option (* pattern, separator *)
123   | Opt of term
124
125   (* level 2 magics *)
126   | Fold of fold_kind * term * string list * term
127     (* base case pattern, recursive case bound names, recursive case pattern *)
128   | Default of term * term  (* "some" case pattern, "none" case pattern *)
129   | Fail
130   | If of term * term * term (* test, pattern if true, pattern if false *)
131
132 and pattern_variable =
133   (* level 1 and 2 variables *)
134   | NumVar of string
135   | IdentVar of string
136   | TermVar of string
137
138   (* level 1 variables *)
139   | Ascription of term * string
140
141   (* level 2 variables *)
142   | FreshVar of string
143
144 type argument_pattern =
145   | IdentArg of int * string (* eta-depth, name *)
146
147 type cic_appl_pattern =
148   | UriPattern of UriManager.uri
149   | VarPattern of string
150   | ImplicitPattern
151   | ApplPattern of cic_appl_pattern list
152
153 (** {2 Standard precedences} *)
154
155 let let_in_prec = 10
156 let binder_prec = 20
157 let apply_prec = 70
158 let simple_prec = 90
159
160 let let_in_assoc = Gramext.NonA
161 let binder_assoc = Gramext.RightA
162 let apply_assoc = Gramext.LeftA
163 let simple_assoc = Gramext.NonA
164