Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions src/dsymbol/conversion/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -142,43 +142,46 @@ class SimpleParser : Parser
expect(tok!"unittest");
if (currentIs(tok!"{"))
skipBraces();
return null;
return allocator.make!Unittest;
}

override MissingFunctionBody parseMissingFunctionBody()
{
// Unlike many of the other parsing functions, it is valid and expected
// for this one to return `null` on valid code. Returning `null` in
// this function means that we are looking at a SpecifiedFunctionBody.
// The super-class will handle re-trying with the correct parsing
// function.

const bool needDo = skipContracts();
if (!needDo)
{
if (currentIs(tok!"{"))
return null;
}
else if (moreTokens && (currentIs(tok!"do") || current.text == "body"))
{
if (needDo && moreTokens && (currentIs(tok!"do") || current.text == "body"))
return null;
}
if (currentIs(tok!";"))
advance();
else
return null;
return allocator.make!MissingFunctionBody;
}

override SpecifiedFunctionBody parseSpecifiedFunctionBody()
{
bool needDo;

// no contracts
if (currentIs(tok!"{"))
skipBraces();
// skip contracts
else needDo = skipContracts();
if (needDo && !currentIs(tok!"{"))
advance();
// body
if (currentIs(tok!"{"))
skipBraces();
else
{
skipContracts();
if (currentIs(tok!"do") || (currentIs(tok!"identifier") && current.text == "body"))
advance();
if (currentIs(tok!"{"))
skipBraces();
}
return allocator.make!SpecifiedFunctionBody;
}

/**
* Skip contracts, and return `true` if the type of contract used requires
* that the next token is `do`.
*/
private bool skipContracts()
{
bool needDo;
Expand All @@ -187,8 +190,7 @@ class SimpleParser : Parser
{
if (currentIs(tok!"in"))
{
if (moreTokens)
advance();
advance();
if (currentIs(tok!"{"))
{
skipBraces();
Expand All @@ -199,13 +201,12 @@ class SimpleParser : Parser
}
else if (currentIs(tok!"out"))
{
if (moreTokens)
advance();
advance();
if (currentIs(tok!"("))
{
immutable bool asExpr = index < tokens.length - 2 &&
tokens[index + 1].type == tok!";" ||
(tokens[index + 1].type == tok!"identifier" && tokens[index + 2].type == tok!";");
immutable bool asExpr = peekIs(tok!";")
|| (peekIs(tok!"identifier")
&& index + 2 < tokens.length && tokens[index + 2].type == tok!";");
skipParens();
if (asExpr)
{
Expand All @@ -219,7 +220,8 @@ class SimpleParser : Parser
needDo = true;
}
}
else break;
else
break;
}
return needDo;
}
Expand Down