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
|
// one can use "it" as a parameter name
|
||||||
functionLiteral
|
functionLiteral
|
||||||
: "{" statements "}"
|
: "{" statements "}"
|
||||||
: "{" (type ".")? modifiers SimpleName "=>" statements "}"
|
: "{" (modifiers SimpleName){","} "=>" statements "}"
|
||||||
: "{" (type ".")? "(" (modifiers SimpleName (":" type)?){","} ")" (":" type)? "=>" 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
|
* functionLiteral // one can use "it" as a parameter name
|
||||||
* : "{" expressions "}"
|
* : "{" expressions "}"
|
||||||
* : "{" (type ".")? modifiers SimpleName "=>" expressions "}"
|
* : "{" (modifiers SimpleName){","} "=>" statements "}"
|
||||||
* : "{" (type ".")? "(" (modifiers SimpleName (":" type)?){","} ")" (":" type)? "=>" expressions "}"
|
* : "{" (type ".")? "(" (modifiers SimpleName (":" type)?){","} ")" (":" type)? "=>" expressions "}"
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
@@ -1038,27 +1038,37 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
advance(); // COLON
|
advance(); // COLON
|
||||||
if (at(DOUBLE_ARROW)) {
|
if (at(DOUBLE_ARROW)) {
|
||||||
error("Expecting a type");
|
error("Expecting a type");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
myJetParsing.parseTypeRef();
|
myJetParsing.parseTypeRef();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!dontExpectParameters) {
|
}
|
||||||
|
else if (!dontExpectParameters) {
|
||||||
PsiBuilder.Marker parameterList = mark();
|
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)) {
|
parameter.done(VALUE_PARAMETER);
|
||||||
errorUntilOffset("To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType => ...}", doubleArrowPos);
|
|
||||||
} else if (at(COMMA)) {
|
if (at(COLON)) {
|
||||||
errorUntilOffset("To specify many parameters, use the full notation: {(p1, p2, ...) => ...}", doubleArrowPos);
|
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)) {
|
}
|
||||||
errorUntilOffset("Expecting '=>'", doubleArrowPos);
|
else if (at(DOUBLE_ARROW)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!at(COMMA)) {
|
||||||
|
errorUntilOffset("Expecting '=>' or ','", doubleArrowPos);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
advance(); // COMMA
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parameterList.done(VALUE_PARAMETER_LIST);
|
parameterList.done(VALUE_PARAMETER_LIST);
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ public class JetPsiChecker implements Annotator {
|
|||||||
if (!redeclarations.add(redeclaration)) return;
|
if (!redeclarations.add(redeclaration)) return;
|
||||||
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(redeclaration);
|
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(redeclaration);
|
||||||
if (declarationPsiElement instanceof JetNamedDeclaration) {
|
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) {
|
else if (declarationPsiElement != null) {
|
||||||
holder.createErrorAnnotation(declarationPsiElement, "Redeclaration");
|
holder.createErrorAnnotation(declarationPsiElement, "Redeclaration");
|
||||||
|
|||||||
@@ -24,4 +24,6 @@ fun foo() {
|
|||||||
{T.(a : A) => a}
|
{T.(a : A) => a}
|
||||||
{T.(a : A) : T => a}
|
{T.(a : A) : T => a}
|
||||||
{T.(a) : T => a}
|
{T.(a) : T => a}
|
||||||
|
|
||||||
|
{x, y => 1}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -435,5 +435,23 @@ JetFile: FunctionLiterals.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
PsiElement(RBRACE)('}')
|
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')
|
PsiWhiteSpace('\n')
|
||||||
PsiElement(RBRACE)('}')
|
PsiElement(RBRACE)('}')
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
fun foo() {
|
fun foo() {
|
||||||
{ => a}
|
{ => a}
|
||||||
{a, b => a}
|
|
||||||
|
|
||||||
{(a => a}
|
{(a => a}
|
||||||
{(a : ) => a}
|
{(a : ) => a}
|
||||||
|
|||||||
@@ -25,24 +25,6 @@ JetFile: FunctionLiterals_ERR.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
PsiElement(RBRACE)('}')
|
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 ')
|
PsiWhiteSpace('\n\n ')
|
||||||
FUNCTION_LITERAL_EXPRESSION
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
FUNCTION_LITERAL
|
FUNCTION_LITERAL
|
||||||
@@ -297,7 +279,10 @@ JetFile: FunctionLiterals_ERR.jet
|
|||||||
PsiElement(COLON)(':')
|
PsiElement(COLON)(':')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiErrorElement:Expecting parameter name
|
||||||
|
<empty list>
|
||||||
PsiElement(DOUBLE_ARROW)('=>')
|
PsiElement(DOUBLE_ARROW)('=>')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
BLOCK
|
BLOCK
|
||||||
|
|||||||
Reference in New Issue
Block a user