Skip to content

Commit 8d609da

Browse files
committed
Merge branch 'master' of github.com:perl6/doc
2 parents 272df19 + b53d3e0 commit 8d609da

File tree

6 files changed

+88
-107
lines changed

6 files changed

+88
-107
lines changed

META.info

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name" : "p6doc",
33
"version" : "*",
44
"description" : "Perl 6 documentation (tools and docs)",
5-
"depends" : [ "URI" ],
5+
"depends" : [ "URI", "File::Temp" ],
66
"provides" : {
77
"Perl6::Type" : "lib/Perl6/Type.pm",
88
"Perl6::TypeGraph" : "lib/Perl6/TypeGraph.pm",

htmlify.p6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ sub MAIN(
114114
$*DEBUG = $debug;
115115

116116
say 'Creating html/ subdirectories ...';
117-
for '', <type language routine images syntax> {
117+
for flat '', <type language routine images syntax> {
118118
mkdir "html/$_" unless "html/$_".IO ~~ :e;
119119
}
120120

lib/Language/classtut.pod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ X<|traits, is rw>
166166
The C<is rw> trait causes the generated accessor method to return something
167167
external code can modify to change the value of the attribute.
168168
169+
You can also supply default values to attributes (which works equally for
170+
those with and without accessors):
171+
172+
has Bool $.done = False;
173+
174+
The assignment is carried out at object build time. The right-hand side is
175+
evaluated at that time, and can even reference earlier attributes:
176+
177+
has Task @!dependencies;
178+
has $.ready = not @!dependencies;
179+
169180
=head1 Static fields?
170181
171182
Perl 6 has no B<static> keyword. Nevertheless any class may declare anything
@@ -304,6 +315,22 @@ as the bind targets for C<BUILD>'s parameters. Zero-boilerplate
304315
initialization! See L<objects|/language/objects#Object Construction> for
305316
more information.
306317
318+
The C<BUILD> method is responsible for initializing all attributes, it must
319+
handle default values too:
320+
321+
has &!callback;
322+
has @!dependencies;
323+
has Bool ($.done, $.ready);
324+
submethod BUILD(
325+
:@!callback,
326+
:@!dependencies,
327+
:$!done = False,
328+
:$!ready = not @!dependencies
329+
) { }
330+
331+
See L<Object Construction|/language/objects#Object Construction> for more
332+
options to influence object construction and attribute initialization.
333+
307334
=head1 Consuming our class
308335
309336
After creating a class, you can create instances of the class. Declaring a

lib/Language/grammars.pod

Lines changed: 4 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -70,107 +70,12 @@ into effect for the Regex:
7070
7171
=SUBTITLE Group of named regexes that form a formal grammar
7272
73-
class Grammar is Cursor { }
74-
75-
C<Grammar> is the superclass that classes automatically get when they are
76-
declared with the C<grammar> keyword instead of C<class>. Grammars should
77-
only be used to parse text; if you wish to extract complex data, an L<action
78-
object|/language/grammars#Action_Objects> is recommended to be used in
73+
L<Grammar|/type/Grammar> is the superclass that classes automatically get when
74+
they are declared with the C<grammar> keyword instead of C<class>. Grammars
75+
should only be used to parse text; if you wish to extract complex data, an
76+
L<action object|/language/grammars#Action_Objects> is recommended to be used in
7977
conjunction with the grammar.
8078
81-
=begin code :allow<B L>
82-
B<grammar> CSV {
83-
token TOP { [ <line> \n? ]+ }
84-
token line {
85-
^^ # Beginning of a line
86-
<value>* % \, # Any number of <value>s with commas in between them
87-
$$ # End of a line
88-
}
89-
token value {
90-
[
91-
| <-[",\n]> # Anything not a double quote, comma or newline
92-
| <quoted-text> # Or some quoted text
93-
]* # Any number of times
94-
}
95-
token quoted-text {
96-
\"
97-
[
98-
| <-["\\]> # Anything not a " or \
99-
| '\"' # Or \", an escaped quotation mark
100-
]* # Any number of times
101-
\"
102-
}
103-
}
104-
105-
say "Valid CSV file!" if CSV.L<parse>( q:to/EOCSV/ );
106-
Year,Make,Model,Length
107-
1997,Ford,E350,2.34
108-
2000,Mercury,Cougar,2.38
109-
EOCSV
110-
=end code
111-
112-
=head2 Methods
113-
114-
=head3 method parse
115-
116-
method parse($str, :$rule = 'TOP', :$actions) returns Match:D
117-
118-
Matches the grammar against C<$str>, using C<$rule> as the starting rule,
119-
optionally applying C<$actions> as its actions object.
120-
121-
This will fail if the grammar does not parse the I<entire> string. If a
122-
parse of only a part of the string is desired, use L<subparse>.
123-
124-
The method returns the resulting L<Match> object and also sets the caller's
125-
C<$/> variable to the Match object.
126-
127-
=begin code :allow<B>
128-
say CSVB<.parse>( q:to/EOCSV/ );
129-
Year,Make,Model,Length
130-
1997,Ford,E350,2.34
131-
2000,Mercury,Cougar,2.38
132-
EOCSV
133-
=end code
134-
135-
This outputs:
136-
137-
「Year,Make,Model,Length
138-
1997,Ford,E350,2.34
139-
2000,Mercury,Cougar,2.38
140-
141-
line => 「Year,Make,Model,Length」
142-
value => 「Year」
143-
value => 「Make」
144-
value => 「Model」
145-
value => 「Length」
146-
line => 「1997,Ford,E350,2.34」
147-
value => 「1997」
148-
value => 「Ford」
149-
value => 「E350」
150-
value => 「2.34」
151-
line => 「2000,Mercury,Cougar,2.38 」
152-
value => 「2000」
153-
value => 「Mercury」
154-
value => 「Cougar」
155-
value => 「2.38 」
156-
157-
=head3 method subparse
158-
159-
method subparse($str, :$rule = 'TOP', :$actions) returns Match:D
160-
161-
Matches the grammar against C<$str>, using C<$rule> as the starting rule,
162-
optionally applying C<$actions> as its actions object.
163-
164-
Unlike L<parse>, C<subparse> will allow the grammar to match only part of
165-
the supplied string.
166-
167-
=head3 method parsefile
168-
169-
method parsefile(Str(Cool) $filename, *%opts) returns Match:D
170-
171-
Parses the contents of the file C<$filename> with the L<parse> method,
172-
passing any named options in C<%opts>.
173-
17479
=head1 Action Objects
17580
17681
A successful grammar match gives you a parse tree of L<Match|/type/Match>

lib/Language/variables.pod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ accessed via C<$!x> and C<$!y>. This is because in Perl 6 all attributes are
157157
private and can be directly accessed within the class by using
158158
C<$!attribute-name>. Perl 6 may automatically generate accessor methods for
159159
you though. For more details on objects, classes and their attributes see
160-
L<objects>.
160+
L<object orientation|/language/objects>.
161161
162162
=head2 The C<?> Twigil
163163
@@ -210,7 +210,7 @@ following is possible too:
210210
=end code
211211
212212
For more details on objects, classes and their attributes and methods see
213-
L<objects>.
213+
L<object orientation|/language/objects>.
214214
215215
=head2 The C«<» Twigil
216216

lib/Type/Grammar.pod

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ More L<documentation on grammars|/language/grammars> is available.
2727
2828
=head2 method parse
2929
30-
method parse($target, :$rule = 'TOP', Parcel :$args = (), Mu :$actions, *%opts)
30+
method parse($target, :$rule = 'TOP', Parcel :$args = (), Mu :$actions = Mu, *%opt) {
3131
3232
Parses the C<$target> (which will be coerced to L<Str|/type/Str> if it isn't
3333
one), using C<$rule> as the starting rule. Additional C<$args> will be given
@@ -49,9 +49,58 @@ if you want to be able to stop in the middle.
4949
Returns a L<Match object|/type/Match> on success, and L<Nil|/type/Nil> on
5050
failure.
5151
52+
grammar CSV {
53+
token TOP { [ <line> \n? ]+ }
54+
token line {
55+
^^ # Beginning of a line
56+
<value>* % \, # Any number of <value>s with commas in between them
57+
$$ # End of a line
58+
}
59+
token value {
60+
[
61+
| <-[",\n]> # Anything not a double quote, comma or newline
62+
| <quoted-text> # Or some quoted text
63+
]* # Any number of times
64+
}
65+
token quoted-text {
66+
\"
67+
[
68+
| <-["\\]> # Anything not a " or \
69+
| '\"' # Or \", an escaped quotation mark
70+
]* # Any number of times
71+
\"
72+
}
73+
}.parse( q:to/EOCSV/ ).say;
74+
Year,Make,Model,Length
75+
1997,Ford,E350,2.34
76+
2000,Mercury,Cougar,2.38
77+
EOCSV
78+
79+
This outputs:
80+
81+
「Year,Make,Model,Length
82+
1997,Ford,E350,2.34
83+
2000,Mercury,Cougar,2.38
84+
85+
line => 「Year,Make,Model,Length」
86+
value => 「Year」
87+
value => 「Make」
88+
value => 「Model」
89+
value => 「Length」
90+
line => 「1997,Ford,E350,2.34」
91+
value => 「1997」
92+
value => 「Ford」
93+
value => 「E350」
94+
value => 「2.34」
95+
line => 「2000,Mercury,Cougar,2.38 」
96+
value => 「2000」
97+
value => 「Mercury」
98+
value => 「Cougar」
99+
value => 「2.38 」
100+
52101
=head2 method subparse
53102
54-
method subparse($target, :$rule = 'TOP', Parcel :$args = (), Mu :$actions, *%opts)
103+
method subparse($target, :$rule = 'TOP', Parcel :$args = (), Mu :$actions = Mu, *%opt) {
55104
56105
Does exactly the same as L<method parse|/routine/parse>, except that cursor
57106
doesn't have to reach the end of the string to succeed. (That is, it doesn't
@@ -66,9 +115,9 @@ have to match the whole string).
66115
67116
=head2 method parsefile
68117
69-
method parsefile(Cool $filename, *%opts);
118+
method parsefile(Str(Cool) $filename, :$enc, *%opts) {
70119
71-
Reads file C<$filename>, and parses it. All named arguments are passsed on to
120+
Reads file C<$filename>, and parses it. All named arguments are passed on to
72121
L<method parse|/routine/parse>.
73122
74123
=end pod

0 commit comments

Comments
 (0)