Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[v6] Fix parsing of @_ placeholder
  • Loading branch information
sorear committed Jan 12, 2011
1 parent b0be6ab commit 8f7f9e8
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions v6/harness
Expand Up @@ -27,6 +27,27 @@ use STD;

augment class NieczaActions {
sub node($M) { { line => $M.cursor.lineof($M.to) } }
method get_placeholder_sig($/) {
# for some reason, STD wants to deparse this
my @things = $*CURLEX<$?SIGNATURE>.split(", ");
shift @things if @things[0] eq '';
my @parms;
for @things -> $t {
if substr($t, 0, 9) eq '$_ is ref' {
push @parms, ::Sig::Parameter.new(optional => True,
slot => '$_', name => '$_');
} elsif $t eq '*@_' {
push @parms, ::Sig::Parameter.new(slurpy => True, slot => '@_',
list => True, name => '*@_');
} elsif defined '$@%&'.index(substr($t,0,1)) {
push @parms, ::Sig::Parameter.new(slot => $t, name => $t,
list => (substr($t,0,1) eq '@'), hash => (substr($t,0,1) eq '%'));
} else {
$/.CURSOR.sorry('Named placeholder parameters NYI');
}
}
return Sig.new(params => @parms);
}
method FALLBACK($meth, $/) {
if $meth eq '::($name)' { # XXX STD miscompilation
if $<O><prec> eq 't=' { # additive
Expand All @@ -49,6 +70,55 @@ method FALLBACK($meth, $/) {
}

augment class STD { #OK exist
sub _subst($M is rw, $text is rw, $regex, $repl) {
$text = $text.Str;
$M = ($text ~~ $regex);
if $M {
$text = $text.substr(0, $M.from) ~
(($repl ~~ Str) ?? $repl !! $repl()) ~
$text.substr($M.to, $text.chars - $M.to);
}
?$M;
}
method add_placeholder($name) {
my $decl = $*CURLEX.<!IN_DECL> // '';
$decl = ' ' ~ $decl if $decl;
my $*IN_DECL = 'variable';

if $*SIGNUM {
return self.sorry("Placeholder variable $name is not allowed in the$decl signature");
}
elsif my $siggy = $*CURLEX.<$?SIGNATURE> {
return self.sorry("Placeholder variable $name cannot override existing signature $siggy");
}
if not $*CURLEX.<!NEEDSIG> {
if $*CURLEX === $*UNIT {
return self.sorry("Placeholder variable $name may not be used outside of a block");
}
return self.sorry("Placeholder variable $name may not be used here because the surrounding$decl block takes no signature");
}
if $name ~~ /\:\:/ {
return self.sorry("Placeholder variable $name may not be package qualified");
}

my $varname = $name;
my $twigil = '';
my $signame = $varname;
my $M;
if _subst($M, $varname, /<[ ^ : ]>/, "") {
$twigil = $M.Str;
$signame = ($twigil eq ':' ?? ':' !! '') ~ $varname;
}
return self if $*CURLEX.{'%?PLACEHOLDERS'}{$signame}++;

if $*CURLEX{$varname} {
return self.sorry("$varname has already been used as a non-placeholder in the surrounding$decl block,\n so you will confuse the reader if you suddenly declare $name here");
}

self.add_my_name($varname);
$*CURLEX{$varname}<used> = 1;
self;
}
role herestop1 {
token stopper { ^^ {} \h*? $*DELIM \h* <.unv>?? $$ \v? }
}
Expand Down

0 comments on commit 8f7f9e8

Please sign in to comment.