Skip to content

Commit e740251

Browse files
committed
First stab at documenting RakuAST::Doc::Declarator
1 parent 077648d commit e740251

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
=begin pod :kind("Type") :subkind("class") :category("basic")
2+
3+
=TITLE class RakuAST::Doc::Declarator
4+
5+
=SUBTITLE
6+
7+
class RakuAST::Doc::Declarator { }
8+
9+
The C<RakuAST::Doc::Declarator> class contains the leading and trailing
10+
documentation of an object doing the C<RakuAST::Doc::DeclaratorTarget>
11+
role.
12+
13+
Support for C<RakuAST> functionality is available in language version
14+
C<6.e+> and was added in Rakudo compiler release 2023.02. In earlier
15+
language versions it is only available when specifying:
16+
17+
use experimental :rakuast;
18+
19+
=head2 Object introspection
20+
21+
C<RakuAST::Doc::Declarator> objects are typically created when parsing
22+
Raku Programming Language code that has objects with leading (C<#|>)
23+
and trailing (C<#=>) documentation on it. So most developers will only
24+
need to know how to introspect the objects created.
25+
26+
=head3 method WHEREFORE
27+
28+
say "attached to a $declarator.WHEREFORE.^name() object";
29+
30+
Returns the object for which this object contains the declarator
31+
documentation.
32+
33+
=head3 method leading
34+
35+
.say for $declarator.leading;
36+
37+
Returns the lines of the leading declarator documentation (one
38+
for each line with C<#|> if the object was created from parsing
39+
Raku source code.
40+
41+
=head3 method trailing
42+
43+
.say for $declarator.trailing;
44+
45+
Returns the lines of the trailing declarator documentation (one
46+
for each line with C<#=> if the object was created from parsing
47+
Raku source code.
48+
49+
=head3 method raku
50+
51+
# method .gist falls back to .raku
52+
say $declarator; # RakuAST::Doc::Declarator.new(...
53+
54+
Returns the string that is needed for the creation of the block
55+
using C<RakuAST> calls.
56+
57+
=head1 Object creation
58+
59+
One seldomly creates C<RakuAST::Doc::Declarator> objects directly. This
60+
documentation is intended for those few people who'd like to devise
61+
their own way of programmatically building a C<RakuAST::Doc::Declarator>
62+
object.
63+
64+
=head2 method new
65+
66+
method new(
67+
Str:D :$WHEREFORE, # the associated RakuAST object
68+
:@leading, # leading lines of documentation
69+
:@trailing # trailing lines of documentation
70+
);
71+
72+
The C<new> method can be called to create a new C<RakuAST::Doc::Declarator>
73+
object. It only takes named arguments.
74+
75+
=begin code :lang<raku>
76+
# there is no syntax for creating just a ::Declarator object
77+
78+
my $declarator = RakuAST::Doc::Declarator.new(
79+
:WHEREFORE(RakuAST::VarDeclaration::Simple.new(...),
80+
:leading("line 1 leading","line 2 leading"),
81+
:trailing("line 1 trailing","line 2 trailing")
82+
);
83+
=end code
84+
85+
Note that the leading and trailing documentation may contain any
86+
left margin whitespace.
87+
88+
=head3 :WHEREFORE
89+
90+
The C<RakuAST> object for which this declarator contains the documentation.
91+
92+
=head3 :leading
93+
94+
A C<Positional> with the lines of leading documentation strings.
95+
96+
=head3 :trailing
97+
98+
A C<Positional> with the lines of trailing documentation strings.
99+
100+
=head1 Object modification
101+
102+
=head2 method set-WHEREFORE
103+
104+
$declarator.set-WHEREFORE($object);
105+
106+
Set the object for which the C<RakuAST::Doc::Declarator> object contains
107+
the documentation.
108+
109+
=head2 method set-leading
110+
111+
$declarator.set-leading; # reset
112+
$declarator.set-leading("foo", "bar");
113+
114+
Set the leading documentation. If no arguments are specified, reset to
115+
not having any leading documentation.
116+
117+
=head2 method add-leading
118+
119+
$declarator.add-leading("additional");
120+
121+
Add a line to the leading documentation.
122+
123+
=head2 method set-trailing
124+
125+
$declarator.set-trailing; # reset
126+
$declarator.set-trailing("foo", "bar");
127+
128+
Set the trailing documentation. If no arguments are specified, reset to
129+
not having any trailing documentation.
130+
131+
=head2 method add-trailing
132+
133+
$declarator.add-trailing("additional");
134+
135+
Add a line to the trailing documentation.
136+
137+
=end pod

0 commit comments

Comments
 (0)