Skip to content

Commit 391212f

Browse files
eernstgCommit Queue
authored andcommitted
Update the specification grammar
The augmentations feature has been modified over a period of time. This CL introduces the associated grammar changes into the specification grammars. Change-Id: Iaa4cdd4c3ffea26ac327265468d68fae59efb2fd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467840 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
1 parent 195c969 commit 391212f

File tree

2 files changed

+58
-40
lines changed

2 files changed

+58
-40
lines changed

tools/spec_parser/Dart.g

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
// CHANGES:
66
//
7+
// v0.57 Introduce augmentation related updates.
8+
//
79
// v0.56 Update constructor declaration syntax to allow `constructorHead`.
810
// Recatogerize 'factory' to be a reserved word and not a built-in identifier.
911
//
@@ -305,6 +307,7 @@ topLevelDefinition
305307
| AUGMENT? EXTERNAL getterSignature ';'
306308
| AUGMENT? EXTERNAL setterSignature ';'
307309
| AUGMENT? EXTERNAL finalVarOrType identifierList ';'
310+
| AUGMENT? ABSTRACT finalVarOrType identifierList ';'
308311
| AUGMENT? getterSignature (functionBody | ';')
309312
| AUGMENT? setterSignature (functionBody | ';')
310313
| AUGMENT? functionSignature (functionBody | ';')
@@ -428,7 +431,8 @@ typeWithParameters
428431

429432
classDeclaration
430433
: AUGMENT? (classModifiers | mixinClassModifiers)
431-
CLASS classNameMaybePrimary superclass? interfaces? classBody
434+
CLASS classNameMaybePrimary superclass? interfaces?
435+
memberedDeclarationBody
432436
| classModifiers MIXIN? CLASS mixinApplicationClass
433437
;
434438

@@ -442,11 +446,15 @@ classNameMaybePrimary
442446
| typeWithParameters
443447
;
444448

445-
classBody
446-
: LBRACE (metadata memberDeclaration)* RBRACE
449+
memberedDeclarationBody
450+
: LBRACE memberDeclarations RBRACE
447451
| ';'
448452
;
449453

454+
memberDeclarations
455+
: (metadata memberDeclaration)*
456+
;
457+
450458
classModifiers
451459
: SEALED
452460
| ABSTRACT? (BASE | INTERFACE | FINAL)?
@@ -479,29 +487,25 @@ mixinApplicationClass
479487
;
480488

481489
mixinDeclaration
482-
: AUGMENT? BASE? MIXIN typeWithParameters
490+
: BASE? MIXIN typeWithParameters
483491
(ON typeNotVoidNotFunctionList)? interfaces?
484-
LBRACE (metadata memberDeclaration)* RBRACE
492+
memberedDeclarationBody
493+
| AUGMENT BASE? MIXIN typeWithParameters interfaces?
494+
memberedDeclarationBody
485495
;
486496

487497
extensionTypeDeclaration
488-
: EXTENSION TYPE primaryConstructor interfaces? extensionTypeBody
498+
: EXTENSION TYPE primaryConstructor interfaces?
499+
memberedDeclarationBody
489500
| AUGMENT EXTENSION TYPE typeWithParameters interfaces?
490-
extensionTypeBody
491-
;
492-
493-
extensionTypeBody
494-
: LBRACE (metadata memberDeclaration)* RBRACE
495-
| ';'
501+
memberedDeclarationBody
496502
;
497503

498504
extensionDeclaration
499-
: EXTENSION typeIdentifierNotType? typeParameters? ON type extensionBody
500-
| AUGMENT EXTENSION typeIdentifierNotType typeParameters? extensionBody
501-
;
502-
503-
extensionBody
504-
: LBRACE (metadata memberDeclaration)* RBRACE
505+
: EXTENSION typeIdentifierNotType? typeParameters? ON type
506+
memberedDeclarationBody
507+
| AUGMENT EXTENSION typeIdentifierNotType typeParameters?
508+
memberedDeclarationBody
505509
;
506510

507511
methodSignature
@@ -697,10 +701,13 @@ mixinApplication
697701
;
698702

699703
enumType
700-
: AUGMENT? ENUM classNameMaybePrimary mixins? interfaces? LBRACE
701-
enumEntry (',' enumEntry)* ','?
702-
(';' (metadata memberDeclaration)*)?
703-
RBRACE
704+
: AUGMENT? ENUM classNameMaybePrimary mixins? interfaces?
705+
LBRACE enumBody? RBRACE
706+
;
707+
708+
enumBody
709+
: enumEntry (',' enumEntry)* ','? (';' memberDeclarations)?
710+
| ';' memberDeclarations
704711
;
705712

