]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/grafiteParser.ml
New tactic unfold.
[helm.git] / helm / ocaml / cic_notation / grafiteParser.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 open Printf
27
28 let grammar = CicNotationParser.level2_ast_grammar
29
30 let term = CicNotationParser.term
31 let statement = Grammar.Entry.create grammar "statement"
32
33 let add_raw_attribute ~text t = CicNotationPt.AttributedTerm (`Raw text, t)
34
35 let default_precedence = 50
36 let default_associativity = Gramext.NonA
37
38 EXTEND
39   GLOBAL: term statement;
40   arg: [
41    [ LPAREN; names = LIST1 IDENT SEP SYMBOL ",";
42       SYMBOL ":"; ty = term; RPAREN -> names,ty
43    | name = IDENT -> [name],CicNotationPt.Implicit
44    ]
45   ];
46   constructor: [ [ name = IDENT; SYMBOL ":"; typ = term -> (name, typ) ] ];
47   tactic_term: [ [ t = term -> t ] ];
48   ident_list0: [
49     [ SYMBOL "["; idents = LIST0 IDENT SEP SYMBOL ";"; SYMBOL "]" -> idents ]
50   ];
51   tactic_term_list1: [
52     [ tactic_terms = LIST1 tactic_term SEP SYMBOL "," -> tactic_terms ]
53   ];
54   reduction_kind: [
55     [ IDENT "normalize" -> `Normalize
56     | IDENT "reduce" -> `Reduce
57     | IDENT "simplify" -> `Simpl
58     | IDENT "unfold"; t = OPT term -> `Unfold t
59     | IDENT "whd" -> `Whd ]
60   ];
61   sequent_pattern_spec: [
62    [ hyp_paths =
63       LIST0
64        [ id = IDENT ;
65          path = OPT [SYMBOL ":" ; path = term -> path ] ->
66          (id,match path with Some p -> p | None -> CicNotationPt.UserInput) ]
67        SEP SYMBOL ";";
68      goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = term -> term ] ->
69       let goal_path =
70        match goal_path with
71           None -> CicNotationPt.UserInput
72         | Some goal_path -> goal_path
73       in
74        hyp_paths,goal_path
75    ]
76   ];
77   pattern_spec: [
78     [ res = OPT [
79        "in";
80        wanted_and_sps =
81         [ "match" ; wanted = term ;
82           sps = OPT [ "in"; sps = sequent_pattern_spec -> sps ] ->
83            Some wanted,sps
84         | sps = sequent_pattern_spec ->
85            None,Some sps
86         ] ->
87          let wanted,hyp_paths,goal_path =
88           match wanted_and_sps with
89              wanted,None -> wanted, [], CicNotationPt.UserInput
90            | wanted,Some (hyp_paths,goal_path) -> wanted,hyp_paths,goal_path
91          in
92           wanted, hyp_paths, goal_path ] ->
93       match res with
94          None -> None,[],CicNotationPt.UserInput
95        | Some ps -> ps]
96   ];
97   direction: [
98     [ SYMBOL ">" -> `LeftToRight
99     | SYMBOL "<" -> `RightToLeft ]
100   ];
101   int: [ [ num = NUMBER -> int_of_string num ] ];
102   tactic: [
103     [ IDENT "absurd"; t = tactic_term ->
104         GrafiteAst.Absurd (loc, t)
105     | IDENT "apply"; t = tactic_term ->
106         GrafiteAst.Apply (loc, t)
107     | IDENT "assumption" ->
108         GrafiteAst.Assumption loc
109     | IDENT "auto";
110       depth = OPT [ IDENT "depth"; SYMBOL "="; i = int -> i ];
111       width = OPT [ IDENT "width"; SYMBOL "="; i = int -> i ];
112       paramodulation = OPT [ IDENT "paramodulation" ] ->  (* ALB *)
113           GrafiteAst.Auto (loc,depth,width,paramodulation)
114     | IDENT "clear"; id = IDENT ->
115         GrafiteAst.Clear (loc,id)
116     | IDENT "clearbody"; id = IDENT ->
117         GrafiteAst.ClearBody (loc,id)
118     | IDENT "change"; what = pattern_spec; "with"; t = tactic_term ->
119         GrafiteAst.Change (loc, what, t)
120     | IDENT "compare"; t = tactic_term ->
121         GrafiteAst.Compare (loc,t)
122     | IDENT "constructor"; n = int ->
123         GrafiteAst.Constructor (loc, n)
124     | IDENT "contradiction" ->
125         GrafiteAst.Contradiction loc
126     | IDENT "cut"; t = tactic_term; ident = OPT [ "as"; id = IDENT -> id] ->
127         GrafiteAst.Cut (loc, ident, t)
128     | IDENT "decide"; IDENT "equality" ->
129         GrafiteAst.DecideEquality loc
130     | IDENT "decompose"; types = OPT ident_list0; what = IDENT;
131       OPT "names"; num = OPT [num = int -> num];
132       idents = OPT ident_list0 ->
133         let idents = match idents with None -> [] | Some idents -> idents in   
134         let types = match types with None -> [] | Some types -> types in
135         let to_spec id = GrafiteAst.Ident id in
136         GrafiteAst.Decompose (loc, List.rev_map to_spec types, what, idents)
137     | IDENT "discriminate"; t = tactic_term ->
138         GrafiteAst.Discriminate (loc, t)
139     | IDENT "elim"; what = tactic_term;
140       using = OPT [ "using"; using = tactic_term -> using ];  
141       OPT "names"; num = OPT [num = int -> num];
142       idents = OPT ident_list0 ->
143         let idents = match idents with None -> [] | Some idents -> idents in
144         GrafiteAst.Elim (loc, what, using, num, idents)
145     | IDENT "elimType"; what = tactic_term;
146       using = OPT [ "using"; using = tactic_term -> using ];  
147       OPT "names"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
148         let idents = match idents with None -> [] | Some idents -> idents in
149         GrafiteAst.ElimType (loc, what, using, num, idents)
150     | IDENT "exact"; t = tactic_term ->
151         GrafiteAst.Exact (loc, t)
152     | IDENT "exists" ->
153         GrafiteAst.Exists loc
154     | IDENT "fail" -> GrafiteAst.Fail loc
155     | IDENT "fold"; kind = reduction_kind; t = tactic_term; p = pattern_spec ->
156         let (pt,_,_) = p in
157           if pt <> None then
158             raise (CicNotationParser.Parse_error
159               (loc, "the pattern cannot specify the term to replace, only its"
160               ^ " paths in the hypotheses and in the conclusion"))
161         else
162          GrafiteAst.Fold (loc, kind, t, p)
163     | IDENT "fourier" ->
164         GrafiteAst.Fourier loc
165     | IDENT "fwd"; hyp = IDENT; idents = OPT ident_list0 ->
166         let idents = match idents with None -> [] | Some idents -> idents in
167         GrafiteAst.FwdSimpl (loc, hyp, idents)
168     | IDENT "generalize"; p=pattern_spec; id = OPT ["as" ; id = IDENT -> id] ->
169        GrafiteAst.Generalize (loc,p,id)
170     | IDENT "goal"; n = int ->
171         GrafiteAst.Goal (loc, n)
172     | IDENT "id" -> GrafiteAst.IdTac loc
173     | IDENT "injection"; t = tactic_term ->
174         GrafiteAst.Injection (loc, t)
175     | IDENT "intro"; ident = OPT IDENT ->
176         let idents = match ident with None -> [] | Some id -> [id] in
177         GrafiteAst.Intros (loc, Some 1, idents)
178     | IDENT "intros"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
179         let idents = match idents with None -> [] | Some idents -> idents in
180         GrafiteAst.Intros (loc, num, idents)
181     | IDENT "lapply"; 
182       depth = OPT [ IDENT "depth"; SYMBOL "="; i = int -> i ];
183       what = tactic_term; 
184       to_what = OPT [ "to" ; t = tactic_term_list1 -> t ];
185       ident = OPT [ "using" ; ident = IDENT -> ident ] ->
186         let to_what = match to_what with None -> [] | Some to_what -> to_what in
187         GrafiteAst.LApply (loc, depth, to_what, what, ident)
188     | IDENT "left" -> GrafiteAst.Left loc
189     | IDENT "letin"; where = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term ->
190         GrafiteAst.LetIn (loc, t, where)
191     | kind = reduction_kind; p = pattern_spec ->
192         GrafiteAst.Reduce (loc, kind, p)
193     | IDENT "reflexivity" ->
194         GrafiteAst.Reflexivity loc
195     | IDENT "replace"; p = pattern_spec; "with"; t = tactic_term ->
196         GrafiteAst.Replace (loc, p, t)
197     | IDENT "rewrite" ; d = direction; t = tactic_term ; p = pattern_spec ->
198        let (pt,_,_) = p in
199         if pt <> None then
200          raise
201           (CicNotationParser.Parse_error
202             (loc,"the pattern cannot specify the term to rewrite, only its paths in the hypotheses and in the conclusion"))
203         else
204          GrafiteAst.Rewrite (loc, d, t, p)
205     | IDENT "right" ->
206         GrafiteAst.Right loc
207     | IDENT "ring" ->
208         GrafiteAst.Ring loc
209     | IDENT "split" ->
210         GrafiteAst.Split loc
211     | IDENT "symmetry" ->
212         GrafiteAst.Symmetry loc
213     | IDENT "transitivity"; t = tactic_term ->
214         GrafiteAst.Transitivity (loc, t)
215     ]
216   ];
217   tactical:
218     [ "sequence" LEFTA
219       [ tacticals = LIST1 NEXT SEP SYMBOL ";" ->
220          match tacticals with
221             [] -> assert false
222           | [tac] -> tac
223           | l -> GrafiteAst.Seq (loc, l)
224       ]
225     | "then" NONA
226       [ tac = tactical; SYMBOL ";";
227         SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
228           (GrafiteAst.Then (loc, tac, tacs))
229       ]
230     | "loops" RIGHTA
231       [ IDENT "do"; count = int; tac = tactical ->
232           GrafiteAst.Do (loc, count, tac)
233       | IDENT "repeat"; tac = tactical ->
234           GrafiteAst.Repeat (loc, tac)
235       ]
236     | "simple" NONA
237       [ IDENT "first";
238         SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
239           GrafiteAst.First (loc, tacs)
240       | IDENT "try"; tac = NEXT ->
241           GrafiteAst.Try (loc, tac)
242       | IDENT "solve";
243         SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
244           GrafiteAst.Solve (loc, tacs)
245       | LPAREN; tac = tactical; RPAREN -> tac
246       | tac = tactic -> GrafiteAst.Tactic (loc, tac)
247       ]
248     ];
249   theorem_flavour: [
250     [ [ IDENT "definition"  ] -> `Definition
251     | [ IDENT "fact"        ] -> `Fact
252     | [ IDENT "lemma"       ] -> `Lemma
253     | [ IDENT "remark"      ] -> `Remark
254     | [ IDENT "theorem"     ] -> `Theorem
255     ]
256   ];
257   inductive_spec: [ [
258     fst_name = IDENT; params = LIST0 [ arg=arg -> arg ];
259     SYMBOL ":"; fst_typ = term; SYMBOL <:unicode<def>>; OPT SYMBOL "|";
260     fst_constructors = LIST0 constructor SEP SYMBOL "|";
261     tl = OPT [ "with";
262       types = LIST1 [
263         name = IDENT; SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>;
264        OPT SYMBOL "|"; constructors = LIST0 constructor SEP SYMBOL "|" ->
265           (name, true, typ, constructors) ] SEP "with" -> types
266     ] ->
267       let params =
268         List.fold_right
269           (fun (names, typ) acc ->
270             (List.map (fun name -> (name, typ)) names) @ acc)
271           params []
272       in
273       let fst_ind_type = (fst_name, true, fst_typ, fst_constructors) in
274       let tl_ind_types = match tl with None -> [] | Some types -> types in
275       let ind_types = fst_ind_type :: tl_ind_types in
276       (params, ind_types)
277   ] ];
278   
279   record_spec: [ [
280     name = IDENT; params = LIST0 [ arg = arg -> arg ] ;
281      SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>; SYMBOL "{" ; 
282      fields = LIST0 [ 
283        name = IDENT ; SYMBOL ":" ; ty = term -> (name,ty) 
284      ] SEP SYMBOL ";"; SYMBOL "}" -> 
285       let params =
286         List.fold_right
287           (fun (names, typ) acc ->
288             (List.map (fun name -> (name, typ)) names) @ acc)
289           params []
290       in
291       (params,name,typ,fields)
292   ] ];
293   
294   macro: [
295     [ [ IDENT "quit"  ] -> GrafiteAst.Quit loc
296 (*     | [ IDENT "abort" ] -> GrafiteAst.Abort loc *)
297     | [ IDENT "print" ]; name = QSTRING -> GrafiteAst.Print (loc, name)
298 (*     | [ IDENT "undo"   ]; steps = OPT NUMBER ->
299         GrafiteAst.Undo (loc, int_opt steps)
300     | [ IDENT "redo"   ]; steps = OPT NUMBER ->
301         GrafiteAst.Redo (loc, int_opt steps) *)
302     | [ IDENT "check"   ]; t = term ->
303         GrafiteAst.Check (loc, t)
304     | [ IDENT "hint" ] -> GrafiteAst.Hint loc
305     | [ IDENT "whelp"; "match" ] ; t = term -> 
306         GrafiteAst.WMatch (loc,t)
307     | [ IDENT "whelp"; IDENT "instance" ] ; t = term -> 
308         GrafiteAst.WInstance (loc,t)
309     | [ IDENT "whelp"; IDENT "locate" ] ; id = IDENT -> 
310         GrafiteAst.WLocate (loc,id)
311     | [ IDENT "whelp"; IDENT "elim" ] ; t = term ->
312         GrafiteAst.WElim (loc, t)
313     | [ IDENT "whelp"; IDENT "hint" ] ; t = term -> 
314         GrafiteAst.WHint (loc,t)
315     | [ IDENT "print" ]; name = QSTRING -> GrafiteAst.Print (loc, name)
316     ]
317   ];
318   alias_spec: [
319     [ IDENT "id"; id = QSTRING; SYMBOL "="; uri = QSTRING ->
320       let alpha = "[a-zA-Z]" in
321       let num = "[0-9]+" in
322       let ident_cont = "\\("^alpha^"\\|"^num^"\\|_\\|\\\\\\)" in
323       let ident = "\\("^alpha^ident_cont^"*\\|_"^ident_cont^"+\\)" in
324       let rex = Str.regexp ("^"^ident^"$") in
325       if Str.string_match rex id 0 then
326         if (try ignore (UriManager.uri_of_string uri); true
327             with UriManager.IllFormedUri _ -> false)
328         then
329           GrafiteAst.Ident_alias (id, uri)
330         else 
331           raise (CicNotationParser.Parse_error (loc,sprintf "Not a valid uri: %s" uri))
332       else
333         raise (CicNotationParser.Parse_error (loc,
334           sprintf "Not a valid identifier: %s" id))
335     | IDENT "symbol"; symbol = QSTRING;
336       instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
337       SYMBOL "="; dsc = QSTRING ->
338         let instance =
339           match instance with Some i -> i | None -> 0
340         in
341         GrafiteAst.Symbol_alias (symbol, instance, dsc)
342     | IDENT "num";
343       instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
344       SYMBOL "="; dsc = QSTRING ->
345         let instance =
346           match instance with Some i -> i | None -> 0
347         in
348         GrafiteAst.Number_alias (instance, dsc)
349     ]
350   ];
351   argument: [
352     [ id = IDENT -> CicNotationPt.IdentArg (0, id)
353     | l = LIST1 [ SYMBOL <:unicode<eta>> (* η *) -> () ] SEP SYMBOL ".";
354       SYMBOL "."; id = IDENT ->
355         CicNotationPt.IdentArg (List.length l, id)
356     ]
357   ];
358   associativity: [
359     [ IDENT "left";  IDENT "associative" -> Gramext.LeftA
360     | IDENT "right"; IDENT "associative" -> Gramext.RightA
361     | IDENT "non"; IDENT "associative" -> Gramext.NonA
362     ]
363   ];
364   precedence: [
365     [ "with"; IDENT "precedence"; n = NUMBER -> int_of_string n ]
366   ];
367   notation: [
368     [ dir = OPT direction; s = QSTRING;
369       assoc = OPT associativity; prec = OPT precedence;
370       IDENT "for";
371       p2 = 
372         [ blob = UNPARSED_AST ->
373             add_raw_attribute ~text:(sprintf "@{%s}" blob)
374               (CicNotationParser.parse_level2_ast (Stream.of_string blob))
375         | blob = UNPARSED_META ->
376             add_raw_attribute ~text:(sprintf "${%s}" blob)
377               (CicNotationParser.parse_level2_meta (Stream.of_string blob))
378         ] ->
379           let assoc =
380             match assoc with
381             | None -> default_associativity
382             | Some assoc -> assoc
383           in
384           let prec =
385             match prec with
386             | None -> default_precedence
387             | Some prec -> prec
388           in
389           let p1 =
390             add_raw_attribute ~text:s
391               (CicNotationParser.parse_level1_pattern (Stream.of_string s))
392           in
393           (dir, p1, assoc, prec, p2)
394     ]
395   ];
396   level3_term: [
397     [ u = URI -> CicNotationPt.UriPattern (UriManager.uri_of_string u)
398     | id = IDENT -> CicNotationPt.VarPattern id
399     | SYMBOL "_" -> CicNotationPt.ImplicitPattern
400     | LPAREN; terms = LIST1 SELF; RPAREN ->
401         (match terms with
402         | [] -> assert false
403         | [term] -> term
404         | terms -> CicNotationPt.ApplPattern terms)
405     ]
406   ];
407   interpretation: [
408     [ s = CSYMBOL; args = LIST0 argument; SYMBOL "="; t = level3_term ->
409         (s, args, t)
410     ]
411   ];
412   command: [ [
413       IDENT "set"; n = QSTRING; v = QSTRING ->
414         GrafiteAst.Set (loc, n, v)
415     | IDENT "drop" -> GrafiteAst.Drop loc
416     | IDENT "qed" -> GrafiteAst.Qed loc
417     | IDENT "variant" ; name = IDENT; SYMBOL ":"; 
418       typ = term; SYMBOL <:unicode<def>> ; newname = IDENT ->
419         GrafiteAst.Obj (loc, 
420           GrafiteAst.Theorem 
421             (`Variant,name,typ,Some (CicNotationPt.Ident (newname, None))))
422     | flavour = theorem_flavour; name = IDENT; SYMBOL ":"; typ = term;
423       body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
424         GrafiteAst.Obj (loc,GrafiteAst.Theorem (flavour, name, typ, body))
425     | flavour = theorem_flavour; name = IDENT;
426       body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
427         GrafiteAst.Obj (loc,
428           GrafiteAst.Theorem (flavour, name, CicNotationPt.Implicit, body))
429     | "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
430         defs = CicNotationParser.let_defs -> 
431           let name,ty = 
432             match defs with
433             | ((CicNotationPt.Ident (name, None), Some ty),_,_) :: _ -> name,ty
434             | ((CicNotationPt.Ident (name, None), None),_,_) :: _ ->
435                 name, CicNotationPt.Implicit
436             | _ -> assert false 
437           in
438           let body = CicNotationPt.Ident (name,None) in
439           GrafiteAst.Obj (loc,GrafiteAst.Theorem(`Definition, name, ty,
440             Some (CicNotationPt.LetRec (ind_kind, defs, body))))
441     | [ IDENT "inductive" ]; spec = inductive_spec ->
442         let (params, ind_types) = spec in
443         GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
444     | [ IDENT "coinductive" ]; spec = inductive_spec ->
445         let (params, ind_types) = spec in
446         let ind_types = (* set inductive flags to false (coinductive) *)
447           List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
448             ind_types
449         in
450         GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
451     | IDENT "coercion" ; name = IDENT -> 
452         GrafiteAst.Coercion (loc, CicNotationPt.Ident (name,Some []))
453     | IDENT "coercion" ; name = URI -> 
454         GrafiteAst.Coercion (loc, CicNotationPt.Uri (name,Some []))
455     | IDENT "alias" ; spec = alias_spec ->
456         GrafiteAst.Alias (loc, spec)
457     | IDENT "record" ; (params,name,ty,fields) = record_spec ->
458         GrafiteAst.Obj (loc,GrafiteAst.Record (params,name,ty,fields))
459     | IDENT "include" ; path = QSTRING ->
460         GrafiteAst.Include (loc,path)
461     | IDENT "default" ; what = QSTRING ; uris = LIST1 URI ->
462        let uris = List.map UriManager.uri_of_string uris in
463         GrafiteAst.Default (loc,what,uris)
464     | IDENT "notation"; (dir, l1, assoc, prec, l2) = notation ->
465         GrafiteAst.Notation (loc, dir, l1, assoc, prec, l2)
466     | IDENT "interpretation"; id = QSTRING;
467       (symbol, args, l3) = interpretation ->
468         GrafiteAst.Interpretation (loc, id, (symbol, args), l3)
469
470     | IDENT "dump" -> GrafiteAst.Dump loc
471     | IDENT "render"; u = URI ->
472         GrafiteAst.Render (loc, UriManager.uri_of_string u)
473   ]];
474   executable: [
475     [ cmd = command; SYMBOL "." -> GrafiteAst.Command (loc, cmd)
476     | tac = tactical; SYMBOL "." -> GrafiteAst.Tactical (loc, tac)
477     | mac = macro; SYMBOL "." -> GrafiteAst.Macro (loc, mac)
478     ]
479   ];
480   comment: [
481     [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT -> 
482        GrafiteAst.Code (loc, ex)
483     | str = NOTE -> 
484        GrafiteAst.Note (loc, str)
485     ]
486   ];
487   statement: [
488     [ ex = executable -> GrafiteAst.Executable (loc,ex)
489     | com = comment -> GrafiteAst.Comment (loc, com)
490     | EOI -> raise End_of_file
491     ]
492   ];
493 END
494
495 let exc_located_wrapper f =
496   try
497     f ()
498   with
499   | Stdpp.Exc_located (_, End_of_file) -> raise End_of_file
500   | Stdpp.Exc_located (floc, Stream.Error msg) ->
501       raise (CicNotationParser.Parse_error (floc, msg))
502   | Stdpp.Exc_located (floc, exn) ->
503       raise (CicNotationParser.Parse_error (floc, (Printexc.to_string exn)))
504
505 let parse_statement stream =
506   exc_located_wrapper (fun () -> (Grammar.Entry.parse statement stream))
507