1 (* Copyright (C) 2006, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
27 GrafiteParser.ast_statement GrafiteParser.localized_option -> bool
31 | GrafiteParser.LSome (GrafiteAst.Executable (loc, _))
32 | GrafiteParser.LSome (GrafiteAst.Comment (loc, _))
33 | GrafiteParser.LNone loc ->
36 let grep_statement ?(status = LexiconEngine.initial_status) ?(callback = ignore)
40 Helm_registry.get_list Helm_registry.string "matita.includes" in
41 let content = HExtlib.input_file fname in
42 let lexbuf = Ulexing.from_utf8_string content in
43 let parse_fun status =
44 GrafiteParser.parse_statement lexbuf ~include_paths status in
45 let rec exaust acc status = (* extract "interesting" statement locations *)
47 try Some (parse_fun status)
48 with End_of_file -> None in
50 | None -> List.rev acc
51 | Some (status, stm) when test stm -> (* "interesting" statement *)
52 let loc_begin, loc_end = HExtlib.loc_of_floc (get_loc stm) in
54 Netconversion.ustring_sub `Enc_utf8 loc_begin (loc_end - loc_begin)
56 callback raw_statement;
57 exaust (raw_statement :: acc) status
58 | Some (status, _stm) -> exaust acc status in
61 let ma_extension_test fname = Filename.check_suffix fname ".ma"
63 let rgrep_statement ?status ?callback ?(fname_test = ma_extension_test)
66 let files = HExtlib.find ~test:fname_test dirname in
73 | Some f -> Some (fun s -> f (fname, s)) in
74 List.map (fun raw -> fname, raw)
75 (grep_statement ?status ?callback ~fname test))