From 18db741b06a1970aed2d31e7878701727a9d45af Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 25 Nov 2013 19:39:35 +0400 Subject: [PATCH] fixed PY-11476 No error given for mismatched accolade and squarebracket --- .../com/jetbrains/python/PyBundle.properties | 1 + .../python/parsing/ExpressionParsing.java | 4 ++-- python/testData/psi/NotClosedBraceDict.py | 3 +++ python/testData/psi/NotClosedBraceDict.txt | 24 +++++++++++++++++++ python/testData/psi/NotClosedBraceSet.py | 1 + python/testData/psi/NotClosedBraceSet.txt | 17 +++++++++++++ .../jetbrains/python/PythonParsingTest.java | 8 +++++++ 7 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 python/testData/psi/NotClosedBraceDict.py create mode 100644 python/testData/psi/NotClosedBraceDict.txt create mode 100644 python/testData/psi/NotClosedBraceSet.py create mode 100644 python/testData/psi/NotClosedBraceSet.txt diff --git a/python/src/com/jetbrains/python/PyBundle.properties b/python/src/com/jetbrains/python/PyBundle.properties index 5ee3ef7d582e..28289e0443db 100644 --- a/python/src/com/jetbrains/python/PyBundle.properties +++ b/python/src/com/jetbrains/python/PyBundle.properties @@ -637,6 +637,7 @@ PARSE.expected.comma=',' expected PARSE.expected.colon=':' expected PARSE.expected.rpar=')' expected PARSE.expected.lpar='(' expected +PARSE.expected.rbrace='}' expected PARSE.expected.tick='`' (backtick) expected PARSE.expected.name=name expected PARSE.expected.colon.or.rbracket=':' or ']' expected diff --git a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java index 65c791a33aed..790b1556fa74 100644 --- a/python/src/com/jetbrains/python/parsing/ExpressionParsing.java +++ b/python/src/com/jetbrains/python/parsing/ExpressionParsing.java @@ -236,7 +236,7 @@ public class ExpressionParsing extends Parsing { break; } } - myBuilder.advanceLexer(); + checkMatches(PyTokenTypes.RBRACE, message("PARSE.expected.rbrace")); startMarker.done(PyElementTypes.DICT_LITERAL_EXPRESSION); } } @@ -264,7 +264,7 @@ public class ExpressionParsing extends Parsing { break; } } - myBuilder.advanceLexer(); + checkMatches(PyTokenTypes.RBRACE, message("PARSE.expected.rbrace")); startMarker.done(PyElementTypes.SET_LITERAL_EXPRESSION); } diff --git a/python/testData/psi/NotClosedBraceDict.py b/python/testData/psi/NotClosedBraceDict.py new file mode 100644 index 000000000000..9a726249b003 --- /dev/null +++ b/python/testData/psi/NotClosedBraceDict.py @@ -0,0 +1,3 @@ +a = { + 'b': 'c', + ] \ No newline at end of file diff --git a/python/testData/psi/NotClosedBraceDict.txt b/python/testData/psi/NotClosedBraceDict.txt new file mode 100644 index 000000000000..1222ea39bdc6 --- /dev/null +++ b/python/testData/psi/NotClosedBraceDict.txt @@ -0,0 +1,24 @@ +PyFile:NotClosedBraceDict.py + PyAssignmentStatement + PyTargetExpression: a + PsiElement(Py:IDENTIFIER)('a') + PsiWhiteSpace(' ') + PsiElement(Py:EQ)('=') + PsiWhiteSpace(' ') + PyDictLiteralExpression + PsiElement(Py:LBRACE)('{') + PsiWhiteSpace('\n ') + PyKeyValueExpression + PyStringLiteralExpression: b + PsiElement(Py:SINGLE_QUOTED_STRING)(''b'') + PsiElement(Py:COLON)(':') + PsiWhiteSpace(' ') + PyStringLiteralExpression: c + PsiElement(Py:SINGLE_QUOTED_STRING)(''c'') + PsiElement(Py:COMMA)(',') + PsiErrorElement:'}' expected + + PsiWhiteSpace('\n ') + PsiElement(Py:RBRACKET)(']') + PsiErrorElement:Statement expected, found Py:RBRACKET + \ No newline at end of file diff --git a/python/testData/psi/NotClosedBraceSet.py b/python/testData/psi/NotClosedBraceSet.py new file mode 100644 index 000000000000..71817f2a3635 --- /dev/null +++ b/python/testData/psi/NotClosedBraceSet.py @@ -0,0 +1 @@ +a = {'b',] \ No newline at end of file diff --git a/python/testData/psi/NotClosedBraceSet.txt b/python/testData/psi/NotClosedBraceSet.txt new file mode 100644 index 000000000000..95b97f058075 --- /dev/null +++ b/python/testData/psi/NotClosedBraceSet.txt @@ -0,0 +1,17 @@ +PyFile:NotClosedBraceSet.py + PyAssignmentStatement + PyTargetExpression: a + PsiElement(Py:IDENTIFIER)('a') + PsiWhiteSpace(' ') + PsiElement(Py:EQ)('=') + PsiWhiteSpace(' ') + PySetLiteralExpression + PsiElement(Py:LBRACE)('{') + PyStringLiteralExpression: b + PsiElement(Py:SINGLE_QUOTED_STRING)(''b'') + PsiElement(Py:COMMA)(',') + PsiErrorElement:'}' expected + + PsiElement(Py:RBRACKET)(']') + PsiErrorElement:Statement expected, found Py:RBRACKET + \ 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 669ac3d3906c..9f612a2539db 100644 --- a/python/testSrc/com/jetbrains/python/PythonParsingTest.java +++ b/python/testSrc/com/jetbrains/python/PythonParsingTest.java @@ -430,6 +430,14 @@ public class PythonParsingTest extends ParsingTestCase { doTest(); } + public void testNotClosedBraceDict() { + doTest(); + } + + public void testNotClosedBraceSet() { + doTest(LanguageLevel.PYTHON33); + } + public void doTest(LanguageLevel languageLevel) { LanguageLevel prev = myLanguageLevel; myLanguageLevel = languageLevel;