func view_with_body(view: &DeclView, consume body: Syntax<Expr>, context: &QuoteContext) -> SyntaxResult<Decl>Rebuild the declaration with a new body block containing the given expression: a block expression re-embeds wholesale, anything else becomes the new body's trailing expression.
View Source
pub func view_with_body(view: &DeclView, consume body: Syntax<Expr>, context: &QuoteContext) -> SyntaxResult<Decl> {
if view.body_lower < 0 {
return lens_failure(code: "syntax.lens.no-body", message: "The viewed declaration has no body block")
}
let pieces: [SyntaxPiece] = []
push_atom_pieces(pieces: pieces, view: view, lower: 0, upper: view.body_lower)
pieces.push(.token(generated_syntax_token(kind: .left_brace, spelling: "{", leading: " ", source_id: 0 - 1, source_span: 0..<0, context: context)))
pieces.push(.splice(" ", [body.raw]))
pieces.push(.token(generated_syntax_token(kind: .right_brace, spelling: "}", leading: " ", source_id: 0 - 1, source_span: 0..<0, context: context)))
push_atom_pieces(pieces: pieces, view: view, lower: view.body_upper, upper: view.atoms.count)
SyntaxResult<Decl>(value: .some(Syntax<Decl>(raw: RawSyntax(category: .decl, pieces: pieces, trailing: "", group_when_spliced: false))), failure: .none)
}