I'm not sure if I have seen this requested or discussed. Is there a parsing reason why Perl 6 would allow nested statement modifiers or is it mainly a sanity-please-don't-hurt-my-eyes reason.
It is silly to do things such as: say "Interesting" if $just_because if $because; But it is sort of useful to be able to do things such as: say "Hrm $_" for 1 .. 3 unless $why_not; The grammar_rules.pg defines a statement as: token statement { | <statement_control> | <block> | <control_block> | <class_block> | <use_statement> | <expression: ;> <statement_modifier>? } It seems like it should be possible to change that to: token statement { | <statement_control> | <block> | <control_block> | <class_block> | <use_statement> | <expression: ;> <statement_modifier>* } pge2past.tg would need to be updated to loop on found statement modifiers rather than only do the first one found. I'm afraid I'm not familiar enough with PIR to write the looping portion but I can read the following section enought to know that it shouldn't be too hard to change. The question is would a patch to add the functionality be accepted if I went to the trouble of figuring out how to do it? Paul Seamons Section of pge2past.tg that re-writes the expression to be enclosed by an if block: transform past (Perl6::Grammar::statement) :language('PIR') { $P0 = node['statement_control'] if $P0 goto statement_control $P0 = node['block'] if $P0 goto statement_block $P0 = node['use_statement'] if $P0 goto statement_use expression: .local pmc stmt $P0 = node['expression'] stmt = tree.'get'('past', $P0, 'Perl6::Grammar::expression') $P0 = node['statement_modifier'] unless $P0 goto expression_1 stmt_modifier: # handle if/unless modifier .local pmc modifier, exprpast, thenpast, elsepast modifier = $P0[0] thenpast = stmt null elsepast $S0 = modifier['KEY'] if $S0 != 'unless' goto stmt_modifier_1 exchange thenpast, elsepast stmt_modifier_1: $P0 = modifier['expression'] exprpast = tree.'get'('past', $P0, 'Perl6::Grammar::expression') stmt = new 'Perl6::PAST::Op' stmt.'init'(exprpast, thenpast, elsepast, 'name'=>'statement_control:if', 'node'=>modifier) expression_1: