summaryrefslogtreecommitdiff
path: root/parse/gram.y
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-17 13:48:46 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-17 13:48:46 -0400
commitd2a198f1959af5023bbc893fe396bb2f08262a61 (patch)
tree8b582e627e48b1024f0d046db9d5bc3fd7efd5be /parse/gram.y
parent7c284022867d6a453b72e90235c8a86ce13fcccc (diff)
downloadmc-d2a198f1959af5023bbc893fe396bb2f08262a61.tar.gz
Add support for 'pkglocal' keyword.
pkglocal makes the export only available within the package.
Diffstat (limited to 'parse/gram.y')
-rw-r--r--parse/gram.y25
1 files changed, 21 insertions, 4 deletions
diff --git a/parse/gram.y b/parse/gram.y
index 625229f..44bb0fd 100644
--- a/parse/gram.y
+++ b/parse/gram.y
@@ -118,6 +118,7 @@ static void addtrait(Type *t, char *str);
%token<tok> Tret /* -> */
%token<tok> Tuse /* use */
%token<tok> Tpkg /* pkg */
+%token<tok> Tpkglocal/* pkglocal */
%token<tok> Tsizeof /* sizeof */
%token<tok> Tident
@@ -132,7 +133,7 @@ static void addtrait(Type *t, char *str);
%type <tok> asnop cmpop addop mulop shiftop optident
-%type <tydef> tydef typeid
+%type <tydef> tydef pkgtydef typeid
%type <trait> traitdef
%type <node> exprln retexpr goto continue break expr atomicexpr
@@ -150,7 +151,7 @@ static void addtrait(Type *t, char *str);
%type <nodelist> arglist argdefs params matches
%type <nodelist> structbody structelts arrayelts
%type <nodelist> tupbody tuprest
-%type <nodelist> decl decllist
+%type <nodelist> decl pkgdecl decllist
%type <nodelist> traitbody implbody
%type <uconlist> unionbody
@@ -280,7 +281,7 @@ pkgbody : pkgitem
| pkgbody Tendln pkgitem
;
-pkgitem : decl {
+pkgitem : pkgdecl {
size_t i;
for (i = 0; i < $1.nn; i++) {
putdcl(file->file.exports, $1.nl[i]);
@@ -288,7 +289,7 @@ pkgitem : decl {
lappend(&file->file.stmts, &file->file.nstmts, $1.nl[i]);
}
}
- | tydef {
+ | pkgtydef {
puttype(file->file.exports, mkname($1.line, $1.name), $1.type);
installucons(file->file.exports, $1.type);
}
@@ -307,6 +308,22 @@ pkgitem : decl {
| /* empty */
;
+pkgdecl : Tpkglocal decl {
+ size_t i;
+ $$ = $2;
+ for (i = 0; i < $$.nn; i++)
+ $$.nl[i]->decl.ispkglocal = 1;
+ }
+ | decl {$$ = $1;}
+ ;
+
+pkgtydef: Tpkglocal tydef {
+ $$ = $2;
+ $$.type->ispkglocal = 1;
+ }
+ | tydef {$$ = $1;}
+ ;
+
visdef : Texport Tcolon
| Tprotect Tcolon
;