Changeset View
Changeset View
Standalone View
Standalone View
autotests/folding/highlight.pl6.fold
- This file was added.
1 | #!/usr/bin/perl6 | ||||
---|---|---|---|---|---|
2 | | ||||
3 | use v6; | ||||
4 | | ||||
5 | if True <beginfold id='1'>{</beginfold id='1'> | ||||
6 | say "Hello"; | ||||
7 | <endfold id='1'>}</endfold id='1'> | ||||
8 | | ||||
9 | if True <beginfold id='1'>{</beginfold id='1'> | ||||
10 | say "Hello"; # Bad indentation intended | ||||
11 | <endfold id='1'>}</endfold id='1'> | ||||
12 | | ||||
13 | if True <beginfold id='1'>{</beginfold id='1'> say "Hello" <endfold id='1'>}</endfold id='1'> | ||||
14 | | ||||
15 | if True <beginfold id='1'>{</beginfold id='1'>say "Hello"<endfold id='1'>}</endfold id='1'> | ||||
16 | | ||||
17 | if True <beginfold id='1'>{</beginfold id='1'> say "Hello" <endfold id='1'>}</endfold id='1'> else <beginfold id='1'>{</beginfold id='1'> say "Goodbye" <endfold id='1'>}</endfold id='1'>; say "world"; | ||||
18 | | ||||
19 | ## <beginfold id='14'>BEGIN</beginfold id='14'> Comments | ||||
20 | | ||||
21 | say 1 #`<beginfold id='4'>(</beginfold id='4'> blah TODO blah | ||||
22 | here? <endfold id='4'>)</endfold id='4'> 2 ; | ||||
23 | say 1 #`<beginfold id='4'>{{</beginfold id='4'> blah TODO blah | ||||
24 | here? <endfold id='4'>}}</endfold id='4'> 2 ; | ||||
25 | say 1 #`<beginfold id='4'>[[</beginfold id='4'> blah TODO blah ] | ||||
26 | here? <endfold id='4'>]]</endfold id='4'> 2 ; | ||||
27 | say 1 #`<beginfold id='4'>«««</beginfold id='4'> blah TODO blah | ||||
28 | here? <endfold id='4'>»»»</endfold id='4'> 2 ; | ||||
29 | say 1 #` ( blah TODO blah | ||||
30 | 2 ; | ||||
31 | | ||||
32 | #`<beginfold id='4'>[</beginfold id='4'> | ||||
33 | This is another multi-line comment. <endfold id='4'>]</endfold id='4'> | ||||
34 | my @sorted = @names.sort<beginfold id='1'>(</beginfold id='1'><beginfold id='1'>{</beginfold id='1'> %sets<beginfold id='1'>{</beginfold id='1'>$_<endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'><endfold id='1'>)</endfold id='1'>.sort<beginfold id='1'>(</beginfold id='1'><beginfold id='1'>{</beginfold id='1'> %matches<beginfold id='1'>{</beginfold id='1'>$_<endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'><endfold id='1'>)</endfold id='1'>.reverse; | ||||
35 | #`<beginfold id='4'>{</beginfold id='4'> So is this, though it's not actually multi-line. <endfold id='4'>}</endfold id='4'> | ||||
36 | | ||||
37 | say 'code again'; | ||||
38 | | ||||
39 | #`<beginfold id='4'>(</beginfold id='4'> Multiple line comments `<beginfold id='4'>(</beginfold id='4'> sub-comment <endfold id='4'>)</endfold id='4'>`<endfold id='4'>)</endfold id='4'>` | ||||
40 | | ||||
41 | ## <endfold id='14'>END</endfold id='14'> Comments | ||||
42 | | ||||
43 | #`<beginfold id='4'>[</beginfold id='4'> | ||||
44 | And this is how a multi would work. | ||||
45 | That says why we do what we do below. | ||||
46 | <endfold id='4'>]</endfold id='4'> | ||||
47 | | ||||
48 | say "No more"; | ||||
49 | | ||||
50 | #`<beginfold id='4'>{{</beginfold id='4'>a}a<endfold id='4'>}}</endfold id='4'> say ok | ||||
51 | | ||||
52 | say "No more"; | ||||
53 | | ||||
54 | say "this is code"; | ||||
55 | | ||||
56 | =begin <beginfold id='3'>pod</beginfold id='3'> | ||||
57 | | ||||
58 | A very simple Pod6 document | ||||
59 | | ||||
60 | =<endfold id='3'>end</endfold id='3'> pod | ||||
61 | | ||||
62 | =begin <beginfold id='3'>head1</beginfold id='3'> | ||||
63 | Top Level Heading | ||||
64 | =<endfold id='3'>end</endfold id='3'> head1 | ||||
65 | | ||||
66 | =head1 Top level heading | ||||
67 | | ||||
68 | =for head1 | ||||
69 | Top Level Heading | ||||
70 | | ||||
71 | =cutsdads | ||||
72 | | ||||
73 | =begin <beginfold id='3'>pod</beginfold id='3'> | ||||
74 | | ||||
75 | =head1 This is a head1 title | ||||
76 | | ||||
77 | This is a paragraph. | ||||
78 | | ||||
79 | =head2 Subsection | ||||
80 | # plop | ||||
81 | Here some text for the subsection. | ||||
82 | | ||||
83 | =<endfold id='3'>end</endfold id='3'> pod | ||||
84 | | ||||
85 | =begin <beginfold id='3'>table</beginfold id='3'> :caption<My Tasks> | ||||
86 | mow lawn | ||||
87 | take out trash | ||||
88 | =<endfold id='3'>end</endfold id='3'> table | ||||
89 | | ||||
90 | =head1 This is a heading block | ||||
91 | This is an ordinary paragraph. | ||||
92 | Its text will be squeezed and | ||||
93 | short lines filled. It is terminated by | ||||
94 | the first blank line. | ||||
95 | | ||||
96 | =head2 This is another heading block | ||||
97 | This is yet another ordinary paragraph, | ||||
98 | at the first virtual column set by the | ||||
99 | previous directive | ||||
100 | | ||||
101 | #| Base class for magicians | ||||
102 | class Magician <beginfold id='1'>{</beginfold id='1'> | ||||
103 | has Int $.level; | ||||
104 | has Str @.spells; | ||||
105 | <endfold id='1'>}</endfold id='1'> | ||||
106 | | ||||
107 | #| Fight mechanics | ||||
108 | sub duel<beginfold id='1'>(</beginfold id='1'>Magician $a, Magician $b<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
109 | <endfold id='1'>}</endfold id='1'> | ||||
110 | #=<beginfold id='4'>«</beginfold id='4'><(( | ||||
111 | <Magicians only, no mortals. > | ||||
112 | Magicians only, no mortals. | ||||
113 | ))><endfold id='4'>»</endfold id='4'> | ||||
114 | | ||||
115 | say Magician.WHY; | ||||
116 | | ||||
117 | #|<beginfold id='4'><<</beginfold id='4'> This is an example of stringification: | ||||
118 | * Numbers turn into strings | ||||
119 | > * Regexes operate on said strings | ||||
120 | * C<with> topicalizes and places result into $_ | ||||
121 | <endfold id='4'>>></endfold id='4'> | ||||
122 | sub search-in-seq<beginfold id='1'>(</beginfold id='1'> Int $end, Int $number <endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
123 | with <beginfold id='1'>(</beginfold id='1'>^$end<endfold id='1'>)</endfold id='1'>.grep<beginfold id='1'>(</beginfold id='1'> /^$number/ <endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
124 | .say for $_<>; | ||||
125 | <endfold id='1'>}</endfold id='1'> | ||||
126 | <endfold id='1'>}</endfold id='1'> | ||||
127 | #= Uses * topic * decont operator | ||||
128 | | ||||
129 | | ||||
130 | =head1 plop | ||||
131 | abc | ||||
132 | | ||||
133 | =head1 plop | ||||
134 | =para | ||||
135 | abc | ||||
136 | | ||||
137 | =head1 plop | ||||
138 | abc | ||||
139 | abc | ||||
140 | | ||||
141 | =head1 plop | ||||
142 | abc | ||||
143 | | ||||
144 | say 1; | ||||
145 | | ||||
146 | =head1 plop | ||||
147 | | ||||
148 | say 1; | ||||
149 | | ||||
150 | =for head1 | ||||
151 | plop | ||||
152 | | ||||
153 | =for table :conf[str, 'str', "str", 1, True] :conf(str, 'str', "str", 1, True) | ||||
154 | =for table :conf<str 'str' "str" 1 True> | ||||
155 | =for table :conf{k => str, k=>'str', k=>"str", k=>1, k=>True} | ||||
156 | =for table :a :!b :42k :+s | ||||
157 | abc | ||||
158 | | ||||
159 | say 2; | ||||
160 | | ||||
161 | =begin <beginfold id='3'>a</beginfold id='3'> | ||||
162 | abc | ||||
163 | =<endfold id='3'>end</endfold id='3'> a | ||||
164 | | ||||
165 | =begin <beginfold id='3'>b</beginfold id='3'> sa | ||||
166 | =<endfold id='3'>end</endfold id='3'> b | ||||
167 | say 2; | ||||
168 | | ||||
169 | =begin <beginfold id='3'>a</beginfold id='3'> | ||||
170 | abc | ||||
171 | | ||||
172 | abc | ||||
173 | | ||||
174 | abc | ||||
175 | =<endfold id='3'>end</endfold id='3'> a | ||||
176 | say 0 ; | ||||
177 | =begin <beginfold id='3'>a</beginfold id='3'>:config{42} | ||||
178 | abc | ||||
179 | | ||||
180 | =head1 The | ||||
181 | Title | ||||
182 | | ||||
183 | abc | ||||
184 | =<endfold id='3'>end</endfold id='3'> ab | ||||
185 | say 1 ; | ||||
186 | | ||||
187 | =begin <beginfold id='3'>b</beginfold id='3'> sa | ||||
188 | =<endfold id='3'>end</endfold id='3'> b | ||||
189 | =begin <beginfold id='3'>a</beginfold id='3'> | ||||
190 | abc | ||||
191 | =begin <beginfold id='3'>b</beginfold id='3'> | ||||
192 | abc | ||||
193 | =<endfold id='3'>end</endfold id='3'> b a | ||||
194 | abc | ||||
195 | | ||||
196 | abc | ||||
197 | =<endfold id='3'>end</endfold id='3'> a | ||||
198 | say 3 ; | ||||
199 | | ||||
200 | =item a | ||||
201 | =item b | ||||
202 | =begin <beginfold id='3'>code</beginfold id='3'> | ||||
203 | =item a | ||||
204 | =<endfold id='3'>end</endfold id='3'> code | ||||
205 | | ||||
206 | =begin <beginfold id='3'>code</beginfold id='3'> | ||||
207 | =item a | ||||
208 | b | ||||
209 | =end code d | ||||
210 | =<endfold id='3'>end</endfold id='3'> code | ||||
211 | | ||||
212 | =begin <beginfold id='3'>comment</beginfold id='3'> | ||||
213 | Here are several | ||||
214 | lines | ||||
215 | of comment | ||||
216 | =<endfold id='3'>end</endfold id='3'> comment | ||||
217 | | ||||
218 | =begin <beginfold id='3'>pod</beginfold id='3'> | ||||
219 | =head1 acB<<I<a>>>a B<c> U<d> BB<a> | ||||
220 | | ||||
221 | C<my $var = 1; say $var;> | ||||
222 | Perl 6 homepage L<https://perl6.org> L<Perl 6 homepage|https://perl6.org> | ||||
223 | Comments L<#Comments> L<Comments|#Comments> | ||||
224 | Perl 6 is awesome Z<Of course it is!> | ||||
225 | Perl 6 is multi-paradigmatic N<Supporting Procedural, Object Oriented, and Functional programming> | ||||
226 | Enter your name K<John Doe> E<0xBB> characters. | ||||
227 | | ||||
228 | A X<hash|hashes, definition of; associative arrays> | ||||
229 | | ||||
230 | =DISCLAIMER | ||||
231 | P<http://www.MegaGigaTeraPetaCorp.com/std/disclaimer.txt> | ||||
232 | | ||||
233 | A X<hash|hashes, definition of; associative arrays> | ||||
234 | is an unordered collection of scalar values indexed by their | ||||
235 | associated string key. | ||||
236 | | ||||
237 | my @names = <Foo Bar Baz>; | ||||
238 | my @upper-case-names = @names.map: { .uc } # OUTPUT: [FOO BAR BAZ] | ||||
239 | | ||||
240 | =<endfold id='3'>end</endfold id='3'> pod | ||||
241 | | ||||
242 | =begin <beginfold id='3'>table</beginfold id='3'> :caption<My Tasks> | ||||
243 | mow lawn | ||||
244 | take out trash | ||||
245 | =<endfold id='3'>end</endfold id='3'> table | ||||
246 | | ||||
247 | =begin <beginfold id='3'>table</beginfold id='3'> :config{caption => "My Tasks"} | ||||
248 | mow lawn | ||||
249 | take out trash | ||||
250 | =<endfold id='3'>end</endfold id='3'> table | ||||
251 | | ||||
252 | | ||||
253 | say "\c999 \c999999999 \c[LATIN CAPITAL LETTER A, LATIN CAPITAL LETTER B] \c77s \c[77,22]"; | ||||
254 | say "\x0 \x00 \x[0] \x[00] \x[f] \xaaa \xfffffff \xffh \x[ffff] \x[fffffff] \x[42,42]"; | ||||
255 | say "\o0 \o00 \o[0] \o[00] \o[7] \o333 \o77777777 \o77h \o[333] \o[77777777] \o[42,42]"; | ||||
256 | | ||||
257 | say Q[A literal string] ; | ||||
258 | say 「More plainly.」 ; | ||||
259 | say Q ^Almost any non-word character can be a delimiter!^ ; | ||||
260 | say Q 「「Delimiters can be repeated/nested if they are adjacent.」」 ; | ||||
261 | | ||||
262 | say Q (this is fine, because of space after Q) ; | ||||
263 | say Q 'and so is this' ; | ||||
264 | say Q<Make sure you <match> opening and closing delimiters> ; | ||||
265 | say Q{This is still a closing curly brace → \} ; | ||||
266 | | ||||
267 | say Q;yes, this is fine; ; | ||||
268 | say Q('this is a function') ; | ||||
269 | | ||||
270 | say 'Very plain'; | ||||
271 | say q[This back\slash stays]; | ||||
272 | say q[This back\\slash stays]; # Identical output | ||||
273 | say q{This is not a closing curly brace → \}, but this is → }; | ||||
274 | say Q :q $There are no backslashes here, only lots of \$\$\$>!$; | ||||
275 | say '(Just kidding. There\'s no money in that string)'; | ||||
276 | say 'No $interpolation {here}!'; | ||||
277 | say Q:q!Just a literal "\n" here!; | ||||
278 | say Q:q[a\[] | ||||
279 | say Q[A literal string] ; | ||||
280 | say 「More plainly.」 ; | ||||
281 | say Q ^Almost any non-word character can be a delimiter!^ ; | ||||
282 | say Q 「「Delimiters can be repeated/nested if they are adjacent.」」 ; | ||||
283 | | ||||
284 | say qq[My favorite color is {$n+2}!]; | ||||
285 | say qq{My favorite color\- is {$n+2}!}; | ||||
286 | say Q:qq{My favorite color\- is {$n+2}!}; | ||||
287 | say "My $color[0].uc( | ||||
288 | ) $n+$n.^name favorite color \q[1is] {$n+2}!abc&uc('a')"; | ||||
289 | | ||||
290 | say qqww|a|; | ||||
291 | say qq:w:w|a|; | ||||
292 | say q:a:v|a|; | ||||
293 | | ||||
294 | say<beginfold id='1'>(</beginfold id='1'>qq:to/TERM INATOR/, 1+1); | ||||
295 | blah blah | ||||
296 | TERM INATOR | ||||
297 | | ||||
298 | | ||||
299 | my $don't-do-that = 1; | ||||
300 | my $piece_of_π = 3.14; | ||||
301 | my $駱駝道 = 1; | ||||
302 | my $lexical = 1; | ||||
303 | my $*dynamic1 = 10; | ||||
304 | my $*dynamic2 = 100; | ||||
305 | | ||||
306 | sub say-all<beginfold id='1'>(</beginfold id='1'><endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
307 | say "$lexical, $*dynamic1, $*dynamic2"; | ||||
308 | <endfold id='1'>}</endfold id='1'> | ||||
309 | | ||||
310 | say-all<beginfold id='1'>(</beginfold id='1'><endfold id='1'>)</endfold id='1'>; | ||||
311 | | ||||
312 | <beginfold id='1'>{</beginfold id='1'> | ||||
313 | my $lexical = 2; | ||||
314 | my $*dynamic1 = 11; | ||||
315 | $*dynamic2 = 101; | ||||
316 | <endfold id='1'>}</endfold id='1'> | ||||
317 | | ||||
318 | my $square = 9 ** 2; | ||||
319 | my @array = 1, 2, 3; # Array variable with three elements | ||||
320 | my %hash = London => 'UK', Berlin => 'Germany'; | ||||
321 | | ||||
322 | class FailHash is Hash <beginfold id='1'>{</beginfold id='1'> | ||||
323 | has Bool $!final = False; | ||||
324 | multi method AT-KEY <beginfold id='1'>(</beginfold id='1'> ::?CLASS:D: Str:D \key <endfold id='1'>)</endfold id='1'><beginfold id='1'>{</beginfold id='1'> | ||||
325 | fail X::OutOfRange.new<beginfold id='1'>(</beginfold id='1'>:what<beginfold id='1'>(</beginfold id='1'>"Hash key"<endfold id='1'>)</endfold id='1'>, :got<beginfold id='1'>(</beginfold id='1'>key<endfold id='1'>)</endfold id='1'>, | ||||
326 | :range<beginfold id='1'>(</beginfold id='1'>self.keys<endfold id='1'>)</endfold id='1'><endfold id='1'>)</endfold id='1'> if $!final && !self.EXISTS-KEY<beginfold id='1'>(</beginfold id='1'>key<endfold id='1'>)</endfold id='1'>; | ||||
327 | callsame | ||||
328 | <endfold id='1'>}</endfold id='1'> | ||||
329 | | ||||
330 | method finalize<beginfold id='1'>(</beginfold id='1'><endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
331 | $!final = True | ||||
332 | <endfold id='1'>}</endfold id='1'> | ||||
333 | <endfold id='1'>}</endfold id='1'> | ||||
334 | | ||||
335 | my %h is FailHash = oranges => "round", bananas => "bendy"; | ||||
336 | | ||||
337 | say %h<oranges>; | ||||
338 | %h.finalize; | ||||
339 | say %h<cherry>; | ||||
340 | CATCH <beginfold id='1'>{</beginfold id='1'> default <beginfold id='1'>{</beginfold id='1'> put .^name, ': ', .Str <endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'> | ||||
341 | | ||||
342 | my <beginfold id='1'>(</beginfold id='1'> @foo, $bar <endfold id='1'>)</endfold id='1'>; | ||||
343 | @foo = <beginfold id='1'>(</beginfold id='1'>$bar<endfold id='1'>)</endfold id='1'> = 42, "str"; | ||||
344 | | ||||
345 | say anon class þ <beginfold id='1'>{</beginfold id='1'><endfold id='1'>}</endfold id='1'>; | ||||
346 | say anon sub þ <beginfold id='1'>{</beginfold id='1'> 42 <endfold id='1'>}</endfold id='1'>; | ||||
347 | | ||||
348 | sub a <beginfold id='1'>{</beginfold id='1'> | ||||
349 | state @x; | ||||
350 | state $l = 'A'; | ||||
351 | @x.push<beginfold id='1'>(</beginfold id='1'>$l++<endfold id='1'>)</endfold id='1'>; | ||||
352 | <endfold id='1'>}</endfold id='1'>; | ||||
353 | | ||||
354 | say a for 1..6; | ||||
355 | | ||||
356 | sub foo<beginfold id='1'>(</beginfold id='1'>$x<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
357 | my $v = @; | ||||
358 | $v<beginfold id='1'>[</beginfold id='1'>$x<endfold id='1'>]</endfold id='1'> = $x; | ||||
359 | say $v; | ||||
360 | <endfold id='1'>}</endfold id='1'> | ||||
361 | | ||||
362 | foo<beginfold id='1'>(</beginfold id='1'>$_<endfold id='1'>)</endfold id='1'> for ^3; | ||||
363 | | ||||
364 | use MONKEY-TYPING; | ||||
365 | augment class Int <beginfold id='1'>{</beginfold id='1'> | ||||
366 | method is-answer <beginfold id='1'>{</beginfold id='1'> self == 42 <endfold id='1'>}</endfold id='1'> | ||||
367 | <endfold id='1'>}</endfold id='1'> | ||||
368 | say 42.is-answer; | ||||
369 | | ||||
370 | my $in = 0; | ||||
371 | | ||||
372 | sub f<beginfold id='1'>(</beginfold id='1'>*@c<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
373 | <beginfold id='1'>(</beginfold id='1'>temp $in<endfold id='1'>)</endfold id='1'>++; | ||||
374 | "<f>\n" | ||||
375 | ~ @c».indent<beginfold id='1'>(</beginfold id='1'>$in<endfold id='1'>)</endfold id='1'>.join<beginfold id='1'>(</beginfold id='1'>"\n"<endfold id='1'>)</endfold id='1'> | ||||
376 | ~ <beginfold id='1'>(</beginfold id='1'>+@c ?? "\n" !! ""<endfold id='1'>)</endfold id='1'> | ||||
377 | ~ '</f>' | ||||
378 | <endfold id='1'>}</endfold id='1'>; | ||||
379 | | ||||
380 | for <ab:c d$e fgh ij*> <beginfold id='1'>{</beginfold id='1'> | ||||
381 | .say if m<beginfold id='2'>/</beginfold id='2'><-alpha><endfold id='2'>/</endfold id='2'>; | ||||
382 | <endfold id='1'>}</endfold id='1'> | ||||
383 | | ||||
384 | for '.' <beginfold id='1'>{</beginfold id='1'> | ||||
385 | .Str.say when !.IO.d; | ||||
386 | .IO.dir<beginfold id='1'>(</beginfold id='1'><endfold id='1'>)</endfold id='1'>».&?BLOCK when .IO.d # lets recurse a little! | ||||
387 | <endfold id='1'>}</endfold id='1'> | ||||
388 | | ||||
389 | use Dog:auth<Somebody>:ver<2.0>; | ||||
390 | | ||||
391 | infix:<+> | ||||
392 | infix:<*> | ||||
393 | infix:«<=» | ||||
394 | | ||||
395 | postfix:<²> | ||||
396 | WOW:That'sAwesome | ||||
397 | WOW:That's<<🆒>> | ||||
398 | party:sweet<16> | ||||
399 | | ||||
400 | infix:<+> | ||||
401 | infix:<<+>> | ||||
402 | infix:«+» | ||||
403 | infix:['+'] | ||||
404 | infix:('+') | ||||
405 | | ||||
406 | my $a:b<c>:d<e> = 100; | ||||
407 | my $a:d<e>:b<c> = 200; | ||||
408 | say $a:b<c>:d<e>; | ||||
409 | | ||||
410 | use Test; plan 1; constant &term:<👍> = &ok.assuming<beginfold id='1'>(</beginfold id='1'>True<endfold id='1'>)</endfold id='1'>; | ||||
411 | 👍 | ||||
412 | | ||||
413 | my $x = do if True <beginfold id='1'>{</beginfold id='1'> 42 <endfold id='1'>}</endfold id='1'>; | ||||
414 | | ||||
415 | say 1000000, 1_000_000, 10_00000, 100_00_00; | ||||
416 | say -2, 12345, 0xBEEF, 0o755, :3<1201>; | ||||
417 | say 1.0, 3.14159, -2.5, :3<21.0012>; | ||||
418 | say 1e0, 6.022e23, 1e-9, -2e48, 2e2i, .42; | ||||
419 | say 2.e2, .2, 0o39, 0xfF3u, 0oi, 0xi, :3<>, :23<gg ; # error | ||||
420 | | ||||
421 | | ||||
422 | for $size «[r/]« <beginfold id='1'>(</beginfold id='1'>2**60, 2**50, 2**40, 2**30, 2**20, 2**10<endfold id='1'>)</endfold id='1'> | ||||
423 | Z <EB PB TB GB MB KB> -> <beginfold id='1'>[</beginfold id='1'>\v,\suffix<endfold id='1'>]</endfold id='1'> | ||||
424 | | ||||
425 | my $a = 32; | ||||
426 | $a += 10; | ||||
427 | $a -= 2; | ||||
428 | $a = 3; | ||||
429 | $a min= 5; | ||||
430 | $s ~= 'b'; | ||||
431 | | ||||
432 | sub infix:<space-concat> <beginfold id='1'>(</beginfold id='1'>$a, $b<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> $a ~ " " ~ $b <endfold id='1'>}</endfold id='1'>; | ||||
433 | my $a = 'word1'; | ||||
434 | $a space-concat= 'word2'; | ||||
435 | | ||||
436 | my Real $a = 1/2; | ||||
437 | $a = 3.14; | ||||
438 | $a .= round; | ||||
439 | | ||||
440 | my $a = True; | ||||
441 | say so $a != True; | ||||
442 | my $i = 10; | ||||
443 | | ||||
444 | my $release = Date.new<beginfold id='1'>(</beginfold id='1'>:2015year, :12month, :24day<endfold id='1'>)</endfold id='1'>; | ||||
445 | my $today = Date.today; | ||||
446 | say so $release !before $today; | ||||
447 | | ||||
448 | say 4 R/ 12; | ||||
449 | say [R/] 2, 4, 16; | ||||
450 | say [RZ~] <1 2 3>,<4 5 6> | ||||
451 | | ||||
452 | say <beginfold id='1'>(</beginfold id='1'>1, 2, 3<endfold id='1'>)</endfold id='1'> »*» 2; | ||||
453 | say <beginfold id='1'>(</beginfold id='1'>1, 2, 3, 4<endfold id='1'>)</endfold id='1'> »~» <a b>; | ||||
454 | say <beginfold id='1'>(</beginfold id='1'>1, 2, 3<endfold id='1'>)</endfold id='1'> »+« <beginfold id='1'>(</beginfold id='1'>4, 5, 6<endfold id='1'>)</endfold id='1'>; | ||||
455 | say <beginfold id='1'>(</beginfold id='1'>&sin, &cos, &sqrt<endfold id='1'>)</endfold id='1'>».<beginfold id='1'>(</beginfold id='1'>0.5<endfold id='1'>)</endfold id='1'>; | ||||
456 | | ||||
457 | say @a »+=» 1; | ||||
458 | my <beginfold id='1'>(</beginfold id='1'>$a, $b, $c<endfold id='1'>)</endfold id='1'>; | ||||
459 | <beginfold id='1'>(</beginfold id='1'><beginfold id='1'>(</beginfold id='1'>$a, $b<endfold id='1'>)</endfold id='1'>, $c<endfold id='1'>)</endfold id='1'> «=» <beginfold id='1'>(</beginfold id='1'><beginfold id='1'>(</beginfold id='1'>1, 2<endfold id='1'>)</endfold id='1'>, 3<endfold id='1'>)</endfold id='1'>; | ||||
460 | | ||||
461 | say !« @wisdom; | ||||
462 | @a»++; | ||||
463 | say -« <beginfold id='1'>[</beginfold id='1'><beginfold id='1'>[</beginfold id='1'>1, 2<endfold id='1'>]</endfold id='1'>, 3<endfold id='1'>]</endfold id='1'>; | ||||
464 | | ||||
465 | @slops».?this-method-may-not-exist<beginfold id='1'>(</beginfold id='1'><endfold id='1'>)</endfold id='1'>; | ||||
466 | | ||||
467 | my %outer = 1, 2, 3 Z=> <a b c>; | ||||
468 | my %inner = 1, 2 Z=> <x z>; | ||||
469 | say %outer «~» %inner; | ||||
470 | | ||||
471 | say $neighbors »>>+<<» <beginfold id='1'>(</beginfold id='1'>$p, *<endfold id='1'>)</endfold id='1'>; | ||||
472 | | ||||
473 | sub plus <beginfold id='1'>{</beginfold id='1'> $^a + $^b <endfold id='1'>}</endfold id='1'>; | ||||
474 | say [[&plus]] 1, 2, 3; | ||||
475 | | ||||
476 | my @n = <beginfold id='1'>[</beginfold id='1'>\~<endfold id='1'>]</endfold id='1'> 1..*; | ||||
477 | say @n<beginfold id='1'>[</beginfold id='1'>^5<endfold id='1'>]</endfold id='1'>; | ||||
478 | | ||||
479 | @l = <a b c d> Z~ 1, 2, *; | ||||
480 | say so 1 S& 2 S& 3; | ||||
481 | @a X[+=] @b; | ||||
482 | multi sub postfix:<++><beginfold id='1'>(</beginfold id='1'>$x is rw<endfold id='1'>)</endfold id='1'> is assoc<non> | ||||
483 | say $filename++ for 1..3; | ||||
484 | $x % $y == $x - floor<beginfold id='1'>(</beginfold id='1'>$x / $y<endfold id='1'>)</endfold id='1'> * $y | ||||
485 | say <a a b c a d> ⊍ bag<beginfold id='1'>(</beginfold id='1'><a a b c c><endfold id='1'>)</endfold id='1'>; | ||||
486 | say -« <1 2 3> | ||||
487 | | ||||
488 | # This is wrong: creates a Hash of Mixes, not Mix: | ||||
489 | my Mix %mix; | ||||
490 | # Works with $ sigil: | ||||
491 | my Mix $mix; | ||||
492 | # Can be typed: | ||||
493 | my Mix<beginfold id='1'>[</beginfold id='1'>Int<endfold id='1'>]</endfold id='1'> $mix-of-ints; | ||||
494 | | ||||
495 | my $x; | ||||
496 | my $x = 7; | ||||
497 | my Int $x = 7; | ||||
498 | my Int:D $x = 7; | ||||
499 | ndef<endfold id='1'>)</endfold id='1'> | ||||
500 | my Int $x where <beginfold id='1'>{</beginfold id='1'> $_ > 3 <endfold id='1'>}</endfold id='1'> = 7; | ||||
501 | my Int $x where * > 3 = 7; | ||||
502 | | ||||
503 | $str ~~ tr:d:c<beginfold id='2'>!</beginfold id='2'>dol<endfold id='2'>!</endfold id='2'>wne!; | ||||
504 | $str ~~ TR:c<beginfold id='2'>/</beginfold id='2'>dol<endfold id='2'>/</endfold id='2'>wne/; | ||||
505 | $str ~~ s<beginfold id='2'>!</beginfold id='2'>foo<endfold id='2'>!</endfold id='2'>fox!; | ||||
506 | $str ~~ <beginfold id='2'>/</beginfold id='2'>foo<endfold id='2'>/</endfold id='2'>bar/; | ||||
507 | $str ~~ <beginfold id='2'>/</beginfold id='2'><endfold id='2'>/</endfold id='2'>/; | ||||
508 | $str ~~ rx<beginfold id='2'>/</beginfold id='2'>foo<endfold id='2'>/</endfold id='2'>bar/; | ||||
509 | $str ~~ Q :regex /foo/; | ||||
510 | $str ~~ s<beginfold id='2'>{</beginfold id='2'>b(.)r<endfold id='2'>}</endfold id='2'> = " d$0n"; | ||||
511 | $str ~~ regex<beginfold id='2'>{</beginfold id='2'>fox<endfold id='2'>}</endfold id='2'>; # error | ||||
512 | $str ~~ regex <beginfold id='2'>{</beginfold id='2'>fox<endfold id='2'>}</endfold id='2'>; | ||||
513 | rx<beginfold id='2'>/</beginfold id='2'> ^ab <endfold id='2'>/</endfold id='2'>; | ||||
514 | / ^ ab /; | ||||
515 | rx<beginfold id='2'>/</beginfold id='2'> \d ** 2<endfold id='2'>/</endfold id='2'>; | ||||
516 | $str ~~ tr:d:c<beginfold id='2'>!</beginfold id='2'>dol<endfold id='2'>!</endfold id='2'>wne!; | ||||
517 | $str ~~ TR:c<beginfold id='2'>/</beginfold id='2'>dol<endfold id='2'>/</endfold id='2'>wne/; | ||||
518 | $str ~~ s<beginfold id='2'>!</beginfold id='2'>foo<endfold id='2'>!</endfold id='2'>fox!; | ||||
519 | $str ~~ rx<beginfold id='2'>/</beginfold id='2'>foo<endfold id='2'>/</endfold id='2'>; | ||||
520 | $str ~~ regex:ds <beginfold id='2'>{</beginfold id='2'>fox<endfold id='2'>}</endfold id='2'>; | ||||
521 | $str ~~ regex<beginfold id='2'>{</beginfold id='2'>fox<endfold id='2'>}</endfold id='2'>; | ||||
522 | my a = <beginfold id='2'>/</beginfold id='2'>a<endfold id='2'>/</endfold id='2'>; | ||||
523 | rx<beginfold id='2'>/</beginfold id='2'> ^ab <endfold id='2'>/</endfold id='2'>; | ||||
524 | a = <beginfold id='2'>/</beginfold id='2'> ^ ab 'a' "$a" \d \n\n <:L :Script<Latin>> <:Block('Basic Latin')> <endfold id='2'>/</endfold id='2'>; | ||||
525 | //; | ||||
526 | rx:sigspace<beginfold id='2'>.</beginfold id='2'>\d+ < :Script +:Block "Basic Latin" + :L> #plop | ||||
527 | '-'<endfold id='2'>.</endfold id='2'>; | ||||
528 | rx<beginfold id='2'>/</beginfold id='2'> \d ** 2 <[\d a d]+[\x233..\] " \c[dsds]]><endfold id='2'>/</endfold id='2'>; | ||||
529 | say $str ~~ m:g<beginfold id='2'>/</beginfold id='2'>[(<[ACGT]> **: 3) \s*]+ \s+ (<[A..Z a a..z \s]>+)<endfold id='2'>/</endfold id='2'>; | ||||
530 | say '$333' ~~ m<beginfold id='2'>/</beginfold id='2'>^^ <?[$]> . \d+ <endfold id='2'>/</endfold id='2'>; | ||||
531 | say '/foo/o/bar/' ~~ <beginfold id='2'>/</beginfold id='2'>\/.**!<beginfold id='1'>{</beginfold id='1'>1..10<endfold id='1'>}</endfold id='1'>\/<endfold id='2'>/</endfold id='2'>; | ||||
532 | rx<beginfold id='1'>(</beginfold id='1'>a<endfold id='1'>)</endfold id='1'>; | ||||
533 | rx <beginfold id='2'>(</beginfold id='2'>a<endfold id='2'>)</endfold id='2'>; | ||||
534 | $str ~~ regex <beginfold id='2'>{</beginfold id='2'>fox<endfold id='2'>}</endfold id='2'>; | ||||
535 | $str ~~ s<beginfold id='2'>{</beginfold id='2'>b(.)r<endfold id='2'>}</endfold id='2'> = " d$0n"; | ||||
536 | if 'abc' ~~ <beginfold id='2'>/</beginfold id='2'> [a||b] (c) <endfold id='2'>/</endfold id='2'> <beginfold id='1'>{</beginfold id='1'> | ||||
537 | say ~$0; # OUTPUT: «c» | ||||
538 | <endfold id='1'>}</endfold id='1'> | ||||
539 | if 'abc' ~~ <beginfold id='2'>/</beginfold id='2'> $<myname> = [ \w+ ] <endfold id='2'>/</endfold id='2'> <beginfold id='1'>{</beginfold id='1'> | ||||
540 | say ~$<myname> # OUTPUT: «abc» | ||||
541 | <endfold id='1'>}</endfold id='1'> | ||||
542 | say 'abc' ~~ <beginfold id='2'>/</beginfold id='2'> a <( b )> c<endfold id='2'>/</endfold id='2'>; | ||||
543 | say 'abc' ~~ <beginfold id='2'>/</beginfold id='2'> <(a <( b )> c)><endfold id='2'>/</endfold id='2'>; | ||||
544 | say "abc" ~~ <beginfold id='2'>/</beginfold id='2'>a. | ab <beginfold id='1'>{</beginfold id='1'> print "win" <endfold id='1'>}</endfold id='1'> <endfold id='2'>/</endfold id='2'>; | ||||
545 | | ||||
546 | so 'hello world' ~~ m:Perl5<beginfold id='9'>/</beginfold id='9'>^hello (world)<endfold id='9'>/</endfold id='9'>; # OUTPUT: «True» | ||||
547 | so 'hello world' ~~ m<beginfold id='2'>/</beginfold id='2'>^hello (world)<endfold id='2'>/</endfold id='2'>; # OUTPUT: «False» | ||||
548 | so 'hello world' ~~ m<beginfold id='2'>/</beginfold id='2'>^ 'hello ' ('world')<endfold id='2'>/</endfold id='2'>; # OUTPUT: «True» | ||||
549 | | ||||
550 | say "Abra abra CADABRA" ~~ m:exhaustive<beginfold id='2'>/</beginfold id='2'>:i a \w+ a<endfold id='2'>/</endfold id='2'>; | ||||
551 | | ||||
552 | my regex ipv4-octet <beginfold id='2'>{</beginfold id='2'> \d ** 1..3 <?{ $/.Int <= 255 && $/.Int >= 0 }> <endfold id='2'>}</endfold id='2'> | ||||
553 | my regex ipv4-octet <beginfold id='2'>{</beginfold id='2'> \d ** 1..3 <?{ True }> <endfold id='2'>}</endfold id='2'> | ||||
554 | say 'abc' ~~ <beginfold id='2'>/</beginfold id='2'> <?before a> && . <endfold id='2'>/</endfold id='2'>; | ||||
555 | say 'abcdefg' ~~ rx<beginfold id='2'>{</beginfold id='2'> abc <[email protected]ending_letters> <endfold id='2'>}</endfold id='2'>; | ||||
556 | s:g<beginfold id='2'>[</beginfold id='2'>\d+ <?before \s* @units><endfold id='2'>]</endfold id='2'> = 5 * $/; | ||||
557 | | ||||
558 | | ||||
559 | sub walk<beginfold id='1'>(</beginfold id='1'>\thing, *@keys<endfold id='1'>)</endfold id='1'> is rw <beginfold id='1'>{</beginfold id='1'> | ||||
560 | my $current := thing; | ||||
561 | for @keys -> $k <beginfold id='1'>{</beginfold id='1'> | ||||
562 | if $k ~~ Int <beginfold id='1'>{</beginfold id='1'> | ||||
563 | $current := $current<beginfold id='1'>[</beginfold id='1'>$k<endfold id='1'>]</endfold id='1'>; | ||||
564 | <endfold id='1'>}</endfold id='1'> | ||||
565 | else <beginfold id='1'>{</beginfold id='1'> | ||||
566 | $current := $current<beginfold id='1'>{</beginfold id='1'>$k<endfold id='1'>}</endfold id='1'>; | ||||
567 | <endfold id='1'>}</endfold id='1'> | ||||
568 | <endfold id='1'>}</endfold id='1'> | ||||
569 | $current; | ||||
570 | <endfold id='1'>}</endfold id='1'> | ||||
571 | | ||||
572 | my %hash; | ||||
573 | walk<beginfold id='1'>(</beginfold id='1'>%hash, 'some', 'key', 1, 2<endfold id='1'>)</endfold id='1'> = 'autovivified'; | ||||
574 | | ||||
575 | say %hash.perl; | ||||
576 | | ||||
577 | class X::WithoutLineNumber is X::AdHoc <beginfold id='1'>{</beginfold id='1'> | ||||
578 | multi method gist<beginfold id='1'>(</beginfold id='1'>X::WithoutLineNumber:D:<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
579 | $.payload | ||||
580 | <endfold id='1'>}</endfold id='1'> | ||||
581 | <endfold id='1'>}</endfold id='1'> | ||||
582 | die X::WithoutLineNumber.new<beginfold id='1'>(</beginfold id='1'>payload => "message"<endfold id='1'>)</endfold id='1'> | ||||
583 | | ||||
584 | <beginfold id='1'>{</beginfold id='1'> return; CATCH <beginfold id='1'>{</beginfold id='1'> default <beginfold id='1'>{</beginfold id='1'> $*ERR.say: .^name, ': ', .Str <endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'> <endfold id='1'>}</endfold id='1'> | ||||
585 | | ||||
586 | multi sub trait_mod:<is><beginfold id='1'>(</beginfold id='1'>Routine $r, :$export!<endfold id='1'>)</endfold id='1'> | ||||
587 | | ||||
588 | react <beginfold id='1'>{</beginfold id='1'> | ||||
589 | whenever signal<beginfold id='1'>(</beginfold id='1'>SIGINT<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
590 | say "goodbye"; | ||||
591 | done | ||||
592 | <endfold id='1'>}</endfold id='1'> | ||||
593 | <endfold id='1'>}</endfold id='1'> | ||||
594 | | ||||
595 | signal<beginfold id='1'>(</beginfold id='1'>SIGINT<endfold id='1'>)</endfold id='1'>.tap: <beginfold id='1'>{</beginfold id='1'> say "bye"; exit <endfold id='1'>}</endfold id='1'>; loop <beginfold id='1'>{</beginfold id='1'><endfold id='1'>}</endfold id='1'> | ||||
596 | | ||||
597 | method base-repeating<beginfold id='1'>(</beginfold id='1'>Rational:D: Int:D<beginfold id='1'>(</beginfold id='1'><endfold id='1'>)</endfold id='1'> $base = 10<endfold id='1'>)</endfold id='1'> | ||||
598 | | ||||
599 | multi sub prefix:<--><beginfold id='1'>(</beginfold id='1'>$x is rw<endfold id='1'>)</endfold id='1'> is assoc<non> | ||||
600 | | ||||
601 | | ||||
602 | multi MAIN<beginfold id='1'>(</beginfold id='1'>Bool :$man<endfold id='1'>)</endfold id='1'> <beginfold id='1'>{</beginfold id='1'> | ||||
603 | run $*EXECUTABLE, '--doc', $*PROGRAM; | ||||
604 | <endfold id='1'>}</endfold id='1'> | ||||
605 | | ||||
606 | for $file.lines -> $line <beginfold id='1'>{</beginfold id='1'> | ||||
607 | next unless $line; # ignore any empty lines | ||||
608 | | ||||
609 | my <beginfold id='1'>(</beginfold id='1'>$pairing, $result<endfold id='1'>)</endfold id='1'> = $line.split<beginfold id='1'>(</beginfold id='1'>' | '<endfold id='1'>)</endfold id='1'>; | ||||
610 | my <beginfold id='1'>(</beginfold id='1'>$p1, $p2<endfold id='1'>)</endfold id='1'> = $pairing.words; | ||||
611 | my <beginfold id='1'>(</beginfold id='1'>$r1, $r2<endfold id='1'>)</endfold id='1'> = $result.split<beginfold id='1'>(</beginfold id='1'>':'<endfold id='1'>)</endfold id='1'>; | ||||
612 | | ||||
613 | %sets<beginfold id='1'>{</beginfold id='1'>$p1<endfold id='1'>}</endfold id='1'> += $r1; | ||||
614 | %sets<beginfold id='1'>{</beginfold id='1'>$p2<endfold id='1'>}</endfold id='1'> += $r2; | ||||
615 | | ||||
616 | if $r1 > $r2 <beginfold id='1'>{</beginfold id='1'> | ||||
617 | %matches<beginfold id='1'>{</beginfold id='1'>$p1<endfold id='1'>}</endfold id='1'>++; | ||||
618 | <endfold id='1'>}</endfold id='1'> else <beginfold id='1'>{</beginfold id='1'> | ||||
619 | %matches<beginfold id='1'>{</beginfold id='1'>$p2<endfold id='1'>}</endfold id='1'>++; | ||||
620 | <endfold id='1'>}</endfold id='1'> | ||||
621 | <endfold id='1'>}</endfold id='1'> | ||||
622 | | ||||
623 | for @sorted -> $n <beginfold id='1'>{</beginfold id='1'> | ||||
624 | my $match-noun = %matches<beginfold id='1'>{</beginfold id='1'>$n<endfold id='1'>}</endfold id='1'> == 1 ?? 'match' !! 'matches'; | ||||
625 | my $set-noun = %sets<beginfold id='1'>{</beginfold id='1'>$n<endfold id='1'>}</endfold id='1'> == 1 ?? 'set' !! 'sets'; | ||||
626 | say "$n has won %matches{$n} $match-noun and %sets{$n} $set-noun"; | ||||
627 | <endfold id='1'>}</endfold id='1'> | ||||
628 | | ||||
629 | say "Math: { 1 + 2 }"; | ||||
630 | | ||||
631 | my @people = <Luke Matthew Mark>; | ||||
632 | say "The synoptics are: {@people}"; | ||||
633 | | ||||
634 | say "{%sets}"; | ||||
635 | say "we have @flavors[0]"; | ||||
636 | say "we have @flavors[]"; | ||||
637 | say "we have @flavors.sort()"; | ||||
638 | say "we have @flavors.sort.join(', ')"; | ||||
639 | | ||||
640 | my @valid-players = $file.get.words; | ||||
641 | | ||||
642 | for $file.lines -> $line <beginfold id='1'>{</beginfold id='1'> | ||||
643 | my <beginfold id='1'>(</beginfold id='1'>$pairing, $result<endfold id='1'>)</endfold id='1'> = $line.split<beginfold id='1'>(</beginfold id='1'>' | '<endfold id='1'>)</endfold id='1'>; | ||||
644 | my <beginfold id='1'>(</beginfold id='1'>$p1, $p2<endfold id='1'>)</endfold id='1'> = $pairing.split<beginfold id='1'>(</beginfold id='1'>' '<endfold id='1'>)</endfold id='1'>; | ||||
645 | if $p1 ∉ @valid-players <beginfold id='1'>{</beginfold id='1'> | ||||
646 | say "Warning: '$p1' is not on our list!"; | ||||
647 | <endfold id='1'>}</endfold id='1'> | ||||
648 | if $p2 ∉ @valid-players <beginfold id='1'>{</beginfold id='1'> | ||||
649 | say "Warning: '$p2' is not on our list!"; | ||||
650 | <endfold id='1'>}</endfold id='1'> | ||||
651 | <endfold id='1'>}</endfold id='1'> |