@@ -192,7 +192,9 @@ object Parsers {
192
192
193
193
def isIdent = in.isIdent
194
194
def isIdent (name : Name ) = in.isIdent(name)
195
- def isSimpleLiteral = simpleLiteralTokens contains in.token
195
+ def isSimpleLiteral =
196
+ simpleLiteralTokens.contains(in.token)
197
+ || isIdent(nme.raw.MINUS ) && numericLitTokens.contains(in.lookahead.token)
196
198
def isLiteral = literalTokens contains in.token
197
199
def isNumericLit = numericLitTokens contains in.token
198
200
def isTemplateIntro = templateIntroTokens contains in.token
@@ -1100,18 +1102,42 @@ object Parsers {
1100
1102
*/
1101
1103
def qualId (): Tree = dotSelectors(termIdent())
1102
1104
1103
- /** SimpleExpr ::= literal
1104
- * | 'id | 'this | 'true | 'false | 'null
1105
- * | null
1105
+ /** Singleton ::= SimpleRef
1106
+ * | SimpleLiteral
1107
+ * | Singleton ‘.’ id
1108
+ */
1109
+ def singleton (): Tree =
1110
+ if isSimpleLiteral then simpleLiteral()
1111
+ else dotSelectors(simpleRef())
1112
+
1113
+ /** SimpleLiteral ::= [‘-’] integerLiteral
1114
+ * | [‘-’] floatingPointLiteral
1115
+ * | booleanLiteral
1116
+ * | characterLiteral
1117
+ * | stringLiteral
1118
+ */
1119
+ def simpleLiteral (): Tree =
1120
+ if isIdent(nme.raw.MINUS ) then
1121
+ val start = in.offset
1122
+ in.nextToken()
1123
+ literal(negOffset = start, inTypeOrSingleton = true )
1124
+ else
1125
+ literal(inTypeOrSingleton = true )
1126
+
1127
+ /** Literal ::= SimpleLiteral
1128
+ * | processedStringLiteral
1129
+ * | symbolLiteral
1130
+ * | ‘null’
1131
+ *
1106
1132
* @param negOffset The offset of a preceding `-' sign, if any.
1107
- * If the literal is not negated, negOffset = in.offset.
1133
+ * If the literal is not negated, negOffset == in.offset.
1108
1134
*/
1109
- def literal (negOffset : Int = in.offset, inPattern : Boolean = false , inType : Boolean = false , inStringInterpolation : Boolean = false ): Tree = {
1135
+ def literal (negOffset : Int = in.offset, inPattern : Boolean = false , inTypeOrSingleton : Boolean = false , inStringInterpolation : Boolean = false ): Tree = {
1110
1136
def literalOf (token : Token ): Tree = {
1111
1137
val isNegated = negOffset < in.offset
1112
1138
def digits0 = in.removeNumberSeparators(in.strVal)
1113
1139
def digits = if (isNegated) " -" + digits0 else digits0
1114
- if ( ! inType)
1140
+ if ! inTypeOrSingleton then
1115
1141
token match {
1116
1142
case INTLIT => return Number (digits, NumberKind .Whole (in.base))
1117
1143
case DECILIT => return Number (digits, NumberKind .Decimal )
@@ -1554,15 +1580,12 @@ object Parsers {
1554
1580
1555
1581
/** SimpleType ::= SimpleLiteral
1556
1582
* | ‘?’ SubtypeBounds
1557
- * | SimpleType1
1583
+ * | SimpleType1 { ‘(’ Singletons ‘)’ }
1584
+ * Singletons ::= Singleton {‘,’ Singleton}
1558
1585
*/
1559
1586
def simpleType (): Tree =
1560
1587
if isSimpleLiteral then
1561
- SingletonTypeTree (literal(inType = true ))
1562
- else if isIdent(nme.raw.MINUS ) && numericLitTokens.contains(in.lookahead.token) then
1563
- val start = in.offset
1564
- in.nextToken()
1565
- SingletonTypeTree (literal(negOffset = start, inType = true ))
1588
+ SingletonTypeTree (simpleLiteral())
1566
1589
else if in.token == USCORE then
1567
1590
if sourceVersion.isAtLeast(`3.1`) then
1568
1591
deprecationWarning(em " `_` is deprecated for wildcard arguments of types: use `?` instead " )
@@ -1575,7 +1598,11 @@ object Parsers {
1575
1598
else if isIdent(nme.* ) && ctx.settings.YkindProjector .value then
1576
1599
typeIdent()
1577
1600
else
1578
- simpleType1()
1601
+ def singletonArgs (t : Tree ): Tree =
1602
+ if in.token == LPAREN
1603
+ then singletonArgs(AppliedTypeTree (t, inParens(commaSeparated(singleton))))
1604
+ else t
1605
+ singletonArgs(simpleType1())
1579
1606
1580
1607
/** SimpleType1 ::= id
1581
1608
* | Singleton `.' id
0 commit comments