Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
foo <a b c> is only one formal argument
  • Loading branch information
sorear committed May 27, 2011
1 parent be60cde commit fbf986f
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/niecza
Expand Up @@ -29,6 +29,80 @@ use STD;
use Sig;

augment class NieczaActions {
sub mkstringycat($/, *@strings) {
my @a;
for @strings -> $s {
my $i = ($s !~~ Op) ?? ::Op::StringLiteral.new(|node($/),
text => $s) !! $s;

# this *might* belong in an optimization pass
if @a && @a[*-1] ~~ ::Op::StringLiteral &&
$i ~~ ::Op::StringLiteral {
@a[*-1] = ::Op::StringLiteral.new(|node($/),
text => (@a[*-1].text ~ $i.text));
} else {
push @a, $i;
}
}
if @a == 0 {
return ::Op::StringLiteral.new(|node($/), text => "");
} elsif @a == 1 {
return (@a[0] ~~ ::Op::StringLiteral) ?? @a[0] !!
mkcall($/, '&prefix:<~>', @a[0]);
} else {
return mkcall($/, '&infix:<~>', @a);
}
}
method process_nibble($/, @bits, $prefix?) {
my @acc;
for @bits -> $n {
my $ast = $n.ast;

if $ast ~~ CClass {
$n.CURSOR.sorry("Cannot use a character class in a string");
$ast = "";
}

if $ast !~~ Op && defined($prefix) && $prefix ne "" {
$ast = $ast.split(/^^<before \h>[ $prefix || \h+ ]/).join("");
}

push @acc, $ast;
}

my $post = $/.CURSOR.postprocessor;
make mkstringycat($/, @acc);

if $post eq 'null' {
# already OK
}
# actually quotewords is a bit trickier than this...
elsif $post eq 'words' || $post eq 'quotewords' {
my $sl = $/.ast;
if !$sl.^isa(::Op::StringLiteral) {
make ::Op::CallMethod.new(|node($/), :name<words>, receiver => $sl);
}
else {
my @tok = $sl.text.words;
@tok = map { ::Op::StringLiteral.new(|node($/), text => $_) }, @tok;

make ((@tok == 1) ?? @tok[0] !! ::Op::Paren.new(|node($/),
inside => ::Op::SimpleParcel.new(|node($/), items => @tok)));
}
}
elsif $post eq 'path' {
# TODO could stand to be a lot fancier.
make ::Op::CallMethod(|node($/), receiver => $/.ast, :name<IO>);
}
elsif $post eq 'run' {
make mkcall($/, 'rungather', $/.ast);
}
else {
$/.CURSOR.sorry("Unhandled postprocessor $post");
}

$/.ast;
}
method simple_longname($/) {
my $r = self.mangle_longname($/);
($r<path>:exists) ?? [ @($r<path>), $r<name> ] !! [ 'MY', $r<name> ];
Expand Down
7 changes: 7 additions & 0 deletions test2.pl
Expand Up @@ -27,6 +27,13 @@
sub foo(X7140::X1122 $) { }
lives_ok { foo($obj) }, 'Parameter :: constraints work (1)';
dies_ok { foo(5) }, 'Parameter :: constraints work (1)';

sub bar(@x) {} #OK
lives_ok { bar <a b c> }, '<> splitting counts as one argument';

my class Foo { method foo() { 12 } }
#is Foo.?foo, 12, '.? works (successful)';
#is +[Foo.?bar], 0, '.? works (unsuccessful, list)';
}

#is $?FILE, 'test.pl', '$?FILE works';
Expand Down

0 comments on commit fbf986f

Please sign in to comment.