PY-31442 Handle multiline expression fragments inside all-triple-quoted f-strings

This commit is contained in:
Mikhail Golubev
2018-10-01 12:46:43 +03:00
parent 9e9e87ad37
commit 5601b6270c
13 changed files with 241 additions and 5 deletions
@@ -0,0 +1,2 @@
s = f'''{1 +
2}'''
@@ -0,0 +1,23 @@
PyFile:MultilineFStringContainingMultilineExpression.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {1 +
2}
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'''')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyBinaryExpression
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
PsiElement(Py:PLUS)('+')
PsiWhiteSpace('\n')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('2')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)(''''')
@@ -0,0 +1,5 @@
s = f"""{f'''
{"bar"
}
'''
}"""
@@ -0,0 +1,34 @@
PyFile:NestedMultilineFStringsWithMultilineExpressions.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {f'''
{"bar"
}
'''
}
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f"""')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression:
{"bar"
}
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'''')
PsiElement(Py:FSTRING_TEXT)('\n')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: bar
PsiElement(Py:SINGLE_QUOTED_STRING)('"bar"')
PsiWhiteSpace('\n')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_TEXT)('\n')
PsiElement(Py:FSTRING_END)(''''')
PsiWhiteSpace('\n')
PsiElement(Py:FSTRING_FRAGMENT_END)('}')
PsiElement(Py:FSTRING_END)('"""')
@@ -0,0 +1,2 @@
s = f"""{f'{1 +
2}'}"""
@@ -0,0 +1,40 @@
PyFile:SingleQuotedFStringInsideMultilineFStringTerminatedByLineBreakInExpression.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {f'{1 +
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f"""')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: {1 +
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyBinaryExpression
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
PsiElement(Py:PLUS)('+')
PsiErrorElement:expression expected
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiWhiteSpace(' \n')
PyExpressionStatement
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('2')
PsiErrorElement:End of statement expected
<empty list>
PsiElement(Py:RBRACE)('}')
PsiErrorElement:Statement expected, found Py:RBRACE
<empty list>
PyExpressionStatement
PyStringLiteralExpression: }"""
PsiElement(Py:SINGLE_QUOTED_STRING)(''}"""')
@@ -0,0 +1,45 @@
PyFile:SingleQuotedFStringInsideMultilineFStringTerminatedByLineBreakInExpressionInParentheses.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {f'{(1 +
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f"""')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: {(1 +
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyParenthesizedExpression
PsiElement(Py:LPAR)('(')
PyBinaryExpression
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
PsiWhiteSpace(' ')
PsiElement(Py:PLUS)('+')
PsiErrorElement:expression expected
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiWhiteSpace(' \n')
PyExpressionStatement
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('2')
PsiErrorElement:End of statement expected
<empty list>
PsiElement(Py:RPAR)(')')
PsiErrorElement:Statement expected, found Py:RPAR
<empty list>
PsiElement(Py:RBRACE)('}')
PsiErrorElement:Statement expected, found Py:RBRACE
<empty list>
PyExpressionStatement
PyStringLiteralExpression: }"""
PsiElement(Py:SINGLE_QUOTED_STRING)(''}"""')
@@ -0,0 +1,2 @@
s = f"""{f'foo
bar'}"""
@@ -0,0 +1,31 @@
PyFile:SingleQuotedFStringInsideMultilineFStringTerminatedByLineBreakInText.py
PyAssignmentStatement
PyTargetExpression: s
PsiElement(Py:IDENTIFIER)('s')
PsiWhiteSpace(' ')
PsiElement(Py:EQ)('=')
PsiWhiteSpace(' ')
PyStringLiteralExpression: {f'foo
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f"""')
PyFStringFragment
PsiElement(Py:FSTRING_FRAGMENT_START)('{')
PyStringLiteralExpression: foo
PyFormattedStringNode
PsiElement(Py:FSTRING_START)('f'')
PsiElement(Py:FSTRING_TEXT)('foo')
PsiErrorElement:Unexpected f-string token
<empty list>
PsiErrorElement:type conversion, : or } expected
<empty list>
PsiErrorElement:Unexpected f-string token
<empty list>
PsiWhiteSpace('\n')
PyExpressionStatement
PyReferenceExpression: bar
PsiElement(Py:IDENTIFIER)('bar')
PsiErrorElement:End of statement expected
<empty list>
PyExpressionStatement
PyStringLiteralExpression: }"""
PsiElement(Py:SINGLE_QUOTED_STRING)(''}"""')