summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <orib@google.com>2013-02-19 14:01:04 -0500
committerOri Bernstein <orib@google.com>2013-02-19 14:01:04 -0500
commit7e94001f96f9c1f05af4be980ef8c25cea6b1342 (patch)
tree67a2b77e7006660dfd6455c710f3add00551da54
parente559a7dc5f76558ea0f56d9bf26385b04b496bd4 (diff)
downloadmc-7e94001f96f9c1f05af4be980ef8c25cea6b1342.tar.gz
Allow empty package names.
This exports the symbols into the main namespace.
-rw-r--r--parse/gram.y14
-rw-r--r--test/exportmain.myr4
2 files changed, 13 insertions, 5 deletions
diff --git a/parse/gram.y b/parse/gram.y
index b15c408..9c047de 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -125,7 +125,7 @@ static void constrainwith(Type *t, char *str);
%type <tylist> typelist typarams
%type <nodelist> typaramlist
-%type <tok> asnop cmpop addop mulop shiftop
+%type <tok> asnop cmpop addop mulop shiftop optident
%type <tydef> tydef typeid
@@ -216,11 +216,17 @@ use : Tuse Tident
{$$ = mkuse($1->line, $2->str, 1);}
;
-package : Tpkg Tident Tasn pkgbody Tendblk
+optident: Tident {$$ = $1;}
+ | /* empty */ {$$ = NULL;}
+ ;
+
+package : Tpkg optident Tasn pkgbody Tendblk
{if (file->file.exports->name)
fatal($1->line, "Package already declared\n");
- updatens(file->file.exports, $2->str);
- updatens(file->file.globls, $2->str);
+ if ($2) {
+ updatens(file->file.exports, $2->str);
+ updatens(file->file.globls, $2->str);
+ }
}
;
diff --git a/test/exportmain.myr b/test/exportmain.myr
index 2cb21d7..36bd5c8 100644
--- a/test/exportmain.myr
+++ b/test/exportmain.myr
@@ -1,5 +1,7 @@
+use std
+
pkg =
- foo : (val:int -> int)
+ const foo : (val:int -> int)
;;