Skip to content

Commit 6ad57b6

Browse files
author
dmitry.naydanov
committed
Trailing comma support: Exprs like (T, \n) shouldn't tuple types/tuple exprs. This is the part of #SCL-10597
1 parent 1ae1115 commit 6ad57b6

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/org/jetbrains/plugins/scala/lang/parser/parsing/expressions/SimpleExpr.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.plugins.scala.lang.parser.parsing.builder.ScalaPsiBuilder
1010
import org.jetbrains.plugins.scala.lang.parser.parsing.top.ClassTemplate
1111
import org.jetbrains.plugins.scala.lang.parser.parsing.types.{Path, TypeArgs}
1212
import org.jetbrains.plugins.scala.lang.parser.parsing.xml.XmlExpr
13+
import org.jetbrains.plugins.scala.lang.parser.util.ParserUtils
1314

1415
import scala.annotation.tailrec
1516

@@ -100,7 +101,7 @@ trait SimpleExpr extends ParserNode with ScalaTokenTypes {
100101
builder error ErrMsg("wrong.expression")
101102
}
102103
}
103-
if (builder.getTokenType == ScalaTokenTypes.tCOMMA) {
104+
if (builder.getTokenType == ScalaTokenTypes.tCOMMA && !ParserUtils.eatTrailingComma(builder, ScalaTokenTypes.tRPARENTHESIS)) {
104105
builder.advanceLexer()
105106
isTuple = true
106107
}

src/org/jetbrains/plugins/scala/lang/parser/parsing/types/Types.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package types
66

77
import org.jetbrains.plugins.scala.lang.lexer.ScalaTokenTypes
88
import org.jetbrains.plugins.scala.lang.parser.parsing.builder.ScalaPsiBuilder
9+
import org.jetbrains.plugins.scala.lang.parser.util.ParserUtils
910

1011
/**
1112
* @author Alexander Podkhalyuzin
@@ -39,7 +40,7 @@ trait Types extends ParserNode {
3940
return (false,isTuple)
4041
}
4142
var exit = true
42-
while (exit && builder.getTokenType == ScalaTokenTypes.tCOMMA) {
43+
while (exit && builder.getTokenType == ScalaTokenTypes.tCOMMA && !ParserUtils.eatTrailingComma(builder, ScalaTokenTypes.tRPARENTHESIS)) {
4344
isTuple = true
4445
builder.advanceLexer() //Ate ,
4546
if (!typesParse) {

testdata/parser/data/trailingcommas/SimpleExpr.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ScalaFile
8484
PsiWhiteSpace(' ')
8585
PsiElement(=)('=')
8686
PsiWhiteSpace(' ')
87-
Tuple
87+
ExpressionInParenthesis
8888
PsiElement(()('(')
8989
PsiWhiteSpace('\n ')
9090
Literal

testdata/parser/data/trailingcommas/SimpleType.test

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,15 @@ ScalaFile
7070
<empty list>
7171
PsiElement(:)(':')
7272
PsiWhiteSpace(' ')
73-
TupleType: (
73+
TypeInParenthesis: (
7474
Int,
7575
)
7676
PsiElement(()('(')
7777
PsiWhiteSpace('\n ')
78-
TypesList
79-
SimpleType: Int
80-
CodeReferenceElement: Int
81-
PsiElement(identifier)('Int')
82-
PsiElement(,)(',')
78+
SimpleType: Int
79+
CodeReferenceElement: Int
80+
PsiElement(identifier)('Int')
81+
PsiElement(,)(',')
8382
PsiWhiteSpace('\n ')
8483
PsiElement())(')')
8584
PsiWhiteSpace(' ')

0 commit comments

Comments
 (0)