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

Commit

Permalink
[nqp]: Add 'unless' statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 23, 2009
1 parent 182e820 commit 4174ed2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/NQP/Actions.pm
Expand Up @@ -63,6 +63,12 @@ method statement_control:sym<if>($/) {
make $past;
}

method statement_control:sym<unless>($/) {
my $past := $<xblock>.ast;
$past.pasttype('unless');
make $past;
}

## Terms

method term:sym<identifier>($/) {
Expand Down
6 changes: 6 additions & 0 deletions src/NQP/Grammar.pm
Expand Up @@ -60,6 +60,12 @@ token statement_control:sym<if> {
[ 'else'\s <else=pblock> ]?
}

token statement_control:sym<unless> {
$<sym>=['unless'] :s
<xblock>
[ <!before 'else'> || <.panic: 'unless does not take "else", please rewrite using "if"'> ]
}

## Terms

proto token term { <...> }
Expand Down
18 changes: 18 additions & 0 deletions t/nqp/03-unless.t
@@ -0,0 +1,18 @@
#!./parrot nqp.pbc

# check control structure 'unless'

say('1..4');

unless 0 { say("ok 1 # on one line"); }

say("ok 2 # statements following unless are okay");

unless 0 {
say("ok 3 # multi-line unless");
}

unless 1 {
print("not ");
}
say("ok 4 # testing conditional");

0 comments on commit 4174ed2

Please sign in to comment.