New module header

Implements the new `module` header syntax as described in "module and package changes" [1]:

```
module [Request, Response, req]
```

The old syntax should still work fine, and is automatically upgraded to the new one
when running `roc format`.

[1] https://docs.google.com/document/d/1E_77fO-44BtoBtXoVeWyGh1xN2KRTWTu8q6i25RNNx0/edit
This commit is contained in:
Agus Zubiaga 2024-02-18 19:10:54 -03:00
parent 7754dd7ef7
commit 057a18573a
No known key found for this signature in database
92 changed files with 1445 additions and 1563 deletions

View file

@ -1 +0,0 @@
interface Foo exposes [] imports []

View file

@ -1,27 +0,0 @@
Module {
comments: [],
header: Interface(
InterfaceHeader {
before_name: [],
name: @10-13 ModuleName(
"Foo",
),
exposes: KeywordItem {
keyword: Spaces {
before: [],
item: ExposesKeyword,
after: [],
},
item: [],
},
imports: KeywordItem {
keyword: Spaces {
before: [],
item: ImportsKeyword,
after: [],
},
item: [],
},
},
),
}

View file

@ -1 +0,0 @@
interface Foo exposes [] imports []

View file

@ -0,0 +1,10 @@
Module {
comments: [],
header: Module(
ModuleHeader {
before_exposes: [],
exposes: [],
interface_imports: None,
},
),
}

View file

@ -1 +0,0 @@
interface T exposes [] imports []

View file

@ -1,27 +0,0 @@
Module {
comments: [],
header: Interface(
InterfaceHeader {
before_name: [],
name: @10-11 ModuleName(
"T",
),
exposes: KeywordItem {
keyword: Spaces {
before: [],
item: ExposesKeyword,
after: [],
},
item: [],
},
imports: KeywordItem {
keyword: Spaces {
before: [],
item: ImportsKeyword,
after: [],
},
item: [],
},
},
),
}

View file

@ -1 +0,0 @@
interface T exposes [] imports []

View file

@ -0,0 +1,25 @@
Module {
comments: [],
header: Module(
ModuleHeader {
before_exposes: [],
exposes: [
@8-9 ExposedName(
"a",
),
@11-12 ExposedName(
"b",
),
@18-19 SpaceBefore(
ExposedName(
"c",
),
[
Newline,
],
),
],
interface_imports: None,
},
),
}

View file

@ -0,0 +1,2 @@
module [a, b,
c]

View file

@ -0,0 +1,10 @@
Module {
comments: [],
header: Module(
ModuleHeader {
before_exposes: [],
exposes: [],
interface_imports: None,
},
),
}

View file

@ -1 +0,0 @@
interface Foo.Bar.Baz exposes [] imports []

View file

@ -1,27 +0,0 @@
Module {
comments: [],
header: Interface(
InterfaceHeader {
before_name: [],
name: @10-21 ModuleName(
"Foo.Bar.Baz",
),
exposes: KeywordItem {
keyword: Spaces {
before: [],
item: ExposesKeyword,
after: [],
},
item: [],
},
imports: KeywordItem {
keyword: Spaces {
before: [],
item: ImportsKeyword,
after: [],
},
item: [],
},
},
),
}

View file

@ -1 +0,0 @@
interface Foo.Bar.Baz exposes [] imports []

View file

@ -0,0 +1 @@
module [Foo, foo, bar]

View file

@ -0,0 +1,20 @@
Module {
comments: [],
header: Module(
ModuleHeader {
before_exposes: [],
exposes: [
@23-26 ExposedName(
"Foo",
),
@28-31 ExposedName(
"foo",
),
@33-36 ExposedName(
"bar",
),
],
interface_imports: None,
},
),
}

View file

@ -0,0 +1 @@
interface Foo exposes [Foo, foo, bar] imports []

View file

