diff --git a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java index 1f1ff832dd7a..3e146a8472f3 100644 --- a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java +++ b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java @@ -422,7 +422,8 @@ public class ExpressionParsing extends Parsing { while (!myBuilder.eof() && myBuilder.getTokenType() != PyTokenTypes.RPAR && myBuilder.getTokenType() != PyTokenTypes.LINE_BREAK && - myBuilder.getTokenType() != PyTokenTypes.STATEMENT_BREAK) { + myBuilder.getTokenType() != PyTokenTypes.STATEMENT_BREAK && + myBuilder.getTokenType() != PyTokenTypes.FSTRING_END) { myBuilder.advanceLexer(); empty = false; } diff --git a/python/testData/psi/MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.py b/python/testData/psi/MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.py new file mode 100644 index 000000000000..47e2a7d69c87 --- /dev/null +++ b/python/testData/psi/MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.py @@ -0,0 +1 @@ +s = f'{ (lambda x: 'foo') }' \ No newline at end of file diff --git a/python/testData/psi/MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.txt b/python/testData/psi/MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.txt new file mode 100644 index 000000000000..1b4351b88afe --- /dev/null +++ b/python/testData/psi/MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.txt @@ -0,0 +1,36 @@ +PyFile:MultilineFStringTerminatedByQuotesInsideParenthesizedExpression.py + PyAssignmentStatement + PyTargetExpression: s + PsiElement(Py:IDENTIFIER)('s') + PsiWhiteSpace(' ') + PsiElement(Py:EQ)('=') + PsiWhiteSpace(' ') + PyStringLiteralExpression: { (lambda x: + PyFormattedStringNode + PsiElement(Py:FSTRING_START)('f'') + PyFStringFragment + PsiElement(Py:FSTRING_FRAGMENT_START)('{') + PsiWhiteSpace(' ') + PyParenthesizedExpression + PsiElement(Py:LPAR)('(') + PyLambdaExpression + PsiElement(Py:LAMBDA_KEYWORD)('lambda') + PsiWhiteSpace(' ') + PyParameterList + PyNamedParameter('x') + PsiElement(Py:IDENTIFIER)('x') + PsiElement(Py:COLON)(':') + PsiErrorElement:expression expected + + PsiWhiteSpace(' ') + PsiElement(Py:FSTRING_END)(''') + PsiErrorElement:End of statement expected + + PyExpressionStatement + PyReferenceExpression: foo + PsiElement(Py:IDENTIFIER)('foo') + PsiErrorElement:End of statement expected + + PyExpressionStatement + PyStringLiteralExpression: ) } + PsiElement(Py:SINGLE_QUOTED_STRING)('') }'') \ 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 dca4feea910c..70058f08b358 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -725,6 +725,10 @@ public class PythonParsingTest extends ParsingTestCase { doTest(LanguageLevel.PYTHON36); } + public void testMultilineFStringTerminatedByQuotesInsideParenthesizedExpression() { + doTest(LanguageLevel.PYTHON36); + } + public void testMultilineFStringContainingMultilineExpression() { doTest(LanguageLevel.PYTHON36); }