From 0c8e3d5d65beaa11308d75fff8f8a00d93bfe686 Mon Sep 17 00:00:00 2001 From: Tobias Mock Date: Sun, 27 Aug 2023 12:48:23 +0200 Subject: [PATCH] Add OCaml style module aliases for re-exporting --- lib/parser.mly | 6 +++--- std/std.smu | 8 ++++---- test/modules.t/local_module.smu | 2 +- test/modules.t/local_otherfile.smu | 2 +- test/typing.ml | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/parser.mly b/lib/parser.mly index 69309950..4c06a43d 100644 --- a/lib/parser.mly +++ b/lib/parser.mly @@ -169,11 +169,11 @@ signature: Signature; l = nonempty_list(sig_item) { l } | Defexternal; ident; sexp_type_expr; option(String_lit) { $loc, $2, $3, $4 } modul: - | Module; id = ident { Module (id, [], []) } /* empty module */ - | Module; id = ident; hd = module_item; m = list(top_item) { Module (id, [], hd :: m) } - | Module; id = ident; s = parens(signature); m = list(top_item) { Module (id, s, m) } + | Module; id = ident { Module_alias (id, Path.Pid (snd id)) } | Module; id = ident; mname = path /* Use location of path */ { Module_alias ((fst mname, snd id), snd mname) } + | Module; id = ident; hd = module_item; m = list(top_item) { Module (id, [], hd :: m) } + | Module; id = ident; s = parens(signature); m = list(top_item) { Module (id, s, m) } %inline path: | id = ident { $loc, Path.Pid (snd id) } diff --git a/std/std.smu b/std/std.smu index 291a89b2..034e3cc2 100644 --- a/std/std.smu +++ b/std/std.smu @@ -14,7 +14,7 @@ (do (f i) (inner (+ i 1))))) (inner from)) -(module array array) -(module hashtbl hashtbl) -(module option option) -(module string string) +(module array) +(module hashtbl) +(module option) +(module string) diff --git a/test/modules.t/local_module.smu b/test/modules.t/local_module.smu index a85f22aa..e5aaeb58 100644 --- a/test/modules.t/local_module.smu +++ b/test/modules.t/local_module.smu @@ -6,7 +6,7 @@ (def test (fun unit unit)) (def poly-test (fun 'a unit)) (def value string)) - (module nested) + (module nested (type t unit)) (type t int) (defn test [] (print "hey thing")) (defn poly-test [a] (print (fmt-str "hey poly " a))) diff --git a/test/modules.t/local_otherfile.smu b/test/modules.t/local_otherfile.smu index a94249e3..c7b5a7a7 100644 --- a/test/modules.t/local_otherfile.smu +++ b/test/modules.t/local_otherfile.smu @@ -6,7 +6,7 @@ (def test (fun unit unit)) (def poly-test (fun 'a unit)) (def value string)) - (module nested) + (module nested (type t unit)) (type t int) (defn test [] (print "hey thing")) (defn poly-test [a] (print (fmt-str "hey poly " a))) diff --git a/test/typing.ml b/test/typing.ml index ce2f3c96..8fcf17de 100644 --- a/test/typing.ml +++ b/test/typing.ml @@ -645,7 +645,7 @@ let test_local_modules_miss_local_dont_find_global () = let test_local_module_unique_names () = test_exn "Module names must be unique. nosig exists already" - (local_module ^ "(module nosig)") + (local_module ^ "(module nosig (type t unit))") let test_local_module_nested_module_alias () = test "nosig/nested/t"