Support parsing opaque destructures as first item in nested body

Closes #3198
This commit is contained in:
Ayaz Hafiz 2022-07-22 16:35:02 -04:00
parent 53e7a41f27
commit b04764bdd6
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
5 changed files with 81 additions and 1 deletions

View File

@ -1045,6 +1045,10 @@ impl<'a> Expr<'a> {
pub fn is_tag(&self) -> bool {
matches!(self, Expr::Tag(_))
}
pub fn is_opaque(&self) -> bool {
matches!(self, Expr::OpaqueRef(_))
}
}
macro_rules! impl_extract_spaces {

View File

@ -413,7 +413,9 @@ impl<'a> ExprState<'a> {
let fail = EExpr::BadOperator(opchar, loc_op.region.start());
Err(fail)
} else if !self.expr.value.is_tag() && !self.arguments.is_empty() {
} else if !(self.expr.value.is_tag() || self.expr.value.is_opaque())
&& !self.arguments.is_empty()
{
let region = Region::across_all(self.arguments.iter().map(|v| &v.region));
Err(argument_error(region, loc_op.region.start()))

View File

@ -0,0 +1,71 @@
Defs(
Defs {
tags: [
Index(2147483648),
],
regions: [
@0-22,
],
space_before: [
Slice(start = 0, length = 0),
],
space_after: [
Slice(start = 0, length = 0),
],
spaces: [],
type_defs: [],
value_defs: [
Body(
@0-6 Apply(
@0-6 OpaqueRef(
"@Thunk",
),
[
@7-9 Identifier(
"it",
),
],
),
@12-22 Apply(
@12-14 Var {
module_name: "",
ident: "id",
},
[
@16-21 ParensAround(
Apply(
@16-18 OpaqueRef(
"@A",
),
[
@19-21 Record(
[],
),
],
Space,
),
),
],
Space,
),
),
],
},
@23-28 SpaceBefore(
Apply(
@23-25 Var {
module_name: "",
ident: "it",
},
[
@26-28 Record(
[],
),
],
Space,
),
[
Newline,
],
),
)

View File

@ -0,0 +1,2 @@
@Thunk it = id (@A {})
it {}

View File

@ -209,6 +209,7 @@ mod test_parse {
pass/one_minus_two.expr,
pass/one_plus_two.expr,
pass/one_spaced_def.expr,
pass/opaque_destructure_first_item_in_body.expr,
pass/opaque_has_abilities.expr,
pass/opaque_reference_expr_with_arguments.expr,
pass/opaque_reference_expr.expr,