706713
enumEntry

tools/spec_parser/dart_spec_parser/Dart.g4

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
// CHANGES:
66
//
7+
// v0.58 Introduce augmentation related updates.
8+
//
79
// v0.57 Update constructor declaration syntax to allow `constructorHead`.
810
// Recatogerize 'factory' to be a reserved word and not a built-in identifier.
911
//
@@ -315,6 +317,7 @@ topLevelDefinition
315317
| AUGMENT? EXTERNAL getterSignature ';'
316318
| AUGMENT? EXTERNAL setterSignature ';'
317319
| AUGMENT? EXTERNAL finalVarOrType identifierList ';'
320+
| AUGMENT? ABSTRACT finalVarOrType identifierList ';'
318321
| AUGMENT? getterSignature (functionBody | ';')
319322
| AUGMENT? setterSignature (functionBody | ';')
320323
| AUGMENT? functionSignature (functionBody | ';')
@@ -438,7 +441,8 @@ typeWithParameters
438441

439442
classDeclaration
440443
: AUGMENT? (classModifiers | mixinClassModifiers)
441-
CLASS classNameMaybePrimary superclass? interfaces? classBody
444+
CLASS classNameMaybePrimary superclass? interfaces?
445+
memberedDeclarationBody
442446
| classModifiers MIXIN? CLASS mixinApplicationClass
443447
;
444448

@@ -452,11 +456,15 @@ classNameMaybePrimary
452456
| typeWithParameters
453457
;
454458

455-
classBody
456-
: LBRACE (metadata memberDeclaration)* RBRACE
459+
memberedDeclarationBody
460+
: LBRACE memberDeclarations RBRACE
457461
| ';'
458462
;
459463

464+
memberDeclarations
465+
: (metadata memberDeclaration)*
466+
;
467+
460468
classModifiers
461469
: SEALED
462470
| ABSTRACT? (BASE | INTERFACE | FINAL)?
@@ -489,25 +497,25 @@ mixinApplicationClass
489497
;
490498

491499
mixinDeclaration
492-
: AUGMENT? BASE? MIXIN typeWithParameters
500+
: BASE? MIXIN typeWithParameters
493501
(ON typeNotVoidNotFunctionList)? interfaces?
494-
LBRACE (metadata memberDeclaration)* RBRACE
502+
memberedDeclarationBody
503+
| AUGMENT BASE? MIXIN typeWithParameters interfaces?
504+
memberedDeclarationBody
495505
;
496506

497507
extensionTypeDeclaration
498-
: EXTENSION TYPE primaryConstructor interfaces? extensionTypeBody
508+
: EXTENSION TYPE primaryConstructor interfaces?
509+
memberedDeclarationBody
499510
| AUGMENT EXTENSION TYPE typeWithParameters interfaces?
500-
extensionTypeBody
501-
;
502-
503-
extensionTypeBody
504-
: LBRACE (metadata memberDeclaration)* RBRACE
505-
| ';'
511+
memberedDeclarationBody
506512
;
507513

508514
extensionDeclaration
509-
: EXTENSION typeIdentifierNotType? typeParameters? ON type extensionBody
510-
| AUGMENT EXTENSION typeIdentifierNotType typeParameters? extensionBody
515+
: EXTENSION typeIdentifierNotType? typeParameters? ON type
516+
memberedDeclarationBody
517+
| AUGMENT EXTENSION typeIdentifierNotType typeParameters?
518+
memberedDeclarationBody
511519
;
512520

513521
extensionBody
@@ -707,10 +715,13 @@ mixinApplication
707715
;
708716

709717
enumType
710-
: AUGMENT? ENUM classNameMaybePrimary mixins? interfaces? LBRACE
711-
enumEntry (',' enumEntry)* ','?
712-
(';' (metadata memberDeclaration)*)?
713-
RBRACE
718+
: AUGMENT? ENUM classNameMaybePrimary mixins? interfaces?
719+
LBRACE enumBody? RBRACE
720+
;
721+
722+
enumBody
723+
: enumEntry (',' enumEntry)* ','? (';' memberDeclarations)?
724+
| ';' memberDeclarations
714725
;
715726

716727
enumEntry

0 commit comments

Comments
 (0)