mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
tweak Python parser to handle incomplete code better (PY-4053)
This commit is contained in:
@@ -460,6 +460,7 @@ public class ExpressionParsing extends Parsing {
|
||||
}
|
||||
if (!parseSingleExpression(false)) {
|
||||
myBuilder.error(message("PARSE.expected.expression"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,13 @@ public class Parsing {
|
||||
return getParsingContext().getFunctionParser();
|
||||
}
|
||||
|
||||
protected void checkMatches(final IElementType token, final String message) {
|
||||
protected boolean checkMatches(final IElementType token, final String message) {
|
||||
if (myBuilder.getTokenType() == token) {
|
||||
myBuilder.advanceLexer();
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
myBuilder.error(message);
|
||||
}
|
||||
myBuilder.error(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean checkMatches(final TokenSet tokenSet, final String message) {
|
||||
|
||||
@@ -532,8 +532,9 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
|
||||
final PsiBuilder.Marker ifPart = myBuilder.mark();
|
||||
myBuilder.advanceLexer();
|
||||
getExpressionParser().parseExpression();
|
||||
checkMatches(PyTokenTypes.COLON, "colon expected");
|
||||
parseSuite();
|
||||
if (checkMatches(PyTokenTypes.COLON, "colon expected")) {
|
||||
parseSuite();
|
||||
}
|
||||
ifPart.done(PyElementTypes.IF_PART_IF);
|
||||
PsiBuilder.Marker elifPart = myBuilder.mark();
|
||||
while (myBuilder.getTokenType() == PyTokenTypes.ELIF_KEYWORD) {
|
||||
|
||||
5
python/testData/psi/MissingParenInCall.py
Normal file
5
python/testData/psi/MissingParenInCall.py
Normal file
@@ -0,0 +1,5 @@
|
||||
def get_key():
|
||||
if isinstance(self.instance,
|
||||
|
||||
def clean():
|
||||
pass
|
||||
41
python/testData/psi/MissingParenInCall.txt
Normal file
41
python/testData/psi/MissingParenInCall.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
PyFile:MissingParenInCall.py
|
||||
PyFunction('get_key')
|
||||
PsiElement(Py:DEF_KEYWORD)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(Py:IDENTIFIER)('get_key')
|
||||
PyParameterList
|
||||
PsiElement(Py:LPAR)('(')
|
||||
PsiElement(Py:RPAR)(')')
|
||||
PsiElement(Py:COLON)(':')
|
||||
PsiWhiteSpace('\n ')
|
||||
PyStatementList
|
||||
PyIfStatement
|
||||
PyIfPartIf
|
||||
PsiElement(Py:IF_KEYWORD)('if')
|
||||
PsiWhiteSpace(' ')
|
||||
PyCallExpression: isinstance
|
||||
PyReferenceExpression: isinstance
|
||||
PsiElement(Py:IDENTIFIER)('isinstance')
|
||||
PyArgumentList
|
||||
PsiElement(Py:LPAR)('(')
|
||||
PyReferenceExpression: instance
|
||||
PyReferenceExpression: self
|
||||
PsiElement(Py:IDENTIFIER)('self')
|
||||
PsiElement(Py:DOT)('.')
|
||||
PsiElement(Py:IDENTIFIER)('instance')
|
||||
PsiElement(Py:COMMA)(',')
|
||||
PsiErrorElement:expression expected
|
||||
<empty list>
|
||||
PsiWhiteSpace('\n\n')
|
||||
PyFunction('clean')
|
||||
PsiElement(Py:DEF_KEYWORD)('def')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(Py:IDENTIFIER)('clean')
|
||||
PyParameterList
|
||||
PsiElement(Py:LPAR)('(')
|
||||
PsiElement(Py:RPAR)(')')
|
||||
PsiElement(Py:COLON)(':')
|
||||
PsiWhiteSpace('\n ')
|
||||
PyStatementList
|
||||
PyPassStatement
|
||||
PsiElement(Py:PASS_KEYWORD)('pass')
|
||||
@@ -279,6 +279,10 @@ public class PythonParsingTest extends ParsingTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testMissingParenInCall() { // PY-4053
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void doTest() {
|
||||
doTest(LanguageLevel.PYTHON25);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user