Skip to content

Commit

Permalink
if a case: ends with return, do not add a break statement
Browse files Browse the repository at this point in the history
  • Loading branch information
pplantinga committed Mar 12, 2014
1 parent 6778cc1 commit da2058f
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions source/delight/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,29 @@ class Parser
/// return statement
string return_state( string token )
{
if ( l.peek() == "\n" )
return token ~ ";";
else
return token ~ " " ~ expression_state( l.pop() ) ~ ";";
string next = l.pop();

string statement = "return";

if ( next != "\n" )
{
statement ~= " " ~ expression_state( next );
next = l.pop();
}

statement ~= ";" ~ endline_state( next );

// Ensure we don't write a "break" right after a "return"
if ( context.front == "case" && l.peek() == "dedent" )
{
string dedent = l.pop();
if ( l.peek() != "case" )
return statement ~ newline_state( dedent );
else
context.removeFront();
}

return statement;
}

/// This code gets passed to D as is
Expand Down

0 comments on commit da2058f

Please sign in to comment.