Skip to content

Commit f34c0e2

Browse files
committed
Update the D grammar
1 parent cddce29 commit f34c0e2

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
with:
5555
path: dmd
5656
repository: dlang/dmd
57-
ref: 7bff453b5e3b16c5eab2874984ed7d973a4f9e5b
57+
ref: 83adb8aeab12ef7902eefae81223fdd300cfc1e0
5858
persist-credentials: false
5959

6060
- name: Checkout JSONTestSuite

examples/d/grammard.ebnf

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Based on grammar from dlang.org commit 9607293a246a0dc7a96417a84266cd0803675dcd
1+
// Based on grammar from dlang.org commit 2c3088b5b6c1f35dfb3a0b2a37d4a0fe891d4350
22
33
import "grammardlex.ebnf";
44
SourceFile @start
@@ -288,30 +288,18 @@ PrimaryExpression @directUnwrap
288288
| "." IdentifierExpression
289289
| <TemplateInstance
290290
| "." TemplateInstance
291-
| <ThisExpression
292-
| "super"
293-
| "null"
294-
| "true"
295-
| "false"
296291
| "$"
297-
| IntegerLiteral
298-
| FloatLiteral
299-
| CharacterLiteral
300-
| <StringLiterals
301-
| <InterpolationExpressionSequence
302-
| <ArrayLiteral
303-
| <AssocArrayLiteral
304-
| <FunctionLiteralNoParen
292+
| <LiteralExpression
305293
| <AssertExpression
306294
| <MixinExpression
307295
| <ImportExpression
308296
| <NewExpression
309297
| FundamentalType "." Identifier
310-
// | "(" Type ")" "." Identifier
298+
// | TypeCtor? "(" Type ")" "." Identifier
311299
// | "(" Type ")" "." TemplateInstance
312300
// | FundamentalType "(" NamedArgumentList? ")"
313301
| TypeCtor "(" Type ")" "." Identifier
314-
// | TypeCtor "(" Type ")" "(" NamedArgumentList? ")"
302+
// | TypeCtor? "(" Type ")" "(" NamedArgumentList? ")"
315303
| <Typeof
316304
| <TypeidExpression
317305
| <IsExpression
@@ -320,6 +308,21 @@ PrimaryExpression @directUnwrap
320308
| <Vector
321309
| <PrimaryExpressionParen
322310
;
311+
LiteralExpression
312+
= <ThisExpression
313+
| "super"
314+
| "null"
315+
| "true"
316+
| "false"
317+
| IntegerLiteral
318+
| FloatLiteral
319+
| CharacterLiteral
320+
| <StringLiterals
321+
| <InterpolationExpressionSequence
322+
| <ArrayLiteral
323+
| <AssocArrayLiteral
324+
| <FunctionLiteralNoParen
325+
;
323326
PrimaryExpressionParen @backtrack
324327
= <FunctionLiteralParen
325328
| <ParenExpression
@@ -400,8 +403,10 @@ AssertExpression
400403
= "assert" "(" AssertArguments ")"
401404
;
402405
AssertArguments
403-
= AssignExpression ","?
404-
| AssignExpression "," AssignExpression ","?
406+
= <AssignExpression
407+
| AssignExpression ","
408+
| AssignExpression "," AssignExpression
409+
| AssignExpression "," AssignExpression ","
405410
;
406411
MixinExpression @directUnwrap
407412
= <Mixin
@@ -560,6 +565,9 @@ NonVoidInitializer @backtrack
560565
= <ArrayStructInitializer
561566
| <AssignExpression
562567
;
568+
VoidInitializer
569+
= "void"
570+
;
563571
ArrayInitializer
564572
= "[" ArrayMemberInitializations? "]"
565573
;
@@ -619,9 +627,6 @@ AliasReassignment
619627
| IdentifierExpression "=" FunctionLiteral ";"
620628
| IdentifierExpression "=" StorageClasses? BasicType Parameters MemberFunctionAttributes? ";"
621629
;
622-
VoidInitializer
623-
= "void"
624-
;
625630
AsmStatement
626631
= "asm" FunctionAttributes? "{" AsmInstructionList? "}"
627632
;
@@ -986,6 +991,7 @@ FunctionAttributeKwd @directUnwrap
986991
;
987992
AtAttribute @directUnwrap
988993
= "@" Identifier>>"disable"
994+
| "@" Identifier>>"__future"
989995
| "@" Identifier>>"nogc"
990996
| "@" Identifier>>"live"
991997
| <Property
@@ -1149,10 +1155,18 @@ IfCondition @backtrack
11491155
| <Expression
11501156
;
11511157
IfConditionDecl
1152-
= Auto Identifier "=" Expression
1153-
| Scope Identifier "=" Expression
1154-
| TypeCtors Identifier "=" Expression
1155-
| TypeCtors? PostfixType Declarator "=" Expression
1158+
= IfConditionStorageClasses Identifier "=" Expression
1159+
| IfConditionStorageClasses? PostfixType Declarator "=" Expression
1160+
;
1161+
IfConditionStorageClasses
1162+
= <IfConditionStorageClass
1163+
| IfConditionStorageClass IfConditionStorageClasses
1164+
;
1165+
IfConditionStorageClass
1166+
= "scope"
1167+
| "auto"
1168+
| "ref"
1169+
| <TypeCtor
11561170
;
11571171
ThenStatement @directUnwrap
11581172
= <ScopeStatement
@@ -1548,15 +1562,14 @@ VariadicParameter
15481562
= VariadicArgumentsAttributes? "..."
15491563
;
15501564
Parameter
1565+
= ParameterDeclaration
1566+
| ParameterDeclaration "..."
1567+
| ParameterDeclaration "=" AssignExpression
1568+
| ParameterDeclaration "=" AssignExpression "..."
1569+
;
1570+
ParameterDeclaration
15511571
= ParameterAttributes? PostfixType Declarator
1552-
| ParameterAttributes? PostfixType Declarator "..."
1553-
| ParameterAttributes? PostfixType Declarator "=" AssignExpression
1554-
| ParameterAttributes? PostfixType Declarator "=" AssignExpression "..."
1555-
| ParameterAttributes PostfixType
1556-
| ParameterAttributes? PostfixType "=" AssignExpression
1557-
| ParameterAttributes? PostfixType "=" AssignExpression "..."
1558-
| PostfixType
1559-
| ParameterAttributes? PostfixType "..."
1572+
| ParameterAttributes? PostfixType
15601573
;
15611574
ParameterAttributes @array @regArray
15621575
= ParameterStorageClass
@@ -1662,13 +1675,13 @@ InOutStatement @directUnwrap
16621675
InContractExpression
16631676
= "in" "(" AssertArguments ")"
16641677
;
1678+
InStatement
1679+
= "in" BlockStatement
1680+
;
16651681
OutContractExpression
16661682
= "out" "(" ";" AssertArguments ")"
16671683
| "out" "(" Identifier ";" AssertArguments ")"
16681684
;
1669-
InStatement
1670-
= "in" BlockStatement
1671-
;
16721685
OutStatement
16731686
= "out" BlockStatement
16741687
| "out" "(" Identifier ")" BlockStatement

