Browse thread
Help for Camlp4: Pcaml.input_file for 3.10?
-
Loup Vaillant
-
Nicolas Pouillard
-
Loup Vaillant
- Martin Jambon
- Nicolas Pouillard
-
Loup Vaillant
-
Nicolas Pouillard
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin.jambon@e...> |
| Subject: | Re: [Caml-list] Help for Camlp4: Pcaml.input_file for 3.10? |
On Tue, 6 May 2008, Loup Vaillant wrote:
> 2008/5/6 Nicolas Pouillard <nicolas.pouillard@gmail.com>:
>> Excerpts from Loup Vaillant's message of Tue May 06 11:57:41 +0200 2008:
>> >
>> > I would like to know if there is any equivalent
>> > of Pcaml.input_file in Ocaml 3.10's Camlp4.
>> > I tried to search the wiki, but with no luck so far.
>> > [...]
>>
>> If I clearly remember this ugly global variable has been removed.
>
> OK, I got it, thank you for the fast response.
>
> Now, I can have the name of the preprocessed file with _loc.
Not exactly: usually you'll get the location in the source file, because
of #line directives. The file being processed may not be the source file.
For instance:
source file: foo.mll
file being processed by camlp4: foo.ml (locations refer to foo.mll)
> But How can I include a file in another? More generally, do we have a
> substitute for it?
I'd like to know too.
This is the syntax extension I wrote for the old camlp4, and as far as I
remember it was working more or less:
(*pp camlp4o pa_extend.cmo q_MLast.cmo -loc loc *)
(* Created by Martin Jambon, 2004 *)
(* No copyright, no guarantee *)
let parse_stream s =
let f = !Pcaml.parse_implem in
let rec loop () =
match f s with
l, true -> List.map fst l @ loop ()
| l, false -> List.map fst l in
loop ()
let parse_file file =
let ic = open_in file in
let stream = Stream.of_channel ic in
let current_file = !Pcaml.input_file in
Pcaml.input_file := file; (* it doesn't work *)
let l = parse_stream stream in
close_in ic;
Pcaml.input_file := current_file;
l
EXTEND
Pcaml.str_item: [
[ "USE"; file = STRING ->
let l = parse_file file in
<:str_item< declare $list:l$ end >> ]
];
END
Martin
--
http://wink.com/profile/mjambon
http://mjambon.com