Update spec parser rules about primary constructors
This CL changes Dart.g and Dart.g4 such that the spec parser will parse primary constructors using a simpler and clearer set of rules. In particular, the body part of a primary constructor has been given its own signature (`primaryConstructorBodySignature`), which makes it easier to denote the constructs which are used along with primary constructors, and it also supports a more comprehensible AST structure. Change-Id: I7c211ecd76596927a044bdedc5dec3a7eaf9a8b5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460420 Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
+17
-19
@@ -485,7 +485,7 @@ mixinDeclaration
|
||||
;
|
||||
|
||||
extensionTypeDeclaration
|
||||
: EXTENSION TYPE classNameMaybePrimary interfaces? extensionTypeBody
|
||||
: EXTENSION TYPE primaryConstructor interfaces? extensionTypeBody
|
||||
| AUGMENT EXTENSION TYPE typeWithParameters interfaces?
|
||||
extensionTypeBody
|
||||
;
|
||||
@@ -512,6 +512,7 @@ methodSignature
|
||||
| STATIC? setterSignature
|
||||
| operatorSignature
|
||||
| constructorSignature
|
||||
| primaryConstructorBodySignature
|
||||
;
|
||||
|
||||
declaration
|
||||
@@ -533,6 +534,7 @@ declaration
|
||||
| redirectingFactoryConstructorSignature
|
||||
| constantConstructorSignature (redirection | initializers)?
|
||||
| constructorSignature (redirection | initializers)?
|
||||
| primaryConstructorBodySignature
|
||||
;
|
||||
|
||||
operatorSignature
|
||||
@@ -566,15 +568,6 @@ setterSignature
|
||||
constructorSignature
|
||||
: constructorName formalParameterList // Old form.
|
||||
| constructorHead formalParameterList // New form.
|
||||
| declaringConstructorSignature
|
||||
;
|
||||
|
||||
declaringConstructorSignature
|
||||
: THIS identifier? declaringParameterList? // New form only.
|
||||
;
|
||||
|
||||
declaringConstantConstructorSignature
|
||||
: CONST THIS identifier? declaringParameterList // New form only.
|
||||
;
|
||||
|
||||
declaringParameterList
|
||||
@@ -637,6 +630,10 @@ constructorName
|
||||
: typeIdentifier ('.' identifierOrNew)?
|
||||
;
|
||||
|
||||
constructorTwoPartName
|
||||
: typeIdentifier '.' identifierOrNew
|
||||
;
|
||||
|
||||
constructorHead
|
||||
: NEW identifier?
|
||||
;
|
||||
@@ -677,21 +674,22 @@ initializerExpression
|
||||
;
|
||||
|
||||
factoryConstructorSignature
|
||||
: CONST? FACTORY constructorName formalParameterList // Old form.
|
||||
| CONST? factoryConstructorHead formalParameterList // New form.
|
||||
: CONST? FACTORY constructorTwoPartName
|
||||
formalParameterList // Old form.
|
||||
| CONST? factoryConstructorHead
|
||||
formalParameterList // New form.
|
||||
;
|
||||
|
||||
redirectingFactoryConstructorSignature
|
||||
: CONST? FACTORY constructorName formalParameterList '='
|
||||
constructorDesignation // Old form.
|
||||
| CONST? factoryConstructorHead formalParameterList '='
|
||||
constructorDesignation // New form.
|
||||
: factoryConstructorSignature '=' constructorDesignation
|
||||
;
|
||||
|
||||
primaryConstructorBodySignature
|
||||
: THIS initializers?
|
||||
;
|
||||
|
||||
constantConstructorSignature
|
||||
: CONST constructorName formalParameterList // Old form.
|
||||
| CONST constructorHead formalParameterList // New form.
|
||||
| declaringConstantConstructorSignature
|
||||
: CONST constructorSignature
|
||||
;
|
||||
|
||||
mixinApplication
|
||||
|
||||
@@ -495,7 +495,7 @@ mixinDeclaration
|
||||
;
|
||||
|
||||
extensionTypeDeclaration
|
||||
: EXTENSION TYPE classNameMaybePrimary interfaces? extensionTypeBody
|
||||
: EXTENSION TYPE primaryConstructor interfaces? extensionTypeBody
|
||||
| AUGMENT EXTENSION TYPE typeWithParameters interfaces?
|
||||
extensionTypeBody
|
||||
;
|
||||
@@ -522,6 +522,7 @@ methodSignature
|
||||
| STATIC? setterSignature
|
||||
| operatorSignature
|
||||
| constructorSignature
|
||||
| primaryConstructorBodySignature
|
||||
;
|
||||
|
||||
declaration
|
||||
@@ -543,6 +544,7 @@ declaration
|
||||
| redirectingFactoryConstructorSignature
|
||||
| constantConstructorSignature (redirection | initializers)?
|
||||
| constructorSignature (redirection | initializers)?
|
||||
| primaryConstructorBodySignature
|
||||
;
|
||||
|
||||
operatorSignature
|
||||
@@ -576,15 +578,6 @@ setterSignature
|
||||
constructorSignature
|
||||
: constructorName formalParameterList // Old form.
|
||||
| constructorHead formalParameterList // New form.
|
||||
| declaringConstructorSignature
|
||||
;
|
||||
|
||||
declaringConstructorSignature
|
||||
: THIS identifier? declaringParameterList? // New form only.
|
||||
;
|
||||
|
||||
declaringConstantConstructorSignature
|
||||
: CONST THIS identifier? declaringParameterList // New form only.
|
||||
;
|
||||
|
||||
declaringParameterList
|
||||
@@ -647,6 +640,10 @@ constructorName
|
||||
: typeIdentifier ('.' identifierOrNew)?
|
||||
;
|
||||
|
||||
constructorTwoPartName
|
||||
: typeIdentifier '.' identifierOrNew
|
||||
;
|
||||
|
||||
constructorHead
|
||||
: NEW identifier?
|
||||
;
|
||||
@@ -687,21 +684,22 @@ initializerExpression
|
||||
;
|
||||
|
||||
factoryConstructorSignature
|
||||
: CONST? FACTORY constructorName formalParameterList // Old form.
|
||||
| CONST? factoryConstructorHead formalParameterList // New form.
|
||||
: CONST? FACTORY constructorTwoPartName
|
||||
formalParameterList // Old form.
|
||||
| CONST? factoryConstructorHead
|
||||
formalParameterList // New form.
|
||||
;
|
||||
|
||||
redirectingFactoryConstructorSignature
|
||||
: CONST? FACTORY constructorName formalParameterList '='
|
||||
constructorDesignation // Old form.
|
||||
| CONST? factoryConstructorHead formalParameterList '='
|
||||
constructorDesignation // New form.
|
||||
: factoryConstructorSignature '=' constructorDesignation
|
||||
;
|
||||
|
||||
primaryConstructorBodySignature
|
||||
: THIS initializers?
|
||||
;
|
||||
|
||||
constantConstructorSignature
|
||||
: CONST constructorName formalParameterList // Old form.
|
||||
| CONST constructorHead formalParameterList // New form.
|
||||
| declaringConstantConstructorSignature
|
||||
: CONST constructorSignature
|
||||
;
|
||||
|
||||
mixinApplication
|
||||
|
||||
Reference in New Issue
Block a user