Skip to content

Commit

Permalink
Add support for omission of implementation as per #4015
Browse files Browse the repository at this point in the history
This CL adds support in the specification parser (Dart.g) for omitting
the implementation from several kinds of declarations. This is needed
because it must be possible to omit the implementation and provide it
in an augmentation.

The implementation is the initializing expression of a variable, the
function body of a top-lovel or static getter, setter, or method, or
the function body of a factory constructor.

Change-Id: If305dae376ba1c5aabcdd698824aca5d5b0fb97a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387160
Reviewed-by: Chloe Stefantsova <[email protected]>
Commit-Queue: Erik Ernst <[email protected]>
  • Loading branch information
eernstg authored and Commit Queue committed Sep 27, 2024
1 parent 8076595 commit 582abe2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 34 deletions.
28 changes: 11 additions & 17 deletions tools/spec_parser/Dart.g
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

// CHANGES:
//
// v0.49 Add support for static and top-level members with no implementation.
//
// v0.48 Add support for enhanced parts.
//
// v0.47 Make `augment` a built-in identifier (this happened in the feature
Expand Down Expand Up @@ -291,10 +293,10 @@ topLevelDefinition
| EXTERNAL getterSignature ';'
| EXTERNAL setterSignature ';'
| EXTERNAL finalVarOrType identifierList ';'
| AUGMENT? getterSignature functionBody
| AUGMENT? setterSignature functionBody
| AUGMENT? functionSignature functionBody
| AUGMENT? (FINAL | CONST) type? staticFinalDeclarationList ';'
| AUGMENT? getterSignature (functionBody | ';')
| AUGMENT? setterSignature (functionBody | ';')
| AUGMENT? functionSignature (functionBody | ';')
| AUGMENT? (FINAL | CONST) type? initializedIdentifierList ';'
| AUGMENT? LATE FINAL type? initializedIdentifierList ';'
| AUGMENT? LATE? varOrType initializedIdentifierList ';'
;
Expand Down Expand Up @@ -506,16 +508,16 @@ methodSignature
;

declaration
: EXTERNAL factoryConstructorSignature
: EXTERNAL? factoryConstructorSignature
| EXTERNAL constantConstructorSignature
| EXTERNAL constructorSignature
| (EXTERNAL STATIC?)? getterSignature
| (EXTERNAL STATIC?)? setterSignature
| (EXTERNAL STATIC?)? functionSignature
| EXTERNAL? STATIC? getterSignature
| EXTERNAL? STATIC? setterSignature
| EXTERNAL? STATIC? functionSignature
| EXTERNAL (STATIC? finalVarOrType | COVARIANT varOrType) identifierList
| EXTERNAL? operatorSignature
| ABSTRACT (finalVarOrType | COVARIANT varOrType) identifierList
| AUGMENT? STATIC (FINAL | CONST) type? staticFinalDeclarationList
| AUGMENT? STATIC (FINAL | CONST) type? initializedIdentifierList
| AUGMENT? STATIC LATE FINAL type? initializedIdentifierList
| AUGMENT? STATIC LATE? varOrType initializedIdentifierList
| AUGMENT? COVARIANT LATE FINAL type? identifierList
Expand All @@ -526,14 +528,6 @@ declaration
| AUGMENT? constructorSignature (redirection | initializers)?
;

staticFinalDeclarationList
: staticFinalDeclaration (',' staticFinalDeclaration)*
;

staticFinalDeclaration
: identifier '=' expression
;

operatorSignature
: type? OPERATOR operator formalParameterList
;
Expand Down
28 changes: 11 additions & 17 deletions tools/spec_parser/dart_spec_parser/Dart.g4
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

// CHANGES:
//
// v0.50 Add support for static and top-level members with no implementation.
//
// v0.49 Add support for enhanced parts.
//
// v0.48 Make `augment` a built-in identifier (this happened in the feature
Expand Down Expand Up @@ -297,10 +299,10 @@ topLevelDefinition
| EXTERNAL getterSignature ';'
| EXTERNAL setterSignature ';'
| EXTERNAL finalVarOrType identifierList ';'
| AUGMENT? getterSignature functionBody
| AUGMENT? setterSignature functionBody
| AUGMENT? functionSignature functionBody
| AUGMENT? (FINAL | CONST) type? staticFinalDeclarationList ';'
| AUGMENT? getterSignature (functionBody | ';')
| AUGMENT? setterSignature (functionBody | ';')
| AUGMENT? functionSignature (functionBody | ';')
| AUGMENT? (FINAL | CONST) type? initializedIdentifierList ';'
| AUGMENT? LATE FINAL type? initializedIdentifierList ';'
| AUGMENT? LATE? varOrType initializedIdentifierList ';'
;
Expand Down Expand Up @@ -512,16 +514,16 @@ methodSignature
;

declaration
: EXTERNAL factoryConstructorSignature
: EXTERNAL? factoryConstructorSignature
| EXTERNAL constantConstructorSignature
| EXTERNAL constructorSignature
| (EXTERNAL STATIC?)? getterSignature
| (EXTERNAL STATIC?)? setterSignature
| (EXTERNAL STATIC?)? functionSignature
| EXTERNAL? STATIC? getterSignature
| EXTERNAL? STATIC? setterSignature
| EXTERNAL? STATIC? functionSignature
| EXTERNAL (STATIC? finalVarOrType | COVARIANT varOrType) identifierList
| EXTERNAL? operatorSignature
| ABSTRACT (finalVarOrType | COVARIANT varOrType) identifierList
| AUGMENT? STATIC (FINAL | CONST) type? staticFinalDeclarationList
| AUGMENT? STATIC (FINAL | CONST) type? initializedIdentifierList
| AUGMENT? STATIC LATE FINAL type? initializedIdentifierList
| AUGMENT? STATIC LATE? varOrType initializedIdentifierList
| AUGMENT? COVARIANT LATE FINAL type? identifierList
Expand All @@ -532,14 +534,6 @@ declaration
| AUGMENT? constructorSignature (redirection | initializers)?
;

staticFinalDeclarationList
: staticFinalDeclaration (',' staticFinalDeclaration)*
;

staticFinalDeclaration
: identifier '=' expression
;

operatorSignature
: type? OPERATOR operator formalParameterList
;
Expand Down

0 comments on commit 582abe2

Please sign in to comment.