1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 2002 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (** Driver for the parser and external preprocessors.
17
18 {b Warning:} this module is unstable and part of
19 {{!Compiler_libs}compiler-libs}.
20
21 *)
22
23 open Format
24
25 type error =
26 | CannotRun of string
27 | WrongMagic of string
28
29 exception Error of error
30
31 val preprocess : string -> string
32 val remove_preprocessed : string -> unit
33
34 type 'a ast_kind =
35 | Structure : Parsetree.structure ast_kind
36 | Signature : Parsetree.signature ast_kind
37
38 val read_ast : 'a ast_kind -> string -> 'a
39 val write_ast : 'a ast_kind -> string -> 'a -> unit
40
41 val file : tool_name:string -> string ->
42 (Lexing.lexbuf -> 'a) -> 'a ast_kind -> 'a
43
44 val apply_rewriters: ?restore:bool -> tool_name:string ->
45 'a ast_kind -> 'a -> 'a
46 (** If [restore = true] (the default), cookies set by external
47 rewriters will be kept for later calls. *)
48
49 val apply_rewriters_str:
50 ?restore:bool -> tool_name:string -> Parsetree.structure ->
51 Parsetree.structure
52 val apply_rewriters_sig:
53 ?restore:bool -> tool_name:string -> Parsetree.signature ->
54 Parsetree.signature
55
56 val report_error : formatter -> error -> unit
57
58
59 val parse_implementation:
60 tool_name:string -> string -> Parsetree.structure
61 val parse_interface:
62 tool_name:string -> string -> Parsetree.signature
63
64 (* [call_external_preprocessor sourcefile pp] *)
65 val call_external_preprocessor : string -> string -> string
66 val open_and_check_magic : string -> string -> in_channel * bool
67