Skip to content

Commit cd346ab

Browse files
authored
feat(compiler)!: Update use syntax (#2041)
1 parent a635597 commit cd346ab

File tree

121 files changed

+1004
-1035
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1004
-1035
lines changed

compiler/src/formatting/fmt.re

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ let print_expression = (fmt, ~infix_wrap=d => group(indent(d)), expr) => {
22132213
},
22142214
)
22152215
| PExpUse(ident, use_items) =>
2216-
string("from")
2216+
string("use")
22172217
++ fmt.print_comment_range(
22182218
fmt,
22192219
~allow_breaks=false,
@@ -2224,7 +2224,7 @@ let print_expression = (fmt, ~infix_wrap=d => group(indent(d)), expr) => {
22242224
ident.loc,
22252225
)
22262226
++ fmt.print_identifier(fmt, ident.txt)
2227-
++ string(" use ")
2227+
++ string(".")
22282228
++ (
22292229
switch (use_items) {
22302230
| PUseAll =>

compiler/src/parsing/parser.messages

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ program: MODULE YIELD
3636
## The known suffix of the stack is as follows:
3737
## MODULE
3838
##
39-
program: MODULE UIDENT EOL FROM YIELD
39+
program: MODULE UIDENT EOL USE YIELD
4040
##
4141
## Ends in an error in state: 40.
4242
##
@@ -386,7 +386,7 @@ program: MODULE UIDENT EOL FOREIGN WASM LIDENT COLON LIDENT THICKARROW
386386

387387
Expected the keyword `from` followed by an external WebAssembly namespace surrounded by `"`.
388388

389-
program: MODULE UIDENT EOL FROM UIDENT YIELD
389+
program: MODULE UIDENT EOL USE UIDENT YIELD
390390
##
391391
## Ends in an error in state: 42.
392392
##
@@ -402,9 +402,9 @@ program: MODULE UIDENT EOL FROM UIDENT YIELD
402402
## In state 102, spurious reduction of production qualified_uid -> lseparated_nonempty_list_inner(dot,type_id_str)
403403
##
404404

405-
Expected the keyword `use` followed by items to use surrounded by `{}` or `*` to use all bindings.
405+
Expected `.` followed by items to use surrounded by `{}` or `*` to use all bindings.
406406

407-
program: MODULE UIDENT EOL FROM UIDENT USE YIELD
407+
program: MODULE UIDENT EOL USE UIDENT DOT YIELD
408408
##
409409
## Ends in an error in state: 43.
410410
##
@@ -413,10 +413,27 @@ program: MODULE UIDENT EOL FROM UIDENT USE YIELD
413413
## The known suffix of the stack is as follows:
414414
## FROM qualified_uid USE
415415
##
416+
program: MODULE UIDENT EOL USE UIDENT DOT EOL YIELD
417+
##
418+
## Ends in an error in state: 92.
419+
##
420+
## lseparated_nonempty_list_inner(dot,type_id_str) -> lseparated_nonempty_list_inner(dot,type_id_str) DOT eols . type_id_str [ DOT ]
421+
## use_stmt -> USE lseparated_nonempty_list_inner(dot,type_id_str) DOT eols . use_shape [ THICKARROW STAR SLASH SEMI RPAREN RCARET RBRACK RBRACE PIPE LCARET INFIX_90 INFIX_80 INFIX_70 INFIX_60 INFIX_50 INFIX_40 INFIX_30 INFIX_120 INFIX_110 INFIX_100 EOL EOF ELSE DASH COMMA COLON AND ]
422+
##
423+
## The known suffix of the stack is as follows:
424+
## USE lseparated_nonempty_list_inner(dot,type_id_str) DOT eols
425+
##
426+
## WARNING: This example involves spurious reductions.
427+
## This implies that, although the LR(1) items shown above provide an
428+
## accurate view of the past (what has been recognized so far), they
429+
## may provide an INCOMPLETE view of the future (what was expected next).
430+
## In state 3, spurious reduction of production nonempty_list(eol) -> EOL
431+
## In state 6, spurious reduction of production eols -> nonempty_list(eol)
432+
##
416433

417434
Expected bindings to use surrounded by `{}` or `*` to use all bindings.
418435

419-
program: MODULE UIDENT EOL FROM UIDENT USE LBRACE YIELD
436+
program: MODULE UIDENT EOL USE UIDENT DOT LBRACE YIELD
420437
##
421438
## Ends in an error in state: 46.
422439
##
@@ -434,7 +451,7 @@ program: MODULE UIDENT EOL FROM UIDENT USE LBRACE YIELD
434451

435452
Expected a lowercase identifier to use a value, the keyword `module` followed by an uppercase identifier to use a module, or the keyword `type` followed by an uppercase identifier to use a type.
436453

437-
program: MODULE UIDENT EOL FROM UIDENT USE LBRACE TYPE YIELD
454+
program: MODULE UIDENT EOL USE UIDENT DOT LBRACE TYPE YIELD
438455
##
439456
## Ends in an error in state: 48.
440457
##
@@ -443,7 +460,7 @@ program: MODULE UIDENT EOL FROM UIDENT USE LBRACE TYPE YIELD
443460
## The known suffix of the stack is as follows:
444461
## TYPE
445462
##
446-
program: MODULE UIDENT EOL FROM UIDENT USE LBRACE MODULE YIELD
463+
program: MODULE UIDENT EOL USE UIDENT DOT LBRACE MODULE YIELD
447464
##
448465
## Ends in an error in state: 57.
449466
##
@@ -455,7 +472,7 @@ program: MODULE UIDENT EOL FROM UIDENT USE LBRACE MODULE YIELD
455472

456473
Expected an uppercase type identifier.
457474

458-
program: MODULE UIDENT EOL FROM UIDENT USE LBRACE EXCEPTION YIELD
475+
program: MODULE UIDENT EOL USE UIDENT DOT LBRACE EXCEPTION YIELD
459476
##
460477
## Ends in an error in state: 57.
461478
##
@@ -582,7 +599,7 @@ program: MODULE UIDENT EOL PROVIDE LBRACE EXCEPTION YIELD
582599

583600
Expected an exception identifier to provide.
584601

585-
program: MODULE UIDENT EOL FROM UIDENT USE LBRACE LIDENT AS LIDENT YIELD
602+
program: MODULE UIDENT EOL USE UIDENT DOT LBRACE LIDENT AS LIDENT YIELD
586603
##
587604
## Ends in an error in state: 62.
588605
##
@@ -619,7 +636,7 @@ program: MODULE UIDENT EOL PROVIDE LBRACE LIDENT AS YIELD
619636

620637
Expected a lowercase alias.
621638

622-
program: MODULE UIDENT EOL FROM UIDENT USE LBRACE LIDENT COMMA YIELD
639+
program: MODULE UIDENT EOL USE UIDENT DOT LBRACE LIDENT COMMA YIELD
623640
##
624641
## Ends in an error in state: 66.
625642
##

compiler/src/parsing/parser.mly

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ use_shape:
354354
| lbrace use_items? rbrace { PUseItems (Option.value ~default:[] $2) }
355355

356356
use_stmt:
357-
| FROM qualified_uid USE use_shape { Expression.use ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) $2 $4 }
357+
| USE qualified_uid_inline dot use_shape { Expression.use ~loc:(to_loc $loc) ~core_loc:(to_loc $loc) $2 $4 }
358358

359359
include_alias:
360360
| AS opt_eols qualified_uid { make_module_alias $3 }
@@ -486,8 +486,11 @@ qualified_lid:
486486
| modid dot id_str { mkid (List.append $1 [$3]) (to_loc $loc) }
487487
| id_str %prec EQUAL { (mkid [$1]) (to_loc $loc) }
488488

489+
%inline qualified_uid_inline:
490+
| lseparated_nonempty_list(dot, type_id_str) { (mkid $1) (to_loc $loc) }
491+
489492
qualified_uid:
490-
| lseparated_nonempty_list(dot, type_id_str) %prec DOT { (mkid $1) (to_loc $loc) }
493+
| qualified_uid_inline %prec DOT { $1 }
491494

492495
lid:
493496
| id_str { (mkid [$1]) (to_loc $loc) }

compiler/test/grainfmt/comments.expected.gr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ let ( // yo
257257
let { /* foo */ foo } = void
258258
let { foo: /* foo */ bar } = void
259259

260-
from Mod use { module /* Foo */ Foo, type /* Foo */ Foo, foo }
260+
use Mod.{ module /* Foo */ Foo, type /* Foo */ Foo, foo }
261+
use Mod.*
261262

262263
match (5) {
263264
1 /* when */ when false => 5,
@@ -461,8 +462,8 @@ foo := /* foo */ /* foo */ foo
461462

462463
return /* return */ foo
463464

464-
from /* from */ Mod use /* Mod */ /* use */ *
465-
from /* from */ Mod use { /* Mod */ /* use */ foo }
465+
use /* use */ Mod./* Mod */ /* dot */ *
466+
use /* use */ Mod.{ /* Mod */ /* dot */ foo }
466467

467468
while (/* true */ true) {
468469
void

compiler/test/grainfmt/comments.input.gr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ let ( // yo
233233
let {foo: /* foo */ foo,} = void
234234
let {foo: /* foo */ bar,} = void
235235

236-
from Mod use { module /* Foo */ Foo, type /* Foo */ Foo, foo }
236+
use Mod.{ module /* Foo */ Foo, type /* Foo */ Foo, foo }
237+
use Mod.*
237238

238239
match (5) {
239240
1 /* when */ when false => 5,
@@ -386,8 +387,8 @@ foo /* foo */ := /* foo */ foo
386387

387388
return /* return */ foo
388389

389-
from /* from */ Mod /* Mod */ use /* use */ *
390-
from /* from */ Mod /* Mod */ use /* use */ {foo}
390+
use /* use */ Mod /* Mod */ . /* dot */ *
391+
use /* use */ Mod /* Mod */ . /* dot */ {foo}
391392

392393
while /* true */ (true) {void}
393394
while (/* true */ true) {void}

compiler/test/grainfmt/includes.expected.gr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ include "option" as Opt
77
include "option" as Opt
88
include /* special include */ "array"
99
include "array" as /* special include */ Foo
10-
from List use { length, map, forEach as each }
11-
from Opt use {
10+
use List.{ length, map, forEach as each }
11+
use Opt.{
1212
module MutableOpt,
1313
module ImmutableOpt as Imm,
1414
type Opt,
1515
type Opt as OptAlias,
1616
}
17-
from Opt use {
17+
use Opt.{
1818
module MutableOpt, /* comment1 */
1919
module ImmutableOpt as /* comment2 */ /* comment3 */ Imm, /* comment4 */
2020
/* comment5 */
@@ -25,13 +25,13 @@ from Opt use {
2525
}
2626

2727
include "runtime/unsafe/wasmi32"
28-
from WasmI32 use { add as (+), mul as (*), xor as (^), shl as (<<) }
28+
use WasmI32.{ add as (+), mul as (*), xor as (^), shl as (<<) }
2929

3030
provide foreign wasm storage_read:
3131
(WasmI64, WasmI64, WasmI64) => WasmI64 as storageRead from "env"
3232

3333
include "runtime/unsafe/wasmi32"
34-
from WasmI32 use {
34+
use WasmI32.{
3535
eq, // comment1
3636
// comment 3
3737
and_ as (&), // comment 2

compiler/test/grainfmt/includes.input.gr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ include "option" as
88
Opt
99
include /* special include */ "array"
1010
include "array" as /* special include */ Foo
11-
from List use { length, map, forEach as each }
12-
from Opt use { module MutableOpt, module ImmutableOpt as Imm, type Opt, type Opt as OptAlias }
13-
from Opt use { module MutableOpt, /* comment1 */ module ImmutableOpt /* comment2 */ as /* comment3 */ Imm /* comment4 */, /* comment5 */ type /* comment6 */ Opt, type Opt as /* comment7 */ OptAlias, exception Exc as /* comment8 */ E, exception Exc2 /* comment9 */ }
11+
use List.{ length, map, forEach as each }
12+
use Opt.{ module MutableOpt, module ImmutableOpt as Imm, type Opt, type Opt as OptAlias }
13+
use Opt.{ module MutableOpt, /* comment1 */ module ImmutableOpt /* comment2 */ as /* comment3 */ Imm /* comment4 */, /* comment5 */ type /* comment6 */ Opt, type Opt as /* comment7 */ OptAlias, exception Exc as /* comment8 */ E, exception Exc2 /* comment9 */ }
1414

1515
include "runtime/unsafe/wasmi32"
16-
from WasmI32 use {
16+
use WasmI32.{
1717
add as (+),
1818
mul as (*),
1919
xor as (^),
@@ -24,7 +24,7 @@ provide foreign wasm storage_read: (WasmI64, WasmI64, WasmI64) => WasmI64 as sto
2424

2525

2626
include "runtime/unsafe/wasmi32"
27-
from WasmI32 use {
27+
use WasmI32.{
2828
eq, // comment1
2929
// comment 3
3030
and_ as (&), // comment 2

compiler/test/input/letMutForLoop.gr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ include "runtime/debugPrint"
55

66
@unsafe
77
let foo = () => {
8-
from WasmI64 use { (+), (<) }
8+
use WasmI64.{ (+), (<) }
99
for (let mut x = 0N; x < 5N; x += 1N) {
1010
DebugPrint.printI64(x)
1111
}

compiler/test/input/list.gr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module List
22

33
include "list"
4-
from List use *
4+
use List.*
55

66
print("OK")

compiler/test/input/long_lists.gr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module LongLists
22

33
include "list"
4-
from List use *
4+
use List.*
55

66
let rec make_list = (x, n) => {
77
let rec helper = (a, b, acc) => {

0 commit comments

Comments
 (0)