support multiline suffixed statements

This commit is contained in:
Luke Boswell 2024-03-24 15:12:19 +11:00
parent cfa7490b86
commit 56d91ce74c
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
15 changed files with 455 additions and 116 deletions

View file

@ -0,0 +1 @@
Expr(BadExprEnd(@14), @0)

View file

@ -0,0 +1,2 @@
Stdout.line!
"Not the same ident, shouldn't parse as an single expr"

View file

@ -0,0 +1 @@
Expr(BadExprEnd(@13), @0)

View file

@ -0,0 +1,3 @@
line! "Foo"
read "Bar"

View file

@ -1,2 +0,0 @@
A.x! "Foo" []
B.y! "Bar" \a -> x + y

View file

@ -1,91 +0,0 @@
Defs {
tags: [
Index(2147483648),
Index(2147483649),
],
regions: [
@0-19,
@20-45,
],
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: [
Body(
@0-4 RecordDestructure(
[],
),
@0-19 Apply(
@0-4 Suffixed(
Var {
module_name: "A",
ident: "x",
},
),
[
@8-13 Str(
PlainLine(
"Foo",
),
),
@17-19 List(
[],
),
],
Space,
),
),
Body(
@20-24 RecordDestructure(
[],
),
@20-45 Apply(
@20-24 Suffixed(
Var {
module_name: "B",
ident: "y",
},
),
[
@27-32 Str(
PlainLine(
"Bar",
),
),
@34-45 Closure(
[
@35-36 Identifier(
"a",
),
],
@40-45 BinOps(
[
(
@40-41 Var {
module_name: "",
ident: "x",
},
@42-43 Plus,
),
],
@44-45 Var {
module_name: "",
ident: "y",
},
),
),
],
Space,
),
),
],
}

View file

@ -1,2 +0,0 @@
A.x! "Foo" []
B.y! "Bar" \a -> x + y

View file

@ -0,0 +1,7 @@
# valid as a single line
A.x! "Foo" []
# valid as a multi-line, with increased ident
B.y!
"Bar"
\a -> x + y

View file

@ -0,0 +1,108 @@
Defs {
tags: [
Index(2147483648),
Index(2147483649),
],
regions: [
@25-44,
@92-131,
],
space_before: [
Slice(start = 0, length = 1),
Slice(start = 1, length = 3),
],
space_after: [
Slice(start = 1, length = 0),
Slice(start = 4, length = 0),
],
spaces: [
LineComment(
" valid as a single line",
),
Newline,
Newline,
LineComment(
" valid as a multi-line, with increased ident",
),
],
type_defs: [],
value_defs: [
Body(
@25-29 RecordDestructure(
[],
),
@25-44 Apply(
@25-29 Suffixed(
Var {
module_name: "A",
ident: "x",
},
),
[
@33-38 Str(
PlainLine(
"Foo",
),
),
@42-44 List(
[],
),
],
Space,
),
),
Body(
@92-96 RecordDestructure(
[],
),
@92-131 Apply(
@92-96 Suffixed(
Var {
module_name: "B",
ident: "y",
},
),
[
@106-111 SpaceBefore(
Str(
PlainLine(
"Bar",
),
),
[
Newline,
],
),
@120-131 SpaceBefore(
Closure(
[
@121-122 Identifier(
"a",
),
],
@126-131 BinOps(
[
(
@126-127 Var {
module_name: "",
ident: "x",
},
@128-129 Plus,
),
],
@130-131 Var {
module_name: "",
ident: "y",
},
),
),
[
Newline,
],
),
],
Space,
),
),
],
}

View file

@ -0,0 +1,7 @@
# valid as a single line
A.x! "Foo" []
# valid as a multi-line, with increased ident
B.y!
"Bar"
\a -> x + y

View file

@ -0,0 +1,14 @@
app "desugar-bang"
packages {
cli: "../basic-cli/platform/main.roc",
}
imports [
cli.Stdout,
]
provides [main] to cli
main =
Stdout.line! "Foo"
"Bar"
|> Stdout.line

View file

@ -0,0 +1,190 @@
Full {
header: Module {
comments: [],
header: App(
AppHeader {
before_name: [],
name: @4-18 PlainLine(
"desugar-bang",
),
packages: Some(
KeywordItem {
keyword: Spaces {
before: [
Newline,
],
item: PackagesKeyword,
after: [],
},
item: Collection {
items: [
@42-79 SpaceBefore(
PackageEntry {
shorthand: "cli",
spaces_after_shorthand: [],
package_name: @47-79 PackageName(
"../basic-cli/platform/main.roc",
),
},
[
Newline,
],
),
],
final_comments: [
Newline,
],
},
},
),
imports: Some(
KeywordItem {
keyword: Spaces {
before: [
Newline,
],
item: ImportsKeyword,
after: [],
},
item: Collection {
items: [
@109-119 SpaceBefore(
Package(
"cli",
ModuleName(
"Stdout",
),
[],
),
[
Newline,
],
),
],
final_comments: [
Newline,
],
},
},
),
provides: ProvidesTo {
provides_keyword: Spaces {
before: [
Newline,
],
item: ProvidesKeyword,
after: [],
},
entries: [
@141-145 ExposedName(
"main",
),
],
types: None,
to_keyword: Spaces {
before: [],
item: ToKeyword,
after: [],
},
to: @150-153 ExistingPackage(
"cli",
),
},
},
),
},
module_defs: Defs {
tags: [
Index(2147483648),
],
regions: [
@155-184,
],
space_before: [
Slice(start = 0, length = 2),
],
space_after: [
Slice(start = 2, length = 0),
],
spaces: [
Newline,
Newline,
],
type_defs: [],
value_defs: [
Body(
@155-159 Identifier(
"main",
),
@155-184 Defs(
Defs {
tags: [
Index(2147483648),
],
regions: [
@155-184,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Body(
@155-184 RecordDestructure(
[],
),
@155-184 Apply(
@166-178 Suffixed(
Var {
module_name: "Stdout",
ident: "line",
},
),
[
@179-184 Str(
PlainLine(
"Foo",
),
),
],
Space,
),
),
],
},
@190-215 SpaceBefore(
BinOps(
[
(
@190-195 SpaceAfter(
Str(
PlainLine(
"Bar",
),
),
[
Newline,
],
),
@201-203 Pizza,
),
],
@204-215 Var {
module_name: "Stdout",
ident: "line",
},
),
[
Newline,
Newline,
],
),
),
),
],
},
}

View file

@ -0,0 +1,15 @@
app "desugar-bang"
packages {
cli: "../basic-cli/platform/main.roc",
}
imports [
cli.Stdout,
]
provides [main] to cli
main =
Stdout.line! "Foo"
"Bar"
|> Stdout.line

View file

@ -224,6 +224,8 @@ mod test_snapshots {
fail/record_type_open_indent.expr,
fail/record_type_tab.expr,
fail/single_no_end.expr,
fail/suffixed_same_ident.expr,
fail/suffixed_single_def.expr,
fail/tab_crash.header,
fail/tag_union_end.expr,
fail/tag_union_lowercase_tag_name.expr,
@ -442,8 +444,9 @@ mod test_snapshots {
pass/sub_var_with_spaces.expr,
pass/sub_with_spaces.expr,
pass/suffixed.expr,
pass/suffixed_def_optional_bang.moduledefs,
pass/suffixed_multiple_defs.moduledefs,
pass/suffixed_nested.expr,
pass/suffixed_one_def.full,
pass/tag_pattern.expr,
pass/ten_times_eleven.expr,
pass/three_arg_closure.expr,