Created
November 12, 2009 19:56
-
-
Save perlpilot/233220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm | |
index 074cf6f..7e338d0 100644 | |
--- a/src/Perl6/Actions.pm | |
+++ b/src/Perl6/Actions.pm | |
@@ -102,9 +102,13 @@ method statementlist($/) { | |
make $past; | |
} | |
-method statement($/) { | |
+method statement($/, $key?) { | |
my $past; | |
- if $<EXPR> { $past := $<EXPR>.ast; } | |
+ if $<EXPR> { | |
+ $past := $<statement_mod_cond> | |
+ ?? PAST::Op.new($<statement_mod_cond>[0].ast, $<EXPR>.ast, :pasttype('unless'), :node($/) ) | |
+ !! $<EXPR>.ast; | |
+ } | |
elsif $<statement_control> { $past := $<statement_control>.ast; } | |
else { $past := 0; } | |
make $past; | |
@@ -311,6 +315,12 @@ sub add_phaser($/, $bank) { | |
make PAST::Stmts.new(:node($/)); | |
} | |
+# Statement modifiers | |
+ | |
+method statement_mod_cond:sym<if>($/) { make $<mod_expr>.ast; } | |
+method statement_mod_cond:sym<unless>($/) { make $<mod_expr>.ast; } | |
+ | |
+ | |
## Terms | |
method term:sym<colonpair>($/) { make $<colonpair>.ast; } | |
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm | |
index e3586d8..57f9da6 100644 | |
--- a/src/Perl6/Grammar.pm | |
+++ b/src/Perl6/Grammar.pm | |
@@ -145,7 +145,10 @@ token statement { | |
<!before <[\])}]> | $ > | |
[ | |
| <statement_control> | |
- | <EXPR> | |
+ | <EXPR> <.ws> | |
+ [ | |
+ | <statement_mod_cond> | |
+ ]? | |
] | |
} | |
@@ -257,6 +260,13 @@ token blorst { | |
\s <.ws> [ <?[{]> <block> | <statement> ] | |
} | |
+## Statement modifiers | |
+ | |
+proto token statement_mod_cond { <...> } | |
+ | |
+token statement_mod_cond:sym<if> { <sym> :s <mod_expr=EXPR> } | |
+token statement_mod_cond:sym<unless> { <sym> :s <mod_expr=EXPR> } | |
+ | |
## Terms | |
token term:sym<colonpair> { <colonpair> } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment