Skip to content

Commit ae408d3

Browse files
eernstgCommit Queue
authored and
Commit Queue
committed
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 <[email protected]> Commit-Queue: Erik Ernst <[email protected]>
1 parent bc18787 commit ae408d3

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

tools/spec_parser/Dart.g

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
// CHANGES:
66
//
7+
// v0.30 Add support for the class modifiers `sealed`, `final`, `base`,
8+
// `interface`, and for `mixin class` declarations. Also add support for
9+
// unnamed libraries (`library;`). Introduce `otherIdentifier` to help
10+
// maintaining consistency when the grammar is modified to mention any words
11+
// that weren't previously mentioned, yet are not reserved or built-in.
12+
//
713
// v0.29 Add an alternative in the `primary` rule to enable method invocations
814
// of the form `super(...)` and `super<...>(...)`. This was added to the
915
// language specification in May 21, b26e7287c318c0112610fe8b7e175289792dfde2,
@@ -361,13 +367,24 @@ typeWithParameters
361367
;
362368
363369
classDeclaration
364-
: ABSTRACT? CLASS typeWithParameters superclass? mixins? interfaces?
365-
LBRACE (metadata classMemberDefinition)* RBRACE
366-
| ABSTRACT? CLASS mixinApplicationClass
370+
: (classModifiers | mixinClassModifiers)
371+
CLASS typeWithParameters superclass? interfaces?
372+
LBRACE (metadata classMemberDeclaration)* RBRACE
373+
| classModifiers CLASS mixinApplicationClass
374+
;
375+
376+
classModifiers
377+
: SEALED
378+
| ABSTRACT? (BASE | INTERFACE | FINAL)?
379+
;
380+
381+
mixinClassModifiers
382+
: ABSTRACT? BASE? MIXIN
367383
;
368384
369385
superclass
370-
: EXTENDS typeNotVoidNotFunction
386+
: EXTENDS typeNotVoidNotFunction mixins?
387+
| mixins
371388
;
372389
373390
mixins
@@ -378,7 +395,7 @@ interfaces
378395
: IMPLEMENTS typeNotVoidNotFunctionList
379396
;
380397
381-
classMemberDefinition
398+
classMemberDeclaration
382399
: methodSignature functionBody
383400
| declaration ';'
384401
;
@@ -388,14 +405,21 @@ mixinApplicationClass
388405
;
389406
390407
mixinDeclaration
391-
: MIXIN typeIdentifier typeParameters?
408+
: mixinModifier? MIXIN typeIdentifier typeParameters?
392409
(ON typeNotVoidNotFunctionList)? interfaces?
393-
LBRACE (metadata mixinMemberDefinition)* RBRACE
410+
LBRACE (metadata mixinMemberDeclaration)* RBRACE
411+
;
412+
413+
mixinModifier
414+
: SEALED
415+
| BASE
416+
| INTERFACE
417+
| FINAL
394418
;
395419
396-
// TODO: We will probably want to make this more strict.
397-
mixinMemberDefinition
398-
: classMemberDefinition
420+
// TODO: We might want to make this more strict.
421+
mixinMemberDeclaration
422+
: classMemberDeclaration
399423
;
400424
401425
extensionDeclaration
@@ -405,7 +429,7 @@ extensionDeclaration
405429
406430
// TODO: We might want to make this more strict.
407431
extensionMemberDefinition
408-
: classMemberDefinition
432+
: classMemberDeclaration
409433
;
410434
411435
methodSignature
@@ -533,7 +557,7 @@ mixinApplication
533557
enumType
534558
: ENUM typeIdentifier typeParameters? mixins? interfaces? LBRACE
535559
enumEntry (',' enumEntry)* (',')?
536-
(';' (metadata classMemberDefinition)*)?
560+
(';' (metadata classMemberDeclaration)*)?
537561
RBRACE
538562
;
539563
@@ -976,12 +1000,7 @@ assignableSelector
9761000
identifierNotFUNCTION
9771001
: IDENTIFIER
9781002
| builtInIdentifier
979-
| ASYNC // Not a built-in identifier.
980-
| HIDE // Not a built-in identifier.
981-
| OF // Not a built-in identifier.
982-
| ON // Not a built-in identifier.
983-
| SHOW // Not a built-in identifier.
984-
| SYNC // Not a built-in identifier.
1003+
| otherIdentifier
9851004
| { asyncEtcPredicate(getCurrentToken().getType()) }? (AWAIT|YIELD)
9861005
;
9871006
@@ -998,12 +1017,7 @@ qualifiedName
9981017
typeIdentifier
9991018
: IDENTIFIER
10001019
| DYNAMIC // Built-in identifier that can be used as a type.
1001-
| ASYNC // Not a built-in identifier.
1002-
| HIDE // Not a built-in identifier.
1003-
| OF // Not a built-in identifier.
1004-
| ON // Not a built-in identifier.
1005-
| SHOW // Not a built-in identifier.
1006-
| SYNC // Not a built-in identifier.
1020+
| otherIdentifier // Occur in grammar rules, are not built-in.
10071021
| { asyncEtcPredicate(getCurrentToken().getType()) }? (AWAIT|YIELD)
10081022
;
10091023
@@ -1319,7 +1333,7 @@ assertion
13191333
;
13201334
13211335
libraryName
1322-
: metadata LIBRARY dottedIdentifierList ';'
1336+
: metadata LIBRARY dottedIdentifierList? ';'
13231337
;
13241338
13251339
dottedIdentifierList
@@ -1602,6 +1616,18 @@ builtInIdentifier
16021616
| TYPEDEF
16031617
;
16041618
1619+
otherIdentifier
1620+
: ASYNC
1621+
| BASE
1622+
| HIDE
1623+
| OF
1624+
| ON
1625+
| SEALED
1626+
| SHOW
1627+
| SYNC
1628+
| WHEN
1629+
;
1630+
16051631
// ---------------------------------------- Lexer rules.
16061632
16071633
fragment
@@ -1627,7 +1653,7 @@ HEX_DIGIT
16271653
| DIGIT
16281654
;
16291655
1630-
// Reserved words.
1656+
// Reserved words (if updated, update `reservedWord` as well).
16311657
16321658
ASSERT
16331659
: 'assert'
@@ -1761,7 +1787,7 @@ WITH
17611787
: 'with'
17621788
;
17631789
1764-
// Built-in identifiers.
1790+
// Built-in identifiers (if updated, update `builtInIdentifier` as well).
17651791
17661792
ABSTRACT
17671793
: 'abstract'
@@ -1865,12 +1891,16 @@ YIELD
18651891
: 'yield'
18661892
;
18671893
1868-
// Other words used in the grammar.
1894+
// Other words used in the grammar (if updated, update `otherIdentifier`, too).
18691895
18701896
ASYNC
18711897
: 'async'
18721898
;
18731899
1900+
BASE
1901+
: 'base'
1902+
;
1903+
18741904
HIDE
18751905
: 'hide'
18761906
;
@@ -1883,6 +1913,10 @@ ON
18831913
: 'on'
18841914
;
18851915
1916+
SEALED
1917+
: 'sealed'
1918+
;
1919+
18861920
SHOW
18871921
: 'show'
18881922
;

0 commit comments

Comments
 (0)