examples/d/grammardlex.ebnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Based on grammar from dlang.org commit 9607293a246a0dc7a96417a84266cd0803675dcd
1+
// Based on grammar from dlang.org commit 2c3088b5b6c1f35dfb3a0b2a37d4a0fe891d4350
22
33
token ByteOrderMark
44
= "\uFEFF"

examples/d/testgrammard.d

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ immutable string[] syntaxErrorExtra = [
241241
"C style cast illegal",
242242
"instead of `long ",
243243
"instead of C-style syntax, use D-style",
244-
"only parameters, functions and `foreach` declarations can be `ref`",
245244
"function cannot have enum storage class",
246245
"token is not allowed in postfix position",
247246
"String postfixes on interpolated expression sequences are not allowed.",
247+
"use `{ }` for an empty statement, not `;`",
248248
];
249249

250250
size_t[syntaxErrorExceptions.length] syntaxErrorExceptionsUsed;
@@ -358,8 +358,6 @@ bool runTests(TestDirType testDirType, string testDir)
358358
{
359359
if (relative.startsWith("protection"))
360360
continue;
361-
if (relative == "mixintype2.d")
362-
continue;
363361
if (relative.startsWith("imports"))
364362
continue;
365363
}
@@ -386,12 +384,14 @@ bool runTests(TestDirType testDirType, string testDir)
386384
expectFailure = true;
387385
}
388386

389-
if (testDirType == TestDirType.failDmd && relative.among(
387+
if (relative.among(
390388
"fail18228.d",
391389
"test12228.d",
392390
"fail_typeof.d",
393391
"fail19912d.d",
394392
"fail54.d",
393+
"ident_all.d",
394+
"ident_c11.d",
395395
))
396396
{
397397
if (expectFailure)
@@ -403,7 +403,8 @@ bool runTests(TestDirType testDirType, string testDir)
403403
if (testDirType == TestDirType.failDmd && relative.among(
404404
"fail11751.d",
405405
"t1252.d",
406-
"fail14009.d"
406+
"fail14009.d",
407+
"mixintype2.d"
407408
))
408409
{
409410
if (!expectFailure)

0 commit comments

Comments
 (0)