X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=blobdiff_plain;f=components%2Fgrafite_parser%2FdependenciesParser.ml;fp=components%2Fgrafite_parser%2FdependenciesParser.ml;h=32ee44491020b96d3108199858b2a7fe0e8d3c2e;hp=0000000000000000000000000000000000000000;hb=f61af501fb4608cc4fb062a0864c774e677f0d76;hpb=58ae1809c352e71e7b5530dc41e2bfc834e1aef1 diff --git a/components/grafite_parser/dependenciesParser.ml b/components/grafite_parser/dependenciesParser.ml new file mode 100644 index 000000000..32ee44491 --- /dev/null +++ b/components/grafite_parser/dependenciesParser.ml @@ -0,0 +1,78 @@ +(* Copyright (C) 2005, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://helm.cs.unibo.it/ + *) + +(* $Id$ *) + +exception UnableToInclude of string + + (* statements meaningful for matitadep *) +type dependency = + | IncludeDep of string + | UriDep of UriManager.uri + +let pp_dependency = function + | IncludeDep str -> "include \"" ^ str ^ "\"" + | UriDep uri -> "uri \"" ^ UriManager.string_of_uri uri ^ "\"" + +let parse_dependencies lexbuf = + let tok_stream,_ = + CicNotationLexer.level2_ast_lexer.Token.tok_func (Obj.magic lexbuf) + in + let rec parse acc = + let continue, acc = + try + (parser + | [< '("QSTRING", s) >] -> + (* because of alias id qstring = qstring :-( *) + (try + true, (UriDep (UriManager.uri_of_string s) :: acc) + with + UriManager.IllFormedUri _ -> true, acc) + | [< '("URI", u) >] -> + true, (UriDep (UriManager.uri_of_string u) :: acc) + | [< '("IDENT", "include"); '("QSTRING", fname) >] -> + true, (IncludeDep fname :: acc) + | [< '("IDENT", "include'"); '("QSTRING", fname) >] -> + true, (IncludeDep fname :: acc) + | [< '("EOI", _) >] -> false, acc + | [< 'tok >] -> true, acc + | [< >] -> false, acc) tok_stream + with + Stream.Error _ -> false, acc + | CicNotationLexer.Error _ -> true, acc + in + if continue then parse acc else acc + in + List.rev (parse []) + +let deps_of_file ma_file = + try + let ic = open_in ma_file in + let istream = Ulexing.from_utf8_channel ic in + let dependencies = parse_dependencies istream in + close_in ic; + dependencies + with End_of_file -> [] +;;