caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Yurii A. Rashkovskii" <yrashk@openeas.org>
To: caml-list@inria.fr
Subject: [Caml-list] module namespace
Date: Sat, 2 Nov 2002 02:24:56 +0200	[thread overview]
Message-ID: <20021102002456.GC8925@rashko> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1230 bytes --]

I've developed small preprocessor module that provides kind of
namespace support for the Objective Caml.

It defines following constructs:

* module ModuleName in [Namespace|Namespace.Namespace]

it defines module ModuleName within namespace

Examples:
 module Test in Org.Openeas = struct let test = () end
 module Test in Org.Openeas : sig val test:unit end

* module type ModuleTypeName in [Namespace|Namespace.Namespace] 

it defines module type ModuleTypeName within namespace

Example:
 module type T = sig val test:unit end

* open ModuleName in [Namespace|Namespace.Namespace] 

it opens module ModuleName from namespace

Example:
 open Unix in Org.Ocaml

* open ModuleName in [Namespace|Namespace.Namespace] as NewModuleName 

the same as previous, but also renames module ModuleName to NewModuleName

Example:
 open Unix in Org.Ocaml as CamlUnix

* use [Namespace|Namespace.Namespace]

it opens namespace module. If namespace name contains dots, they are
replaced with underline.

Example:
 use Org.Openeas



If somebody is interested, I want to hear comments, questions,
bugs of current implementation and so on. 

Early source code is attached.

-- 
Thanks,
Yurii.

[-- Attachment #1.2: pa_ns.ml --]
[-- Type: text/plain, Size: 3851 bytes --]

(*******************************************************)
(*                                                     *)
(* OCamlNS                                             *)
(*                                                     *)
(* Copyright (c) 2001, 2002.                           *)
(* E/AS Software Foundation                            *)
(*                                                     *)
(* Author(s):                                          *)
(*    Yurii A. Rashkovskii                             *)
(*                                                     *)
(* This program is free software; you can redistribute *)
(* it and/or modify it under the terms of the GNU      *)
(* Lesser General Public License as published by the   *)
(* Free Software Foundation; version 2 of the License. *)
(*                                                     *)
(*******************************************************)

open Stdpp;;
open Pcaml;;

let mod_ident = Grammar.Entry.create gram "mod_ident";;
let module_binding = Grammar.Entry.create gram "module_binding";;


let rename_module = ref (fun loc -> <:str_item< open Pervasives >>);;

let gen_mod_name l =
    let nsname = ref "" in
    List.iter (fun x -> nsname := !nsname ^ (x ^ "_")) l ; 
    (String.sub !nsname 0 ((String.length !nsname)-1));;

let gen_ns_name l =
    let nsname = ref "" in
    List.iter (fun x -> nsname := !nsname ^ (x ^ "_")) l ; !nsname;;
    
let gen_module loc mn ns me =
    let name = "caml_namespace___" ^ (gen_ns_name ns) ^ "__module___" ^ mn in
    <:str_item< module $uid:name$ = $me$ >>
;;    

let gen_module_type loc mn ns mt =
    let name = "caml_namespace___" ^ (gen_ns_name ns) ^ "__moduletype___" ^ mn in
    <:str_item< module type$uid:name$ = $mt$ >>
;;    

let gen_module_open loc mn ns =
    let name = "caml_namespace___" ^ (gen_ns_name ns) ^ "__module___" ^ mn in
    rename_module := (fun loc -> <:str_item< module $uid:mn$ = $uid:name$>>);    
    <:str_item< open $uid:name$>>
;;    

let gen_module_use loc ns =
    let name = (gen_mod_name ns) in
    <:str_item< open $uid:name$>>
;;    

let gen_module_open_as loc mn ns asn =
    let name = "caml_namespace___" ^ (gen_ns_name ns) ^ "__module___" ^ mn in
    rename_module := (fun loc -> <:str_item< module $uid:asn$ = $uid:name$>>);    
    <:str_item< open $uid:name$>>
;;    

let gen_module_sig loc mn ns mt =
    let name = "caml_namespace___" ^ (gen_ns_name ns) ^ "__module___" ^ mn in
    <:sig_item< module $uid:name$ : $mt$ >>
;;    

EXTEND

  mod_ident:
    [ RIGHTA
      [ i = UIDENT -> [i]
      | i = LIDENT -> [i]
      | i = UIDENT; "."; j = SELF -> i :: j ] ]
  ;

  module_binding:
    [ RIGHTA
      [ "("; m = UIDENT; ":"; mt = module_type; ")"; mb = SELF ->
          <:module_expr< functor ( $m$ : $mt$ ) -> $mb$ >>
      | ":"; mt = module_type; "="; me = module_expr ->
          <:module_expr< ( $me$ : $mt$ ) >>
      | "="; me = module_expr -> <:module_expr< $me$ >> ] ]
  ;

  str_item: LEVEL "top"
  [
    [ "module"; i = UIDENT; "in" ; ns = mod_ident ; 
       me = module_binding ->
      gen_module loc i ns me
     |
     "module";"type"; i = UIDENT; "in" ; ns = mod_ident ; "=";
       mt = module_type ->
      gen_module_type loc i ns mt
     | 
     "open"; i = UIDENT; "in" ; ns = mod_ident ->
      gen_module_open loc i ns ; !rename_module loc
     | 
     "open"; i = UIDENT; "in" ; ns = mod_ident ; "as" ; asn = UIDENT ->
      gen_module_open_as loc i ns asn; !rename_module loc
     | 
     "use"; ns = mod_ident  ->
      gen_module_use loc ns
    ]

  ];

  sig_item: LEVEL "top"
  [
    [ "module"; i = UIDENT; "in" ; ns = mod_ident ; ":" ; mt = module_type ->
      gen_module_sig loc i ns mt
    ]

  ];

END
;

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2002-11-02  0:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-11-02  0:24 Yurii A. Rashkovskii [this message]
2002-11-02  8:51 ` Alessandro Baretta
2002-11-02 16:10   ` Yurii A. Rashkovskii
2002-11-02 16:34     ` Alessandro Baretta
2002-11-02 16:57       ` Chris Hecker
2002-11-02 17:20       ` Yurii A. Rashkovskii
2002-11-02 17:40         ` Alessandro Baretta
2002-11-02 19:14           ` Yurii A. Rashkovskii
2002-11-02 22:37       ` Lauri Alanko
2002-11-04  8:07         ` Alessandro Baretta
2002-11-05 16:27           ` Jeffrey Palmer
2002-11-05 22:30             ` Alessandro Baretta
2002-11-06 10:30             ` Andreas Rossberg
2002-11-06 14:17               ` Yurii A. Rashkovskii
2002-11-06 16:27                 ` Alessandro Baretta
2002-11-06 16:56                   ` Yurii A. Rashkovskii
2002-11-06 19:30                     ` Christian Lindig
2002-11-06 20:36                       ` Alessandro Baretta

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=20021102002456.GC8925@rashko \
    --to=yrashk@openeas.org \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).