@ -4768,10 +4768,10 @@ mod test_fmt {
// MODULES
#[test]
fn single_line_interface() {
fn single_line_module() {
module_formats_same(indoc!(
r"
interface Foo exposes [] imports []"
module []"
));
}
@ -4781,12 +4781,14 @@ mod test_fmt {
module_formats_to(
indoc!(
r"
interface Foo exposes [] imports []
module []
a = 42 # Yay greetings"
),
indoc!(
r"
interface Foo exposes [] imports []
module []
a = 42 # Yay greetings
"
),
@ -4794,49 +4796,25 @@ mod test_fmt {
}
#[test]
fn multiline_interface() {
fn module_exposing() {
module_formats_same(indoc!(
r"
interface Foo
exposes []
imports []"
module [Bar, Baz, a, b]"
));
}
#[test]
fn interface_exposing() {
fn module_exposing_multiline() {
module_formats_same(indoc!(
r"
interface Foo
exposes [Bar, Baz, a, b]
imports []"
));
}
module [
Stuff,
Things,
somethingElse,
]
#[test]
fn interface_importing() {
module_formats_same(indoc!(
r"
interface Foo
exposes [Bar, Baz, a, b]
imports [Blah, Thing.{ foo, bar }, Stuff]"
));
}
#[test]
fn multi_line_interface() {
module_formats_same(indoc!(
r"
interface Foo
exposes [
Stuff,
Things,
somethingElse,
]
imports [
Blah,
Baz.{ stuff, things },
]"
import Blah
import Baz exposing [stuff, things]"
));
}
@ -4866,9 +4844,7 @@ mod test_fmt {
&format!(
indoc!(
r#"
interface Foo
exposes []
imports []
module []
# comment 1{space}
def = "" # comment 2{space}
@ -4879,9 +4855,7 @@ mod test_fmt {
),
indoc!(
r#"
interface Foo
exposes []
imports []
module []
# comment 1
def = "" # comment 2
@ -5700,7 +5674,7 @@ mod test_fmt {
module_formats_same(indoc!(
r"
interface Foo exposes [] imports []
module []
expect x == y
@ -5727,7 +5701,7 @@ mod test_fmt {
module_formats_same(indoc!(
r"
interface Foo exposes [] imports []
module []
expect
foo bar
@ -5831,7 +5805,7 @@ mod test_fmt {
fn ability_member_doc_comments() {
module_formats_same(indoc!(
r"
interface Foo exposes [] imports []
module []
A implements
## This is member ab
@ -5850,9 +5824,7 @@ mod test_fmt {
module_formats_same(indoc!(
r"
# hello world
interface Foo
exposes []
imports []
module []
"
));
@ -5876,6 +5848,17 @@ mod test_fmt {
));
}
#[test]
fn comments_before_exposes_preserved() {
module_formats_same(indoc!(
r"
module
# comment
[a, b]
"
));
}
#[test]
fn clauses_with_multiple_abilities() {
expr_formats_same(indoc!(

View file

@ -301,8 +301,8 @@ mod test_snapshots {
pass/def_without_newline.expr,
pass/destructure_tag_assignment.expr,
pass/empty_app_header.header,
pass/empty_module_header.header,
pass/empty_hosted_header.header,
pass/empty_interface_header.header,
pass/empty_list.expr,
pass/empty_package_header.header,
pass/empty_platform_header.header,
@ -333,7 +333,7 @@ mod test_snapshots {
pass/inline_import.expr,
pass/inline_ingested_file.expr,
pass/int_with_underscore.expr,
pass/interface_with_newline.header,
pass/module_with_newline.header,
pass/lambda_in_chain.expr,
pass/lambda_indent.expr,
pass/list_closing_indent_not_enough.expr,
@ -348,6 +348,7 @@ mod test_snapshots {
pass/minus_twelve_minus_five.expr,
pass/mixed_docs.expr,
pass/module_def_newline.moduledefs,
pass/module_multiline_exposes.header,
pass/multi_backpassing.expr,
pass/multi_backpassing_in_def.moduledefs,
pass/multi_backpassing_with_apply.expr,
@ -369,7 +370,6 @@ mod test_snapshots {
pass/nested_def_annotation.moduledefs,
pass/nested_def_without_newline.expr,
pass/nested_if.expr,
pass/nested_module.header,
pass/newline_after_equals.expr, // Regression test for https://github.com/roc-lang/roc/issues/51
pass/newline_after_mul.expr,
pass/newline_after_paren.expr,
@ -409,6 +409,7 @@ mod test_snapshots {
pass/outdented_colon_in_record.expr,
pass/outdented_list.expr,
pass/outdented_record.expr,
pass/old_interface_header.header,
pass/packed_singleton_list.expr,
pass/parens_in_type_def_apply.expr,
pass/parens_in_value_def_annotation.expr,