File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -1771,14 +1771,24 @@ say foo rand; # OUTPUT: «Type check failed in binding to parameter '<anon>'; ex
1771
1771
= head2 Using regexes within grammar's actions
1772
1772
1773
1773
= begin code
1774
+ # Define a grammar
1774
1775
grammar will-fail {
1775
1776
token TOP {^ <word> $}
1776
1777
token word { \w+ }
1777
1778
}
1778
1779
1780
+ # Define an action class
1779
1781
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
+ }
1781
1786
}
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»
1782
1792
= end code
1783
1793
1784
1794
Will fail with C < Cannot assign to a readonly variable ($/) or a value >
You can’t perform that action at this time.
0 commit comments