@@ -1520,15 +1520,13 @@ bool Parser::canParseType() {
1520
1520
switch (Tok.getKind ()) {
1521
1521
case tok::kw_Self:
1522
1522
case tok::kw_Any:
1523
+ case tok::identifier:
1523
1524
case tok::code_complete:
1524
1525
if (!canParseTypeIdentifier ())
1525
1526
return false ;
1526
1527
break ;
1527
- case tok::kw_protocol: // Deprecated composition syntax
1528
- case tok::identifier:
1529
- if (!canParseTypeIdentifierOrTypeComposition ())
1530
- return false ;
1531
- break ;
1528
+ case tok::kw_protocol:
1529
+ return canParseOldStyleProtocolComposition ();
1532
1530
case tok::l_paren: {
1533
1531
consumeToken ();
1534
1532
if (!canParseTypeTupleBody ())
@@ -1561,14 +1559,22 @@ bool Parser::canParseType() {
1561
1559
return false ;
1562
1560
}
1563
1561
1564
- // '.Type', '.Protocol', '?', and '!' still leave us with type-simple.
1562
+ // A member type, '.Type', '.Protocol', '?', and '!' still leave us with
1563
+ // type-simple.
1565
1564
while (true ) {
1566
- if ((Tok.is (tok::period) || Tok.is (tok::period_prefix)) &&
1567
- (peekToken ().isContextualKeyword (" Type" )
1568
- || peekToken ().isContextualKeyword (" Protocol" ))) {
1565
+ if (Tok.isAny (tok::period_prefix, tok::period)) {
1569
1566
consumeToken ();
1570
- consumeToken (tok::identifier);
1571
- continue ;
1567
+
1568
+ if (Tok.isContextualKeyword (" Type" ) ||
1569
+ Tok.isContextualKeyword (" Protocol" )) {
1570
+ consumeToken ();
1571
+ continue ;
1572
+ }
1573
+
1574
+ if (canParseTypeIdentifier ())
1575
+ continue ;
1576
+
1577
+ return false ;
1572
1578
}
1573
1579
if (isOptionalToken (Tok)) {
1574
1580
consumeOptionalToken ();
@@ -1581,6 +1587,13 @@ bool Parser::canParseType() {
1581
1587
break ;
1582
1588
}
1583
1589
1590
+ while (Tok.isContextualPunctuator (" &" )) {
1591
+ consumeToken ();
1592
+ // FIXME: Should be 'canParseTypeSimple', but we don't have one.
1593
+ if (!canParseType ())
1594
+ return false ;
1595
+ }
1596
+
1584
1597
if (isAtFunctionTypeArrow ()) {
1585
1598
// Handle type-function if we have an '->' with optional
1586
1599
// 'async' and/or 'throws'.
@@ -1605,25 +1618,10 @@ bool Parser::canParseType() {
1605
1618
return true ;
1606
1619
}
1607
1620
1608
- bool Parser::canParseTypeIdentifierOrTypeComposition () {
1609
- if (Tok.is (tok::kw_protocol))
1610
- return canParseOldStyleProtocolComposition ();
1611
-
1612
- while (true ) {
1613
- if (!canParseTypeIdentifier ())
1614
- return false ;
1615
-
1616
- if (Tok.isContextualPunctuator (" &" )) {
1617
- consumeToken ();
1618
- continue ;
1619
- } else {
1620
- return true ;
1621
- }
1622
- }
1623
- }
1624
-
1625
- bool Parser::canParseSimpleTypeIdentifier () {
1621
+ bool Parser::canParseTypeIdentifier () {
1626
1622
// Parse an identifier.
1623
+ //
1624
+ // FIXME: We should expect e.g. 'X.var'. Almost any keyword is a valid member component.
1627
1625
if (!Tok.isAny (tok::identifier, tok::kw_Self, tok::kw_Any, tok::code_complete))
1628
1626
return false ;
1629
1627
consumeToken ();
@@ -1635,28 +1633,11 @@ bool Parser::canParseSimpleTypeIdentifier() {
1635
1633
return true ;
1636
1634
}
1637
1635
1638
- bool Parser::canParseTypeIdentifier () {
1639
- while (true ) {
1640
- if (!canParseSimpleTypeIdentifier ())
1641
- return false ;
1642
-
1643
- // Treat 'Foo.<anything>' as an attempt to write a dotted type
1644
- // unless <anything> is 'Type' or 'Protocol'.
1645
- if ((Tok.is (tok::period) || Tok.is (tok::period_prefix)) &&
1646
- !peekToken ().isContextualKeyword (" Type" ) &&
1647
- !peekToken ().isContextualKeyword (" Protocol" )) {
1648
- consumeToken ();
1649
- } else {
1650
- return true ;
1651
- }
1652
- }
1653
- }
1654
-
1655
1636
bool Parser::canParseBaseTypeForQualifiedDeclName () {
1656
1637
BacktrackingScope backtrack (*this );
1657
1638
1658
1639
// Parse a simple type identifier.
1659
- if (!canParseSimpleTypeIdentifier ())
1640
+ if (!canParseTypeIdentifier ())
1660
1641
return false ;
1661
1642
1662
1643
// Qualified name base types must be followed by a period.
0 commit comments