Implement tuple type parsing

Also change some tests with newly relaxed indentation requirements, and remove an irrelevant test (since unindented close parens are now perfectly valid, the test is no longer useful).
This commit is contained in:
Joshua Warner 2022-11-22 19:08:17 -08:00
parent a6a90178ce
commit c6b5273144
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
22 changed files with 703 additions and 46 deletions

View file

@ -0,0 +1,4 @@
f : (Str)a -> (Str)a
f = \x -> x
f ("Str", 42)

View file

@ -0,0 +1,136 @@
Defs(
Defs {
tags: [
Index(2147483649),
],
regions: [
@0-32,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Annotation(
@0-1 Identifier(
"f",
),
@4-20 Function(
[
@4-10 Tuple {
fields: [
@5-8 Apply(
"",
"Str",
[],
),
],
ext: Some(
@9-10 BoundVariable(
"a",
),
),
},
],
@14-20 Tuple {
fields: [
@15-18 Apply(
"",
"Str",
[],
),
],
ext: Some(
@19-20 BoundVariable(
"a",
),
),
},
),
),
AnnotatedBody {
ann_pattern: @0-1 Identifier(
"f",
),
ann_type: @4-20 Function(
[
@4-10 Tuple {
fields: [
@5-8 Apply(
"",
"Str",
[],
),
],
ext: Some(
@9-10 BoundVariable(
"a",
),
),
},
],
@14-20 Tuple {
fields: [
@15-18 Apply(
"",
"Str",
[],
),
],
ext: Some(
@19-20 BoundVariable(
"a",
),
),
},
),
comment: None,
body_pattern: @21-22 Identifier(
"f",
),
body_expr: @25-32 Closure(
[
@26-27 Identifier(
"x",
),
],
@31-32 Var {
module_name: "",
ident: "x",
},
),
},
],
},
@34-47 SpaceBefore(
Apply(
@34-35 Var {
module_name: "",
ident: "f",
},
[
@36-47 Tuple(
[
@37-42 Str(
PlainLine(
"Str",
),
),
@44-46 Num(
"42",
),
],
),
],
Space,
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,4 @@
f : (Str)a -> (Str)a
f = \x -> x
f ("Str", 42)

View file

@ -0,0 +1,4 @@
f : I64 -> (I64, I64)
f = \x -> (x, x + 1)
f 42

View file

@ -0,0 +1,129 @@
Defs(
Defs {
tags: [
Index(2147483649),
],
regions: [
@0-42,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Annotation(
@0-1 Identifier(
"f",
),
@4-21 Function(
[
@4-7 Apply(
"",
"I64",
[],
),
],
@11-21 Tuple {
fields: [
@12-15 Apply(
"",
"I64",
[],
),
@17-20 Apply(
"",
"I64",
[],
),
],
ext: None,
},
),
),
AnnotatedBody {
ann_pattern: @0-1 Identifier(
"f",
),
ann_type: @4-21 Function(
[
@4-7 Apply(
"",
"I64",
[],
),
],
@11-21 Tuple {
fields: [
@12-15 Apply(
"",
"I64",
[],
),
@17-20 Apply(
"",
"I64",
[],
),
],
ext: None,
},
),
comment: None,
body_pattern: @22-23 Identifier(
"f",
),
body_expr: @26-42 Closure(
[
@27-28 Identifier(
"x",
),
],
@32-42 Tuple(
[
@33-34 Var {
module_name: "",
ident: "x",
},
@36-41 BinOps(
[
(
@36-37 Var {
module_name: "",
ident: "x",
},
@38-39 Plus,
),
],
@40-41 Num(
"1",
),
),
],
),
),
},
],
},
@44-48 SpaceBefore(
Apply(
@44-45 Var {
module_name: "",
ident: "f",
},
[
@46-48 Num(
"42",
),
],
Space,
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,4 @@
f : I64 -> (I64, I64)
f = \x -> (x, x + 1)
f 42

View file

@ -0,0 +1,4 @@
f : (Str, Str) -> (Str, Str)
f = \x -> x
f (1, 2)

View file

@ -0,0 +1,138 @@
Defs(
Defs {
tags: [
Index(2147483649),
],
regions: [
@0-39,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Annotation(
@0-1 Identifier(
"f",
),
@3-27 Function(
[
@3-13 Tuple {
fields: [
@4-7 Apply(
"",
"Str",
[],
),
@9-12 Apply(
"",
"Str",
[],
),
],
ext: None,
},
],
@17-27 Tuple {
fields: [
@18-21 Apply(
"",
"Str",
[],
),
@23-26 Apply(
"",
"Str",
[],
),
],
ext: None,
},
),
),
AnnotatedBody {
ann_pattern: @0-1 Identifier(
"f",
),
ann_type: @3-27 Function(
[
@3-13 Tuple {
fields: [
@4-7 Apply(
"",
"Str",
[],
),
@9-12 Apply(
"",
"Str",
[],
),
],
ext: None,
},
],
@17-27 Tuple {
fields: [
@18-21 Apply(
"",
"Str",
[],
),
@23-26 Apply(
"",
"Str",
[],
),
],
ext: None,
},
),
comment: None,
body_pattern: @28-29 Identifier(
"f",
),
body_expr: @32-39 Closure(
[
@33-34 Identifier(
"x",
),
],
@38-39 Var {
module_name: "",
ident: "x",
},
),
},
],
},
@41-49 SpaceBefore(
Apply(
@41-42 Var {
module_name: "",
ident: "f",
},
[
@43-49 Tuple(
[
@44-45 Num(
"1",
),
@47-48 Num(
"2",
),
],
),
],
Space,
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,4 @@
f: (Str, Str) -> (Str, Str)
f = \x -> x
f (1, 2)

View file

@ -0,0 +1,4 @@
f : (Str, Str)a -> (Str, Str)a
f = \x -> x
f (1, 2)

View file

@ -0,0 +1,154 @@
Defs(
Defs {
tags: [
Index(2147483649),
],
regions: [
@0-41,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Annotation(
@0-1 Identifier(
"f",
),
@3-29 Function(
[
@3-14 Tuple {
fields: [
@4-7 Apply(
"",
"Str",
[],
),
@9-12 Apply(
"",
"Str",
[],
),
],
ext: Some(
@13-14 BoundVariable(
"a",
),
),
},
],
@18-29 Tuple {
fields: [
@19-22 Apply(
"",
"Str",
[],
),
@24-27 Apply(
"",
"Str",
[],
),
],
ext: Some(
@28-29 BoundVariable(
"a",
),
),
},
),
),
AnnotatedBody {
ann_pattern: @0-1 Identifier(
"f",
),
ann_type: @3-29 Function(
[
@3-14 Tuple {
fields: [
@4-7 Apply(
"",
"Str",
[],
),
@9-12 Apply(
"",
"Str",
[],
),
],
ext: Some(
@13-14 BoundVariable(
"a",
),
),
},
],
@18-29 Tuple {
fields: [
@19-22 Apply(
"",
"Str",
[],
),
@24-27 Apply(
"",
"Str",
[],
),
],
ext: Some(
@28-29 BoundVariable(
"a",
),
),
},
),
comment: None,
body_pattern: @30-31 Identifier(
"f",
),
body_expr: @34-41 Closure(
[
@35-36 Identifier(
"x",
),
],
@40-41 Var {
module_name: "",
ident: "x",
},
),
},
],
},
@43-51 SpaceBefore(
Apply(
@43-44 Var {
module_name: "",
ident: "f",
},
[
@45-51 Tuple(
[
@46-47 Num(
"1",
),
@49-50 Num(
"2",
),
],
),
],
Space,
),
[
Newline,
Newline,
],
),
)

View file

@ -0,0 +1,4 @@
f: (Str, Str)a -> (Str, Str)a
f = \x -> x
f (1, 2)

View file

@ -186,6 +186,8 @@ mod test_parse {
pass/list_patterns.expr,
pass/lowest_float.expr,
pass/lowest_int.expr,
pass/tuple_type.expr,
pass/tuple_type_ext.expr,
pass/malformed_ident_due_to_underscore.expr,
pass/malformed_pattern_field_access.expr, // See https://github.com/roc-lang/roc/issues/399
pass/malformed_pattern_module_name.expr, // See https://github.com/roc-lang/roc/issues/399
@ -302,6 +304,8 @@ mod test_parse {
pass/when_with_negative_numbers.expr,
pass/when_with_numbers.expr,
pass/when_with_records.expr,
pass/function_with_tuple_type.expr,
pass/function_with_tuple_ext_type.expr,
pass/where_clause_function.expr,
pass/where_clause_multiple_bound_abilities.expr,
pass/where_clause_multiple_has_across_newlines.expr,