mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-25 13:36:37 +00:00
Module Params' proposal import syntax
I previously implemented the syntax in "Proposal: Module and Package Changes" [1]:
```
import [map, map2] from JsonDecode as JD
```
However, we decided [2] to use the one that appears in "Proposal: Module Params" [3]:
```
import JsonDecode as JD exposing [map, map2]
```
The new implementation also now supports comments and newlines between all the tokens.
[1] https://docs.google.com/document/d/1E_77fO-44BtoBtXoVeWyGh1xN2KRTWTu8q6i25RNNx0/edit
[2] 405410612
[3] https://docs.google.com/document/d/110MwQi7Dpo1Y69ECFXyyvDWzF4OYv1BLojIm08qDTvg/edit
This commit is contained in:
parent
5cd084b73c
commit
c56091ee3e
20 changed files with 767 additions and 204 deletions
|
|
@ -1 +1 @@
|
|||
NotEndOfFile(@12)
|
||||
NotEndOfFile(@0)
|
||||
|
|
@ -19,7 +19,7 @@ Defs {
|
|||
"Json",
|
||||
),
|
||||
alias: None,
|
||||
exposed: [],
|
||||
exposed: None,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
import JsonEncode as JE
|
||||
|
||||
import BytesDecode as BD
|
||||
|
|
|
|||
|
|
@ -4,20 +4,18 @@ Defs {
|
|||
Index(2147483649),
|
||||
],
|
||||
regions: [
|
||||
@0-23,
|
||||
@0-24,
|
||||
@24-49,
|
||||
],
|
||||
space_before: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 0, length = 1),
|
||||
Slice(start = 0, length = 0),
|
||||
],
|
||||
space_after: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 1, length = 0),
|
||||
],
|
||||
spaces: [
|
||||
Newline,
|
||||
Slice(start = 0, length = 0),
|
||||
],
|
||||
spaces: [],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
ModuleImport {
|
||||
|
|
@ -25,11 +23,16 @@ Defs {
|
|||
"JsonEncode",
|
||||
),
|
||||
alias: Some(
|
||||
@21-23 ModuleName(
|
||||
"JE",
|
||||
@21-23 SpaceAfter(
|
||||
ModuleName(
|
||||
"JE",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
),
|
||||
exposed: [],
|
||||
exposed: None,
|
||||
},
|
||||
ModuleImport {
|
||||
name: @31-42 ModuleName(
|
||||
|
|
@ -40,7 +43,7 @@ Defs {
|
|||
"BD",
|
||||
),
|
||||
),
|
||||
exposed: [],
|
||||
exposed: None,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
import
|
||||
# comment
|
||||
Json as J exposing [map]
|
||||
|
||||
import Json
|
||||
# comment
|
||||
as J exposing [map]
|
||||
|
||||
import Json
|
||||
as
|
||||
# comment
|
||||
J
|
||||
|
||||
import Json
|
||||
as
|
||||
# comment
|
||||
J
|
||||
exposing [map]
|
||||
|
||||
import Json
|
||||
as
|
||||
# comment
|
||||
J
|
||||
exposing [
|
||||
map,
|
||||
map2,
|
||||
]
|
||||
|
||||
import Json
|
||||
# comment
|
||||
exposing [
|
||||
map,
|
||||
map2,
|
||||
]
|
||||
|
||||
import Json as J
|
||||
# comment
|
||||
exposing [map]
|
||||
|
||||
import Json
|
||||
exposing
|
||||
# comment
|
||||
[map]
|
||||
|
||||
import Json as J
|
||||
exposing
|
||||
# comment
|
||||
[map]
|
||||
|
||||
import Json as J exposing [
|
||||
# comment
|
||||
map,
|
||||
]
|
||||
|
||||
import
|
||||
# comment 1
|
||||
Json
|
||||
# comment 2
|
||||
as
|
||||
# comment 3
|
||||
J
|
||||
# comment 4
|
||||
exposing
|
||||
# comment 5
|
||||
[
|
||||
# comment 6
|
||||
map,
|
||||
]
|
||||
|
|
@ -0,0 +1,431 @@
|
|||
Defs {
|
||||
tags: [
|
||||
Index(2147483648),
|
||||
Index(2147483649),
|
||||
Index(2147483650),
|
||||
Index(2147483651),
|
||||
Index(2147483652),
|
||||
Index(2147483653),
|
||||
Index(2147483654),
|
||||
Index(2147483655),
|
||||
Index(2147483656),
|
||||
Index(2147483657),
|
||||
Index(2147483658),
|
||||
],
|
||||
regions: [
|
||||
@0-49,
|
||||
@51-100,
|
||||
@102-138,
|
||||
@138-187,
|
||||
@189-252,
|
||||
@254-312,
|
||||
@314-363,
|
||||
@365-409,
|
||||
@411-460,
|
||||
@462-513,
|
||||
@515-672,
|
||||
],
|
||||
space_before: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 0, length = 2),
|
||||
Slice(start = 2, length = 2),
|
||||
Slice(start = 4, length = 0),
|
||||
Slice(start = 4, length = 2),
|
||||
Slice(start = 6, length = 2),
|
||||
Slice(start = 8, length = 2),
|
||||
Slice(start = 10, length = 2),
|
||||
Slice(start = 12, length = 2),
|
||||
Slice(start = 14, length = 2),
|
||||
Slice(start = 16, length = 2),
|
||||
],
|
||||
space_after: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 2, length = 0),
|
||||
Slice(start = 4, length = 0),
|
||||
Slice(start = 4, length = 0),
|
||||
Slice(start = 6, length = 0),
|
||||
Slice(start = 8, length = 0),
|
||||
Slice(start = 10, length = 0),
|
||||
Slice(start = 12, length = 0),
|
||||
Slice(start = 14, length = 0),
|
||||
Slice(start = 16, length = 0),
|
||||
Slice(start = 18, length = 0),
|
||||
],
|
||||
spaces: [
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
Newline,
|
||||
],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
ModuleImport {
|
||||
name: @25-29 SpaceBefore(
|
||||
ModuleName(
|
||||
"Json",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
alias: Some(
|
||||
@33-34 ModuleName(
|
||||
"J",
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@45-48 ExposedName(
|
||||
"map",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @58-62 SpaceAfter(
|
||||
ModuleName(
|
||||
"Json",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
alias: Some(
|
||||
@84-85 ModuleName(
|
||||
"J",
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@96-99 ExposedName(
|
||||
"map",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @109-113 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: Some(
|
||||
@135-136 SpaceBefore(
|
||||
SpaceAfter(
|
||||
ModuleName(
|
||||
"J",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
exposed: None,
|
||||
},
|
||||
ModuleImport {
|
||||
name: @145-149 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: Some(
|
||||
@171-172 SpaceBefore(
|
||||
ModuleName(
|
||||
"J",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@183-186 ExposedName(
|
||||
"map",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @196-200 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: Some(
|
||||
@222-223 SpaceBefore(
|
||||
ModuleName(
|
||||
"J",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@234-237 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@247-251 SpaceBefore(
|
||||
ExposedName(
|
||||
"map2",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @261-265 SpaceAfter(
|
||||
ModuleName(
|
||||
"Json",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
alias: None,
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@294-297 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@307-311 SpaceBefore(
|
||||
ExposedName(
|
||||
"map2",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @321-325 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: Some(
|
||||
@329-330 SpaceAfter(
|
||||
ModuleName(
|
||||
"J",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@359-362 ExposedName(
|
||||
"map",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @372-376 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: None,
|
||||
exposed: Some(
|
||||
(
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
[
|
||||
@405-408 ExposedName(
|
||||
"map",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @418-422 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: Some(
|
||||
@426-427 ModuleName(
|
||||
"J",
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
[
|
||||
@456-459 ExposedName(
|
||||
"map",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @469-473 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: Some(
|
||||
@477-478 ModuleName(
|
||||
"J",
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@508-511 SpaceBefore(
|
||||
SpaceAfter(
|
||||
ExposedName(
|
||||
"map",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @542-546 SpaceBefore(
|
||||
SpaceAfter(
|
||||
ModuleName(
|
||||
"Json",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment 2",
|
||||
),
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment 1",
|
||||
),
|
||||
],
|
||||
),
|
||||
alias: Some(
|
||||
@590-591 SpaceBefore(
|
||||
SpaceAfter(
|
||||
ModuleName(
|
||||
"J",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment 4",
|
||||
),
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment 3",
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment 5",
|
||||
),
|
||||
],
|
||||
[
|
||||
@663-666 SpaceBefore(
|
||||
SpaceAfter(
|
||||
ExposedName(
|
||||
"map",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" comment 6",
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
import
|
||||
# comment
|
||||
Json as J exposing [map]
|
||||
|
||||
import Json
|
||||
# comment
|
||||
as J exposing [map]
|
||||
|
||||
import Json as
|
||||
# comment
|
||||
J
|
||||
|
||||
import Json as
|
||||
# comment
|
||||
J exposing [map]
|
||||
|
||||
import Json as
|
||||
# comment
|
||||
J exposing [map,
|
||||
map2]
|
||||
|
||||
import Json
|
||||
# comment
|
||||
exposing [map,
|
||||
map2]
|
||||
|
||||
import Json as J
|
||||
# comment
|
||||
exposing [map]
|
||||
|
||||
import Json exposing
|
||||
# comment
|
||||
[map]
|
||||
|
||||
import Json as J exposing
|
||||
# comment
|
||||
[map]
|
||||
|
||||
import Json as J exposing [
|
||||
# comment
|
||||
map
|
||||
]
|
||||
|
||||
import
|
||||
# comment 1
|
||||
Json
|
||||
# comment 2
|
||||
as
|
||||
# comment 3
|
||||
J
|
||||
# comment 4
|
||||
exposing
|
||||
# comment 5
|
||||
[
|
||||
# comment 6
|
||||
map
|
||||
]
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
import [map, Decode] from JsonDecode as JD
|
||||
import [
|
||||
# some comment
|
||||
map,
|
||||
Decode,
|
||||
] from JsonDecode as JD
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
Defs {
|
||||
tags: [
|
||||
Index(2147483648),
|
||||
Index(2147483649),
|
||||
],
|
||||
regions: [
|
||||
@0-42,
|
||||
@43-110,
|
||||
],
|
||||
space_before: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 0, length = 1),
|
||||
],
|
||||
space_after: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 1, length = 0),
|
||||
],
|
||||
spaces: [
|
||||
Newline,
|
||||
],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
ModuleImport {
|
||||
name: @26-36 ModuleName(
|
||||
"JsonDecode",
|
||||
),
|
||||
alias: Some(
|
||||
@40-42 ModuleName(
|
||||
"JD",
|
||||
),
|
||||
),
|
||||
exposed: [
|
||||
@8-11 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@13-19 ExposedName(
|
||||
"Decode",
|
||||
),
|
||||
],
|
||||
},
|
||||
ModuleImport {
|
||||
name: @94-104 ModuleName(
|
||||
"JsonDecode",
|
||||
),
|
||||
alias: Some(
|
||||
@108-110 ModuleName(
|
||||
"JD",
|
||||
),
|
||||
),
|
||||
exposed: [
|
||||
@71-74 SpaceBefore(
|
||||
ExposedName(
|
||||
"map",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
LineComment(
|
||||
" some comment",
|
||||
),
|
||||
],
|
||||
),
|
||||
@80-86 SpaceBefore(
|
||||
SpaceAfter(
|
||||
ExposedName(
|
||||
"Decode",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
import [map, Decode] from JsonDecode as JD
|
||||
import [
|
||||
# some comment
|
||||
map,
|
||||
Decode
|
||||
] from JsonDecode as JD
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import [map, Decoder] from Json
|
||||
import [
|
||||
import Json exposing [map, Decoder]
|
||||
import Json exposing [
|
||||
map,
|
||||
Decoder,
|
||||
] from Json
|
||||
]
|
||||
import Json exposing []
|
||||
|
|
|
|||
|
|
@ -2,56 +2,83 @@ Defs {
|
|||
tags: [
|
||||
Index(2147483648),
|
||||
Index(2147483649),
|
||||
Index(2147483650),
|
||||
],
|
||||
regions: [
|
||||
@0-31,
|
||||
@32-67,
|
||||
@0-35,
|
||||
@36-75,
|
||||
@76-99,
|
||||
],
|
||||
space_before: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 0, length = 1),
|
||||
Slice(start = 1, length = 1),
|
||||
],
|
||||
space_after: [
|
||||
Slice(start = 0, length = 0),
|
||||
Slice(start = 1, length = 0),
|
||||
Slice(start = 2, length = 0),
|
||||
],
|
||||
spaces: [
|
||||
Newline,
|
||||
Newline,
|
||||
],
|
||||
type_defs: [],
|
||||
value_defs: [
|
||||
ModuleImport {
|
||||
name: @27-31 ModuleName(
|
||||
name: @7-11 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: None,
|
||||
exposed: [
|
||||
@8-11 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@13-20 ExposedName(
|
||||
"Decoder",
|
||||
),
|
||||
],
|
||||
},
|
||||
ModuleImport {
|
||||
name: @63-67 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: None,
|
||||
exposed: [
|
||||
@40-43 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@49-56 SpaceBefore(
|
||||
ExposedName(
|
||||
"Decoder",
|
||||
),
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
Newline,
|
||||
@22-25 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@27-34 ExposedName(
|
||||
"Decoder",
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @43-47 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: None,
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[
|
||||
@58-61 ExposedName(
|
||||
"map",
|
||||
),
|
||||
@67-74 SpaceBefore(
|
||||
ExposedName(
|
||||
"Decoder",
|
||||
),
|
||||
[
|
||||
Newline,
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
ModuleImport {
|
||||
name: @83-87 ModuleName(
|
||||
"Json",
|
||||
),
|
||||
alias: None,
|
||||
exposed: Some(
|
||||
(
|
||||
[],
|
||||
[],
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import [map, Decoder] from Json
|
||||
import [map,
|
||||
Decoder] from Json
|
||||
import Json exposing [map, Decoder]
|
||||
import Json exposing [map,
|
||||
Decoder]
|
||||
import Json exposing []
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ mod test_snapshots {
|
|||
pass/if_def.expr,
|
||||
pass/import.moduledefs,
|
||||
pass/import_with_alias.moduledefs,
|
||||
pass/import_with_everything.moduledefs,
|
||||
pass/import_with_comments.moduledefs,
|
||||
pass/import_with_exposed.moduledefs,
|
||||
pass/int_with_underscore.expr,
|
||||
pass/interface_with_newline.header,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue