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