Distinguish between tuple and parenthesized expression
This commit is contained in:
@@ -72,6 +72,7 @@ public interface JetNodeTypes {
|
||||
JetNodeType LONG_CONSTANT = new JetNodeType("LONG_CONSTANT", JetConstantExpression.class);
|
||||
|
||||
JetNodeType TUPLE = new JetNodeType("TUPLE", JetTupleExpression.class);
|
||||
JetNodeType PARENTHESIZED = new JetNodeType("PARENTHESIZED", JetParenthesizedExpression.class);
|
||||
JetNodeType TYPEOF = new JetNodeType("TYPEOF", JetTypeofExpression.class);
|
||||
JetNodeType NEW = new JetNodeType("NEW", JetNewExpression.class);
|
||||
JetNodeType RETURN = new JetNodeType("RETURN", JetReturnExpression.class);
|
||||
|
||||
@@ -1032,13 +1032,20 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
|
||||
myBuilder.disableNewlines();
|
||||
advance(); // LPAR
|
||||
|
||||
int commaPassed = 0;
|
||||
if (!at(RPAR)) {
|
||||
while (true) {
|
||||
while (at(COMMA)) errorAndAdvance("Expecting a tuple entry (expression)");
|
||||
while (at(COMMA)) {
|
||||
commaPassed++;
|
||||
errorAndAdvance("Expecting a tuple entry (expression)");
|
||||
}
|
||||
|
||||
parseExpression();
|
||||
|
||||
if (!at(COMMA)) break;
|
||||
advance(); // COMMA
|
||||
commaPassed++;
|
||||
|
||||
if (at(RPAR)) {
|
||||
error("Expecting a tuple entry (expression)");
|
||||
break;
|
||||
@@ -1049,7 +1056,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
expect(RPAR, "Expecting ')'");
|
||||
myBuilder.restoreNewlinesState();
|
||||
|
||||
mark.done(TUPLE);
|
||||
mark.done(commaPassed > 0 ? TUPLE : PARENTHESIZED);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author max
|
||||
*/
|
||||
public class JetParenthesizedExpression extends JetExpression {
|
||||
public JetParenthesizedExpression(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(JetVisitor visitor) {
|
||||
visitor.visitParenthesizedExpression(this);
|
||||
}
|
||||
|
||||
public JetExpression getExpression() {
|
||||
return findChildByClass(JetExpression.class);
|
||||
}
|
||||
}
|
||||
@@ -261,4 +261,8 @@ public class JetVisitor extends PsiElementVisitor {
|
||||
public void visitThisExpression(JetThisExpression expression) {
|
||||
visitExpression(expression);
|
||||
}
|
||||
|
||||
public void visitParenthesizedExpression(JetParenthesizedExpression expression) {
|
||||
visitExpression(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ JetFile: ByCaluses.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(by)('by')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
@@ -141,7 +141,7 @@ JetFile: ByCaluses.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(by)('by')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
CALL_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
|
||||
@@ -49,7 +49,7 @@ JetFile: FunctionCalls.jet
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiElement(GT)('>')
|
||||
PsiWhiteSpace('\n ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
@@ -251,7 +251,7 @@ JetFile: FunctionCalls.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiElement(GT)('>')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
@@ -273,7 +273,7 @@ JetFile: FunctionCalls.jet
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
VALUE_ARGUMENT
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
INTEGER_CONSTANT
|
||||
@@ -291,7 +291,7 @@ JetFile: FunctionCalls.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiElement(GT)('>')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('a')
|
||||
|
||||
@@ -68,7 +68,7 @@ JetFile: NewlinesInParentheses.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
@@ -87,7 +87,7 @@ JetFile: NewlinesInParentheses.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
FUNCTION_LITERAL
|
||||
PsiElement(LBRACE)('{')
|
||||
@@ -110,7 +110,7 @@ JetFile: NewlinesInParentheses.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
FUNCTION_LITERAL
|
||||
|
||||
@@ -104,7 +104,7 @@ JetFile: Precedence.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiElement(GT)('>')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
@@ -126,7 +126,7 @@ JetFile: Precedence.jet
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
VALUE_ARGUMENT
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
@@ -144,7 +144,7 @@ JetFile: Precedence.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiElement(GT)('>')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
@@ -166,13 +166,13 @@ JetFile: Precedence.jet
|
||||
PsiElement(COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
VALUE_ARGUMENT
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiElement(GT)('>')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
@@ -214,7 +214,7 @@ JetFile: Precedence.jet
|
||||
VALUE_ARGUMENT_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
VALUE_ARGUMENT
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
@@ -230,7 +230,7 @@ JetFile: Precedence.jet
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('b')
|
||||
PsiElement(GT)('>')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('x')
|
||||
@@ -286,7 +286,7 @@ JetFile: Precedence.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(PLUS)('+')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
@@ -299,7 +299,7 @@ JetFile: Precedence.jet
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace('\n ')
|
||||
BINARY_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
|
||||
@@ -20,7 +20,7 @@ JetFile: SimpleExpressions.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiElement(COMMA)(',')
|
||||
@@ -266,7 +266,7 @@ JetFile: SimpleExpressions.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
INTEGER_CONSTANT
|
||||
PsiElement(INTEGER_LITERAL)('10')
|
||||
|
||||
@@ -212,7 +212,7 @@ JetFile: BitArith.jet
|
||||
PsiWhiteSpace(' ')
|
||||
BINARY_EXPRESSION
|
||||
BINARY_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
@@ -343,7 +343,7 @@ JetFile: BitArith.jet
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
BINARY_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
BINARY_EXPRESSION
|
||||
|
||||
@@ -41,7 +41,7 @@ JetFile: HashMap.jet
|
||||
PsiWhiteSpace(' ')
|
||||
CALL_EXPRESSION
|
||||
DOT_QIALIFIED_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
THIS_EXPRESSION
|
||||
@@ -127,7 +127,7 @@ JetFile: HashMap.jet
|
||||
PsiWhiteSpace(' ')
|
||||
CALL_EXPRESSION
|
||||
DOT_QIALIFIED_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
THIS_EXPRESSION
|
||||
|
||||
@@ -895,7 +895,7 @@ JetFile: BinaryHeap.jet
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
BINARY_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
THIS_EXPRESSION
|
||||
@@ -1058,7 +1058,7 @@ JetFile: BinaryHeap.jet
|
||||
PsiElement(EQ)('=')
|
||||
PsiWhiteSpace(' ')
|
||||
BINARY_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
THIS_EXPRESSION
|
||||
@@ -1076,7 +1076,7 @@ JetFile: BinaryHeap.jet
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(ANDAND)('&&')
|
||||
PsiWhiteSpace(' ')
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
THIS_EXPRESSION
|
||||
|
||||
@@ -143,7 +143,7 @@ JetFile: Comparison.jet
|
||||
PsiWhiteSpace(' ')
|
||||
CALL_EXPRESSION
|
||||
DOT_QIALIFIED_EXPRESSION
|
||||
TUPLE
|
||||
PARENTHESIZED
|
||||
PsiElement(LPAR)('(')
|
||||
BINARY_EXPRESSION
|
||||
REFERENCE_EXPRESSION
|
||||
|
||||
Reference in New Issue
Block a user