New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<&foo> [REGEX] syntax does not find &foo in the regex's own scope, only in the parent scope #5230
Comments
From @smlsThe following fails to compile with "Undeclared routine: regex": my token foo (&another-regex) { <&another-regex> }; Since routine arguments are supposed to become available to the routine body as lexical symbols, and <&foo> is the regex syntax for calling another regex by its lexical name, I assume this error is a bug. For comparison, the following two variations do compile and work just fine: my token foo ($another-regex) { $another-regex }; my token foo (&another-regex) { {say &another-regex} }; (This is Rakudo version 2016.03-108-g98b5b8c built on MoarVM version 2016.03-104-g10d3971 |
From @smlsUPDATE: It's not specific to the & sigil, as it also does not work with $ arguments: my token foo ($a) { <$a> }; # Error: Variable '$a' is not declared And it's not specific to arguments, as it also does not work when the variable is declared using a ':my' directive inside the regex body: my token foo { :my &a = /a/; <&a> } # Error: Undeclared routine: a On the other hand, it *does* work if the variable is declared in the parent scope: my &a = /a/; my token foo { <&a> } So the problems seems to be, that the < > regex call syntax looks up lexicals only in the *parent* scope of the regex it is used in, and not in the scope of the regex itself. psch++ suggested that this may be intended behavior: http://irclog.perlgeek.de/perl6/2016-04-11#i_12317275 psch++ also suggested a work-around by wrapping the regex in a Perl 6 method, so that the parameter becomes part of the parent scope of the regex: my method foo (&a) { self.CALL_SUBRULE: / <&a> / } Still, it feels strange that the < > syntax behaves this way. |
From @smlsIRC comment <http://irclog.perlgeek.de/perl6/2016-04-22#i_12380115>​: 23:30 TimToady: looks like a bug to me |
From @zoffixznetStill present in rakudo 405519 <Zoffix> m: my token foo ($a) { <$a> }; |
@coke - Status changed from 'new' to 'open' |
From @skidsOn Sat, 09 Jul 2016 19:48:54 -0700, cpan@zoffix.com wrote:
In addition to compiling, actually calling the regex presents some additional To use arguments with the <&a()> form, you cannot use a sub or method: $ perl6 -e 'my method a () { "a" ~~ /aa/ }; my token foo { <&a()> }; say "aa" ~~ /<foo>/' ...but regexes work fine. To use the <&a> form, you merely need to define it in the parent scope: $ perl6 -e 'my token foo { :my regex a { a }; <&a> }; "aa" ~~ /<foo>/' ... ...however to use the <a> form and hit a lexical method, it can be directly in the scope: $ perl6 -e 'my token foo { :my regex a { a }; <a> }; say "aa" ~~ /<foo>/' ...but is must be a regex, not a sub or method $ perl6 -e 'my method a ($cursor:) { "aa" ~~ /a/ }; my token foo { <a> }; say "aa" ~~ /<foo>/' $ perl6 -e 'my sub a ($cursor) { "aa" ~~ /a/ }; my token foo { <a> }; say "aa" ~~ /<foo>/' ... that latter part may be to spec. However the spec, after being very careful to only Internally, <&a> seems to route through assertion:sym<var> which installs a CALL_SUBRULE invocation, The tests in S05-metasyntax/angle-brackets.t auto-RTed as RT#124519 through RT#124523 make a lot |
Migrated from rt.perl.org#127872 (status was 'open')
Searchable as RT127872$
The text was updated successfully, but these errors were encountered: