* How to achieve this camlp4 syntax extension
@ 2009-04-02 11:42 Conglun Yao
2009-04-02 12:33 ` [Caml-list] " Jérémie Dimino
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Conglun Yao @ 2009-04-02 11:42 UTC (permalink / raw)
To: caml-list
Dear all,
I tried to achieve the following syntax extension, but failed.
Add expression .[ ] after a module name, inside .[ ] I want to refer
to the specified module, like
let _ = M1.M2.[ here is my syntax, using M1.M2 module ]
Here is my attempt (failed)
EXTEND Gram
GLOBAL: expr;
expr: LEVEL "top"[
[ e1 = module_longident; "."; "["; (*t = test_syntax;*) "]" ->
<:expr< $id:e1$ test >>
]];
END
Different kinds of error happened, when trying to use it.
Even the ordinary expression: List.length [1; 2;3 ], failed. 'List'
is parsed as module_longident, try to match the rule I defined.
Thanks for any help.
Conglun
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] How to achieve this camlp4 syntax extension
2009-04-02 11:42 How to achieve this camlp4 syntax extension Conglun Yao
@ 2009-04-02 12:33 ` Jérémie Dimino
2009-04-02 12:40 ` David Teller
2009-04-02 13:00 ` Zheng Li
2 siblings, 0 replies; 7+ messages in thread
From: Jérémie Dimino @ 2009-04-02 12:33 UTC (permalink / raw)
To: Conglun Yao; +Cc: caml-list
Conglun Yao wrote:
> I tried to achieve the following syntax extension, but failed.
>
> Add expression .[ ] after a module name, inside .[ ] I want to refer
> to the specified module, like
>
> let _ = M1.M2.[ here is my syntax, using M1.M2 module ]
You should have a look at delimited overloading:
http://pa-do.forge.ocamlcore.org/
It defines the same kind of syntax extension.
Cheers,
Jérémie
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] How to achieve this camlp4 syntax extension
2009-04-02 11:42 How to achieve this camlp4 syntax extension Conglun Yao
2009-04-02 12:33 ` [Caml-list] " Jérémie Dimino
@ 2009-04-02 12:40 ` David Teller
2009-04-02 12:48 ` Conglun Yao
2009-04-02 13:00 ` Zheng Li
2 siblings, 1 reply; 7+ messages in thread
From: David Teller @ 2009-04-02 12:40 UTC (permalink / raw)
To: Conglun Yao; +Cc: caml-list
Hi,
I'm not going to quite answer your question yet -- I'd need to check
the source of Camlp4 for this. However, I can point out that what you're
trying to do looks very much like pa_open, by Alain Frisch.
let _ = open M1.M2 in e
will execute [e] using module [M1.M2].
Cheers,
David
On Thu, 2009-04-02 at 12:42 +0100, Conglun Yao wrote:
> Dear all,
>
> I tried to achieve the following syntax extension, but failed.
>
> Add expression .[ ] after a module name, inside .[ ] I want to refer
> to the specified module, like
>
> let _ = M1.M2.[ here is my syntax, using M1.M2 module ]
>
> Here is my attempt (failed)
>
> EXTEND Gram
>
> GLOBAL: expr;
>
> expr: LEVEL "top"[
> [ e1 = module_longident; "."; "["; (*t = test_syntax;*) "]" ->
> <:expr< $id:e1$ test >>
> ]];
>
> END
>
> Different kinds of error happened, when trying to use it.
>
> Even the ordinary expression: List.length [1; 2;3 ], failed. 'List'
> is parsed as module_longident, try to match the rule I defined.
>
> Thanks for any help.
>
> Conglun
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] How to achieve this camlp4 syntax extension
2009-04-02 12:40 ` David Teller
@ 2009-04-02 12:48 ` Conglun Yao
0 siblings, 0 replies; 7+ messages in thread
From: Conglun Yao @ 2009-04-02 12:48 UTC (permalink / raw)
To: David Teller; +Cc: caml-list
David and Jérémie,
Thanks for your guys quick response.
It seems I get idea how to achieve it. pa_do and pa_open are useful!
It's a pity I viewed the code of pa_infix before, but never noticed it
was part of a project.
Conglun
On Thu, Apr 2, 2009 at 1:40 PM, David Teller
<David.Teller@univ-orleans.fr> wrote:
> Hi,
> I'm not going to quite answer your question yet -- I'd need to check
> the source of Camlp4 for this. However, I can point out that what you're
> trying to do looks very much like pa_open, by Alain Frisch.
>
> let _ = open M1.M2 in e
>
> will execute [e] using module [M1.M2].
>
> Cheers,
> David
>
> On Thu, 2009-04-02 at 12:42 +0100, Conglun Yao wrote:
>> Dear all,
>>
>> I tried to achieve the following syntax extension, but failed.
>>
>> Add expression .[ ] after a module name, inside .[ ] I want to refer
>> to the specified module, like
>>
>> let _ = M1.M2.[ here is my syntax, using M1.M2 module ]
>>
>> Here is my attempt (failed)
>>
>> EXTEND Gram
>>
>> GLOBAL: expr;
>>
>> expr: LEVEL "top"[
>> [ e1 = module_longident; "."; "["; (*t = test_syntax;*) "]" ->
>> <:expr< $id:e1$ test >>
>> ]];
>>
>> END
>>
>> Different kinds of error happened, when trying to use it.
>>
>> Even the ordinary expression: List.length [1; 2;3 ], failed. 'List'
>> is parsed as module_longident, try to match the rule I defined.
>>
>> Thanks for any help.
>>
>> Conglun
>>
>> _______________________________________________
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to achieve this camlp4 syntax extension
2009-04-02 11:42 How to achieve this camlp4 syntax extension Conglun Yao
2009-04-02 12:33 ` [Caml-list] " Jérémie Dimino
2009-04-02 12:40 ` David Teller
@ 2009-04-02 13:00 ` Zheng Li
2009-04-02 20:23 ` Conglun Yao
2 siblings, 1 reply; 7+ messages in thread
From: Zheng Li @ 2009-04-02 13:00 UTC (permalink / raw)
To: Conglun Yao; +Cc: caml-list
On 4/2/2009 1:42 PM, Conglun Yao wrote:
>
> Different kinds of error happened, when trying to use it.
>
> Even the ordinary expression: List.length [1; 2;3 ], failed. 'List'
> is parsed as module_longident, try to match the rule I defined.
>
> Thanks for any help.
>
> Conglun
You may have a look at the source code of my pa_scope [1]. It deals with
these issues and support both open scope (via @) and closed scope (via
.{}, .[], .()). The code is just ~50 lines.
HTH.
[1] http://www.pps.jussieu.fr/~li/software/index.html#pa_scope
--
Zheng
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: How to achieve this camlp4 syntax extension
2009-04-02 13:00 ` Zheng Li
@ 2009-04-02 20:23 ` Conglun Yao
2009-04-14 0:24 ` [Caml-list] " Christophe TROESTLER
0 siblings, 1 reply; 7+ messages in thread
From: Conglun Yao @ 2009-04-02 20:23 UTC (permalink / raw)
To: Zheng Li; +Cc: caml-list
Nice code!!! Thank you very much.
I'm trying to get the Module name, then used in my syntax extension.
ModuleName.[ my extension ]
It's really a great idea to perform checking in the rule definition.
Conglun
On Thu, Apr 2, 2009 at 2:00 PM, Zheng Li <zheng_li@users.sourceforge.net> wrote:
> On 4/2/2009 1:42 PM, Conglun Yao wrote:
>>
>> Different kinds of error happened, when trying to use it.
>>
>> Even the ordinary expression: List.length [1; 2;3 ], failed. 'List'
>> is parsed as module_longident, try to match the rule I defined.
>>
>> Thanks for any help.
>>
>> Conglun
>
> You may have a look at the source code of my pa_scope [1]. It deals with
> these issues and support both open scope (via @) and closed scope (via .{},
> .[], .()). The code is just ~50 lines.
>
> HTH.
>
> [1] http://www.pps.jussieu.fr/~li/software/index.html#pa_scope
>
> --
> Zheng
>
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Caml-list] Re: How to achieve this camlp4 syntax extension
2009-04-02 20:23 ` Conglun Yao
@ 2009-04-14 0:24 ` Christophe TROESTLER
0 siblings, 0 replies; 7+ messages in thread
From: Christophe TROESTLER @ 2009-04-14 0:24 UTC (permalink / raw)
To: yaoconglun; +Cc: OCaml Mailing List
> On 4/2/2009 1:42 PM, Conglun Yao wrote:
>>
>> Different kinds of error happened, when trying to use it.
>>
>> Even the ordinary expression: List.length [1; 2;3 ], failed. 'List'
>> is parsed as module_longident, try to match the rule I defined.
Not sure whether you are still looking for a solution to this but, as
it was not possible to use theses constructions together with pa_do
(same grammar rule to modify), I added hooks so you can provide your
own functions for them. E.g.,
val module_square_brackets : (module_longident -> Loc.t -> expr -> expr) ref
allows you to replace [M.[ e ]] by [!module_square_brackets m _loc e]
where [m] is the internal representation of [M] and [_loc] is the
location of the whole expression [M.[ e ]].
This is available in the last version of delimited overloading
(downloadable at http://pa-do.forge.ocamlcore.org/ ).
Hope it helps,
ChriS
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-04-14 0:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-02 11:42 How to achieve this camlp4 syntax extension Conglun Yao
2009-04-02 12:33 ` [Caml-list] " Jérémie Dimino
2009-04-02 12:40 ` David Teller
2009-04-02 12:48 ` Conglun Yao
2009-04-02 13:00 ` Zheng Li
2009-04-02 20:23 ` Conglun Yao
2009-04-14 0:24 ` [Caml-list] " Christophe TROESTLER
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox