]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/grafiteParser.ml
added metadata "commands"
[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" ];
116       full = OPT [ IDENT "full" ] ->  (* ALB *)
117           GrafiteAst.Auto (loc,depth,width,paramodulation,full)
118     | IDENT "clear"; id = IDENT ->
119         GrafiteAst.Clear (loc,id)
120     | IDENT "clearbody"; id = IDENT ->
121         GrafiteAst.ClearBody (loc,id)
122     | IDENT "change"; what = pattern_spec; "with"; t = tactic_term ->
123         GrafiteAst.Change (loc, what, t)
124     | IDENT "compare"; t = tactic_term ->
125         GrafiteAst.Compare (loc,t)
126     | IDENT "constructor"; n = int ->
127         GrafiteAst.Constructor (loc, n)
128     | IDENT "contradiction" ->
129         GrafiteAst.Contradiction loc
130     | IDENT "cut"; t = tactic_term; ident = OPT [ "as"; id = IDENT -> id] ->
131         GrafiteAst.Cut (loc, ident, t)
132     | IDENT "decide"; IDENT "equality" ->
133         GrafiteAst.DecideEquality loc
134     | IDENT "decompose"; types = OPT ident_list0; what = IDENT;
135       OPT "names"; num = OPT [num = int -> num];
136       idents = OPT ident_list0 ->
137         let idents = match idents with None -> [] | Some idents -> idents in   
138         let types = match types with None -> [] | Some types -> types in
139         let to_spec id = GrafiteAst.Ident id in
140         GrafiteAst.Decompose (loc, List.rev_map to_spec types, what, idents)
141     | IDENT "discriminate"; t = tactic_term ->
142         GrafiteAst.Discriminate (loc, t)
143     | IDENT "elim"; what = tactic_term;
144       using = OPT [ "using"; using = tactic_term -> using ];  
145       OPT "names"; num = OPT [num = int -> num];
146       idents = OPT ident_list0 ->
147         let idents = match idents with None -> [] | Some idents -> idents in
148         GrafiteAst.Elim (loc, what, using, num, idents)
149     | IDENT "elimType"; what = tactic_term;
150       using = OPT [ "using"; using = tactic_term -> using ];  
151       OPT "names"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
152         let idents = match idents with None -> [] | Some idents -> idents in
153         GrafiteAst.ElimType (loc, what, using, num, idents)
154     | IDENT "exact"; t = tactic_term ->
155         GrafiteAst.Exact (loc, t)
156     | IDENT "exists" ->
157         GrafiteAst.Exists loc
158     | IDENT "fail" -> GrafiteAst.Fail loc
159     | IDENT "fold"; kind = reduction_kind; t = tactic_term; p = pattern_spec ->
160         let (pt,_,_) = p in
161           if pt <> None then
162             raise (CicNotationParser.Parse_error
163               (loc, "the pattern cannot specify the term to replace, only its"
164               ^ " paths in the hypotheses and in the conclusion"))
165         else
166          GrafiteAst.Fold (loc, kind, t, p)
167     | IDENT "fourier" ->
168         GrafiteAst.Fourier loc
169     | IDENT "fwd"; hyp = IDENT; idents = OPT ident_list0 ->
170         let idents = match idents with None -> [] | Some idents -> idents in
171         GrafiteAst.FwdSimpl (loc, hyp, idents)
172     | IDENT "generalize"; p=pattern_spec; id = OPT ["as" ; id = IDENT -> id] ->
173        GrafiteAst.Generalize (loc,p,id)
174     | IDENT "goal"; n = int ->
175         GrafiteAst.Goal (loc, n)
176     | IDENT "id" -> GrafiteAst.IdTac loc
177     | IDENT "injection"; t = tactic_term ->
178         GrafiteAst.Injection (loc, t)
179     | IDENT "intro"; ident = OPT IDENT ->
180         let idents = match ident with None -> [] | Some id -> [id] in
181         GrafiteAst.Intros (loc, Some 1, idents)
182     | IDENT "intros"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
183         let idents = match idents with None -> [] | Some idents -> idents in
184         GrafiteAst.Intros (loc, num, idents)
185     | IDENT "lapply"; 
186       depth = OPT [ IDENT "depth"; SYMBOL "="; i = int -> i ];
187       what = tactic_term; 
188       to_what = OPT [ "to" ; t = tactic_term_list1 -> t ];
189       ident = OPT [ "using" ; ident = IDENT -> ident ] ->
190         let to_what = match to_what with None -> [] | Some to_what -> to_what in
191         GrafiteAst.LApply (loc, depth, to_what, what, ident)
192     | IDENT "left" -> GrafiteAst.Left loc
193     | IDENT "letin"; where = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term ->
194         GrafiteAst.LetIn (loc, t, where)
195     | kind = reduction_kind; p = pattern_spec ->
196         GrafiteAst.Reduce (loc, kind, p)
197     | IDENT "reflexivity" ->
198         GrafiteAst.Reflexivity loc
199     | IDENT "replace"; p = pattern_spec; "with"; t = tactic_term ->
200         GrafiteAst.Replace (loc, p, t)
201     | IDENT "rewrite" ; d = direction; t = tactic_term ; p = pattern_spec ->
202        let (pt,_,_) = p in
203         if pt <> None then
204          raise
205           (CicNotationParser.Parse_error
206             (loc,"the pattern cannot specify the term to rewrite, only its paths in the hypotheses and in the conclusion"))
207         else
208          GrafiteAst.Rewrite (loc, d, t, p)
209     | IDENT "right" ->
210         GrafiteAst.Right loc
211     | IDENT "ring" ->
212         GrafiteAst.Ring loc
213     | IDENT "split" ->
214         GrafiteAst.Split loc
215     | IDENT "symmetry" ->
216         GrafiteAst.Symmetry loc
217     | IDENT "transitivity"; t = tactic_term ->
218         GrafiteAst.Transitivity (loc, t)
219     ]
220   ];
221   tactical:
222     [ "sequence" LEFTA
223       [ tacticals = LIST1 NEXT SEP SYMBOL ";" ->
224          match tacticals with
225             [] -> assert false
226           | [tac] -> tac
227           | l -> GrafiteAst.Seq (loc, l)
228       ]
229     | "then" NONA
230       [ tac = tactical; SYMBOL ";";
231         SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
232           (GrafiteAst.Then (loc, tac, tacs))
233       ]
234     | "loops" RIGHTA
235       [ IDENT "do"; count = int; tac = tactical ->
236           GrafiteAst.Do (loc, count, tac)
237       | IDENT "repeat"; tac = tactical ->
238           GrafiteAst.Repeat (loc, tac)
239       ]
240     | "simple" NONA
241       [ IDENT "first";
242         SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
243           GrafiteAst.First (loc, tacs)
244       | IDENT "try"; tac = NEXT ->
245           GrafiteAst.Try (loc, tac)
246       | IDENT "solve";
247         SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
248           GrafiteAst.Solve (loc, tacs)
249       | LPAREN; tac = tactical; RPAREN -> tac
250       | tac = tactic -> GrafiteAst.Tactic (loc, tac)
251       ]
252     ];
253   theorem_flavour: [
254     [ [ IDENT "definition"  ] -> `Definition
255     | [ IDENT "fact"        ] -> `Fact
256     | [ IDENT "lemma"       ] -> `Lemma
257     | [ IDENT "remark"      ] -> `Remark
258     | [ IDENT "theorem"     ] -> `Theorem
259     ]
260   ];
261   inductive_spec: [ [
262     fst_name = IDENT; params = LIST0 [ arg=arg -> arg ];
263     SYMBOL ":"; fst_typ = term; SYMBOL <:unicode<def>>; OPT SYMBOL "|";
264     fst_constructors = LIST0 constructor SEP SYMBOL "|";
265     tl = OPT [ "with";
266       types = LIST1 [
267         name = IDENT; SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>;
268        OPT SYMBOL "|"; constructors = LIST0 constructor SEP SYMBOL "|" ->
269           (name, true, typ, constructors) ] SEP "with" -> types
270     ] ->
271       let params =
272         List.fold_right
273           (fun (names, typ) acc ->
274             (List.map (fun name -> (name, typ)) names) @ acc)
275           params []
276       in
277       let fst_ind_type = (fst_name, true, fst_typ, fst_constructors) in
278       let tl_ind_types = match tl with None -> [] | Some types -> types in
279       let ind_types = fst_ind_type :: tl_ind_types in
280       (params, ind_types)
281   ] ];
282   
283   record_spec: [ [
284     name = IDENT; params = LIST0 [ arg = arg -> arg ] ;
285      SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>; SYMBOL "{" ; 
286      fields = LIST0 [ 
287        name = IDENT ; SYMBOL ":" ; ty = term -> (name,ty) 
288      ] SEP SYMBOL ";"; SYMBOL "}" -> 
289       let params =
290         List.fold_right
291           (fun (names, typ) acc ->
292             (List.map (fun name -> (name, typ)) names) @ acc)
293           params []
294       in
295       (params,name,typ,fields)
296   ] ];
297   
298   macro: [
299     [ [ IDENT "quit"  ] -> GrafiteAst.Quit loc
300 (*     | [ IDENT "abort" ] -> GrafiteAst.Abort loc *)
301     | [ IDENT "print" ]; name = QSTRING -> GrafiteAst.Print (loc, name)
302 (*     | [ IDENT "undo"   ]; steps = OPT NUMBER ->
303         GrafiteAst.Undo (loc, int_opt steps)
304     | [ IDENT "redo"   ]; steps = OPT NUMBER ->
305         GrafiteAst.Redo (loc, int_opt steps) *)
306     | [ IDENT "check"   ]; t = term ->
307         GrafiteAst.Check (loc, t)
308     | [ IDENT "hint" ] -> GrafiteAst.Hint loc
309     | [ IDENT "whelp"; "match" ] ; t = term -> 
310         GrafiteAst.WMatch (loc,t)
311     | [ IDENT "whelp"; IDENT "instance" ] ; t = term -> 
312         GrafiteAst.WInstance (loc,t)
313     | [ IDENT "whelp"; IDENT "locate" ] ; id = IDENT -> 
314         GrafiteAst.WLocate (loc,id)
315     | [ IDENT "whelp"; IDENT "elim" ] ; t = term ->
316         GrafiteAst.WElim (loc, t)
317     | [ IDENT "whelp"; IDENT "hint" ] ; t = term -> 
318         GrafiteAst.WHint (loc,t)
319     | [ IDENT "print" ]; name = QSTRING -> GrafiteAst.Print (loc, name)
320     ]
321   ];
322   alias_spec: [
323     [ IDENT "id"; id = QSTRING; SYMBOL "="; uri = QSTRING ->
324       let alpha = "[a-zA-Z]" in
325       let num = "[0-9]+" in
326       let ident_cont = "\\("^alpha^"\\|"^num^"\\|_\\|\\\\\\)" in
327       let ident = "\\("^alpha^ident_cont^"*\\|_"^ident_cont^"+\\)" in
328       let rex = Str.regexp ("^"^ident^"$") in
329       if Str.string_match rex id 0 then
330         if (try ignore (UriManager.uri_of_string uri); true
331             with UriManager.IllFormedUri _ -> false)
332         then
333           GrafiteAst.Ident_alias (id, uri)
334         else 
335           raise (CicNotationParser.Parse_error (loc,sprintf "Not a valid uri: %s" uri))
336       else
337         raise (CicNotationParser.Parse_error (loc,
338           sprintf "Not a valid identifier: %s" id))
339     | IDENT "symbol"; symbol = QSTRING;
340       instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
341       SYMBOL "="; dsc = QSTRING ->
342         let instance =
343           match instance with Some i -> i | None -> 0
344         in
345         GrafiteAst.Symbol_alias (symbol, instance, dsc)
346     | IDENT "num";
347       instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
348       SYMBOL "="; dsc = QSTRING ->
349         let instance =
350           match instance with Some i -> i | None -> 0
351         in
352         GrafiteAst.Number_alias (instance, dsc)
353     ]
354   ];
355   argument: [
356     [ l = LIST0 [ SYMBOL <:unicode<eta>> (* η *); SYMBOL "." -> () ];
357       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
378                 (Ulexing.from_utf8_string blob))
379         | blob = UNPARSED_META ->
380             add_raw_attribute ~text:(sprintf "${%s}" blob)
381               (CicNotationParser.parse_level2_meta
382                 (Ulexing.from_utf8_string blob))
383         ] ->
384           let assoc =
385             match assoc with
386             | None -> default_associativity
387             | Some assoc -> assoc
388           in
389           let prec =
390             match prec with
391             | None -> default_precedence
392             | Some prec -> prec
393           in
394           let p1 =
395             add_raw_attribute ~text:s
396               (CicNotationParser.parse_level1_pattern
397                 (Ulexing.from_utf8_string s))
398           in
399           (dir, p1, assoc, prec, p2)
400     ]
401   ];
402   level3_term: [
403     [ u = URI -> Ast.UriPattern (UriManager.uri_of_string u)
404     | id = IDENT -> Ast.VarPattern id
405     | SYMBOL "_" -> Ast.ImplicitPattern
406     | LPAREN; terms = LIST1 SELF; RPAREN ->
407         (match terms with
408         | [] -> assert false
409         | [term] -> term
410         | terms -> Ast.ApplPattern terms)
411     ]
412   ];
413   interpretation: [
414     [ s = CSYMBOL; args = LIST0 argument; SYMBOL "="; t = level3_term ->
415         (s, args, t)
416     ]
417   ];
418   command: [ [
419       IDENT "set"; n = QSTRING; v = QSTRING ->
420         GrafiteAst.Set (loc, n, v)
421     | IDENT "drop" -> GrafiteAst.Drop loc
422     | IDENT "qed" -> GrafiteAst.Qed loc
423     | IDENT "variant" ; name = IDENT; SYMBOL ":"; 
424       typ = term; SYMBOL <:unicode<def>> ; newname = IDENT ->
425         GrafiteAst.Obj (loc, 
426           GrafiteAst.Theorem 
427             (`Variant,name,typ,Some (Ast.Ident (newname, None))))
428     | flavour = theorem_flavour; name = IDENT; SYMBOL ":"; typ = term;
429       body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
430         GrafiteAst.Obj (loc,GrafiteAst.Theorem (flavour, name, typ, body))
431     | flavour = theorem_flavour; name = IDENT;
432       body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
433         GrafiteAst.Obj (loc,
434           GrafiteAst.Theorem (flavour, name, Ast.Implicit, body))
435     | "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
436         defs = CicNotationParser.let_defs -> 
437           let name,ty = 
438             match defs with
439             | ((Ast.Ident (name, None), Some ty),_,_) :: _ -> name,ty
440             | ((Ast.Ident (name, None), None),_,_) :: _ ->
441                 name, Ast.Implicit
442             | _ -> assert false 
443           in
444           let body = Ast.Ident (name,None) in
445           GrafiteAst.Obj (loc,GrafiteAst.Theorem(`Definition, name, ty,
446             Some (Ast.LetRec (ind_kind, defs, body))))
447     | [ IDENT "inductive" ]; spec = inductive_spec ->
448         let (params, ind_types) = spec in
449         GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
450     | [ IDENT "coinductive" ]; spec = inductive_spec ->
451         let (params, ind_types) = spec in
452         let ind_types = (* set inductive flags to false (coinductive) *)
453           List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
454             ind_types
455         in
456         GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
457     | IDENT "coercion" ; name = IDENT -> 
458         GrafiteAst.Coercion (loc, Ast.Ident (name,Some []))
459     | IDENT "coercion" ; name = URI -> 
460         GrafiteAst.Coercion (loc, Ast.Uri (name,Some []))
461     | IDENT "alias" ; spec = alias_spec ->
462         GrafiteAst.Alias (loc, spec)
463     | IDENT "record" ; (params,name,ty,fields) = record_spec ->
464         GrafiteAst.Obj (loc,GrafiteAst.Record (params,name,ty,fields))
465     | IDENT "include" ; path = QSTRING ->
466         GrafiteAst.Include (loc,path)
467     | IDENT "default" ; what = QSTRING ; uris = LIST1 URI ->
468        let uris = List.map UriManager.uri_of_string uris in
469         GrafiteAst.Default (loc,what,uris)
470     | IDENT "notation"; (dir, l1, assoc, prec, l2) = notation ->
471         GrafiteAst.Notation (loc, dir, l1, assoc, prec, l2)
472     | IDENT "interpretation"; id = QSTRING;
473       (symbol, args, l3) = interpretation ->
474         GrafiteAst.Interpretation (loc, id, (symbol, args), l3)
475     | IDENT "metadata"; [IDENT "dependency" | IDENT "baseuri" ] ; URI ->
476         (** metadata commands lives only in .moo, where they are in marshalled
477          * form *)
478         raise (CicNotationParser.Parse_error (loc, "metadata not allowed here"))
479
480     | IDENT "dump" -> GrafiteAst.Dump loc
481     | IDENT "render"; u = URI ->
482         GrafiteAst.Render (loc, UriManager.uri_of_string u)
483   ]];
484   executable: [
485     [ cmd = command; SYMBOL "." -> GrafiteAst.Command (loc, cmd)
486     | tac = tactical; SYMBOL "." -> GrafiteAst.Tactical (loc, tac)
487     | mac = macro; SYMBOL "." -> GrafiteAst.Macro (loc, mac)
488     ]
489   ];
490   comment: [
491     [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT -> 
492        GrafiteAst.Code (loc, ex)
493     | str = NOTE -> 
494        GrafiteAst.Note (loc, str)
495     ]
496   ];
497   statement: [
498     [ ex = executable -> GrafiteAst.Executable (loc,ex)
499     | com = comment -> GrafiteAst.Comment (loc, com)
500     | EOI -> raise End_of_file
501     ]
502   ];
503 END
504
505 let exc_located_wrapper f =
506   try
507     f ()
508   with
509   | Stdpp.Exc_located (_, End_of_file) -> raise End_of_file
510   | Stdpp.Exc_located (floc, Stream.Error msg) ->
511       raise (CicNotationParser.Parse_error (floc, msg))
512   | Stdpp.Exc_located (floc, exn) ->
513       raise (CicNotationParser.Parse_error (floc, (Printexc.to_string exn)))
514
515 let parse_statement lexbuf =
516   exc_located_wrapper
517     (fun () -> (Grammar.Entry.parse statement (Obj.magic lexbuf)))
518
519 let parse_dependencies lexbuf = 
520   let tok_stream,_ =
521     CicNotationLexer.level2_ast_lexer.Token.tok_func (Obj.magic lexbuf)
522   in
523   let rec parse acc = 
524     (parser
525     | [< '("URI", u) >] ->
526         parse (GrafiteAst.UriDep (UriManager.uri_of_string u) :: acc)
527     | [< '("IDENT", "include"); '("QSTRING", fname) >] ->
528         parse (GrafiteAst.IncludeDep fname :: acc)
529     | [< '("IDENT", "set"); '("QSTRING", "baseuri"); '("QSTRING", baseuri) >] ->
530         parse (GrafiteAst.BaseuriDep baseuri :: acc)
531     | [< '("EOI", _) >] -> acc
532     | [< 'tok >] -> parse acc
533     | [<  >] -> acc) tok_stream
534   in
535   List.rev (parse [])
536