]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_notation/grafiteParser.ml
changed ast representation of exists, now an 'exists simble with a lambda child is...
[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     [ l = LIST0 [ SYMBOL <:unicode<eta>> (* η *); SYMBOL "." -> () ];
356       id = IDENT ->
357         Ast.IdentArg (List.length l, id)
358     ]
359   ];
360   associativity: [
361     [ IDENT "left";  IDENT "associative" -> Gramext.LeftA
362     | IDENT "right"; IDENT "associative" -> Gramext.RightA
363     | IDENT "non"; IDENT "associative" -> Gramext.NonA
364     ]
365   ];
366   precedence: [
367     [ "with"; IDENT "precedence"; n = NUMBER -> int_of_string n ]
368   ];
369   notation: [
370     [ dir = OPT direction; s = QSTRING;
371       assoc = OPT associativity; prec = OPT precedence;
372       IDENT "for";
373       p2 = 
374         [ blob = UNPARSED_AST ->
375             add_raw_attribute ~text:(sprintf "@{%s}" blob)
376               (CicNotationParser.parse_level2_ast (Stream.of_string blob))
377         | blob = UNPARSED_META ->
378             add_raw_attribute ~text:(sprintf "${%s}" blob)
379               (CicNotationParser.parse_level2_meta (Stream.of_string blob))
380         ] ->
381           let assoc =
382             match assoc with
383             | None -> default_associativity
384             | Some assoc -> assoc
385           in
386           let prec =
387             match prec with
388             | None -> default_precedence
389             | Some prec -> prec
390           in
391           let p1 =
392             add_raw_attribute ~text:s
393               (CicNotationParser.parse_level1_pattern (Stream.of_string s))
394           in
395           (dir, p1, assoc, prec, p2)
396     ]
397   ];
398   level3_term: [
399     [ u = URI -> Ast.UriPattern (UriManager.uri_of_string u)
400     | id = IDENT -> Ast.VarPattern id
401     | SYMBOL "_" -> Ast.ImplicitPattern
402     | LPAREN; terms = LIST1 SELF; RPAREN ->
403         (match terms with
404         | [] -> assert false
405         | [term] -> term
406         | terms -> Ast.ApplPattern terms)
407     ]
408   ];
409   interpretation: [
410     [ s = CSYMBOL; args = LIST0 argument; SYMBOL "="; t = level3_term ->
411         (s, args, t)
412     ]
413   ];
414   command: [ [
415       IDENT "set"; n = QSTRING; v = QSTRING ->
416         GrafiteAst.Set (loc, n, v)
417     | IDENT "drop" -> GrafiteAst.Drop loc
418     | IDENT "qed" -> GrafiteAst.Qed loc
419     | IDENT "variant" ; name = IDENT; SYMBOL ":"; 
420       typ = term; SYMBOL <:unicode<def>> ; newname = IDENT ->
421         GrafiteAst.Obj (loc, 
422           GrafiteAst.Theorem 
423             (`Variant,name,typ,Some (Ast.Ident (newname, None))))
424     | flavour = theorem_flavour; name = IDENT; SYMBOL ":"; typ = term;
425       body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
426         GrafiteAst.Obj (loc,GrafiteAst.Theorem (flavour, name, typ, body))
427     | flavour = theorem_flavour; name = IDENT;
428       body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
429         GrafiteAst.Obj (loc,
430           GrafiteAst.Theorem (flavour, name, Ast.Implicit, body))
431     | "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
432         defs = CicNotationParser.let_defs -> 
433           let name,ty = 
434             match defs with
435             | ((Ast.Ident (name, None), Some ty),_,_) :: _ -> name,ty
436             | ((Ast.Ident (name, None), None),_,_) :: _ ->
437                 name, Ast.Implicit
438             | _ -> assert false 
439           in
440           let body = Ast.Ident (name,None) in
441           GrafiteAst.Obj (loc,GrafiteAst.Theorem(`Definition, name, ty,
442             Some (Ast.LetRec (ind_kind, defs, body))))
443     | [ IDENT "inductive" ]; spec = inductive_spec ->
444         let (params, ind_types) = spec in
445         GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
446     | [ IDENT "coinductive" ]; spec = inductive_spec ->
447         let (params, ind_types) = spec in
448         let ind_types = (* set inductive flags to false (coinductive) *)
449           List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
450             ind_types
451         in
452         GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
453     | IDENT "coercion" ; name = IDENT -> 
454         GrafiteAst.Coercion (loc, Ast.Ident (name,Some []))
455     | IDENT "coercion" ; name = URI -> 
456         GrafiteAst.Coercion (loc, Ast.Uri (name,Some []))
457     | IDENT "alias" ; spec = alias_spec ->
458         GrafiteAst.Alias (loc, spec)
459     | IDENT "record" ; (params,name,ty,fields) = record_spec ->
460         GrafiteAst.Obj (loc,GrafiteAst.Record (params,name,ty,fields))
461     | IDENT "include" ; path = QSTRING ->
462         GrafiteAst.Include (loc,path)
463     | IDENT "default" ; what = QSTRING ; uris = LIST1 URI ->
464        let uris = List.map UriManager.uri_of_string uris in
465         GrafiteAst.Default (loc,what,uris)
466     | IDENT "notation"; (dir, l1, assoc, prec, l2) = notation ->
467         GrafiteAst.Notation (loc, dir, l1, assoc, prec, l2)
468     | IDENT "interpretation"; id = QSTRING;
469       (symbol, args, l3) = interpretation ->
470         GrafiteAst.Interpretation (loc, id, (symbol, args), l3)
471
472     | IDENT "dump" -> GrafiteAst.Dump loc
473     | IDENT "render"; u = URI ->
474         GrafiteAst.Render (loc, UriManager.uri_of_string u)
475   ]];
476   executable: [
477     [ cmd = command; SYMBOL "." -> GrafiteAst.Command (loc, cmd)
478     | tac = tactical; SYMBOL "." -> GrafiteAst.Tactical (loc, tac)
479     | mac = macro; SYMBOL "." -> GrafiteAst.Macro (loc, mac)
480     ]
481   ];
482   comment: [
483     [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT -> 
484        GrafiteAst.Code (loc, ex)
485     | str = NOTE -> 
486        GrafiteAst.Note (loc, str)
487     ]
488   ];
489   statement: [
490     [ ex = executable -> GrafiteAst.Executable (loc,ex)
491     | com = comment -> GrafiteAst.Comment (loc, com)
492     | EOI -> raise End_of_file
493     ]
494   ];
495 END
496
497 let exc_located_wrapper f =
498   try
499     f ()
500   with
501   | Stdpp.Exc_located (_, End_of_file) -> raise End_of_file
502   | Stdpp.Exc_located (floc, Stream.Error msg) ->
503       raise (CicNotationParser.Parse_error (floc, msg))
504   | Stdpp.Exc_located (floc, exn) ->
505       raise (CicNotationParser.Parse_error (floc, (Printexc.to_string exn)))
506
507 let parse_statement stream =
508   exc_located_wrapper (fun () -> (Grammar.Entry.parse statement stream))
509
510 let parse_dependencies stream = 
511   let tok_stream,_ = CicNotationLexer.level2_ast_lexer.Token.tok_func stream in
512   let rec parse acc = 
513     (parser
514     | [< '("URI", u) >] ->
515         parse (GrafiteAst.UriDep (UriManager.uri_of_string u) :: acc)
516     | [< '("IDENT", "include"); '("QSTRING", fname) >] ->
517         parse (GrafiteAst.IncludeDep fname :: acc)
518     | [< '("IDENT", "set"); '("QSTRING", "baseuri"); '("QSTRING", baseuri) >] ->
519         parse (GrafiteAst.BaseuriDep baseuri :: acc)
520     | [< '("EOI", _) >] -> acc
521     | [< 'tok >] -> parse acc
522     | [<  >] -> acc) tok_stream
523   in
524   List.rev (parse [])
525