TOC Index
Provide leading/trailing doc functionality
role RakuAST::Doc::DeclaratorTarget { }
The RakuAST::Doc::DeclaratorTarget role is done by objects that support leading and trailing documentation.
Support for RakuAST functionality is available in language version 6.e+ and was added in Rakudo compiler release 2023.02. In earlier language versions it is only available when specifying:
use experimental :rakuast;
Objects doing the RakuAST::Doc::DeclaratorTarget role are typically created when parsing Raku Programming Language code for objects that allow leading (#|) and trailing (#=) documentation on them. So most developers will only need to know how to introspect the objects created.
with $target.WHY { say "leading: $_.leading()"; say "trailing: $_.trailing()";}
Returns the RakuAST::Doc::Declarator object containing the declarator documentation, if any.
Each object doing the RakuAST::Doc::DeclaratorTarget role has its own why of creation. So there's nothing general that can be said about it here.
$target.set-WHY($declarator);
Set the RakuAST::Doc::Declarator object to be associated.
my $WHY := $target.cut-WHY;
Removes the RakuAST::Doc::Declarator object, if any. Intended to be used when deparsing / stringification to prevent an infinite loop because the RakuAST::Doc::Declarator object points to its target, and the other way around. Usually called on a clone of the original target.
$target.set-leading; # reset$target.set-leading("foo", "bar");
Set the leading documentation. If no arguments are specified, reset to not having any leading documentation. Creates a RakuAST::Doc::Declarator object and sets it in the .WHY if there wasn't one already.
$target.add-leading("additional");
Add a line to the leading documentation. Creates a RakuAST::Doc::Declarator object and sets it in the .WHY if there wasn't one already.
$target.set-trailing; # reset$target.set-trailing("foo", "bar");
Set the trailing documentation. If no arguments are specified, reset to not having any trailing documentation. Creates a RakuAST::Doc::Declarator object and sets it in the .WHY if there wasn't one already.
$target.add-trailing("additional");
Add a line to the trailing documentation. Creates a RakuAST::Doc::Declarator object and sets it in the .WHY if there wasn't one already.