Skip to content

Commit 8c39423

Browse files
authored
De-trap a trap's description
Closes #3721
1 parent 7490425 commit 8c39423

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

doc/Language/traps.pod6

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,14 +1771,24 @@ say foo rand; # OUTPUT: «Type check failed in binding to parameter '<anon>'; ex
17711771
=head2 Using regexes within grammar's actions
17721772
17731773
=begin code
1774+
# Define a grammar
17741775
grammar will-fail {
17751776
token TOP {^ <word> $}
17761777
token word { \w+ }
17771778
}
17781779
1780+
# Define an action class
17791781
class will-fail-actions {
1780-
method TOP ($/) { my $foo = ~$/; say $foo ~~ /foo/; }
1782+
method TOP ($/) { # <- note the $/ in the signature, which is readonly
1783+
my $foo = ~$/;
1784+
say $foo ~~ /foo/; # <- the regex tries to assign the result to $/ and will fail
1785+
}
17811786
}
1787+
1788+
# Try to parse something...
1789+
will-fail.parse('word', :actions(will-fail-actions));
1790+
CATCH { default { put .^name, ': ', .Str } };
1791+
# OUTPUT: «X::AdHoc: Cannot assign to a readonly variable or a value␤»
17821792
=end code
17831793
17841794
Will fail with C<Cannot assign to a readonly variable ($/) or a value>

0 commit comments

Comments
 (0)