Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
allow identifiers to begin with "next"
If one declared a sub that began with "next", "redo" or "last",
it was treated like statement "next" directly followed by an
identifier, which crashed.
  • Loading branch information
FROGGS committed Jan 18, 2013
1 parent 5c25b77 commit 8ac18c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/NQP/Grammar.pm
Expand Up @@ -773,9 +773,9 @@ grammar NQP::Grammar is HLL::Grammar {

token prefix:sym<return> { <sym> \s <O('%list_prefix')> { $*RETURN_USED := 1 } }
token prefix:sym<make> { <sym> \s <O('%list_prefix')> }
token term:sym<last> { <sym> { $*CONTROL_USED := 1 } }
token term:sym<next> { <sym> { $*CONTROL_USED := 1 } }
token term:sym<redo> { <sym> { $*CONTROL_USED := 1 } }
token term:sym<last> { <sym> <!before <identifier> > { $*CONTROL_USED := 1 } }
token term:sym<next> { <sym> <!before <identifier> > { $*CONTROL_USED := 1 } }
token term:sym<redo> { <sym> <!before <identifier> > { $*CONTROL_USED := 1 } }

method smartmatch($/) {
# swap rhs into invocant position
Expand Down
10 changes: 9 additions & 1 deletion t/nqp/11-sub.t
Expand Up @@ -2,7 +2,7 @@

# check subs

say('1..14');
say('1..17');

sub one ( ) {
say("ok 1 # sub def and call");
Expand Down Expand Up @@ -78,3 +78,11 @@ say('ok ', term:sym<self>());

say( (nqp::isinvokable(sub() {}) ?? 'ok 13' !! 'no 13' ) ~ ' nqp::isinvokable on sub');
say( (!nqp::isinvokable(666) ?? 'ok 14' !! 'no 14' ) ~ ' nqp::isinvokable on non sub');

# #73, test that a sub can start with last, next and redo
sub last_() { 15 };
say('ok ', last_());
sub next_() { 16 };
say('ok ', next_());
sub redo_() { 17 };
say('ok ', redo_());

0 comments on commit 8ac18c6

Please sign in to comment.