1 (* *)(* Copyright (C) 2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
27 eexception Parse_error of Token.flocation * string
28 llet grammar = Grammar.gcreate CicNotationLexer.notation_lexer
29 llet level1_pattern = Grammar.Entry.create grammar "level1_pattern"llet level2_pattern = Grammar.Entry.create grammar "level2_pattern"llet level3_term = Grammar.Entry.create grammar "level3_term"llet notation = Grammar.Entry.create grammar "notation"(* level1 <-> level 2 *)
30 llet interpretation = Grammar.Entry.create grammar "interpretation"(* level2 <-> level 3 *)
32 llet return_term loc term = ()
33 llet loc_of_floc ({Lexing.pos_cnum = loc_begin}, {Lexing.pos_cnum = loc_end}) =
36 let (x, y) = loc_of_floc floc in
37 failwith (sprintf "Error at characters %d - %d: %s" x y msg)
38 llet int_of_string s =
39 try Pervasives.int_of_string s with
41 failwith (sprintf "Lexer failure: string_of_int \"%s\" failed" s)
46 | l -> Layout (Box (H, l))
47 llet fold_binder binder pt_names body =
48 let fold_cluster binder names ty body =
50 (fun name body -> Binder (binder, (Cic.Name name, ty), body)) names body
52 List.fold_right (fun (names, ty) body -> fold_cluster binder names ty body)
54 llet return_term loc term = AttributedTerm (`Loc loc, term)
57 (let _ = (level1_pattern : 'level1_pattern Grammar.Entry.e)
58 and _ = (level2_pattern : 'level2_pattern Grammar.Entry.e)
59 and _ = (level3_term : 'level3_term Grammar.Entry.e)
60 and _ = (notation : 'notation Grammar.Entry.e)
61 and _ = (interpretation : 'interpretation Grammar.Entry.e) in
62 let grammar_entry_create s =
63 Grammar.Entry.create (Grammar.of_entry level1_pattern) s
65 let l1_pattern : 'l1_pattern Grammar.Entry.e =
66 grammar_entry_create "l1_pattern"
67 and literal : 'literal Grammar.Entry.e = grammar_entry_create "literal"
68 and sep : 'sep Grammar.Entry.e = grammar_entry_create "sep"
69 and l1_magic_pattern : 'l1_magic_pattern Grammar.Entry.e =
70 grammar_entry_create "l1_magic_pattern"
71 and l1_pattern_variable : 'l1_pattern_variable Grammar.Entry.e =
72 grammar_entry_create "l1_pattern_variable"
73 and l1_simple_pattern : 'l1_simple_pattern Grammar.Entry.e =
74 grammar_entry_create "l1_simple_pattern"
75 and sort : 'sort Grammar.Entry.e = grammar_entry_create "sort"
76 and explicit_subst : 'explicit_subst Grammar.Entry.e =
77 grammar_entry_create "explicit_subst"
78 and meta_subst : 'meta_subst Grammar.Entry.e =
79 grammar_entry_create "meta_subst"
80 and possibly_typed_name : 'possibly_typed_name Grammar.Entry.e =
81 grammar_entry_create "possibly_typed_name"
82 and match_pattern : 'match_pattern Grammar.Entry.e =
83 grammar_entry_create "match_pattern"
84 and binder : 'binder Grammar.Entry.e = grammar_entry_create "binder"
85 and bound_names : 'bound_names Grammar.Entry.e =
86 grammar_entry_create "bound_names"
87 and induction_kind : 'induction_kind Grammar.Entry.e =
88 grammar_entry_create "induction_kind"
89 and let_defs : 'let_defs Grammar.Entry.e =
90 grammar_entry_create "let_defs"
91 and l2_pattern_variable : 'l2_pattern_variable Grammar.Entry.e =
92 grammar_entry_create "l2_pattern_variable"
93 and l2_magic_pattern : 'l2_magic_pattern Grammar.Entry.e =
94 grammar_entry_create "l2_magic_pattern"
95 and l2_pattern : 'l2_pattern Grammar.Entry.e =
96 grammar_entry_create "l2_pattern"
97 and argument : 'argument Grammar.Entry.e =
98 grammar_entry_create "argument"
99 and associativity : 'associativity Grammar.Entry.e =
100 grammar_entry_create "associativity"
101 and precedence : 'precedence Grammar.Entry.e =
102 grammar_entry_create "precedence"
104 [Grammar.Entry.obj (level1_pattern : 'level1_pattern Grammar.Entry.e),
108 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
109 Gramext.Stoken ("EOI", "")],
111 (fun _ (p : 'l1_pattern)
112 (loc : Lexing.position * Lexing.position) ->
113 (boxify p : 'level1_pattern))]];
114 Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e), None,
119 (l1_simple_pattern : 'l1_simple_pattern Grammar.Entry.e)))],
121 (fun (p : 'l1_simple_pattern list)
122 (loc : Lexing.position * Lexing.position) ->
123 (p : 'l1_pattern))]];
124 Grammar.Entry.obj (literal : 'literal Grammar.Entry.e), None,
126 [[Gramext.Stoken ("NUMBER", "")],
128 (fun (n : string) (loc : Lexing.position * Lexing.position) ->
129 (`Number n : 'literal));
130 [Gramext.Stoken ("KEYWORD", "")],
132 (fun (k : string) (loc : Lexing.position * Lexing.position) ->
133 (`Keyword k : 'literal));
134 [Gramext.Stoken ("SYMBOL", "")],
136 (fun (s : string) (loc : Lexing.position * Lexing.position) ->
137 (`Symbol s : 'literal))]];
138 Grammar.Entry.obj (sep : 'sep Grammar.Entry.e), None,
140 [[Gramext.Stoken ("SYMBOL", "\\SEP");
142 (Grammar.Entry.obj (literal : 'literal Grammar.Entry.e))],
144 (fun (sep : 'literal) _ (loc : Lexing.position * Lexing.position) ->
147 (l1_magic_pattern : 'l1_magic_pattern Grammar.Entry.e),
150 [[Gramext.Stoken ("SYMBOL", "\\OPT");
153 (l1_simple_pattern : 'l1_simple_pattern Grammar.Entry.e))],
155 (fun (p : 'l1_simple_pattern) _
156 (loc : Lexing.position * Lexing.position) ->
157 (Opt p : 'l1_magic_pattern));
158 [Gramext.Stoken ("SYMBOL", "\\LIST1");
161 (l1_simple_pattern : 'l1_simple_pattern Grammar.Entry.e));
163 (Gramext.Snterm (Grammar.Entry.obj (sep : 'sep Grammar.Entry.e)))],
165 (fun (sep : 'sep option) (p : 'l1_simple_pattern) _
166 (loc : Lexing.position * Lexing.position) ->
167 (List1 (p, sep) : 'l1_magic_pattern));
168 [Gramext.Stoken ("SYMBOL", "\\LIST0");
171 (l1_simple_pattern : 'l1_simple_pattern Grammar.Entry.e));
173 (Gramext.Snterm (Grammar.Entry.obj (sep : 'sep Grammar.Entry.e)))],
175 (fun (sep : 'sep option) (p : 'l1_simple_pattern) _
176 (loc : Lexing.position * Lexing.position) ->
177 (List0 (p, sep) : 'l1_magic_pattern))]];
179 (l1_pattern_variable : 'l1_pattern_variable Grammar.Entry.e),
182 [[Gramext.Stoken ("SYMBOL", "\\IDENT"); Gramext.Stoken ("IDENT", "")],
184 (fun (id : string) _ (loc : Lexing.position * Lexing.position) ->
185 (IdentVar id : 'l1_pattern_variable));
186 [Gramext.Stoken ("SYMBOL", "\\NUM"); Gramext.Stoken ("IDENT", "")],
188 (fun (id : string) _ (loc : Lexing.position * Lexing.position) ->
189 (NumVar id : 'l1_pattern_variable));
190 [Gramext.Stoken ("SYMBOL", "\\TERM"); Gramext.Stoken ("IDENT", "")],
192 (fun (id : string) _ (loc : Lexing.position * Lexing.position) ->
193 (TermVar id : 'l1_pattern_variable));
194 [Gramext.Stoken ("IDENT", "")],
196 (fun (id : string) (loc : Lexing.position * Lexing.position) ->
197 (TermVar id : 'l1_pattern_variable))]];
199 (l1_simple_pattern : 'l1_simple_pattern Grammar.Entry.e),
201 [Some "layout", Some Gramext.LeftA,
202 [[Gramext.Stoken ("SYMBOL", "[");
204 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
205 Gramext.Stoken ("SYMBOL", "\\AS"); Gramext.Stoken ("IDENT", "");
206 Gramext.Stoken ("SYMBOL", "]")],
208 (fun _ (id : string) _ (p : 'l1_pattern) _
209 (loc : Lexing.position * Lexing.position) ->
211 (Variable (Ascription (Layout (Box (H, p)), id))) :
212 'l1_simple_pattern));
213 [Gramext.Stoken ("SYMBOL", "[");
215 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
216 Gramext.Stoken ("SYMBOL", "]")],
218 (fun _ (p : 'l1_pattern) _
219 (loc : Lexing.position * Lexing.position) ->
220 (return_term loc (Layout (Box (H, p))) : 'l1_simple_pattern));
221 [Gramext.Stoken ("SYMBOL", "\\BREAK")],
223 (fun _ (loc : Lexing.position * Lexing.position) ->
224 (return_term loc (Layout Break) : 'l1_simple_pattern));
225 [Gramext.Stoken ("SYMBOL", "\\VBOX"); Gramext.Stoken ("SYMBOL", "[");
227 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
228 Gramext.Stoken ("SYMBOL", "]")],
230 (fun _ (p : 'l1_pattern) _ _
231 (loc : Lexing.position * Lexing.position) ->
232 (return_term loc (Layout (Box (V, p))) : 'l1_simple_pattern));
233 [Gramext.Stoken ("SYMBOL", "\\HBOX"); Gramext.Stoken ("SYMBOL", "[");
235 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
236 Gramext.Stoken ("SYMBOL", "]")],
238 (fun _ (p : 'l1_pattern) _ _
239 (loc : Lexing.position * Lexing.position) ->
240 (return_term loc (Layout (Box (H, p))) : 'l1_simple_pattern));
241 [Gramext.Stoken ("SYMBOL", "\\ROOT");
243 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
244 Gramext.Stoken ("SYMBOL", "\\OF"); Gramext.Sself],
246 (fun (arg : 'l1_simple_pattern) _ (index : 'l1_pattern) _
247 (loc : Lexing.position * Lexing.position) ->
248 (return_term loc (Layout (Root (arg, Layout (Box (H, index))))) :
249 'l1_simple_pattern));
250 [Gramext.Stoken ("SYMBOL", "\\SQRT"); Gramext.Sself],
252 (fun (p : 'l1_simple_pattern) _
253 (loc : Lexing.position * Lexing.position) ->
254 (return_term loc (Layout (Sqrt p)) : 'l1_simple_pattern));
255 [Gramext.Stoken ("SYMBOL", "\\FRAC"); Gramext.Sself; Gramext.Sself],
257 (fun (p2 : 'l1_simple_pattern) (p1 : 'l1_simple_pattern) _
258 (loc : Lexing.position * Lexing.position) ->
259 (return_term loc (Layout (Frac (p1, p2))) : 'l1_simple_pattern));
260 [Gramext.Stoken ("SYMBOL", "[");
262 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
263 Gramext.Stoken ("SYMBOL", "\\ATOP");
265 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
266 Gramext.Stoken ("SYMBOL", "]")],
268 (fun _ (p2 : 'l1_pattern) _ (p1 : 'l1_pattern) _
269 (loc : Lexing.position * Lexing.position) ->
270 (return_term loc (Layout (Atop (boxify p1, boxify p2))) :
271 'l1_simple_pattern));
272 [Gramext.Stoken ("SYMBOL", "[");
274 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
275 Gramext.Stoken ("SYMBOL", "\\OVER");
277 (Grammar.Entry.obj (l1_pattern : 'l1_pattern Grammar.Entry.e));
278 Gramext.Stoken ("SYMBOL", "]")],
280 (fun _ (p2 : 'l1_pattern) _ (p1 : 'l1_pattern) _
281 (loc : Lexing.position * Lexing.position) ->
282 (return_term loc (Layout (Frac (boxify p1, boxify p2))) :
283 'l1_simple_pattern));
284 [Gramext.Sself; Gramext.Stoken ("SYMBOL", "\\ABOVE"); Gramext.Sself],
286 (fun (p2 : 'l1_simple_pattern) _ (p1 : 'l1_simple_pattern)
287 (loc : Lexing.position * Lexing.position) ->
288 (return_term loc (Layout (Above (p1, p2))) :
289 'l1_simple_pattern));
290 [Gramext.Sself; Gramext.Stoken ("SYMBOL", "\\BELOW"); Gramext.Sself],
292 (fun (p2 : 'l1_simple_pattern) _ (p1 : 'l1_simple_pattern)
293 (loc : Lexing.position * Lexing.position) ->
294 (return_term loc (Layout (Below (p1, p2))) :
295 'l1_simple_pattern));
296 [Gramext.Sself; Gramext.Stoken ("SYMBOL", "\\SUP"); Gramext.Sself],
298 (fun (p2 : 'l1_simple_pattern) _ (p1 : 'l1_simple_pattern)
299 (loc : Lexing.position * Lexing.position) ->
300 (return_term loc (Layout (Sup (p1, p2))) : 'l1_simple_pattern));
301 [Gramext.Sself; Gramext.Stoken ("SYMBOL", "\\SUB"); Gramext.Sself],
303 (fun (p2 : 'l1_simple_pattern) _ (p1 : 'l1_simple_pattern)
304 (loc : Lexing.position * Lexing.position) ->
305 (return_term loc (Layout (Sub (p1, p2))) : 'l1_simple_pattern))];
306 Some "simple", Some Gramext.NonA,
308 (Grammar.Entry.obj (literal : 'literal Grammar.Entry.e))],
310 (fun (l : 'literal) (loc : Lexing.position * Lexing.position) ->
311 (return_term loc (Literal l) : 'l1_simple_pattern));
314 (l1_pattern_variable : 'l1_pattern_variable Grammar.Entry.e))],
316 (fun (v : 'l1_pattern_variable)
317 (loc : Lexing.position * Lexing.position) ->
318 (return_term loc (Variable v) : 'l1_simple_pattern));
321 (l1_magic_pattern : 'l1_magic_pattern Grammar.Entry.e))],
323 (fun (m : 'l1_magic_pattern)
324 (loc : Lexing.position * Lexing.position) ->
325 (return_term loc (Magic m) : 'l1_simple_pattern))]];
326 Grammar.Entry.obj (level2_pattern : 'level2_pattern Grammar.Entry.e),
330 (Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e))],
332 (fun (p : 'l2_pattern) (loc : Lexing.position * Lexing.position) ->
333 (p : 'level2_pattern))]];
334 Grammar.Entry.obj (sort : 'sort Grammar.Entry.e), None,
336 [[Gramext.Stoken ("SYMBOL", "\\TYPE")],
338 (fun _ (loc : Lexing.position * Lexing.position) ->
340 [Gramext.Stoken ("SYMBOL", "\\SET")],
342 (fun _ (loc : Lexing.position * Lexing.position) -> (`Set : 'sort));
343 [Gramext.Stoken ("SYMBOL", "\\PROP")],
345 (fun _ (loc : Lexing.position * Lexing.position) ->
347 Grammar.Entry.obj (explicit_subst : 'explicit_subst Grammar.Entry.e),
348 None, [None, None, []];
349 Grammar.Entry.obj (meta_subst : 'meta_subst Grammar.Entry.e), None,
352 (possibly_typed_name : 'possibly_typed_name Grammar.Entry.e),
355 [[Gramext.Stoken ("IDENT", "")],
357 (fun (id : string) (loc : Lexing.position * Lexing.position) ->
358 (Cic.Name id, None : 'possibly_typed_name));
359 [Gramext.Stoken ("SYMBOL", "("); Gramext.Stoken ("IDENT", "");
360 Gramext.Stoken ("SYMBOL", ":");
362 (Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e));
363 Gramext.Stoken ("SYMBOL", ")")],
365 (fun _ (typ : 'l2_pattern) _ (id : string) _
366 (loc : Lexing.position * Lexing.position) ->
367 (Cic.Name id, Some typ : 'possibly_typed_name))]];
368 Grammar.Entry.obj (match_pattern : 'match_pattern Grammar.Entry.e),
371 [[Gramext.Stoken ("SYMBOL", "("); Gramext.Stoken ("IDENT", "");
375 (possibly_typed_name :
376 'possibly_typed_name Grammar.Entry.e)));
377 Gramext.Stoken ("SYMBOL", ")")],
379 (fun _ (vars : 'possibly_typed_name list) (id : string) _
380 (loc : Lexing.position * Lexing.position) ->
381 (id, vars : 'match_pattern));
382 [Gramext.Stoken ("IDENT", "")],
384 (fun (id : string) (loc : Lexing.position * Lexing.position) ->
385 (id, [] : 'match_pattern))]];
386 Grammar.Entry.obj (binder : 'binder Grammar.Entry.e), None,
388 [[Gramext.Stoken ("SYMBOL", "λ")],
390 (fun _ (loc : Lexing.position * Lexing.position) ->
391 (`Lambda : 'binder));
392 [Gramext.Stoken ("SYMBOL", "∀")],
394 (fun _ (loc : Lexing.position * Lexing.position) ->
395 (`Forall : 'binder));
396 [Gramext.Stoken ("SYMBOL", "∃")],
398 (fun _ (loc : Lexing.position * Lexing.position) ->
399 (`Exists : 'binder));
400 [Gramext.Stoken ("SYMBOL", "Π")],
402 (fun _ (loc : Lexing.position * Lexing.position) ->
404 Grammar.Entry.obj (bound_names : 'bound_names Grammar.Entry.e), None,
408 [[Gramext.Stoken ("SYMBOL", "(");
410 (Gramext.Stoken ("IDENT", ""),
411 Gramext.Stoken ("SYMBOL", ","));
414 [[Gramext.Stoken ("SYMBOL", ":");
417 (l2_pattern : 'l2_pattern Grammar.Entry.e))],
419 (fun (p : 'l2_pattern) _
420 (loc : Lexing.position * Lexing.position) ->
422 Gramext.Stoken ("SYMBOL", ")")],
424 (fun _ (ty : 'e__2 option) (vars : string list) _
425 (loc : Lexing.position * Lexing.position) ->
426 (vars, ty : 'e__3))])],
428 (fun (clusters : 'e__3 list)
429 (loc : Lexing.position * Lexing.position) ->
430 (clusters : 'bound_names));
432 (Gramext.Stoken ("IDENT", ""), Gramext.Stoken ("SYMBOL", ","));
435 [[Gramext.Stoken ("SYMBOL", ":");
438 (l2_pattern : 'l2_pattern Grammar.Entry.e))],
440 (fun (p : 'l2_pattern) _
441 (loc : Lexing.position * Lexing.position) ->
444 (fun (ty : 'e__1 option) (vars : string list)
445 (loc : Lexing.position * Lexing.position) ->
446 ([vars, ty] : 'bound_names))]];
447 Grammar.Entry.obj (induction_kind : 'induction_kind Grammar.Entry.e),
450 [[Gramext.Stoken ("IDENT", "corec")],
452 (fun _ (loc : Lexing.position * Lexing.position) ->
453 (`CoInductive : 'induction_kind));
454 [Gramext.Stoken ("IDENT", "rec")],
456 (fun _ (loc : Lexing.position * Lexing.position) ->
457 (`Inductive : 'induction_kind))]];
458 Grammar.Entry.obj (let_defs : 'let_defs Grammar.Entry.e), None,
462 [[Gramext.Stoken ("IDENT", "");
465 (bound_names : 'bound_names Grammar.Entry.e));
468 [[Gramext.Stoken ("IDENT", "on");
469 Gramext.Stoken ("IDENT", "")],
472 (loc : Lexing.position * Lexing.position) ->
476 [[Gramext.Stoken ("SYMBOL", ":");
479 (l2_pattern : 'l2_pattern Grammar.Entry.e))],
481 (fun (p : 'l2_pattern) _
482 (loc : Lexing.position * Lexing.position) ->
484 Gramext.Stoken ("SYMBOL", "≝");
487 (l2_pattern : 'l2_pattern Grammar.Entry.e))],
489 (fun (body : 'l2_pattern) _ (ty : 'e__5 option)
490 (index_name : 'e__4 option) (args : 'bound_names)
492 (loc : Lexing.position * Lexing.position) ->
493 (let body = fold_binder `Lambda args body in
497 | Some ty -> Some (fold_binder `Pi args ty)
499 let rec position_of name p =
502 | n :: _ when n = name -> Some p, p
503 | _ :: tl -> position_of name (p + 1) tl
505 let rec find_arg name n =
507 [] -> fail loc (sprintf "Argument %s not found" name)
509 match position_of name 0 l with
510 None, len -> find_arg name (n + len) tl
511 | Some where, len -> n + where
514 match index_name with
516 | Some name -> find_arg name 0 args
518 (Cic.Name name, ty), body, index :
520 Gramext.Stoken ("IDENT", "and"))],
522 (fun (defs : 'e__6 list)
523 (loc : Lexing.position * Lexing.position) ->
524 (defs : 'let_defs))]];
526 (l2_pattern_variable : 'l2_pattern_variable Grammar.Entry.e),
529 [[Gramext.Stoken ("SYMBOL", "\\FRESH"); Gramext.Stoken ("IDENT", "")],
531 (fun (id : string) _ (loc : Lexing.position * Lexing.position) ->
532 (FreshVar id : 'l2_pattern_variable));
533 [Gramext.Stoken ("SYMBOL", "\\IDENT"); Gramext.Stoken ("IDENT", "")],
535 (fun (id : string) _ (loc : Lexing.position * Lexing.position) ->
536 (IdentVar id : 'l2_pattern_variable));
537 [Gramext.Stoken ("SYMBOL", "\\NUM"); Gramext.Stoken ("IDENT", "")],
539 (fun (id : string) _ (loc : Lexing.position * Lexing.position) ->
540 (NumVar id : 'l2_pattern_variable))]];
542 (l2_magic_pattern : 'l2_magic_pattern Grammar.Entry.e),
545 [[Gramext.Stoken ("SYMBOL", "\\DEFAULT");
547 (Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e));
549 (Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e))],
551 (fun (none : 'l2_pattern) (some : 'l2_pattern) _
552 (loc : Lexing.position * Lexing.position) ->
553 (Default (some, none) : 'l2_magic_pattern));
554 [Gramext.Stoken ("SYMBOL", "\\FOLD");
556 [[Gramext.Stoken ("IDENT", "right")],
558 (fun _ (loc : Lexing.position * Lexing.position) ->
560 [Gramext.Stoken ("IDENT", "left")],
562 (fun _ (loc : Lexing.position * Lexing.position) ->
565 (Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e));
566 Gramext.Stoken ("SYMBOL", "\\LAMBDA"); Gramext.Stoken ("IDENT", "");
568 (Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e))],
570 (fun (recursive : 'l2_pattern) (id : string) _ (base : 'l2_pattern)
571 (kind : 'e__7) _ (loc : Lexing.position * Lexing.position) ->
572 (Fold (kind, base, [id], recursive) : 'l2_magic_pattern))]];
573 Grammar.Entry.obj (l2_pattern : 'l2_pattern Grammar.Entry.e), None,
574 [Some "letin", Some Gramext.NonA,
575 [[Gramext.Stoken ("IDENT", "let");
578 (induction_kind : 'induction_kind Grammar.Entry.e));
580 (Grammar.Entry.obj (let_defs : 'let_defs Grammar.Entry.e));
581 Gramext.Stoken ("IDENT", "in"); Gramext.Sself],
583 (fun (body : 'l2_pattern) _ (defs : 'let_defs) (k : 'induction_kind)
584 _ (loc : Lexing.position * Lexing.position) ->
585 (return_term loc (LetRec (k, defs, body)) : 'l2_pattern));
586 [Gramext.Stoken ("IDENT", "let");
589 (possibly_typed_name : 'possibly_typed_name Grammar.Entry.e));
590 Gramext.Stoken ("SYMBOL", "≝"); Gramext.Sself;
591 Gramext.Stoken ("", "in"); Gramext.Sself],
593 (fun (p2 : 'l2_pattern) _ (p1 : 'l2_pattern) _
594 (var : 'possibly_typed_name) _
595 (loc : Lexing.position * Lexing.position) ->
596 (return_term loc (LetIn (var, p1, p2)) : 'l2_pattern))];
597 Some "binder", Some Gramext.RightA,
599 (Grammar.Entry.obj (binder : 'binder Grammar.Entry.e));
601 (Grammar.Entry.obj (bound_names : 'bound_names Grammar.Entry.e));
602 Gramext.Stoken ("SYMBOL", "."); Gramext.Sself],
604 (fun (body : 'l2_pattern) _ (names : 'bound_names) (b : 'binder)
605 (loc : Lexing.position * Lexing.position) ->
606 (return_term loc (fold_binder b names body) : 'l2_pattern))];
607 Some "extension", None, [];
608 Some "apply", Some Gramext.LeftA,
609 [[Gramext.Sself; Gramext.Sself],
611 (fun (p2 : 'l2_pattern) (p1 : 'l2_pattern)
612 (loc : Lexing.position * Lexing.position) ->
615 Appl (hd :: tl) | AttributedTerm (_, Appl (hd :: tl)) ->
619 return_term loc (Appl (aux p1 @ [p2])) :
621 Some "simple", Some Gramext.NonA,
624 (l2_magic_pattern : 'l2_magic_pattern Grammar.Entry.e))],
626 (fun (m : 'l2_magic_pattern)
627 (loc : Lexing.position * Lexing.position) ->
628 (return_term loc (Magic m) : 'l2_pattern));
631 (l2_pattern_variable : 'l2_pattern_variable Grammar.Entry.e))],
633 (fun (v : 'l2_pattern_variable)
634 (loc : Lexing.position * Lexing.position) ->
635 (return_term loc (Variable v) : 'l2_pattern));
636 [Gramext.Stoken ("SYMBOL", "("); Gramext.Sself;
637 Gramext.Stoken ("SYMBOL", ")")],
639 (fun _ (p : 'l2_pattern) _
640 (loc : Lexing.position * Lexing.position) ->
642 [Gramext.Stoken ("SYMBOL", "("); Gramext.Sself;
643 Gramext.Stoken ("SYMBOL", ":"); Gramext.Sself;
644 Gramext.Stoken ("SYMBOL", ")")],
646 (fun _ (p2 : 'l2_pattern) _ (p1 : 'l2_pattern) _
647 (loc : Lexing.position * Lexing.position) ->
648 (return_term loc (Appl [Symbol ("cast", 0); p1; p2]) :
652 [[Gramext.Stoken ("SYMBOL", "[");
655 (l2_pattern : 'l2_pattern Grammar.Entry.e));
656 Gramext.Stoken ("SYMBOL", "]")],
658 (fun _ (ty : 'l2_pattern) _
659 (loc : Lexing.position * Lexing.position) ->
661 Gramext.Stoken ("IDENT", "match"); Gramext.Sself;
664 [[Gramext.Stoken ("SYMBOL", ":"); Gramext.Stoken ("IDENT", "")],
667 (loc : Lexing.position * Lexing.position) ->
669 Gramext.Stoken ("IDENT", "with"); Gramext.Stoken ("SYMBOL", "[");
674 (match_pattern : 'match_pattern Grammar.Entry.e));
675 Gramext.Stoken ("SYMBOL", "⇒");
678 (l2_pattern : 'l2_pattern Grammar.Entry.e))],
680 (fun (rhs : 'l2_pattern) _ (lhs : 'match_pattern)
681 (loc : Lexing.position * Lexing.position) ->
682 (lhs, rhs : 'e__10))],
683 Gramext.Stoken ("SYMBOL", "|"));
684 Gramext.Stoken ("SYMBOL", "]")],
686 (fun _ (patterns : 'e__10 list) _ _ (indty_ident : 'e__9 option)
687 (t : 'l2_pattern) _ (outtyp : 'e__8 option)
688 (loc : Lexing.position * Lexing.position) ->
689 (return_term loc (Case (t, indty_ident, outtyp, patterns)) :
691 [Gramext.Stoken ("SYMBOL", "")],
693 (fun (s : string) (loc : Lexing.position * Lexing.position) ->
694 (return_term loc (Symbol (s, 0)) : 'l2_pattern));
695 [Gramext.Snterm (Grammar.Entry.obj (sort : 'sort Grammar.Entry.e))],
697 (fun (s : 'sort) (loc : Lexing.position * Lexing.position) ->
698 (return_term loc (Sort s) : 'l2_pattern));
699 [Gramext.Stoken ("META", "");
701 (Grammar.Entry.obj (meta_subst : 'meta_subst Grammar.Entry.e))],
703 (fun (s : 'meta_subst) (m : string)
704 (loc : Lexing.position * Lexing.position) ->
705 (return_term loc (Meta (int_of_string m, s)) : 'l2_pattern));
706 [Gramext.Stoken ("META", "")],
708 (fun (m : string) (loc : Lexing.position * Lexing.position) ->
709 (return_term loc (Meta (int_of_string m, [])) : 'l2_pattern));
710 [Gramext.Stoken ("IMPLICIT", "")],
712 (fun _ (loc : Lexing.position * Lexing.position) ->
713 (return_term loc Implicit : 'l2_pattern));
714 [Gramext.Stoken ("NUMBER", "")],
716 (fun (n : string) (loc : Lexing.position * Lexing.position) ->
717 (return_term loc (Num (n, 0)) : 'l2_pattern));
718 [Gramext.Stoken ("URI", "")],
720 (fun (u : string) (loc : Lexing.position * Lexing.position) ->
721 (return_term loc (Uri (u, None)) : 'l2_pattern));
722 [Gramext.Stoken ("IDENT", "");
725 (explicit_subst : 'explicit_subst Grammar.Entry.e))],
727 (fun (s : 'explicit_subst) (id : string)
728 (loc : Lexing.position * Lexing.position) ->
729 (return_term loc (Ident (id, Some s)) : 'l2_pattern));
730 [Gramext.Stoken ("IDENT", "")],
732 (fun (id : string) (loc : Lexing.position * Lexing.position) ->
733 (return_term loc (Ident (id, None)) : 'l2_pattern))]];
734 Grammar.Entry.obj (argument : 'argument Grammar.Entry.e), None,
736 [[Gramext.Stoken ("SYMBOL", "η"); Gramext.Stoken ("IDENT", "");
737 Gramext.Stoken ("SYMBOL", "."); Gramext.Sself],
739 (fun (a : 'argument) _ (id : string) _
740 (loc : Lexing.position * Lexing.position) ->
741 (EtaArg (Some id, a) : 'argument));
742 [Gramext.Stoken ("SYMBOL", "η"); Gramext.Stoken ("SYMBOL", ".");
745 (fun (a : 'argument) _ _
746 (loc : Lexing.position * Lexing.position) ->
747 (EtaArg (None, a) : 'argument));
748 [Gramext.Stoken ("IDENT", "")],
750 (fun (id : string) (loc : Lexing.position * Lexing.position) ->
751 (IdentArg id : 'argument))]];
752 Grammar.Entry.obj (level3_term : 'level3_term Grammar.Entry.e), None,
754 [[Gramext.Stoken ("SYMBOL", "("); Gramext.Slist1 Gramext.Sself;
755 Gramext.Stoken ("SYMBOL", ")")],
757 (fun _ (terms : 'level3_term list) _
758 (loc : Lexing.position * Lexing.position) ->
762 | terms -> ApplPattern terms :
765 (Grammar.Entry.obj (argument : 'argument Grammar.Entry.e))],
767 (fun (a : 'argument) (loc : Lexing.position * Lexing.position) ->
768 (ArgPattern a : 'level3_term));
769 [Gramext.Stoken ("URI", "")],
771 (fun (u : string) (loc : Lexing.position * Lexing.position) ->
772 (UriPattern u : 'level3_term))]];
773 Grammar.Entry.obj (associativity : 'associativity Grammar.Entry.e),
776 [[Gramext.Stoken ("IDENT", "right");
777 Gramext.Stoken ("IDENT", "associative")],
779 (fun _ _ (loc : Lexing.position * Lexing.position) ->
780 (`Right : 'associativity));
781 [Gramext.Stoken ("IDENT", "left");
782 Gramext.Stoken ("IDENT", "associative")],
784 (fun _ _ (loc : Lexing.position * Lexing.position) ->
785 (`Left : 'associativity))]];
786 Grammar.Entry.obj (precedence : 'precedence Grammar.Entry.e), None,
788 [[Gramext.Stoken ("IDENT", "at");
789 Gramext.Stoken ("IDENT", "precedence");
790 Gramext.Stoken ("NUMBER", "")],
792 (fun (n : string) _ _ (loc : Lexing.position * Lexing.position) ->
793 (n : 'precedence))]];
794 Grammar.Entry.obj (notation : 'notation Grammar.Entry.e), None,
796 [[Gramext.Stoken ("IDENT", "notation");
799 (level1_pattern : 'level1_pattern Grammar.Entry.e));
800 Gramext.Stoken ("IDENT", "for");
803 (level2_pattern : 'level2_pattern Grammar.Entry.e));
807 (associativity : 'associativity Grammar.Entry.e)));
811 (precedence : 'precedence Grammar.Entry.e)))],
813 (fun (prec : 'precedence option) (assoc : 'associativity option)
814 (p2 : 'level2_pattern) _ (p1 : 'level1_pattern) _
815 (loc : Lexing.position * Lexing.position) ->
817 Grammar.Entry.obj (interpretation : 'interpretation Grammar.Entry.e),
820 [[Gramext.Stoken ("IDENT", "interpretation");
821 Gramext.Stoken ("SYMBOL", "");
824 (Grammar.Entry.obj (argument : 'argument Grammar.Entry.e)));
825 Gramext.Stoken ("IDENT", "as");
827 (Grammar.Entry.obj (level3_term : 'level3_term Grammar.Entry.e))],
829 (fun (t : 'level3_term) _ (args : 'argument list) (s : string) _
830 (loc : Lexing.position * Lexing.position) ->
831 (() : 'interpretation))]]])
833 let exc_located_wrapper f =
835 Stdpp.Exc_located (floc, Stream.Error msg) ->
836 raise (Parse_error (floc, msg))
837 | Stdpp.Exc_located (floc, exn) ->
838 raise (Parse_error (floc, Printexc.to_string exn))
840 let parse_syntax_pattern stream =
841 exc_located_wrapper (fun () -> Grammar.Entry.parse level1_pattern stream)
843 let parse_ast_pattern stream =
844 exc_located_wrapper (fun () -> Grammar.Entry.parse level2_pattern stream)
846 let parse_interpretation stream =
847 exc_located_wrapper (fun () -> Grammar.Entry.parse level3_term stream)
849 (* vim:set encoding=utf8 foldmethod=marker: *)