diff --git a/crates/codegen/src/expr.rs b/crates/codegen/src/expr.rs index 50641a9..8cdbaca 100644 --- a/crates/codegen/src/expr.rs +++ b/crates/codegen/src/expr.rs @@ -200,8 +200,10 @@ impl GenRust for Postfix { for (name, expr) in fields { cg.add(&name.get_rust()); - cg.add(": "); - expr.gen_rust(ctx, cg); + if let Some(expr) = expr { + cg.add(": "); + expr.gen_rust(ctx, cg); + } cg.add(","); } diff --git a/crates/parser/src/ast/expr.rs b/crates/parser/src/ast/expr.rs index 13365c3..969cf21 100644 --- a/crates/parser/src/ast/expr.rs +++ b/crates/parser/src/ast/expr.rs @@ -56,7 +56,7 @@ pub enum Postfix { inner: String, delimiter: MacroDelimiter, }, - StructCall(Vec<(Identifier, Expression)>), + StructCall(Vec<(Identifier, Option)>), Assign(String, Box), Index(Expression), As(TypeExpr), diff --git a/crates/parser/src/grammar.pest b/crates/parser/src/grammar.pest index 4a45207..cf4df27 100644 --- a/crates/parser/src/grammar.pest +++ b/crates/parser/src/grammar.pest @@ -523,7 +523,7 @@ macro_call_bracket = { "!" ~ "[" ~ macro_inner_v* ~ "]" } macro_call_brace = { "!" ~ "{" ~ macro_inner_v* ~ "}" } struct_field_decl = { - identifier ~ ":" ~ expr + identifier ~ (":" ~ expr)? } struct_px = { diff --git a/crates/parser/src/parser/common/expr.rs b/crates/parser/src/parser/common/expr.rs index 12f076f..b3236d8 100644 --- a/crates/parser/src/parser/common/expr.rs +++ b/crates/parser/src/parser/common/expr.rs @@ -155,7 +155,7 @@ impl<'a> TryFrom> for Postfix { let mut pi = p.into_inner(); Ok(( Identifier::try_from(pi.next().unwrap())?, - Expression::try_from(pi.next().unwrap()).get()?, + pi.next().map(Expression::try_from).transpose().get()?, )) }))),