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