trailing comma after star parameter is a syntax error (PY-4039)

This commit is contained in:
Dmitry Jemerov
2011-11-25 19:45:00 +01:00
parent d12724b499
commit 805e6b5481
4 changed files with 59 additions and 0 deletions
@@ -138,6 +138,7 @@ public class FunctionParsing extends Parsing {
}
boolean first = true;
boolean afterStarParameter = false;
while (myBuilder.getTokenType() != endToken) {
if (first) {
first = false;
@@ -155,9 +156,16 @@ public class FunctionParsing extends Parsing {
parseParameterSubList();
continue;
}
boolean isStarParameter = atAnyOfTokens(PyTokenTypes.MULT, PyTokenTypes.EXP);
if (!parseParameter(endToken, isLambda)) {
if (afterStarParameter) {
myBuilder.error("expression expected");
}
break;
}
if (isStarParameter) {
afterStarParameter = true;
}
}
if (myBuilder.getTokenType() == endToken && endToken == PyTokenTypes.RPAR) {
+5
View File
@@ -0,0 +1,5 @@
def some_function(*args,): # <- missing highlighting here
pass
def some_function(**kwargs,): # <- missing highlighting here
pass
+42
View File
@@ -0,0 +1,42 @@
PyFile:CommaAfterStarArg.py
PyFunction('some_function')
PsiElement(Py:DEF_KEYWORD)('def')
PsiWhiteSpace(' ')
PsiElement(Py:IDENTIFIER)('some_function')
PyParameterList
PsiElement(Py:LPAR)('(')
PyNamedParameter('args')
PsiElement(Py:MULT)('*')
PsiElement(Py:IDENTIFIER)('args')
PsiElement(Py:COMMA)(',')
PsiErrorElement:expression expected
<empty list>
PsiElement(Py:RPAR)(')')
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PsiComment(Py:END_OF_LINE_COMMENT)('# <- missing highlighting here')
PsiWhiteSpace('\n ')
PyStatementList
PyPassStatement
PsiElement(Py:PASS_KEYWORD)('pass')
PsiWhiteSpace('\n\n')
PyFunction('some_function')
PsiElement(Py:DEF_KEYWORD)('def')
PsiWhiteSpace(' ')
PsiElement(Py:IDENTIFIER)('some_function')
PyParameterList
PsiElement(Py:LPAR)('(')
PyNamedParameter('kwargs')
PsiElement(Py:EXP)('**')
PsiElement(Py:IDENTIFIER)('kwargs')
PsiElement(Py:COMMA)(',')
PsiErrorElement:expression expected
<empty list>
PsiElement(Py:RPAR)(')')
PsiElement(Py:COLON)(':')
PsiWhiteSpace(' ')
PsiComment(Py:END_OF_LINE_COMMENT)('# <- missing highlighting here')
PsiWhiteSpace('\n ')
PyStatementList
PyPassStatement
PsiElement(Py:PASS_KEYWORD)('pass')
@@ -310,6 +310,10 @@ public class PythonParsingTest extends ParsingTestCase {
doTest();
}
public void testCommaAfterStarArg() { // PY-4039
doTest();
}
public void doTest() {
doTest(LanguageLevel.PYTHON25);
}