Skip to content

Commit

Permalink
Add rule <block> for '{' <statement_list> '}'
Browse files Browse the repository at this point in the history
  • Loading branch information
bschmalhofer committed Feb 22, 2009
1 parent 35e9551 commit a83c125
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
20 changes: 12 additions & 8 deletions src/pct/actions.pm
Expand Up @@ -111,6 +111,10 @@ method statement_list($/) {
make $stmts;
}

method block($/) {
make $( $<statement_list> );
}

method inline_sea_short_tag($/) {
make PAST::Op.new(
PAST::Val.new(
Expand All @@ -133,7 +137,7 @@ method namespace_definition($/, $key) {
PAST::Block.new(
:namespace($?NS),
:blocktype('immediate'),
$( $<statement_list> )
$( $<block> )
);
$?NS := '';

Expand Down Expand Up @@ -368,7 +372,7 @@ method conditional_expression($/) {
make PAST::Op.new(
:node($/),
$( $<expression> ),
$( $<statement_list> )
$( $<block> )
);
}

Expand All @@ -377,7 +381,7 @@ method do_while_statement($/) {
:pasttype('repeat_while'),
:node($/),
$( $<expression> ),
$( $<statement_list> )
$( $<block> )
);
}

Expand All @@ -387,7 +391,7 @@ method if_statement($/) {

my $else := undef;
if +$<else_clause> {
$else := $( $<else_clause>[0]<statement_list> );
$else := $( $<else_clause>[0]<block> );
}
my $first_eif := undef;
if +$<elseif_clause> {
Expand Down Expand Up @@ -520,7 +524,7 @@ method for_statement($/) {
my $init := $( $<var_assign> );

my $cond := $( $<expression>[0] );
my $work := PAST::Stmts.new( $( $<statement_list> ), $( $<expression>[1] ) );
my $work := PAST::Stmts.new( $( $<block> ), $( $<expression>[1] ) );
my $while := PAST::Op.new(
$cond,
$work,
Expand Down Expand Up @@ -623,7 +627,7 @@ method closure($/, $key) {
my $block := @?BLOCK.shift();

$block.control('return_pir');
$block.push( $( $<statement_list> ) );
$block.push( $( $<block> ) );

make $block;
}
Expand All @@ -647,7 +651,7 @@ method function_definition($/, $key) {

$block.name( ~$<function_name> );
$block.control('return_pir');
$block.push( $( $<statement_list> ) );
$block.push( $( $<block> ) );

make $block;
}
Expand Down Expand Up @@ -773,7 +777,7 @@ method class_method_definition($/, $key) {
)
);

$block.push( $( $<statement_list> ) );
$block.push( $( $<block> ) );

make $block;
}
Expand Down
22 changes: 13 additions & 9 deletions src/pct/grammar.pg
Expand Up @@ -146,7 +146,11 @@ rule statement {
}

rule statement_list {
<statement>* {*}
<statement>* {*}
}

rule block {
'{' <statement_list> '}' {*}
}

rule statement_delimiter {
Expand All @@ -161,7 +165,7 @@ rule empty_statement {

rule namespace_definition {
'namespace' <namespace_name>? {*} #= open
'{' <statement_list> '}' {*} #= close
<block> {*} #= close
}

# return can appear inside and outside functions
Expand Down Expand Up @@ -196,7 +200,7 @@ rule argument_list {
}

rule conditional_expression {
'(' <expression> ')' '{' <statement_list> '}'
'(' <expression> ')' <block>
{*}
}

Expand All @@ -208,7 +212,7 @@ rule if_statement {
}

rule else_clause {
'else' '{' <statement_list> '}'
'else' <block>
}

rule switch_statement {
Expand All @@ -227,12 +231,12 @@ rule while_statement {
}

rule do_while_statement {
'do' '{' <statement_list> '}' 'while' '(' <expression> ')' <.statement_delimiter>
'do' <block> 'while' '(' <expression> ')' <.statement_delimiter>
{*}
}

rule for_statement {
'for' '(' <var_assign> ';' <expression> ';' <expression> ')' '{' <statement_list> '}'
'for' '(' <var_assign> ';' <expression> ';' <expression> ')' <block>
{*}
}

Expand Down Expand Up @@ -451,7 +455,7 @@ rule term {
# declarations
rule closure {
'function' <param_list> <bind_list>? {*} #= open
'{' <statement_list> '}' {*} #= close
<block> {*} #= close
}

rule bind_list {
Expand All @@ -460,7 +464,7 @@ rule bind_list {

rule function_definition {
'function' <function_name> <param_list> {*} #= open
'{' <statement_list> '}' {*} #= close
<block> {*} #= close
}

rule param_list {
Expand Down Expand Up @@ -511,7 +515,7 @@ rule class_static_member_definition {

rule class_method_definition {
'function' <method_name> <param_list> {*} #= open
'{' <statement_list> '}' {*} #= close
<block> {*} #= close
}

token curly_interpolation {
Expand Down

0 comments on commit a83c125

Please sign in to comment.