diff --git a/python/src/com/jetbrains/python/PyTokenTypes.java b/python/src/com/jetbrains/python/PyTokenTypes.java index 7df4b49c4807..063b0d23a43b 100644 --- a/python/src/com/jetbrains/python/PyTokenTypes.java +++ b/python/src/com/jetbrains/python/PyTokenTypes.java @@ -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"); diff --git a/python/src/com/jetbrains/python/parsing/StatementParsing.java b/python/src/com/jetbrains/python/parsing/StatementParsing.java index 743c739a9c3c..8c466b741a59 100644 --- a/python/src/com/jetbrains/python/parsing/StatementParsing.java +++ b/python/src/com/jetbrains/python/parsing/StatementParsing.java @@ -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() { diff --git a/python/testData/psi/InconsistentDedent.py b/python/testData/psi/InconsistentDedent.py new file mode 100644 index 000000000000..b87400a420b3 --- /dev/null +++ b/python/testData/psi/InconsistentDedent.py @@ -0,0 +1,3 @@ +def foo(): + pass + print 1 \ No newline at end of file diff --git a/python/testData/psi/InconsistentDedent.txt b/python/testData/psi/InconsistentDedent.txt new file mode 100644 index 000000000000..1ee44c60498d --- /dev/null +++ b/python/testData/psi/InconsistentDedent.txt @@ -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 + + PsiWhiteSpace('\n ') + PyPrintStatement + PsiElement(Py:PRINT_KEYWORD)('print') + PsiWhiteSpace(' ') + PyNumericLiteralExpression + PsiElement(Py:INTEGER_LITERAL)('1') \ 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 4ccbb77e3e60..8dc18ba4f804 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -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); }