mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
PY-81646 Get rid of EMPTY_EXPRESSION nodes within SLICE_ITEM
GitOrigin-RevId: 6ffe0027790bb41b8ac18251903529aa1b1243f6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ff19de5654
commit
aa82ce5f70
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.ast;
|
||||
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -9,14 +11,32 @@ import org.jetbrains.annotations.Nullable;
|
||||
@ApiStatus.Experimental
|
||||
public interface PyAstSliceItem extends PyAstExpression {
|
||||
default @Nullable PyAstExpression getLowerBound() {
|
||||
return childToPsi(PythonDialectsTokenSetProvider.getInstance().getExpressionTokens(), 0);
|
||||
return getChildExpression(0);
|
||||
}
|
||||
|
||||
default @Nullable PyAstExpression getUpperBound() {
|
||||
return childToPsi(PythonDialectsTokenSetProvider.getInstance().getExpressionTokens(), 1);
|
||||
return getChildExpression(1);
|
||||
}
|
||||
|
||||
default @Nullable PyAstExpression getStride() {
|
||||
return childToPsi(PythonDialectsTokenSetProvider.getInstance().getExpressionTokens(), 2);
|
||||
return getChildExpression(2);
|
||||
}
|
||||
|
||||
private @Nullable PyAstExpression getChildExpression(int index) {
|
||||
ASTNode[] children = getNode().getChildren(TokenSet.ANY);
|
||||
int i = 0;
|
||||
while (i < children.length && index > 0) {
|
||||
if (children[i].getElementType() == PyTokenTypes.COLON) {
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
i += 2;
|
||||
}
|
||||
index--;
|
||||
}
|
||||
if (i < children.length && children[i].getElementType() != PyTokenTypes.COLON) {
|
||||
return (PyAstExpression)children[i].getPsi();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -693,18 +693,13 @@ public class ExpressionParsing extends Parsing {
|
||||
|
||||
private boolean parseSubscriptionIndexArgument() {
|
||||
SyntaxTreeBuilder.Marker sliceItem = myBuilder.mark();
|
||||
if (!parseSingleExpression(false)) {
|
||||
myBuilder.mark().done(PyElementTypes.EMPTY_EXPRESSION);
|
||||
}
|
||||
parseSingleExpression(false);
|
||||
if (!matchToken(PyTokenTypes.COLON)) {
|
||||
sliceItem.rollbackTo();
|
||||
return parseNamedTestExpression(false, false);
|
||||
}
|
||||
boolean exprParseResult = parseSingleExpression(false);
|
||||
parseSingleExpression(false);
|
||||
if (myBuilder.getTokenType() == PyTokenTypes.COLON) {
|
||||
if (!exprParseResult) {
|
||||
myBuilder.mark().done(PyElementTypes.EMPTY_EXPRESSION);
|
||||
}
|
||||
myBuilder.advanceLexer();
|
||||
parseSingleExpression(false);
|
||||
}
|
||||
|
||||
@@ -5,11 +5,7 @@ PyFile:ExtendedSlices.py
|
||||
PsiElement(Py:IDENTIFIER)('d')
|
||||
PsiElement(Py:LBRACKET)('[')
|
||||
PySliceItem
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PsiElement(Py:RBRACKET)(']')
|
||||
PsiWhiteSpace('\n')
|
||||
@@ -22,8 +18,6 @@ PyFile:ExtendedSlices.py
|
||||
PyNumericLiteralExpression
|
||||
PsiElement(Py:INTEGER_LITERAL)('1')
|
||||
PsiElement(Py:COLON)(':')
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PyNumericLiteralExpression
|
||||
PsiElement(Py:INTEGER_LITERAL)('2')
|
||||
@@ -94,8 +88,6 @@ PyFile:ExtendedSlices.py
|
||||
PsiElement(Py:LBRACKET)('[')
|
||||
PyTupleExpression
|
||||
PySliceItem
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PyNumericLiteralExpression
|
||||
PsiElement(Py:INTEGER_LITERAL)('42')
|
||||
@@ -108,8 +100,6 @@ PyFile:ExtendedSlices.py
|
||||
PsiElement(Py:COMMA)(',')
|
||||
PsiWhiteSpace(' ')
|
||||
PySliceItem
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PyNumericLiteralExpression
|
||||
PsiElement(Py:INTEGER_LITERAL)('24')
|
||||
|
||||
@@ -15,8 +15,6 @@ PyFile:RangeAsLHS.py
|
||||
PsiElement(Py:IDENTIFIER)('foo')
|
||||
PsiElement(Py:LBRACKET)('[')
|
||||
PySliceItem
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PsiElement(Py:RBRACKET)(']')
|
||||
PsiWhiteSpace(' ')
|
||||
|
||||
@@ -9,7 +9,5 @@ PyFile:SliceList.py
|
||||
PsiElement(Py:IDENTIFIER)('b1')
|
||||
PsiElement(Py:COMMA)(',')
|
||||
PySliceItem
|
||||
PyEmptyExpression
|
||||
<empty list>
|
||||
PsiElement(Py:COLON)(':')
|
||||
PsiElement(Py:RBRACKET)(']')
|
||||
Reference in New Issue
Block a user