better diagnostics for inconsistent unindent (PY-890)

This commit is contained in:
Dmitry Jemerov
2010-06-24 18:49:16 +04:00
parent a679f3af29
commit e6f4db240a
5 changed files with 35 additions and 2 deletions
@@ -16,7 +16,7 @@ public class PyTokenTypes {
public static final PyElementType TAB = new PyElementType("TAB");
public static final PyElementType FORMFEED = new PyElementType("FORMFEED");
public static final IElementType BAD_CHARACTER = TokenType.BAD_CHARACTER;
public static final IElementType INCONSISTENT_DEDENT = TokenType.BAD_CHARACTER;
public static final PyElementType INCONSISTENT_DEDENT = new PyElementType("INCONSISTENT_DEDENT");
public static final PyElementType END_OF_LINE_COMMENT = new PyElementType("END_OF_LINE_COMMENT");
@@ -205,7 +205,12 @@ public class StatementParsing extends Parsing implements ITokenTypeRemapper {
}
builder.advanceLexer();
builder.error("statement expected, found " + firstToken.toString());
if (firstToken == PyTokenTypes.INCONSISTENT_DEDENT) {
builder.error("unindent does not match any outer indentation level");
}
else {
builder.error("statement expected, found " + firstToken.toString());
}
}
private boolean hasPrintStatement() {
@@ -0,0 +1,3 @@
def foo():
pass
print 1
@@ -0,0 +1,21 @@
PyFile:InconsistentDedent.py
PyFunction('foo')
PsiElement(Py:DEF_KEYWORD)('def')
PsiWhiteSpace(' ')
PsiElement(Py:IDENTIFIER)('foo')
PyParameterList
PsiElement(Py:LPAR)('(')
PsiElement(Py:RPAR)(')')
PsiElement(Py:COLON)(':')
PsiWhiteSpace('\n ')
PyStatementList
PyPassStatement
PsiElement(Py:PASS_KEYWORD)('pass')
PsiErrorElement:unindent does not match any outer indentation level
<empty list>
PsiWhiteSpace('\n ')
PyPrintStatement
PsiElement(Py:PRINT_KEYWORD)('print')
PsiWhiteSpace(' ')
PyNumericLiteralExpression
PsiElement(Py:INTEGER_LITERAL)('1')
@@ -206,6 +206,10 @@ public class PythonParsingTest extends ParsingTestCase {
doTest();
}
public void testInconsistentDedent() throws Exception { // PY-1131
doTest();
}
public void doTest() throws Exception {
doTest(LanguageLevel.PYTHON25);
}