PY-31442 Fix handling of multline expressions in f-strings following other statements

This commit is contained in:
Mikhail Golubev
2018-10-01 12:46:44 +03:00
parent 2287a27ed0
commit 6749fd59a2
2 changed files with 13 additions and 2 deletions
@@ -111,6 +111,11 @@ public class PythonIndentingProcessor extends MergingLexerAdapter {
return super.getTokenEnd();
}
@NotNull
private String getBaseTokenText() {
return getBufferSequence().subSequence(getBaseTokenStart(), getBaseTokenEnd()).toString();
}
private boolean isBaseAt(IElementType tokenType) {
return getBaseTokenType() == tokenType;
}
@@ -189,10 +194,12 @@ public class PythonIndentingProcessor extends MergingLexerAdapter {
}
private void checkFString() {
final String tokenText = getTokenText();
final String tokenText = getBaseTokenText();
if (isBaseAt(PyTokenTypes.FSTRING_START)) {
final int prefixLength = PyStringLiteralUtil.getPrefixLength(tokenText);
myFStringStack.push(tokenText.substring(prefixLength));
final String openingQuotes = tokenText.substring(prefixLength);
assert !openingQuotes.isEmpty();
myFStringStack.push(openingQuotes);
}
else if (isBaseAt(PyTokenTypes.FSTRING_END)) {
while (!myFStringStack.isEmpty()) {
@@ -725,6 +725,10 @@ public class PythonParsingTest extends ParsingTestCase {
doTest(LanguageLevel.PYTHON36);
}
public void testMultilineFStringContainingMultilineExpressionAfterStatementBreak() {
doTest(LanguageLevel.PYTHON36);
}
public void testNestedMultilineFStringsWithMultilineExpressions() {
doTest(LanguageLevel.PYTHON36);
}