4
4
5
5
// CHANGES:
6
6
//
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
+ //
7
13
// v0.29 Add an alternative in the `primary` rule to enable method invocations
8
14
// of the form `super(...)` and `super<...>(...)`. This was added to the
9
15
// language specification in May 21, b26e7287c318c0112610fe8b7e175289792dfde2,
@@ -361,13 +367,24 @@ typeWithParameters
361
367
;
362
368
363
369
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
367
383
;
368
384
369
385
superclass
370
- : EXTENDS typeNotVoidNotFunction
386
+ : EXTENDS typeNotVoidNotFunction mixins?
387
+ | mixins
371
388
;
372
389
373
390
mixins
@@ -378,7 +395,7 @@ interfaces
378
395
: IMPLEMENTS typeNotVoidNotFunctionList
379
396
;
380
397
381
- classMemberDefinition
398
+ classMemberDeclaration
382
399
: methodSignature functionBody
383
400
| declaration ';'
384
401
;
@@ -388,14 +405,21 @@ mixinApplicationClass
388
405
;
389
406
390
407
mixinDeclaration
391
- : MIXIN typeIdentifier typeParameters?
408
+ : mixinModifier? MIXIN typeIdentifier typeParameters?
392
409
(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
394
418
;
395
419
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
399
423
;
400
424
401
425
extensionDeclaration
@@ -405,7 +429,7 @@ extensionDeclaration
405
429
406
430
// TODO: We might want to make this more strict.
407
431
extensionMemberDefinition
408
- : classMemberDefinition
432
+ : classMemberDeclaration
409
433
;
410
434
411
435
methodSignature
@@ -533,7 +557,7 @@ mixinApplication
533
557
enumType
534
558
: ENUM typeIdentifier typeParameters? mixins? interfaces? LBRACE
535
559
enumEntry (',' enumEntry)* (',')?
536
- (' ;' (metadata classMemberDefinition )* )?
560
+ (';' (metadata classMemberDeclaration )*)?
537
561
RBRACE
538
562
;
539
563
@@ -976,12 +1000,7 @@ assignableSelector
976
1000
identifierNotFUNCTION
977
1001
: IDENTIFIER
978
1002
| 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
985
1004
| { asyncEtcPredicate(getCurrentToken().getType()) }? (AWAIT|YIELD)
986
1005
;
987
1006
@@ -998,12 +1017,7 @@ qualifiedName
998
1017
typeIdentifier
999
1018
: IDENTIFIER
1000
1019
| 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.
1007
1021
| { asyncEtcPredicate(getCurrentToken().getType()) }? (AWAIT|YIELD)
1008
1022
;
1009
1023
@@ -1319,7 +1333,7 @@ assertion
1319
1333
;
1320
1334
1321
1335
libraryName
1322
- : metadata LIBRARY dottedIdentifierList ' ;'
1336
+ : metadata LIBRARY dottedIdentifierList? ';'
1323
1337
;
1324
1338
1325
1339
dottedIdentifierList
@@ -1602,6 +1616,18 @@ builtInIdentifier
1602
1616
| TYPEDEF
1603
1617
;
1604
1618
1619
+ otherIdentifier
1620
+ : ASYNC
1621
+ | BASE
1622
+ | HIDE
1623
+ | OF
1624
+ | ON
1625
+ | SEALED
1626
+ | SHOW
1627
+ | SYNC
1628
+ | WHEN
1629
+ ;
1630
+
1605
1631
// ---------------------------------------- Lexer rules.
1606
1632
1607
1633
fragment
@@ -1627,7 +1653,7 @@ HEX_DIGIT
1627
1653
| DIGIT
1628
1654
;
1629
1655
1630
- // Reserved words.
1656
+ // Reserved words (if updated, update `reservedWord` as well) .
1631
1657
1632
1658
ASSERT
1633
1659
: 'assert'
@@ -1761,7 +1787,7 @@ WITH
1761
1787
: 'with'
1762
1788
;
1763
1789
1764
- // Built-in identifiers.
1790
+ // Built-in identifiers (if updated, update `builtInIdentifier` as well) .
1765
1791
1766
1792
ABSTRACT
1767
1793
: 'abstract'
@@ -1865,12 +1891,16 @@ YIELD
1865
1891
: 'yield'
1866
1892
;
1867
1893
1868
- // Other words used in the grammar.
1894
+ // Other words used in the grammar (if updated, update `otherIdentifier`, too) .
1869
1895
1870
1896
ASYNC
1871
1897
: 'async'
1872
1898
;
1873
1899
1900
+ BASE
1901
+ : 'base'
1902
+ ;
1903
+
1874
1904
HIDE
1875
1905
: 'hide'
1876
1906
;
@@ -1883,6 +1913,10 @@ ON
1883
1913
: 'on'
1884
1914
;
1885
1915
1916
+ SEALED
1917
+ : 'sealed'
1918
+ ;
1919
+
1886
1920
SHOW
1887
1921
: 'show'
1888
1922
;
0 commit comments