diff --git a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java index e5bdc0eb259c..3d24cb42350b 100644 --- a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java +++ b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java @@ -1,34 +1,15 @@ -/* - * Copyright 2005 Pythonid Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS"; BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package com.jetbrains.python.parsing; import com.intellij.lang.PsiBuilder; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.tree.IElementType; -import static com.jetbrains.python.PyBundle.message; import com.jetbrains.python.PyElementTypes; import com.jetbrains.python.PyTokenTypes; +import static com.jetbrains.python.PyBundle.message; + /** - * Created by IntelliJ IDEA. - * User: yole - * Date: 29.05.2005 - * Time: 10:26:06 - * To change this template use File | Settings | File Templates. + * @author yole */ public class ExpressionParsing extends Parsing { private static final Logger LOG = Logger.getInstance("#ru.yole.pythonlanguage.parsing.ExpressionParsing"); @@ -130,7 +111,7 @@ public class ExpressionParsing extends Parsing { } while (myBuilder.getTokenType() == PyTokenTypes.IF_KEYWORD) { myBuilder.advanceLexer(); - parseExpression(); + parseOldExpression(); } if (myBuilder.getTokenType() == endToken) { myBuilder.advanceLexer(); @@ -432,6 +413,13 @@ public class ExpressionParsing extends Parsing { return parseTestExpression(false, isTargetExpression); } + public boolean parseOldExpression() { + if (myBuilder.getTokenType() == PyTokenTypes.LAMBDA_KEYWORD) { + return parseLambdaExpression(false); + } + return parseORTestExpression(myBuilder, false, false); + } + private boolean parseTestExpression(boolean stopOnIn, boolean isTargetExpression) { if (myBuilder.getTokenType() == PyTokenTypes.LAMBDA_KEYWORD) { return parseLambdaExpression(false); diff --git a/python/testData/psi/ListComprehensionNestedIf.py b/python/testData/psi/ListComprehensionNestedIf.py new file mode 100644 index 000000000000..8890e8d43116 --- /dev/null +++ b/python/testData/psi/ListComprehensionNestedIf.py @@ -0,0 +1 @@ +[x for x in range(10) if x % 2 if x % 3] diff --git a/python/testData/psi/ListComprehensionNestedIf.txt b/python/testData/psi/ListComprehensionNestedIf.txt new file mode 100644 index 000000000000..700cc8780c88 --- /dev/null +++ b/python/testData/psi/ListComprehensionNestedIf.txt @@ -0,0 +1,45 @@ +PyFile:ListComprehensionNestedIf.py + PyExpressionStatement + PyListCompExpression + PsiElement(Py:LBRACKET)('[') + PyReferenceExpression: x + PsiElement(Py:IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(Py:FOR_KEYWORD)('for') + PsiWhiteSpace(' ') + PyTargetExpression: x + PsiElement(Py:IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(Py:IN_KEYWORD)('in') + PsiWhiteSpace(' ') + PyCallExpression: range + PyReferenceExpression: range + PsiElement(Py:IDENTIFIER)('range') + PyArgumentList + PsiElement(Py:LPAR)('(') + PyNumericLiteralExpression + PsiElement(Py:INTEGER_LITERAL)('10') + PsiElement(Py:RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(Py:IF_KEYWORD)('if') + PsiWhiteSpace(' ') + PyBinaryExpression + PyReferenceExpression: x + PsiElement(Py:IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(Py:PERC)('%') + PsiWhiteSpace(' ') + PyNumericLiteralExpression + PsiElement(Py:INTEGER_LITERAL)('2') + PsiWhiteSpace(' ') + PsiElement(Py:IF_KEYWORD)('if') + PsiWhiteSpace(' ') + PyBinaryExpression + PyReferenceExpression: x + PsiElement(Py:IDENTIFIER)('x') + PsiWhiteSpace(' ') + PsiElement(Py:PERC)('%') + PsiWhiteSpace(' ') + PyNumericLiteralExpression + PsiElement(Py:INTEGER_LITERAL)('3') + PsiElement(Py:RBRACKET)(']') \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PythonParsingTest.java b/python/testSrc/com/jetbrains/python/PythonParsingTest.java index 9b36c2c3ffb7..64115bd42a5c 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -112,6 +112,10 @@ public class PythonParsingTest extends ParsingTestCase { doTest(); } + public void testListComprehensionNestedIf() throws Exception { // PY-322 + doTest(); + } + public void doTest() throws Exception { doTest(LanguageLevel.PYTHON25); }