So we have this Perl6 we are looking to convert to RakuAST:
method setICalComponent(ICalComponentAncestry $_) {
my $to-parent;
$!icc = do {
when ICalComponent {
$to-parent = cast(ICalObject, $_);
$_;
}
default {
$to-parent = $_;
cast(ICalComponent, $_);
}
}
self.setICalObject($to-parent);
}
Given that I have no idea what the actual node names are, nor their intended use¸ this is how I would envision the conversion would look like:
$set-ical-component := RakuAST::MethodCreation.new(
'setICalComponent',
RakuAST::ParameterList.new(
RakuAST::Parameter.new( type => ICalConmponentAncestry, RakuAST::VariableReference.new('$_') )
),
RakuAST::Block.new(
RakuAST::StatementList.new(
RakuAST::ScopedVariableDeclaration.new('$to-parent')
),
RakuAST.Statement.new(
RakuAST.VariableAssignment.new(
RakuAST::VariableReference.new('$!icc'),
RakuAST::DoBlock.new(
RakuAST.Block.new(
RakuAST::StatementList.new(
RakuAST::WhenBlock(
expression => RakuAST::TypeReference('ICalComponent'),
RakuAST::Block.new(
RakuAST::StatementList(
RakuAST::VariableAssignment.new(
RakuAST::VariableRefernce.new('$to-parent'),
RAKUAST::CallRoutine.new(
'cast',
RakuAST::ParameterList.new(
# This, really should be a call to a function
# that returns either:
# - The type name of the implementor
# - The imlementor's RakuAST::TypeReference
RakuAST::TypeReference('ICalObject'),
RakuAST::VariableReference.new('$_')
),
),
),
RakuAST::VariableReference('$_')
)
)
),
RakuAST::DefaultBlock.new(
RakuAST::StatementList.new(
RakuAST::VariableAssignment.new(
RakuAST::VariableRefernce.new('$to-parent'),
RakuAST::VariableRefernce.new('$!');
),
RAKUAST::CallRoutine.new(
'cast',
RakuAST::ParameterList.new(
RakuAST::TypeRefernce('ICalComponent'),
RakuAST::VariableReference.new('$_')
),
),
)
)
)
),
),
)
RakuAST::CallMethod.new(
'setICalObject',
RakuAST::ParameterList.new(
RakuAST::VariableReference.new('$to-parent')
)
)
)
)
)
I see several cases of
RakuAST.VariableAssignment
, which I think you meantRakuAST::VariableAssignment
?