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 LONG_CONSTANT = new JetNodeType("LONG_CONSTANT", JetConstantExpression.class);
|
||||||
|
|
||||||
JetNodeType TUPLE = new JetNodeType("TUPLE", JetTupleExpression.class);
|
JetNodeType TUPLE = new JetNodeType("TUPLE", JetTupleExpression.class);
|
||||||
|
JetNodeType PARENTHESIZED = new JetNodeType("PARENTHESIZED", JetParenthesizedExpression.class);
|
||||||
JetNodeType TYPEOF = new JetNodeType("TYPEOF", JetTypeofExpression.class);
|
JetNodeType TYPEOF = new JetNodeType("TYPEOF", JetTypeofExpression.class);
|
||||||
JetNodeType NEW = new JetNodeType("NEW", JetNewExpression.class);
|
JetNodeType NEW = new JetNodeType("NEW", JetNewExpression.class);
|
||||||
JetNodeType RETURN = new JetNodeType("RETURN", JetReturnExpression.class);
|
JetNodeType RETURN = new JetNodeType("RETURN", JetReturnExpression.class);
|
||||||
|
|||||||
@@ -1032,13 +1032,20 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
myBuilder.disableNewlines();
|
myBuilder.disableNewlines();
|
||||||
advance(); // LPAR
|
advance(); // LPAR
|
||||||
|
int commaPassed = 0;
|
||||||
if (!at(RPAR)) {
|
if (!at(RPAR)) {
|
||||||
while (true) {
|
while (true) {
|
||||||
while (at(COMMA)) errorAndAdvance("Expecting a tuple entry (expression)");
|
while (at(COMMA)) {
|
||||||
|
commaPassed++;
|
||||||
|
errorAndAdvance("Expecting a tuple entry (expression)");
|
||||||
|
}
|
||||||
|
|
||||||
parseExpression();
|
parseExpression();
|
||||||
|
|
||||||
if (!at(COMMA)) break;
|
if (!at(COMMA)) break;
|
||||||
advance(); // COMMA
|
advance(); // COMMA
|
||||||
|
commaPassed++;
|
||||||
|
|
||||||
if (at(RPAR)) {
|
if (at(RPAR)) {
|
||||||
error("Expecting a tuple entry (expression)");
|
error("Expecting a tuple entry (expression)");
|
||||||
break;
|
break;
|
||||||
@@ -1049,7 +1056,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
expect(RPAR, "Expecting ')'");
|
expect(RPAR, "Expecting ')'");
|
||||||
myBuilder.restoreNewlinesState();
|
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) {
|
public void visitThisExpression(JetThisExpression expression) {
|
||||||
visitExpression(expression);
|
visitExpression(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void visitParenthesizedExpression(JetParenthesizedExpression expression) {
|
||||||
|
visitExpression(expression);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ JetFile: ByCaluses.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(by)('by')
|
PsiElement(by)('by')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
@@ -141,7 +141,7 @@ JetFile: ByCaluses.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(by)('by')
|
PsiElement(by)('by')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
CALL_EXPRESSION
|
CALL_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ JetFile: FunctionCalls.jet
|
|||||||
PsiElement(IDENTIFIER)('foo')
|
PsiElement(IDENTIFIER)('foo')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
PsiWhiteSpace('\n ')
|
PsiWhiteSpace('\n ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
@@ -251,7 +251,7 @@ JetFile: FunctionCalls.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
@@ -273,7 +273,7 @@ JetFile: FunctionCalls.jet
|
|||||||
PsiElement(COMMA)(',')
|
PsiElement(COMMA)(',')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
VALUE_ARGUMENT
|
VALUE_ARGUMENT
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
INTEGER_CONSTANT
|
INTEGER_CONSTANT
|
||||||
@@ -291,7 +291,7 @@ JetFile: FunctionCalls.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ JetFile: NewlinesInParentheses.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
@@ -87,7 +87,7 @@ JetFile: NewlinesInParentheses.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
FUNCTION_LITERAL
|
FUNCTION_LITERAL
|
||||||
PsiElement(LBRACE)('{')
|
PsiElement(LBRACE)('{')
|
||||||
@@ -110,7 +110,7 @@ JetFile: NewlinesInParentheses.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
FUNCTION_LITERAL
|
FUNCTION_LITERAL
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ JetFile: Precedence.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('x')
|
PsiElement(IDENTIFIER)('x')
|
||||||
@@ -126,7 +126,7 @@ JetFile: Precedence.jet
|
|||||||
PsiElement(COMMA)(',')
|
PsiElement(COMMA)(',')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
VALUE_ARGUMENT
|
VALUE_ARGUMENT
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
@@ -144,7 +144,7 @@ JetFile: Precedence.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('x')
|
PsiElement(IDENTIFIER)('x')
|
||||||
@@ -166,13 +166,13 @@ JetFile: Precedence.jet
|
|||||||
PsiElement(COMMA)(',')
|
PsiElement(COMMA)(',')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
VALUE_ARGUMENT
|
VALUE_ARGUMENT
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('x')
|
PsiElement(IDENTIFIER)('x')
|
||||||
@@ -214,7 +214,7 @@ JetFile: Precedence.jet
|
|||||||
VALUE_ARGUMENT_LIST
|
VALUE_ARGUMENT_LIST
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
VALUE_ARGUMENT
|
VALUE_ARGUMENT
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
@@ -230,7 +230,7 @@ JetFile: Precedence.jet
|
|||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
PsiElement(GT)('>')
|
PsiElement(GT)('>')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('x')
|
PsiElement(IDENTIFIER)('x')
|
||||||
@@ -286,7 +286,7 @@ JetFile: Precedence.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(PLUS)('+')
|
PsiElement(PLUS)('+')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
@@ -299,7 +299,7 @@ JetFile: Precedence.jet
|
|||||||
PsiElement(RPAR)(')')
|
PsiElement(RPAR)(')')
|
||||||
PsiWhiteSpace('\n ')
|
PsiWhiteSpace('\n ')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ JetFile: SimpleExpressions.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
PsiElement(RPAR)(')')
|
PsiElement(RPAR)(')')
|
||||||
PsiElement(COMMA)(',')
|
PsiElement(COMMA)(',')
|
||||||
@@ -266,7 +266,7 @@ JetFile: SimpleExpressions.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
INTEGER_CONSTANT
|
INTEGER_CONSTANT
|
||||||
PsiElement(INTEGER_LITERAL)('10')
|
PsiElement(INTEGER_LITERAL)('10')
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ JetFile: BitArith.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
@@ -343,7 +343,7 @@ JetFile: BitArith.jet
|
|||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ JetFile: HashMap.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
CALL_EXPRESSION
|
CALL_EXPRESSION
|
||||||
DOT_QIALIFIED_EXPRESSION
|
DOT_QIALIFIED_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
THIS_EXPRESSION
|
THIS_EXPRESSION
|
||||||
@@ -127,7 +127,7 @@ JetFile: HashMap.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
CALL_EXPRESSION
|
CALL_EXPRESSION
|
||||||
DOT_QIALIFIED_EXPRESSION
|
DOT_QIALIFIED_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
THIS_EXPRESSION
|
THIS_EXPRESSION
|
||||||
|
|||||||
@@ -895,7 +895,7 @@ JetFile: BinaryHeap.jet
|
|||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
THIS_EXPRESSION
|
THIS_EXPRESSION
|
||||||
@@ -1058,7 +1058,7 @@ JetFile: BinaryHeap.jet
|
|||||||
PsiElement(EQ)('=')
|
PsiElement(EQ)('=')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
THIS_EXPRESSION
|
THIS_EXPRESSION
|
||||||
@@ -1076,7 +1076,7 @@ JetFile: BinaryHeap.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiElement(ANDAND)('&&')
|
PsiElement(ANDAND)('&&')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
THIS_EXPRESSION
|
THIS_EXPRESSION
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ JetFile: Comparison.jet
|
|||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
CALL_EXPRESSION
|
CALL_EXPRESSION
|
||||||
DOT_QIALIFIED_EXPRESSION
|
DOT_QIALIFIED_EXPRESSION
|
||||||
TUPLE
|
PARENTHESIZED
|
||||||
PsiElement(LPAR)('(')
|
PsiElement(LPAR)('(')
|
||||||
BINARY_EXPRESSION
|
BINARY_EXPRESSION
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
|
|||||||
Reference in New Issue
Block a user