Skip to content

Commit a0a48fa

Browse files
committed
First stab at documenting RakuAST::Type::Subset
1 parent ba34839 commit a0a48fa

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

‎doc/Type/RakuAST/Type.rakudoc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ They currently are (in alphabetical order):
1717
=item L<C<RakuAST::Type::Parameterized>|/type/Type/Parameterized>
1818
=item L<C<RakuAST::Type::Setting>|/type/Type/Setting>
1919
=item L<C<RakuAST::Type::Simple>|/type/Type/Simple>
20+
=item L<C<RakuAST::Type::Subset>|/type/Type/Subset>
2021

2122
=end pod
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
=begin pod :kind("Type") :subkind("class") :category("basic")
2+
3+
=TITLE class RakuAST::Type::Subset
4+
5+
=SUBTITLE Represent a type without any additional features
6+
7+
class RakuAST::Type::Subset { }
8+
9+
The C<RakuAST::Type::Subset> class represents an C<enum> specification.
10+
11+
=head2 Object introspection
12+
13+
C<RakuAST::Type::Subset> object is typically created when parsing
14+
Raku Programming Language code. So most developers will only need to
15+
know how to introspect the objects created.
16+
17+
=head3 is-coercive
18+
19+
=begin code :preamble<my $subset>
20+
say $subset.is-coercive; # True or False
21+
=end code
22+
23+
The C<is-coercive> method returns whether the "of" type is coercive.
24+
25+
=head3 name
26+
27+
=begin code :preamble<my $subset>
28+
say $subset.name; # RakuAST::Name.from-identifier("Foo")
29+
=end code
30+
31+
Returns the C<L<RakuAST::Name>|/type/RakuAST/Name> object of this
32+
C<RakuAST::Type::Subset> object.
33+
34+
=head3 of
35+
36+
=begin code :preamble<my $subset>
37+
say $subset.of; # RakuAST::Type::Simple.from-identifier("Int")
38+
=end code
39+
40+
Returns the C<RakuAST::Type>> object of this C<RakuAST::Type::Subset>
41+
to which the C<enum> B<values> are constrained.
42+
43+
=head3 scope
44+
45+
=begin code :preamble<my $subset>
46+
say $subset.scope; # my
47+
=end code
48+
49+
Returns the scope of the C<RakuAST::Type::Subset> object as a string.
50+
Usually "our", but can also be "my" or "anon".
51+
52+
=head3 traits
53+
54+
=begin code :preamble<my $subset>
55+
dd $subset.traits; # ()
56+
=end code
57+
58+
Returns a (possibly empty) list of L<C<RakuAST::Trait>|/Type/RakuAST/Trait>
59+
object that were applied to the C<enum>.
60+
61+
=head3 where
62+
63+
=begin code :preamble<my $subset>
64+
dd $subset.where; # * %% 2
65+
=end code
66+
67+
Returns the L<C<RakuAST::Expression>|/Type/RakuAST/Expression> object
68+
that represents the names and values of this C<enum>.
69+
70+
=head2 Object creation
71+
72+
There are is only one way to reate a C<RakuAST::Type::Subset> object.
73+
74+
=head3 new
75+
76+
=begin code
77+
my $subset = RakuAST::Type::Subset.new(
78+
scope => "my",
79+
name => RakuAST::Name.from-identifier('Foo'),
80+
of => RakuAST::Type::Simple.from-identifier('Int'),
81+
where => RakuAST::ApplyInfix.new(
82+
left => RakuAST::Term::Whatever.new,
83+
infix => RakuAST::Infix.new('%%'),
84+
right => RakuAST::IntLiteral.new(2)
85+
),
86+
);
87+
dd $subset; # my Int subset Foo where * %% 2
88+
=end code
89+
90+
Creates a C<RakuAST::Type::Subset> object from the given named arguments.
91+
92+
=item scope - string indicating scope (my/our/anon), default: "our"
93+
=item of - RakuAST::Type object constraining values, default: none
94+
=item name - RakuAST::Name object with the name of the enum, default: ""
95+
=item where - RakuAST::Expression to constrain values with, default: none
96+
=item traits - List of RakuAST::Trait objects, default: none
97+
98+
=end pod

0 commit comments

Comments
 (0)