JET-172 Allow many parameters of a function literals to be declared without parentheses
This commit is contained in:
@@ -245,7 +245,7 @@ tupleLiteral
|
||||
// one can use "it" as a parameter name
|
||||
functionLiteral
|
||||
: "{" statements "}"
|
||||
: "{" (type ".")? modifiers SimpleName "=>" statements "}"
|
||||
: "{" (modifiers SimpleName){","} "=>" statements "}"
|
||||
: "{" (type ".")? "(" (modifiers SimpleName (":" type)?){","} ")" (":" type)? "=>" statements "}"
|
||||
;
|
||||
|
||||
|
||||
@@ -987,7 +987,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
/*
|
||||
* functionLiteral // one can use "it" as a parameter name
|
||||
* : "{" expressions "}"
|
||||
* : "{" (type ".")? modifiers SimpleName "=>" expressions "}"
|
||||
* : "{" (modifiers SimpleName){","} "=>" statements "}"
|
||||
* : "{" (type ".")? "(" (modifiers SimpleName (":" type)?){","} ")" (":" type)? "=>" expressions "}"
|
||||
* ;
|
||||
*/
|
||||
@@ -1038,27 +1038,37 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
advance(); // COLON
|
||||
if (at(DOUBLE_ARROW)) {
|
||||
error("Expecting a type");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
myJetParsing.parseTypeRef();
|
||||
}
|
||||
}
|
||||
} else if (!dontExpectParameters) {
|
||||
}
|
||||
else if (!dontExpectParameters) {
|
||||
PsiBuilder.Marker parameterList = mark();
|
||||
PsiBuilder.Marker parameter = mark();
|
||||
int parameterNamePos = matchTokenStreamPredicate(new LastBefore(new At(IDENTIFIER), new AtOffset(doubleArrowPos)));
|
||||
|
||||
createTruncatedBuilder(parameterNamePos).parseModifierList(MODIFIER_LIST);
|
||||
while (!eof()) {
|
||||
PsiBuilder.Marker parameter = mark();
|
||||
int parameterNamePos = matchTokenStreamPredicate(new LastBefore(new At(IDENTIFIER), new AtOffset(doubleArrowPos)));
|
||||
|
||||
expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(DOUBLE_ARROW));
|
||||
createTruncatedBuilder(parameterNamePos).parseModifierList(MODIFIER_LIST);
|
||||
|
||||
parameter.done(VALUE_PARAMETER);
|
||||
expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(DOUBLE_ARROW));
|
||||
|
||||
if (at(COLON)) {
|
||||
errorUntilOffset("To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType => ...}", doubleArrowPos);
|
||||
} else if (at(COMMA)) {
|
||||
errorUntilOffset("To specify many parameters, use the full notation: {(p1, p2, ...) => ...}", doubleArrowPos);
|
||||
} else if (!at(DOUBLE_ARROW)) {
|
||||
errorUntilOffset("Expecting '=>'", doubleArrowPos);
|
||||
parameter.done(VALUE_PARAMETER);
|
||||
|
||||
if (at(COLON)) {
|
||||
errorUntilOffset("To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType => ...}", doubleArrowPos);
|
||||
}
|
||||
else if (at(DOUBLE_ARROW)) {
|
||||
break;
|
||||
}
|
||||
else if (!at(COMMA)) {
|
||||
errorUntilOffset("Expecting '=>' or ','", doubleArrowPos);
|
||||
}
|
||||
else {
|
||||
advance(); // COMMA
|
||||
}
|
||||
}
|
||||
|
||||
parameterList.done(VALUE_PARAMETER_LIST);
|
||||
|
||||
@@ -77,7 +77,9 @@ public class JetPsiChecker implements Annotator {
|
||||
if (!redeclarations.add(redeclaration)) return;
|
||||
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(redeclaration);
|
||||
if (declarationPsiElement instanceof JetNamedDeclaration) {
|
||||
holder.createErrorAnnotation(((JetNamedDeclaration) declarationPsiElement).getNameIdentifier(), "Redeclaration");
|
||||
PsiElement nameIdentifier = ((JetNamedDeclaration) declarationPsiElement).getNameIdentifier();
|
||||
assert nameIdentifier != null : declarationPsiElement.getText() + " has nameIdentifier 'null'";
|
||||
holder.createErrorAnnotation(nameIdentifier, "Redeclaration");
|
||||
}
|
||||
else if (declarationPsiElement != null) {
|
||||
holder.createErrorAnnotation(declarationPsiElement, "Redeclaration");
|
||||
|
||||
@@ -24,4 +24,6 @@ fun foo() {
|
||||
{T.(a : A) => a}
|
||||
{T.(a : A) : T => a}
|
||||
{T.(a) : T => a}
|
||||
|
||||
{x, y => 1}
|
||||
}
|
||||
|
||||
@@ -435,5 +435,23 @@ JetFile: FunctionLiterals.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
FUNCTION_LITERAL_EXPRESSION
|
||||
FUNCTION_LITERAL
|
||||
PsiElement(LBRACE)('{')
|
||||
VALUE_PARAMETER_LIST
|
||||
VALUE_PARAMETER
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
VALUE_PARAMETER
|
||||
PsiElement(IDENTIFIER)('y')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('1')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -1,6 +1,5 @@
|
||||
fun foo() {
|
||||
{ => a}
|
||||
{a, b => a}
|
||||
|
||||
{(a => a}
|
||||
{(a : ) => a}
|
||||
|
||||
@@ -25,24 +25,6 @@ JetFile: FunctionLiterals_ERR.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n ')
|
||||
FUNCTION_LITERAL_EXPRESSION
|
||||
FUNCTION_LITERAL
|
||||
PsiElement(LBRACE)('{')
|
||||
VALUE_PARAMETER_LIST
|
||||
VALUE_PARAMETER
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiErrorElement:To specify many parameters, use the full notation: {(p1, p2, ...) => ...}
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiWhiteSpace('\n\n ')
|
||||
FUNCTION_LITERAL_EXPRESSION
|
||||
FUNCTION_LITERAL
|
||||
@@ -297,7 +279,10 @@ JetFile: FunctionLiterals_ERR.jet
|
||||
PsiElement(COLON)(':')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiWhiteSpace(' ')
|
||||
VALUE_PARAMETER
|
||||
PsiErrorElement:Expecting parameter name
|
||||
<empty list>
|
||||
PsiElement(DOUBLE_ARROW)('=>')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
|
||||
Reference in New Issue
Block a user