alavrik / piqi

Piqi – universal schema language: JSON, XML, Protocol Buffers data validation and conversion
http://piqi.org
Apache License 2.0
246 stars 36 forks source link

importing common/ad does not use the complete path #4

Closed williamleferrand closed 13 years ago

williamleferrand commented 13 years ago

Hi Anton,

I'm doing

.import [ .module common/ad ]

but in the generated ml file I get

module Ad = Ad

instead of the expected (at least by me :) ) module Ad = Common.Ad .

Am I missing something here?

thx!

but

alavrik commented 13 years ago

Hi William,

This behavior is correct.

It would be too much for the system to automatically nest OCaml modules (as OCaml doesn't have namespaces).

Piqi complier (piqic) processes one .piqi module at a time. In order to implement nesting it would have to process a whole hierarchy of .piqi modules at once, potentially producing a gigantic top-level OCaml module most of which will not be used in your application.

None of this -- processing more than one file at a time and generating an overblown top-level .ml module -- seem reasonable to me.

Anton

alavrik commented 13 years ago

So, basically, you need to manage you OCaml flat module namespace manually and Piqi can assist you in two ways:

1) You can use custom module names, as we've already discussed, e.g.:

.module common/ad
.ocaml-module "Common_ad"

... .import [ .module common/ad ]

This will result in module Ad = Common_ad

2) There are optional name and ocaml-name properties in the import statement. If you want your imported module name to be different from the original module name, you can do it like that:

.import [
    .module common/ad
    .ocaml-name "Common_ad"
 ]

This will result in module Common_ad = Ad

BTW, I would appreciate if you ask questions like this in Piqi Google Group: http://groups.google.com/group/piqi This way, questions, answers and the whole discussion will be more visible (and searchable) to other users. Thanks!

williamleferrand commented 13 years ago

Ok, I'll post the next question on the ocaml group, thx!

2011/4/9 alavrik < reply@reply.github.com>

So, basically, you need to manage you OCaml flat module namespace manually and Piqi can assist you in two ways:

1) You can use custom module names, as we've already discussed previously, e.g.:

.module common/ad .ocaml-module "Common_ad" ... .import [ .module common/ad ]

This will result in module Ad = Common_ad

2) There are optional name and ocaml-name properties in the import statement. If you want your imported module name to be different from the original module name, you can do it like that:

.import [ .module common/ad .ocaml-name "Common_ad" ]

This will result in module Common_ad = Ad

P.S. I would appreciate if you ask questions like that in Piqi Google Group: http://groups.google.com/group/piqi This way, questions, answers and the whole discussion will be more visible (and searchable) to other users. Thanks!

Reply to this email directly or view it on GitHub: https://github.com/alavrik/piqi/issues/4#comment_976042

William Le Ferrand

Speed matters : http://www.corefarm.com

Mobile : (+1) (415) 683-1484 Web : http://williamleferrand.github.com/

williamleferrand commented 13 years ago

In fact I don't really get your reply.

When I import module "common/ad" :

.import [ .module common/ad ]

it would be possible to have something like

module Ad = Common.Ad in the generated file, rather than module Ad = Ad, without going through all the piqi files wouldn't it ?

2011/4/9 alavrik < reply@reply.github.com>

Hi William,

This behavior is correct.

It would be too much for the system to automatically nest OCaml modules (as OCaml doesn't have namespaces). Piqi complier (piqic) processes one .piqi module at a time. In order to implement nesting it would have to process a whole hierarchy of .piqi modules at once, potentially producing a gigantic top-level OCaml module most of which will not be used in your application. None of this -- processing more than one file at a time and generating an overblown top-level .ml module -- seem reasonable to me.

Reply to this email directly or view it on GitHub: https://github.com/alavrik/piqi/issues/4#comment_975960

William Le Ferrand

Speed matters : http://www.corefarm.com

Mobile : (+1) (415) 683-1484 Web : http://williamleferrand.github.com/

alavrik commented 13 years ago

But where would you get the "Common" OCaml module from? How would you generate it?

What if "common" directory contains other .piqi modules in addition to your "ad.piqi"?

alavrik commented 13 years ago

Closing the issue: works as designed and no comments from the reporter.