Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

first pass at interpolated namespaces #163

Closed p6rt closed 14 years ago

p6rt commented 16 years ago

Migrated from rt.perl.org#56700 (status was 'rejected')

Searchable as RT56700$

p6rt commented 16 years ago

From @jeffhorwitz

I wanted some feedback on this patch before I apply it. It implements "just enough" interpolated namespace support for mod_perl6 to work (see S02). In fact, the only supported form is the following subroutine call​:

  :​:($ns)​::foo()

It can most certainly be refactored to work with more test cases by someone with more PCT-fu than I currently have. In the meantime, I'd like to apply this to avoid having to rewrite it every time there's a change in Rakudo, which is, um, often. Please let me know if there are any glaring problems or a better way to implement it. And yes, all tests still pass as of r29098. :)

-jeff

p6rt commented 16 years ago

From @jeffhorwitz

rakudo-interpns.patch ```diff Index: languages/perl6/src/builtins/misc.pir =================================================================== --- languages/perl6/src/builtins/misc.pir (revision 29098) +++ languages/perl6/src/builtins/misc.pir (working copy) @@ -12,6 +12,19 @@ .return($P0) .end +.sub 'resolve_sym' + .param string ns + .param string name + .param pmc args :slurpy + .local pmc sym + .local pmc nskey + + nskey = split '::', ns + sym = get_hll_global nskey, name + + .return(sym) +.end + # Local Variables: # mode: pir # fill-column: 100 Index: languages/perl6/src/parser/actions.pm =================================================================== --- languages/perl6/src/parser/actions.pm (revision 29098) +++ languages/perl6/src/parser/actions.pm (working copy) @@ -1930,6 +1930,27 @@ $past := build_call( $( $ ) ); $past.name( ~$ ); } + # call sub with an interpolated namespace + # right now we only support this exact form: ::($ns)::name() + elsif $key eq 'interpolated func args' { + my $resolve_past := PAST::Op.new( + :name('resolve_sym'), + :pasttype('call'), + :node($/) + ); + $resolve_past.unshift(PAST::Val.new( + :value( ~$[0] ) + )); + $resolve_past.unshift( + $( $[0] ) + ); + $past := build_call( $( $ ) ); + $past.unshift($resolve_past); + + # build_call will set 'name' for us. we reset that to undef so the + # sub call invokes the first PAST argument ($resolve_past) instead + $past.name(undef); + } elsif $key eq 'listop args' { $past := build_call( $( $ ) ); $past.name( ~$ ); Index: languages/perl6/src/parser/grammar.pg =================================================================== --- languages/perl6/src/parser/grammar.pg (revision 29098) +++ languages/perl6/src/parser/grammar.pg (working copy) @@ -517,6 +517,8 @@ [ | 'VAR(' ')' {*} #= VAR | {*} #= typename + | <.unsp>? '.'? + '(' ')' {*} #= interpolated func args | [ | <.unsp>? '.'? '(' ')' {*} #= func args @@ -604,10 +606,10 @@ } token circumfix { - | '(' ')' {*} #= ( ) - | '[' ']' {*} #= [ ] - | > {*} #= { } - | '(' ')' {*} #= $( ) + | '(' ')' {*} #= ( ) + | '[' ']' {*} #= [ ] + | > {*} #= { } + | '(' ')' {*} #= $( ) } token variable { @@ -619,6 +621,8 @@ token sigil { '$' | '@' | '%' | '&' | '::' } +token variable_sigil { '$' | '@' | '%' } + token twigil { <[.!^:*+?=]> } token name { @@ -718,6 +722,14 @@ {*} } +token interpolated_name { + [ '::' ]+ '::' +} + +token interpolated_ident { + '(' ')' +} + token name { [ '::' ]* {*} ```
p6rt commented 14 years ago

From @coke

On Tue Jul 08 10​:35​:02 2008, jhorwitz wrote​:

I wanted some feedback on this patch before I apply it. It implements "just enough" interpolated namespace support for mod_perl6 to work (see S02). In fact, the only supported form is the following subroutine call​:

:​:($ns)​::foo()

It can most certainly be refactored to work with more test cases by someone with more PCT-fu than I currently have. In the meantime, I'd like to apply this to avoid having to rewrite it every time there's a change in Rakudo, which is, um, often. Please let me know if there are any glaring problems or a better way to implement it. And yes, all tests still pass as of r29098. :)

-jeff

Jeff - really sorry about the delay on the reply here. =-)

This patch will no longer cleanly apply. I'm going to go ahead and close this ticket.

I hesitate to suggest supplying a new patch, but if you do, I promise to bug pmichaud & jnthn about it. =)

-- Will "Coke" Coleda

p6rt commented 14 years ago

The RT System itself - Status changed from 'new' to 'open'

p6rt commented 14 years ago

@coke - Status changed from 'open' to 'rejected'