Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add $obj."method"(...) syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Nov 22, 2009
1 parent dae637e commit 23bb989
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/NQP/Actions.pm
Expand Up @@ -461,7 +461,7 @@ method regex_declarator($/, $key?) {

method dotty($/) {
my $past := $<args> ?? $<args>[0].ast !! PAST::Op.new( :node($/) );
$past.name( ~$<identifier> );
$past.name( $<quote> ?? $<quote>.ast !! ~$<longname> );
$past.pasttype('callmethod');
make $past;
}
Expand Down
7 changes: 6 additions & 1 deletion src/NQP/Grammar.pm
Expand Up @@ -307,7 +307,12 @@ rule regex_declarator {
}

token dotty {
'.' <identifier>
'.'
[ <longname=identifier>
| <?['"]> <quote>
[ <?[(]> || <.panic: "Quoted method name requires parenthesized arguments"> ]
]

[
| <?[(]> <args>
| ':' \s <args=.arglist>
Expand Down
7 changes: 6 additions & 1 deletion t/nqp/26-methodops.t
Expand Up @@ -2,7 +2,7 @@

# method ops (just method calls for now)

plan(3);
plan(4);

class Foo {
method blarg() {
Expand All @@ -11,6 +11,9 @@ class Foo {
method blargless() {
'ok 3 # argument-less method calls work'
}
method blast() {
'ok 4 # string method calls work'
}
}

class Bar {
Expand All @@ -28,3 +31,5 @@ my $foo := Foo.new();
say($foo.blarg());
say(blarg());
say($foo.blargless);
my $t := 'st';
say($foo."bla$t"());

0 comments on commit 23bb989

Please sign in to comment.