@@ -192,7 +192,9 @@ object Parsers {
192192
193193 def isIdent = in.isIdent
194194 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)
196198 def isLiteral = literalTokens contains in.token
197199 def isNumericLit = numericLitTokens contains in.token
198200 def isTemplateIntro = templateIntroTokens contains in.token
@@ -1100,18 +1102,42 @@ object Parsers {
11001102 */
11011103 def qualId (): Tree = dotSelectors(termIdent())
11021104
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+ *
11061132 * @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.
11081134 */
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 = {
11101136 def literalOf (token : Token ): Tree = {
11111137 val isNegated = negOffset < in.offset
11121138 def digits0 = in.removeNumberSeparators(in.strVal)
11131139 def digits = if (isNegated) " -" + digits0 else digits0
1114- if ( ! inType)
1140+ if ! inTypeOrSingleton then
11151141 token match {
11161142 case INTLIT => return Number (digits, NumberKind .Whole (in.base))
11171143 case DECILIT => return Number (digits, NumberKind .Decimal )
@@ -1554,15 +1580,12 @@ object Parsers {
15541580
15551581 /** SimpleType ::= SimpleLiteral
15561582 * | ‘?’ SubtypeBounds
1557- * | SimpleType1
1583+ * | SimpleType1 { ‘(’ Singletons ‘)’ }
1584+ * Singletons ::= Singleton {‘,’ Singleton}
15581585 */
15591586 def simpleType (): Tree =
15601587 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())
15661589 else if in.token == USCORE then
15671590 if sourceVersion.isAtLeast(`3.1`) then
15681591 deprecationWarning(em " `_` is deprecated for wildcard arguments of types: use `?` instead " )
@@ -1575,7 +1598,11 @@ object Parsers {
15751598 else if isIdent(nme.* ) && ctx.settings.YkindProjector .value then
15761599 typeIdent()
15771600 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())
15791606
15801607 /** SimpleType1 ::= id
15811608 * | Singleton `.' id
0 commit comments