Skip to content

Commit

Permalink
Merge pull request #242 from BBasile/issue-241
Browse files Browse the repository at this point in the history
fix #241 - `body` should be supported as identifier
merged-on-behalf-of: BBasile <BBasile@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Jun 14, 2018
2 parents b7f792f + 9d6fa82 commit 086cf06
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/dparse/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class Formatter(Sink)
debug(verbose) writeln("BodyStatement");

newline();
put("body");
put("do");
format(bodyStatement.blockStatement);
}

Expand Down
4 changes: 2 additions & 2 deletions src/dparse/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private enum operators = [

/// Kewords
private enum keywords = [
"abstract", "alias", "align", "asm", "assert", "auto", "body", "bool",
"abstract", "alias", "align", "asm", "assert", "auto", "bool",
"break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat",
"char", "class", "const", "continue", "creal", "dchar", "debug", "default",
"delegate", "delete", "deprecated", "do", "double", "else", "enum",
Expand Down Expand Up @@ -287,7 +287,7 @@ public bool isOperator(IdType type) nothrow pure @safe @nogc
* Keyword token types.
*/
public alias Keywords = AliasSeq!(tok!"abstract", tok!"alias", tok!"align",
tok!"asm", tok!"assert", tok!"auto", tok!"body", tok!"break",
tok!"asm", tok!"assert", tok!"auto", tok!"break",
tok!"case", tok!"cast", tok!"catch", tok!"class", tok!"const",
tok!"continue", tok!"debug", tok!"default", tok!"delegate",
tok!"delete", tok!"deprecated", tok!"do", tok!"else", tok!"enum",
Expand Down
15 changes: 8 additions & 7 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ class Parser
{
mixin(traceEnterAndExit!(__FUNCTION__));
auto node = allocator.make!BodyStatement;
if (!currentIsOneOf(tok!"body", tok!"do"))
if (!currentIs(tok!"do") && current.text != "body")
return null;
advance();
mixin(simpleParseItem!("blockStatement|parseBlockStatement"));
Expand Down Expand Up @@ -3026,7 +3026,7 @@ class Parser
}
else if (currentIs(tok!"{"))
mixin(parseNodeQ!(`node.blockStatement`, `BlockStatement`));
else if (currentIsOneOf(tok!"in", tok!"out", tok!"body", tok!"do"))
else if (currentIsOneOf(tok!"in", tok!"out", tok!"do") || current.text == "body")
{
if (currentIs(tok!"in"))
{
Expand All @@ -3042,7 +3042,7 @@ class Parser
}
// Allow function bodies without body statements because this is
// valid inside of interfaces.
if (currentIsOneOf(tok!"body", tok!"do"))
if (currentIsOneOf(tok!"do") || current.text == "body")
mixin(parseNodeQ!(`node.bodyStatement`, `BodyStatement`));
}
else
Expand Down Expand Up @@ -3190,8 +3190,8 @@ class Parser
if (currentIsOneOf(tok!"function", tok!"delegate"))
{
node.functionOrDelegate = advance().type;
if (!currentIsOneOf(tok!"(", tok!"in", tok!"body", tok!"do",
tok!"out", tok!"{", tok!"=>"))
if (!currentIsOneOf(tok!"(", tok!"in", tok!"do",
tok!"out", tok!"{", tok!"=>") && current.text != "body")
mixin(parseNodeQ!(`node.returnType`, `Type`));
}
if (startsWith(tok!"identifier", tok!"=>"))
Expand Down Expand Up @@ -4702,6 +4702,8 @@ class Parser
node.dot = advance();
goto case;
case tok!"identifier":
if (current.text == "body")
goto case tok!"do";
if (peekIs(tok!"=>"))
mixin(parseNodeQ!(`node.functionLiteralExpression`, `FunctionLiteralExpression`));
else
Expand Down Expand Up @@ -4739,7 +4741,6 @@ class Parser
case tok!"{":
case tok!"in":
case tok!"out":
case tok!"body":
case tok!"do":
mixin(parseNodeQ!(`node.functionLiteralExpression`, `FunctionLiteralExpression`));
break;
Expand Down Expand Up @@ -7718,7 +7719,7 @@ protected: final:
mixin(tokenCheck!"(");
mixin(tokenCheck!")");
StackBuffer attributes;
while (moreTokens() && !currentIsOneOf(tok!"{", tok!"in", tok!"out", tok!"body", tok!"do", tok!";"))
while (moreTokens() && !currentIsOneOf(tok!"{", tok!"in", tok!"out", tok!"do", tok!";") && current.text != "body")
if (!attributes.put(parseMemberFunctionAttribute()))
return null;
ownArray(node.memberFunctionAttributes, attributes);
Expand Down
1 change: 0 additions & 1 deletion test/fuzzer.d
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ again:
case tok!"asm":
case tok!"assert":
case tok!"auto":
case tok!"body":
case tok!"break":
case tok!"case":
case tok!"cast":
Expand Down
18 changes: 18 additions & 0 deletions test/pass_files/body_as_ident.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
void body()
in
{
}
body
{
Corpulence body;
alias b = body;
}

struct Foo(Body)
{
static if (is(Body)){}
}

enum Body;

@Body void foo();
1 change: 0 additions & 1 deletion test/tester.d
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ void testTokenChecks()
case tok!"asm":
case tok!"assert":
case tok!"auto":
case tok!"body":
case tok!"break":
case tok!"case":
case tok!"cast":
Expand Down

0 comments on commit 086cf06

Please sign in to comment.