* [camlp4] str_item filters & toplevel?
@ 2008-04-17 14:17 Martin Jambon
2008-04-17 14:42 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 6+ messages in thread
From: Martin Jambon @ 2008-04-17 14:17 UTC (permalink / raw)
To: caml-list
I started from the wiki page describing how to use AST filters:
http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
The example doesn't work in the toplevel (3.10.1), although it works
otherwise. How to make it work?
Here is my testing session:
$ cat simplify.ml
open Camlp4.PreCast
let simplify = Ast.map_expr begin function
| <:expr< $x$ + zero >> | <:expr< zero + $x$ >> -> x
| x -> x
end
in AstFilters.register_str_item_filter simplify#str_item
let _ =
prerr_string "Loaded \"simplify\"\n";
flush stderr
$ ocamlc -c -pp camlp4of -I +camlp4 simplify.ml
$ \ocaml -I +camlp4 camlp4lib.cma simplify.cmo
Loaded "simplify"
Objective Caml version 3.10.1
# 1 + zero;;
Unbound value zero
#
$ camlp4o ./simplify.cmo -str '1 + zero'
Loaded "simplify"
1
--
http://wink.com/profile/mjambon
http://mjambon.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] [camlp4] str_item filters & toplevel?
2008-04-17 14:17 [camlp4] str_item filters & toplevel? Martin Jambon
@ 2008-04-17 14:42 ` Nicolas Pouillard
2008-04-17 15:25 ` Martin Jambon
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pouillard @ 2008-04-17 14:42 UTC (permalink / raw)
To: Martin Jambon; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
Excerpts from Martin Jambon's message of Thu Apr 17 16:17:15 +0200 2008:
> I started from the wiki page describing how to use AST filters:
> http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
>
> The example doesn't work in the toplevel (3.10.1), although it works
> otherwise. How to make it work?
By patching the camlp4 sources :)
--
Nicolas Pouillard aka Ertai
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] [camlp4] str_item filters & toplevel?
2008-04-17 14:42 ` [Caml-list] " Nicolas Pouillard
@ 2008-04-17 15:25 ` Martin Jambon
2008-04-17 18:35 ` Nicolas Pouillard
0 siblings, 1 reply; 6+ messages in thread
From: Martin Jambon @ 2008-04-17 15:25 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: caml-list
On Thu, 17 Apr 2008, Nicolas Pouillard wrote:
> Excerpts from Martin Jambon's message of Thu Apr 17 16:17:15 +0200 2008:
>> I started from the wiki page describing how to use AST filters:
>> http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
>>
>> The example doesn't work in the toplevel (3.10.1), although it works
>> otherwise. How to make it work?
>
> By patching the camlp4 sources :)
Is it a bug that has to be fixed?
If it's already fixed, which version?
Thanks,
Martin
--
http://wink.com/profile/mjambon
http://mjambon.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] [camlp4] str_item filters & toplevel?
2008-04-17 15:25 ` Martin Jambon
@ 2008-04-17 18:35 ` Nicolas Pouillard
2008-04-17 19:19 ` Martin Jambon
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pouillard @ 2008-04-17 18:35 UTC (permalink / raw)
To: Martin Jambon; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 821 bytes --]
Excerpts from Martin Jambon's message of Thu Apr 17 17:25:20 +0200 2008:
> On Thu, 17 Apr 2008, Nicolas Pouillard wrote:
>
> > Excerpts from Martin Jambon's message of Thu Apr 17 16:17:15 +0200 2008:
> >> I started from the wiki page describing how to use AST filters:
> >> http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
> >>
> >> The example doesn't work in the toplevel (3.10.1), although it works
> >> otherwise. How to make it work?
> >
> > By patching the camlp4 sources :)
>
> Is it a bug that has to be fixed?
It could be seen as a bug, but the behavior is not completely clear, since
applying the filters to each toplevel phrase is different from calling them
only once on the whole module implem.
> If it's already fixed, which version?
Not already fixed.
--
Nicolas Pouillard aka Ertai
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] [camlp4] str_item filters & toplevel?
2008-04-17 18:35 ` Nicolas Pouillard
@ 2008-04-17 19:19 ` Martin Jambon
2008-04-18 7:19 ` Nicolas Pouillard
0 siblings, 1 reply; 6+ messages in thread
From: Martin Jambon @ 2008-04-17 19:19 UTC (permalink / raw)
To: Nicolas Pouillard; +Cc: caml-list
On Thu, 17 Apr 2008, Nicolas Pouillard wrote:
> Excerpts from Martin Jambon's message of Thu Apr 17 17:25:20 +0200 2008:
>> On Thu, 17 Apr 2008, Nicolas Pouillard wrote:
>>
>>> Excerpts from Martin Jambon's message of Thu Apr 17 16:17:15 +0200 2008:
>>>> I started from the wiki page describing how to use AST filters:
>>>> http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
>>>>
>>>> The example doesn't work in the toplevel (3.10.1), although it works
>>>> otherwise. How to make it work?
>>>
>>> By patching the camlp4 sources :)
>>
>> Is it a bug that has to be fixed?
>
> It could be seen as a bug, but the behavior is not completely clear, since
> applying the filters to each toplevel phrase is different from calling them
> only once on the whole module implem.
Thanks.
I'll look at the code for a better understanding.
I think that the 2 following cases are pretty common:
a. inserting some constant code once at the beginning of the file (or
module), such as "open Foo"
b. replacing a str_item by other str_items
Both were problematic in camlp4 3.09, requiring some fragile or
undocumented hacks. It would be extremely useful to have a clean solution
to these problems.
It seems to me that both (a) and (b) could be implemented and
made available in the toplevel without theoretical difficulties.
I can imagine a third situation consisting in performing a full
file/module analysis and inserting something at the beginning or at the
end. That also could be implemented, although it would clearly not be
available in the toplevel.
Martin
>> If it's already fixed, which version?
>
> Not already fixed.
>
> --
> Nicolas Pouillard aka Ertai
--
http://wink.com/profile/mjambon
http://mjambon.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] [camlp4] str_item filters & toplevel?
2008-04-17 19:19 ` Martin Jambon
@ 2008-04-18 7:19 ` Nicolas Pouillard
0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Pouillard @ 2008-04-18 7:19 UTC (permalink / raw)
To: Martin Jambon; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 2260 bytes --]
Excerpts from Martin Jambon's message of Thu Apr 17 21:19:44 +0200 2008:
> On Thu, 17 Apr 2008, Nicolas Pouillard wrote:
>
> > Excerpts from Martin Jambon's message of Thu Apr 17 17:25:20 +0200 2008:
> >> On Thu, 17 Apr 2008, Nicolas Pouillard wrote:
> >>
> >>> Excerpts from Martin Jambon's message of Thu Apr 17 16:17:15 +0200 2008:
> >>>> I started from the wiki page describing how to use AST filters:
> >>>> http://brion.inria.fr/gallium/index.php/Camlp4MapGenerator
> >>>>
> >>>> The example doesn't work in the toplevel (3.10.1), although it works
> >>>> otherwise. How to make it work?
> >>>
> >>> By patching the camlp4 sources :)
> >>
> >> Is it a bug that has to be fixed?
> >
> > It could be seen as a bug, but the behavior is not completely clear, since
> > applying the filters to each toplevel phrase is different from calling them
> > only once on the whole module implem.
>
> Thanks.
> I'll look at the code for a better understanding.
>
> I think that the 2 following cases are pretty common:
>
> a. inserting some constant code once at the beginning of the file (or
> module), such as "open Foo"
> b. replacing a str_item by other str_items
>
> Both were problematic in camlp4 3.09, requiring some fragile or
> undocumented hacks. It would be extremely useful to have a clean solution
> to these problems.
>
> It seems to me that both (a) and (b) could be implemented and
Currently both can be implemented on a per file basis, moreover they are
implemented by using the *same* registering construct.
> made available in the toplevel without theoretical difficulties.
If one don't add new registration functions the behavior will be odd.
> I can imagine a third situation consisting in performing a full
> file/module analysis and inserting something at the beginning or at the
> end. That also could be implemented, although it would clearly not be
> available in the toplevel.
So in the toplevel, filters registered using register_str_item_filter will be
called once on an empty phrase.
And a new function register_toplevel_phrase_filter will gather functions to
be called on each toplevel phrase.
> >> If it's already fixed, which version?
> >
> > Not already fixed.
--
Nicolas Pouillard aka Ertai
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-04-18 7:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-17 14:17 [camlp4] str_item filters & toplevel? Martin Jambon
2008-04-17 14:42 ` [Caml-list] " Nicolas Pouillard
2008-04-17 15:25 ` Martin Jambon
2008-04-17 18:35 ` Nicolas Pouillard
2008-04-17 19:19 ` Martin Jambon
2008-04-18 7:19 ` Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox