Skip to content

Commit

Permalink
Add support for overriding ocaml name of an imported module
Browse files Browse the repository at this point in the history
For example, given an import statement like this:

.import [
    .module m
    .ocaml-module "Foo.Bar"
    .ocaml-name "Fum"
]

piqic-ocaml will generate the following statement at the top of the generated
_piqi.ml:

module Fum = Foo.Bar
  • Loading branch information
alavrik committed Jun 10, 2015
1 parent 21d56f5 commit eb446e4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion piqic-ocaml/piqi.piqi-ocaml.piqi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


.extend [
.typedef piqi
(.typedef piqi import)

.with.field [
.name ocaml-module
Expand Down
11 changes: 9 additions & 2 deletions piqic-ocaml/piqic_ocaml_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,17 @@ let gen_typedefs context (typedefs:T.typedef list) =
let gen_import context import =
let open Import in
let index = C.resolve_import context import in
let piqi = index.i_piqi in
let imported_modname =
match import.ocaml_module with
| Some modname -> (* local override *)
modname
| None -> (* original modname *)
let piqi = index.i_piqi in
some_of piqi.P.ocaml_module
in
iod " " [
ios "module "; ios (some_of import.ocaml_name); ios "=";
ios (some_of piqi.P.ocaml_module);
ios imported_modname;
eol; eol
]

Expand Down
Loading

0 comments on commit eb446e4

Please sign in to comment.