Update the spec parser to support new();`

This CL changes the spec parser specification (Dart.g and Dart.g4) such
that the grammar allows for the new style of constructor declarations
(such as `new();` and `new name();`). It also adjusts the declaring body
constructor syntax to use the same style (`this();` and `this name();`).
Finally, it updates a few non-terminals to use a naming that avoids the
ambiguity of `classNamePart`. These changes introduce about 5 new
failures when parsing $SDK/tests/language.

Change-Id: I3e6ac9f0782e3bde863a13c93a54a089c93c7e13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456640
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
Erik Ernst
2025-11-03 01:35:25 -08:00
committed by Commit Queue
parent ccac64c181
commit 5656806517
2 changed files with 52 additions and 30 deletions
+26 -15
View File
@@ -4,6 +4,9 @@
// CHANGES:
//
// v0.56 Update constructor declaration syntax to allow `constructorHead`.
// Recatogerize 'factory' to be a reserved word and not a built-in identifier.
//
// v0.55 Use `typeWithParameters` consistently, simplify primary constructor
// rule.
//
@@ -125,7 +128,7 @@
// `builtinIdentifier` and `reservedWord`; update `typeAlias` to enable
// non-function type aliases; add missing `metadata` to formal parameter
// declarations; correct `symbolLiteral` to allow `VOID`;
//
// v0.12 (82403371ac00ddf004be60fa7b705474d2864509) Cf. language issue #1341:
// correct `metadata`. Change `qualifiedName` such that it only includes the
// cases with a '.'; the remaining case is added where `qualifiedName` is used.
@@ -425,7 +428,7 @@ typeWithParameters
classDeclaration
: AUGMENT? (classModifiers | mixinClassModifiers)
CLASS classNamePart superclass? interfaces? classBody
CLASS classNameMaybePrimary superclass? interfaces? classBody
| classModifiers MIXIN? CLASS mixinApplicationClass
;
@@ -434,7 +437,7 @@ primaryConstructor
declaringParameterList
;
classNamePart
classNameMaybePrimary
: primaryConstructor
| typeWithParameters
;
@@ -482,7 +485,7 @@ mixinDeclaration
;
extensionTypeDeclaration
: EXTENSION TYPE classNamePart interfaces? extensionTypeBody
: EXTENSION TYPE classNameMaybePrimary interfaces? extensionTypeBody
| AUGMENT EXTENSION TYPE typeWithParameters interfaces?
extensionTypeBody
;
@@ -561,16 +564,17 @@ setterSignature
;
constructorSignature
: constructorName formalParameterList
: constructorName formalParameterList // Old form.
| constructorHead formalParameterList // New form.
| declaringConstructorSignature
;
declaringConstructorSignature
: THIS ('.' identifierOrNew)? declaringParameterList?
: THIS identifier? declaringParameterList? // New form only.
;
declaringConstantConstructorSignature
: CONST THIS ('.' identifierOrNew)? declaringParameterList
: CONST THIS identifier? declaringParameterList // New form only.
;
declaringParameterList
@@ -630,12 +634,15 @@ defaultDeclaringNamedParameter
;
constructorName
: typeIdentifierOrNew ('.' identifierOrNew)?
: typeIdentifier ('.' identifierOrNew)?
;
typeIdentifierOrNew
: typeIdentifier
| NEW
constructorHead
: NEW identifier?
;
factoryConstructorHead
: FACTORY identifier?
;
identifierOrNew
@@ -670,16 +677,20 @@ initializerExpression
;
factoryConstructorSignature
: CONST? FACTORY constructorName formalParameterList
: CONST? FACTORY constructorName formalParameterList // Old form.
| CONST? factoryConstructorHead formalParameterList // New form.
;
redirectingFactoryConstructorSignature
: CONST? FACTORY constructorName formalParameterList '='
constructorDesignation
constructorDesignation // Old form.
| CONST? factoryConstructorHead formalParameterList '='
constructorDesignation // New form.
;
constantConstructorSignature
: CONST constructorName formalParameterList
: CONST constructorName formalParameterList // Old form.
| CONST constructorHead formalParameterList // New form.
| declaringConstantConstructorSignature
;
@@ -688,7 +699,7 @@ mixinApplication
;
enumType
: AUGMENT? ENUM classNamePart mixins? interfaces? LBRACE
: AUGMENT? ENUM classNameMaybePrimary mixins? interfaces? LBRACE
enumEntry (',' enumEntry)* ','?
(';' (metadata memberDeclaration)*)?
RBRACE
+26 -15
View File
@@ -4,6 +4,9 @@
// CHANGES:
//
// v0.57 Update constructor declaration syntax to allow `constructorHead`.
// Recatogerize 'factory' to be a reserved word and not a built-in identifier.
//
// v0.56 Use `typeWithParameters` consistently, simplify primary constructor
// rule.
//
@@ -435,7 +438,7 @@ typeWithParameters
classDeclaration
: AUGMENT? (classModifiers | mixinClassModifiers)
CLASS classNamePart superclass? interfaces? classBody
CLASS classNameMaybePrimary superclass? interfaces? classBody
| classModifiers MIXIN? CLASS mixinApplicationClass
;
@@ -444,7 +447,7 @@ primaryConstructor
declaringParameterList
;
classNamePart
classNameMaybePrimary
: primaryConstructor
| typeWithParameters
;
@@ -492,7 +495,7 @@ mixinDeclaration
;
extensionTypeDeclaration
: EXTENSION TYPE classNamePart interfaces? extensionTypeBody
: EXTENSION TYPE classNameMaybePrimary interfaces? extensionTypeBody
| AUGMENT EXTENSION TYPE typeWithParameters interfaces?
extensionTypeBody
;
@@ -571,16 +574,17 @@ setterSignature
;
constructorSignature
: constructorName formalParameterList
: constructorName formalParameterList // Old form.
| constructorHead formalParameterList // New form.
| declaringConstructorSignature
;
declaringConstructorSignature
: THIS ('.' identifierOrNew)? declaringParameterList?
: THIS identifier? declaringParameterList? // New form only.
;
declaringConstantConstructorSignature
: CONST THIS ('.' identifierOrNew)? declaringParameterList
: CONST THIS identifier? declaringParameterList // New form only.
;
declaringParameterList
@@ -640,12 +644,15 @@ defaultDeclaringNamedParameter
;
constructorName
: typeIdentifierOrNew ('.' identifierOrNew)?
: typeIdentifier ('.' identifierOrNew)?
;
typeIdentifierOrNew
: typeIdentifier
| NEW
constructorHead
: NEW identifier?
;
factoryConstructorHead
: FACTORY identifier?
;
identifierOrNew
@@ -680,16 +687,20 @@ initializerExpression
;
factoryConstructorSignature
: CONST? FACTORY constructorName formalParameterList
: CONST? FACTORY constructorName formalParameterList // Old form.
| CONST? factoryConstructorHead formalParameterList // New form.
;
redirectingFactoryConstructorSignature
: CONST? FACTORY constructorName formalParameterList '='
constructorDesignation
constructorDesignation // Old form.
| CONST? factoryConstructorHead formalParameterList '='
constructorDesignation // New form.
;
constantConstructorSignature
: CONST constructorName formalParameterList
: CONST constructorName formalParameterList // Old form.
| CONST constructorHead formalParameterList // New form.
| declaringConstantConstructorSignature
;
@@ -698,7 +709,7 @@ mixinApplication
;
enumType
: AUGMENT? ENUM classNamePart mixins? interfaces? LBRACE
: AUGMENT? ENUM classNameMaybePrimary mixins? interfaces? LBRACE
enumEntry (',' enumEntry)* ','?
(';' (metadata memberDeclaration)*)?
RBRACE
@@ -1834,7 +1845,7 @@ EXPONENT
fragment
DIGITS
: DIGIT ('_'* DIGIT)*
: DIGIT ('_'* DIGIT)*
;
fragment