From: Martin Jambon <martin.jambon@ens-lyon.org>
To: Loup Vaillant <loup.vaillant@gmail.com>
Cc: Nicolas Pouillard <nicolas.pouillard@gmail.com>,
caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Help for Camlp4: Pcaml.input_file for 3.10?
Date: Tue, 6 May 2008 18:34:14 +0200 (CEST) [thread overview]
Message-ID: <Pine.LNX.4.64.0805061822040.14872@martin.ec.wink.com> (raw)
In-Reply-To: <6f9f8f4a0805060910v68c19a5dv76f9abcc879f1fb6@mail.gmail.com>
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
next prev parent reply other threads:[~2008-05-06 16:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-06 9:57 Loup Vaillant
2008-05-06 10:31 ` [Caml-list] " Nicolas Pouillard
2008-05-06 16:10 ` Loup Vaillant
2008-05-06 16:34 ` Martin Jambon [this message]
2008-05-07 16:12 ` Nicolas Pouillard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0805061822040.14872@martin.ec.wink.com \
--to=martin.jambon@ens-lyon.org \
--cc=caml-list@inria.fr \
--cc=loup.vaillant@gmail.com \
--cc=nicolas.pouillard@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox