Skip to content

Commit

Permalink
Merge pull request #420 from dfinity-lab/import
Browse files Browse the repository at this point in the history
Named import sugar
  • Loading branch information
rossberg authored May 16, 2019
2 parents 84d5165 + 8a405af commit ef2f494
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 31 deletions.
2 changes: 2 additions & 0 deletions design/Syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Productions marked * probably deferred to later versions.
shared? func <id>? <typ-params>? <pat> (: <typ>)? =? <exp> function
type <id> <typ-params>? = <typ> type
actor? class <id> <typ-params>? <pat> (: <typ>)? =? <exp> class
module <id>? =? { <dec>* } module
import <id>? =? <text> import
```

## Programs
Expand Down
13 changes: 7 additions & 6 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,6 @@ exp_un :
{ assign_op e (fun e' -> UnE(ref Type.Pre, op, e') @? at $sloc) (at $sloc) }
| NOT e=exp_un
{ NotE e @? at $sloc }
| IMPORT f=TEXT
{ ImportE (f, ref "") @? at $sloc }
| DEBUG_SHOW e=exp_un
{ ShowE (ref Type.Pre, e) @? at $sloc }

Expand Down Expand Up @@ -467,13 +465,13 @@ exp_nonvar :
| e=exp_nondec
{ e }
| d=dec_nonvar
{ BlockE([d]) @? at $sloc }
{ match d.it with ExpD e -> e | _ -> BlockE([d]) @? at $sloc }

exp :
| e=exp_nonvar
{ e }
| d=dec_var
{ BlockE([d]) @? at $sloc }
{ match d.it with ExpD e -> e | _ -> BlockE([d]) @? at $sloc }


case :
Expand Down Expand Up @@ -592,8 +590,11 @@ dec_nonvar :
else List.map share_expfield efs
in ClassD(xf "class" $sloc, tps, s, p, x, efs') @? at $sloc }
| MODULE xf=id_opt EQ? LCURLY ds=seplist(dec, semicolon) RCURLY
{ let _named, id = xf "module" $sloc in
ModuleD(id, ds) @? at $sloc }
{ let _named, x = xf "module" $sloc in
ModuleD(x, ds) @? at $sloc }
| IMPORT xf=id_opt EQ? f=TEXT
{ let named, x = xf "import" $sloc in
let_or_exp named x (ImportE (f, ref "")) (at $sloc) }

dec :
| d=dec_var
Expand Down
12 changes: 6 additions & 6 deletions stdlib/examples/produce-exchange/serverActor.as
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
--------------------
*/

let P = (import "../../prelude.as");
let Option = (import "../../option.as");
let T = (import "serverTypes.as");
let L = (import "serverLang.as");
let Model = (import "serverModel.as");
let Result = (import "../../result.as");
import P = "../../prelude.as";
import Option = "../../option.as";
import T = "serverTypes.as";
import L = "serverLang.as";
import Model = "serverModel.as";
import Result = "../../result.as";

type Result<Ok,Err> = Result.Result<Ok,Err>;

Expand Down
5 changes: 3 additions & 2 deletions stdlib/examples/produce-exchange/serverLang.as
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
*/

let Result = (import "../../result.as");
import Result = "../../result.as";
import T = "serverTypes.as";

type Result<Ok,Err> = Result.Result<Ok,Err>;
let T = import "serverTypes.as";

/**
`Req`
Expand Down
20 changes: 10 additions & 10 deletions stdlib/examples/produce-exchange/serverModel.as
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,32 @@ uses are is not.
*/


let P = (import "../../prelude.as");
import P = "../../prelude.as";

let T = (import "serverTypes.as");
let L = (import "serverLang.as");
let M = (import "serverModelTypes.as");
import T = "serverTypes.as";
import L = "serverLang.as";
import M = "serverModelTypes.as";

let Hash = (import "../../hash.as").BitVec;
type Hash = Hash.t;

let Option = (import "../../option.as");
let Trie = (import "../../trie.as");
import Option = "../../option.as";
import Trie = "../../trie.as";

type Trie<K,V> = Trie.Trie<K,V>;
type Key<K> = Trie.Key<K>;

type Table<K,V> = Trie.Trie<K,V>;
let Table = (import "../../trie.as");
let Table = Trie;

type Map<K,V> = Trie.Trie<K,V>;
let Map = (import "../../trie.as");
let Map = Trie;

let DT = (import "../../docTable.as");
import DT = "../../docTable.as";
let DocTable = DT.DocTable;
type DocTable<X,Y,Z> = DT.DocTable<X,Y,Z>;

let Result = (import "../../result.as");
import Result = "../../result.as";
type Result<Ok,Err> = Result.Result<Ok,Err>;

type RouteInventoryMap = Trie<(T.RouteId, T.InventoryId), (M.RouteDoc, M.InventoryDoc)>;
Expand Down
4 changes: 2 additions & 2 deletions stdlib/examples/produce-exchange/serverModelTypes.as
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ Representation
*/

let T = (import "serverTypes.as");
import T = "serverTypes.as";

let Trie = (import "../../trie.as");
import Trie = "../../trie.as";
type Trie<K,V> = Trie.Trie<K,V>;

type Map<X, Y> = Trie<X, Y>;
Expand Down
2 changes: 1 addition & 1 deletion test/fail/self-import.as
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import "self-import.as" : ()
import "self-import.as";
1 change: 0 additions & 1 deletion test/run/import-module.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
let L = import "lib/ListM.as";
type stack = L.List<Int>;
let s = L.cons<Int>(1,L.nil<Int>());

4 changes: 2 additions & 2 deletions test/run/import.as
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
assert (import "lib/hello-string.as" == "Hello!");
assert (import "lib/dir" == "Hello!");
assert ((import "lib/hello-string.as") == "Hello!");
assert ((import "lib/dir") == "Hello!");
1 change: 0 additions & 1 deletion test/run/lib/ListM.as
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
type List<T> = ?(T, List<T>);
func nil<T>() : List<T> = null;
func cons<T>(x : T, l : List<T>) : List<T> = ?(x, l);

0 comments on commit ef2f494

Please sign in to comment.