mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Merge pull request #2855 from rtfeldman/outdented-parse
Make sure outdented records parse
This commit is contained in:
commit
953c7aa9ff
8 changed files with 177 additions and 3 deletions
|
@ -2,7 +2,9 @@ use crate::ast::{
|
||||||
AssignedField, Collection, CommentOrNewline, Def, Expr, ExtractSpaces, Has, Pattern, Spaceable,
|
AssignedField, Collection, CommentOrNewline, Def, Expr, ExtractSpaces, Has, Pattern, Spaceable,
|
||||||
TypeAnnotation, TypeDef, TypeHeader, ValueDef,
|
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::ident::{lowercase_ident, parse_ident, Ident};
|
||||||
use crate::keyword;
|
use crate::keyword;
|
||||||
use crate::parser::{
|
use crate::parser::{
|
||||||
|
@ -2591,14 +2593,15 @@ fn record_help<'a>(
|
||||||
and!(
|
and!(
|
||||||
trailing_sep_by0(
|
trailing_sep_by0(
|
||||||
word1(b',', ERecord::End),
|
word1(b',', ERecord::End),
|
||||||
space0_around_ee(
|
space0_before_optional_after(
|
||||||
loc!(record_field_help(min_indent)),
|
loc!(record_field_help(min_indent)),
|
||||||
min_indent,
|
min_indent,
|
||||||
ERecord::IndentEnd,
|
ERecord::IndentEnd,
|
||||||
ERecord::IndentEnd
|
ERecord::IndentEnd
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
space0_e(min_indent, ERecord::IndentEnd)
|
// Allow outdented closing braces
|
||||||
|
space0_e(0, ERecord::IndentEnd)
|
||||||
),
|
),
|
||||||
word1(b'}', ERecord::End)
|
word1(b'}', ERecord::End)
|
||||||
)
|
)
|
||||||
|
|
|
@ -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,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
|
@ -0,0 +1,4 @@
|
||||||
|
x = foo (baz {
|
||||||
|
bar: blah
|
||||||
|
})
|
||||||
|
x
|
|
@ -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,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
|
@ -0,0 +1,4 @@
|
||||||
|
a = [
|
||||||
|
1, 2, 3
|
||||||
|
]
|
||||||
|
a
|
|
@ -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,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
|
@ -0,0 +1,4 @@
|
||||||
|
x = foo {
|
||||||
|
bar: blah
|
||||||
|
}
|
||||||
|
x
|
|
@ -218,6 +218,9 @@ mod test_parse {
|
||||||
pass/opaque_reference_pattern.expr,
|
pass/opaque_reference_pattern.expr,
|
||||||
pass/opaque_reference_pattern_with_arguments.expr,
|
pass/opaque_reference_pattern_with_arguments.expr,
|
||||||
pass/ops_with_newlines.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/packed_singleton_list.expr,
|
||||||
pass/parenthetical_apply.expr,
|
pass/parenthetical_apply.expr,
|
||||||
pass/parenthetical_basic_field.expr,
|
pass/parenthetical_basic_field.expr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue