Merge pull request #2855 from rtfeldman/outdented-parse

Make sure outdented records parse
This commit is contained in:
Richard Feldman 2022-04-14 13:53:11 -04:00 committed by GitHub
commit 953c7aa9ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 177 additions and 3 deletions

View File

@ -2,7 +2,9 @@ use crate::ast::{
AssignedField, Collection, CommentOrNewline, Def, Expr, ExtractSpaces, Has, Pattern, Spaceable,
TypeAnnotation, TypeDef, TypeHeader, ValueDef,
};
use crate::blankspace::{space0_after_e, space0_around_ee, space0_before_e, space0_e};
use crate::blankspace::{
space0_after_e, space0_around_ee, space0_before_e, space0_before_optional_after, space0_e,
};
use crate::ident::{lowercase_ident, parse_ident, Ident};
use crate::keyword;
use crate::parser::{
@ -2591,14 +2593,15 @@ fn record_help<'a>(
and!(
trailing_sep_by0(
word1(b',', ERecord::End),
space0_around_ee(
space0_before_optional_after(
loc!(record_field_help(min_indent)),
min_indent,
ERecord::IndentEnd,
ERecord::IndentEnd
),
),
space0_e(min_indent, ERecord::IndentEnd)
// Allow outdented closing braces
space0_e(0, ERecord::IndentEnd)
),
word1(b'}', ERecord::End)
)

View File

@ -0,0 +1,62 @@
Defs(
[
@0-29 Value(
Body(
@0-1 Identifier(
"x",
),
@4-29 Apply(
@4-7 Var {
module_name: "",
ident: "foo",
},
[
@9-28 ParensAround(
Apply(
@9-12 Var {
module_name: "",
ident: "baz",
},
[
@13-28 Record(
Collection {
items: [
@17-26 SpaceBefore(
RequiredValue(
@17-20 "bar",
[],
@22-26 Var {
module_name: "",
ident: "blah",
},
),
[
Newline,
],
),
],
final_comments: [
Newline,
],
},
),
],
Space,
),
),
],
Space,
),
),
),
],
@30-31 SpaceBefore(
Var {
module_name: "",
ident: "x",
},
[
Newline,
],
),
)

View File

@ -0,0 +1,4 @@
x = foo (baz {
bar: blah
})
x

View File

@ -0,0 +1,43 @@
Defs(
[
@0-17 Value(
Body(
@0-1 Identifier(
"a",
),
@4-17 List(
Collection {
items: [
@8-9 SpaceBefore(
Num(
"1",
),
[
Newline,
],
),
@11-12 Num(
"2",
),
@14-15 Num(
"3",
),
],
final_comments: [
Newline,
],
},
),
),
),
],
@18-19 SpaceBefore(
Var {
module_name: "",
ident: "a",
},
[
Newline,
],
),
)

View File

@ -0,0 +1,4 @@
a = [
1, 2, 3
]
a

View File

@ -0,0 +1,51 @@
Defs(
[
@0-23 Value(
Body(
@0-1 Identifier(
"x",
),
@4-23 Apply(
@4-7 Var {
module_name: "",
ident: "foo",
},
[
@8-23 Record(
Collection {
items: [
@12-21 SpaceBefore(
RequiredValue(
@12-15 "bar",
[],
@17-21 Var {
module_name: "",
ident: "blah",
},
),
[
Newline,
],
),
],
final_comments: [
Newline,
],
},
),
],
Space,
),
),
),
],
@24-25 SpaceBefore(
Var {
module_name: "",
ident: "x",
},
[
Newline,
],
),
)

View File

@ -0,0 +1,4 @@
x = foo {
bar: blah
}
x

View File

@ -218,6 +218,9 @@ mod test_parse {
pass/opaque_reference_pattern.expr,
pass/opaque_reference_pattern_with_arguments.expr,
pass/ops_with_newlines.expr,
pass/outdented_list.expr,
pass/outdented_record.expr,
pass/outdented_app_with_record.expr,
pass/packed_singleton_list.expr,
pass/parenthetical_apply.expr,
pass/parenthetical_basic_field.expr,