Add Dart.g support for class modifiers

This CL adds/changes the specification grammar to support the upcoming 'class modifiers' feature. Also, it changes the rule about `superclass` to agree with the language specification (it is easy to see that it derives the same set of programs). Also introduces a non-terminal `otherIdentifier` listing those words which are not reserved, not built-in, but are still explicitly mentioned in grammar (e.g., `show`, `on`, and others). This is safer than maintaining a repeated list of words multiple places in the grammar.

Change-Id: I23dc303f9f9a06a665e19f375fe23378042434c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283183
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
This commit is contained in:
Erik Ernst
2023-02-15 11:37:57 +00:00
committed by Commit Queue
parent bc18787263
commit ae408d3706
+62 -28
View File
@@ -4,6 +4,12 @@
// CHANGES:
//
// v0.30 Add support for the class modifiers `sealed`, `final`, `base`,
// `interface`, and for `mixin class` declarations. Also add support for
// unnamed libraries (`library;`). Introduce `otherIdentifier` to help
// maintaining consistency when the grammar is modified to mention any words
// that weren't previously mentioned, yet are not reserved or built-in.
//
// v0.29 Add an alternative in the `primary` rule to enable method invocations
// of the form `super(...)` and `super<...>(...)`. This was added to the
// language specification in May 21, b26e7287c318c0112610fe8b7e175289792dfde2,
@@ -361,13 +367,24 @@ typeWithParameters
;
classDeclaration
: ABSTRACT? CLASS typeWithParameters superclass? mixins? interfaces?
LBRACE (metadata classMemberDefinition)* RBRACE
| ABSTRACT? CLASS mixinApplicationClass
: (classModifiers | mixinClassModifiers)
CLASS typeWithParameters superclass? interfaces?
LBRACE (metadata classMemberDeclaration)* RBRACE
| classModifiers CLASS mixinApplicationClass
;
classModifiers
: SEALED
| ABSTRACT? (BASE | INTERFACE | FINAL)?
;
mixinClassModifiers
: ABSTRACT? BASE? MIXIN
;
superclass
: EXTENDS typeNotVoidNotFunction
: EXTENDS typeNotVoidNotFunction mixins?
| mixins
;
mixins
@@ -378,7 +395,7 @@ interfaces
: IMPLEMENTS typeNotVoidNotFunctionList
;
classMemberDefinition
classMemberDeclaration
: methodSignature functionBody
| declaration ';'
;
@@ -388,14 +405,21 @@ mixinApplicationClass
;
mixinDeclaration
: MIXIN typeIdentifier typeParameters?
: mixinModifier? MIXIN typeIdentifier typeParameters?
(ON typeNotVoidNotFunctionList)? interfaces?
LBRACE (metadata mixinMemberDefinition)* RBRACE
LBRACE (metadata mixinMemberDeclaration)* RBRACE
;
// TODO: We will probably want to make this more strict.
mixinMemberDefinition
: classMemberDefinition
mixinModifier
: SEALED
| BASE
| INTERFACE
| FINAL
;
// TODO: We might want to make this more strict.
mixinMemberDeclaration
: classMemberDeclaration
;
extensionDeclaration
@@ -405,7 +429,7 @@ extensionDeclaration
// TODO: We might want to make this more strict.
extensionMemberDefinition
: classMemberDefinition
: classMemberDeclaration
;
methodSignature
@@ -533,7 +557,7 @@ mixinApplication
enumType
: ENUM typeIdentifier typeParameters? mixins? interfaces? LBRACE
enumEntry (',' enumEntry)* (',')?
(';' (metadata classMemberDefinition)*)?
(';' (metadata classMemberDeclaration)*)?
RBRACE
;
@@ -976,12 +1000,7 @@ assignableSelector
identifierNotFUNCTION
: IDENTIFIER
| builtInIdentifier
| ASYNC // Not a built-in identifier.
| HIDE // Not a built-in identifier.
| OF // Not a built-in identifier.
| ON // Not a built-in identifier.
| SHOW // Not a built-in identifier.
| SYNC // Not a built-in identifier.
| otherIdentifier
| { asyncEtcPredicate(getCurrentToken().getType()) }? (AWAIT|YIELD)
;
@@ -998,12 +1017,7 @@ qualifiedName
typeIdentifier
: IDENTIFIER
| DYNAMIC // Built-in identifier that can be used as a type.
| ASYNC // Not a built-in identifier.
| HIDE // Not a built-in identifier.
| OF // Not a built-in identifier.
| ON // Not a built-in identifier.
| SHOW // Not a built-in identifier.
| SYNC // Not a built-in identifier.
| otherIdentifier // Occur in grammar rules, are not built-in.
| { asyncEtcPredicate(getCurrentToken().getType()) }? (AWAIT|YIELD)
;
@@ -1319,7 +1333,7 @@ assertion
;
libraryName
: metadata LIBRARY dottedIdentifierList ';'
: metadata LIBRARY dottedIdentifierList? ';'
;
dottedIdentifierList
@@ -1602,6 +1616,18 @@ builtInIdentifier
| TYPEDEF
;
otherIdentifier
: ASYNC
| BASE
| HIDE
| OF
| ON
| SEALED
| SHOW
| SYNC
| WHEN
;
// ---------------------------------------- Lexer rules.
fragment
@@ -1627,7 +1653,7 @@ HEX_DIGIT
| DIGIT
;
// Reserved words.
// Reserved words (if updated, update `reservedWord` as well).
ASSERT
: 'assert'
@@ -1761,7 +1787,7 @@ WITH
: 'with'
;
// Built-in identifiers.
// Built-in identifiers (if updated, update `builtInIdentifier` as well).
ABSTRACT
: 'abstract'
@@ -1865,12 +1891,16 @@ YIELD
: 'yield'
;
// Other words used in the grammar.
// Other words used in the grammar (if updated, update `otherIdentifier`, too).
ASYNC
: 'async'
;
BASE
: 'base'
;
HIDE
: 'hide'
;
@@ -1883,6 +1913,10 @@ ON
: 'on'
;
SEALED
: 'sealed'
;
SHOW
: 'show'
;