if i have a MemberDeclListSyntax or AttributeListSyntax, and i am iterating through their list items, how do i modify the list such that some of the elements are conditionally excluded? something like a compactMap operation?
as far as i could tell from browsing API you can only remove list items one at a time which doesn’t mix well with iteration, and this takes an Int index which is different from a SyntaxChildrenIndex so i don’t know what order (forward or reversed) i need to delete the children in.
override
func visit(_ list:MemberDeclListSyntax) -> Syntax
{
let filteredList:MemberDeclListSyntax = .init(list.filter({ _ in true }))
return super.visit(filteredList)
}
error: cannot convert value of type '[MemberDeclListSyntax.Element]' (aka 'Array<MemberDeclListItemSyntax>') to expected argument type 'Syntax'
let filteredList:MemberDeclListSyntax = .init(list.filter({ _ in true }))
^
error: value of optional type 'MemberDeclListSyntax?' must be unwrapped to a value of type 'MemberDeclListSyntax'
let filteredList:MemberDeclListSyntax = .init(list.filter({ _ in true }))
^
note: coalesce using '??' to provide a default when the optional value contains 'nil'
let filteredList:MemberDeclListSyntax = .init(list.filter({ _ in true }))
^
?? <#default value#>
note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
let filteredList:MemberDeclListSyntax = .init(list.filter({ _ in true }))
more generally, how do you delete things with a SyntaxRewriter? if a MemberDeclListSyntax would become empty, how do i drop the container?