From badf79aee5d6987378d6bda73b445bc23127cf0d Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 25 Mar 2011 16:07:07 +0300 Subject: [PATCH] Closure parameters for constructor invocations --- grammar/src/expressions.grm | 10 +- .../lang/parsing/JetExpressionParsing.java | 9 +- .../psi/examples/collections/List.jet | 5 +- .../psi/examples/collections/List.txt | 203 +++++++++--------- 4 files changed, 111 insertions(+), 116 deletions(-) diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 91c31de989c..eda191c7db3 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -174,12 +174,16 @@ prefixUnaryOperation postfixUnaryOperation : "++" : "--" - : typeArguments? valueArguments (label? functionLiteral) - : typeArguments (label? functionLiteral) + : callSuffix : arrayAccess : memberAccessOperation postfixUnaryOperation // TODO: Review ; +callSuffix + : typeArguments? valueArguments (label? functionLiteral) + : typeArguments (label? functionLiteral) + ; + memberAccessOperation : "." : "?." : "#" : "?" ; @@ -221,7 +225,7 @@ expressions ; constructorInvocation - : userType valueArguments + : userType callSuffix ; arrayAccess diff --git a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index 86802897aac..859bd54beb5 100644 --- a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -374,7 +374,10 @@ public class JetExpressionParsing extends AbstractJetParsing { } /* - * typeParameters? valueParameters? functionLiteral* + * callSuffix + * : typeArguments? valueArguments (label? functionLiteral*) + * : typeArguments (label? functionLiteral*) + * ; */ private boolean parseCallSuffix() { if (parseCallWithClosure()) { @@ -1361,7 +1364,7 @@ public class JetExpressionParsing extends AbstractJetParsing { * "new" constructorInvocation // identical to new functionCall * * constructorInvocation - * : userType valueArguments + * : userType callSuffix */ private void parseNew() { assert _at(NEW_KEYWORD); @@ -1370,7 +1373,7 @@ public class JetExpressionParsing extends AbstractJetParsing { advance(); // NEW_KEYWORD myJetParsing.parseTypeRef(); - parseValueArgumentList(); + parseCallSuffix(); creation.done(NEW); } diff --git a/idea/testData/psi/examples/collections/List.jet b/idea/testData/psi/examples/collections/List.jet index 0a8d852eb41..490da9ae039 100644 --- a/idea/testData/psi/examples/collections/List.jet +++ b/idea/testData/psi/examples/collections/List.jet @@ -11,12 +11,11 @@ enum class List(theSize : Int) : IList { get() = this == Nil - override fun iterator() = new IIterator() { + override fun iterator() = object IIterator() { private var current = List.this - override val hasNext { + override val hasNext get() = current == Nil - } override fun next() { val result = current.value diff --git a/idea/testData/psi/examples/collections/List.txt b/idea/testData/psi/examples/collections/List.txt index 01cbc9a7b50..4b0bdd0658a 100644 --- a/idea/testData/psi/examples/collections/List.txt +++ b/idea/testData/psi/examples/collections/List.txt @@ -225,126 +225,115 @@ JetFile: List.jet PsiWhiteSpace(' ') PsiElement(EQ)('=') PsiWhiteSpace(' ') - CALL_EXPRESSION - NEW - PsiElement(new)('new') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('IIterator') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') + OBJECT_LITERAL + PsiElement(object)('object') PsiWhiteSpace(' ') - FUNCTION_LITERAL + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CALL + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('IIterator') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') - BODY - PROPERTY - MODIFIER_LIST - PsiElement(private)('private') - PsiWhiteSpace(' ') - PsiElement(var)('var') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('current') + PROPERTY + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('current') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('List') + PsiElement(DOT)('.') + THIS_EXPRESSION + PsiElement(this)('this') + PsiWhiteSpace('\n\n ') + PROPERTY + MODIFIER_LIST + PsiElement(override)('override') + PsiWhiteSpace(' ') + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('hasNext') + PsiWhiteSpace('\n ') + PROPERTY_ACCESSOR + PsiElement(get)('get') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') PsiWhiteSpace(' ') PsiElement(EQ)('=') PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION + BINARY_EXPRESSION REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('List') - PsiElement(DOT)('.') - THIS_EXPRESSION - PsiElement(this)('this') - PsiWhiteSpace('\n\n ') - CALL_EXPRESSION - PROPERTY - MODIFIER_LIST - PsiElement(override)('override') + PsiElement(IDENTIFIER)('current') PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQEQ)('==') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Nil') + PsiWhiteSpace('\n\n ') + FUN + MODIFIER_LIST + PsiElement(override)('override') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('next') + TYPE_PARAMETER_LIST + + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + PROPERTY PsiElement(val)('val') PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('hasNext') - PsiWhiteSpace(' ') - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - PsiWhiteSpace('\n ') - BODY - BINARY_EXPRESSION - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('get') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - BINARY_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('current') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(EQEQ)('==') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Nil') - PsiWhiteSpace('\n ') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n\n ') - FUN - MODIFIER_LIST - PsiElement(override)('override') - PsiWhiteSpace(' ') - PsiElement(fun)('fun') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('next') - TYPE_PARAMETER_LIST - - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - BLOCK - PsiElement(LBRACE)('{') - PsiWhiteSpace('\n ') - PROPERTY - PsiElement(val)('val') - PsiWhiteSpace(' ') - PsiElement(IDENTIFIER)('result') - PsiWhiteSpace(' ') - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('current') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('value') - PsiWhiteSpace('\n ') - BINARY_EXPRESSION + PsiElement(IDENTIFIER)('result') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('current') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(EQ)('=') - PsiWhiteSpace(' ') - DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('current') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('tail') - PsiWhiteSpace('\n ') - RETURN - PsiElement(return)('return') - PsiWhiteSpace(' ') + PsiElement(DOT)('.') REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('result') - PsiWhiteSpace('\n ') - PsiElement(RBRACE)('}') + PsiElement(IDENTIFIER)('value') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('current') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('current') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('tail') + PsiWhiteSpace('\n ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('result') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n ') PsiElement(RBRACE)('}') PsiWhiteSpace('\n')