use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class StatementParsing method parseStatement.
public void parseStatement() {
while (myBuilder.getTokenType() == PyTokenTypes.STATEMENT_BREAK) {
myBuilder.advanceLexer();
}
final IElementType firstToken;
firstToken = myBuilder.getTokenType();
if (firstToken == null)
return;
if (firstToken == PyTokenTypes.WHILE_KEYWORD) {
parseWhileStatement();
return;
}
if (firstToken == PyTokenTypes.IF_KEYWORD) {
parseIfStatement(PyTokenTypes.IF_KEYWORD, PyTokenTypes.ELIF_KEYWORD, PyTokenTypes.ELSE_KEYWORD, PyElementTypes.IF_STATEMENT);
return;
}
if (firstToken == PyTokenTypes.FOR_KEYWORD) {
parseForStatement(myBuilder.mark());
return;
}
if (firstToken == PyTokenTypes.TRY_KEYWORD) {
parseTryStatement();
return;
}
if (firstToken == PyTokenTypes.DEF_KEYWORD) {
getFunctionParser().parseFunctionDeclaration(myBuilder.mark(), false);
return;
}
if (firstToken == PyTokenTypes.AT) {
getFunctionParser().parseDecoratedDeclaration();
return;
}
if (firstToken == PyTokenTypes.CLASS_KEYWORD) {
parseClassDeclaration();
return;
}
if (firstToken == PyTokenTypes.WITH_KEYWORD) {
parseWithStatement(myBuilder.mark());
return;
}
if (firstToken == PyTokenTypes.ASYNC_KEYWORD) {
parseAsyncStatement();
return;
}
parseSimpleStatement();
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class ExpressionParsing method parseUnaryExpression.
protected boolean parseUnaryExpression(boolean isTargetExpression) {
final IElementType tokenType = myBuilder.getTokenType();
if (PyTokenTypes.UNARY_OPERATIONS.contains(tokenType)) {
final PsiBuilder.Marker expr = myBuilder.mark();
myBuilder.advanceLexer();
if (!parseUnaryExpression(isTargetExpression)) {
myBuilder.error(message("PARSE.expected.expression"));
}
expr.done(PyElementTypes.PREFIX_EXPRESSION);
return true;
} else {
return parsePowerExpression(isTargetExpression);
}
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class StatementParsing method parseFromImportStatement.
/*
Really parses two forms:
from identifier import id, id... -- may be either relative or absolute
from . import identifier -- only relative
*/
private void parseFromImportStatement() {
PsiBuilder builder = myContext.getBuilder();
assertCurrentToken(PyTokenTypes.FROM_KEYWORD);
myFutureImportPhase = Phase.FROM;
final PsiBuilder.Marker fromImportStatement = builder.mark();
builder.advanceLexer();
boolean from_future = false;
boolean had_dots = parseRelativeImportDots();
IElementType statementType = PyElementTypes.FROM_IMPORT_STATEMENT;
if (had_dots && parseOptionalDottedName() || parseDottedName()) {
final ImportTypes types = checkFromImportKeyword();
statementType = types.statement;
final IElementType elementType = types.element;
if (myFutureImportPhase == Phase.FUTURE) {
myFutureImportPhase = Phase.IMPORT;
from_future = true;
}
if (builder.getTokenType() == PyTokenTypes.MULT) {
final PsiBuilder.Marker star_import_mark = builder.mark();
builder.advanceLexer();
star_import_mark.done(types.starElement);
} else if (builder.getTokenType() == PyTokenTypes.LPAR) {
builder.advanceLexer();
parseImportElements(elementType, false, true, from_future);
checkMatches(PyTokenTypes.RPAR, ") expected");
} else {
parseImportElements(elementType, false, false, from_future);
}
} else if (had_dots) {
// from . import ...
final ImportTypes types = checkFromImportKeyword();
statementType = types.statement;
parseImportElements(types.element, false, false, from_future);
}
checkEndOfStatement();
fromImportStatement.done(statementType);
myFutureImportPhase = Phase.NONE;
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class StatementParsing method parseAsyncStatement.
private void parseAsyncStatement() {
assertCurrentToken(PyTokenTypes.ASYNC_KEYWORD);
final PsiBuilder.Marker marker = myBuilder.mark();
myBuilder.advanceLexer();
final IElementType token = myBuilder.getTokenType();
if (token == PyTokenTypes.DEF_KEYWORD) {
getFunctionParser().parseFunctionDeclaration(marker, true);
} else if (token == PyTokenTypes.WITH_KEYWORD) {
parseWithStatement(marker);
} else if (token == PyTokenTypes.FOR_KEYWORD) {
parseForStatement(marker);
} else {
marker.drop();
myBuilder.error("'def' or 'with' or 'for' expected");
}
}
use of com.intellij.psi.tree.IElementType in project kotlin by JetBrains.
the class BasicExpressionTypingVisitor method visitBinaryWithTypeRHSExpression.
@Override
public KotlinTypeInfo visitBinaryWithTypeRHSExpression(@NotNull KtBinaryExpressionWithTypeRHS expression, ExpressionTypingContext context) {
ExpressionTypingContext contextWithNoExpectedType = context.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT);
KtExpression left = expression.getLeft();
KtTypeReference right = expression.getRight();
if (right == null) {
return facade.getTypeInfo(left, contextWithNoExpectedType).clearType();
}
IElementType operationType = expression.getOperationReference().getReferencedNameElementType();
boolean allowBareTypes = BARE_TYPES_ALLOWED.contains(operationType);
TypeResolutionContext typeResolutionContext = new TypeResolutionContext(context.scope, context.trace, true, allowBareTypes, context.isDebuggerContext);
PossiblyBareType possiblyBareTarget = components.typeResolver.resolvePossiblyBareType(typeResolutionContext, right);
KotlinTypeInfo typeInfo = facade.getTypeInfo(left, contextWithNoExpectedType);
KotlinType subjectType = typeInfo.getType();
KotlinType targetType = reconstructBareType(right, possiblyBareTarget, subjectType, context.trace, components.builtIns);
if (subjectType != null) {
checkBinaryWithTypeRHS(expression, contextWithNoExpectedType, targetType, subjectType);
DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo();
if (operationType == AS_KEYWORD) {
DataFlowValue value = createDataFlowValue(left, subjectType, context);
typeInfo = typeInfo.replaceDataFlowInfo(dataFlowInfo.establishSubtyping(value, targetType, components.languageVersionSettings));
}
}
KotlinType result = operationType == AS_SAFE ? TypeUtils.makeNullable(targetType) : targetType;
KotlinTypeInfo resultTypeInfo = components.dataFlowAnalyzer.checkType(typeInfo.replaceType(result), expression, context);
RttiExpressionInformation rttiInformation = new RttiExpressionInformation(expression.getLeft(), subjectType, result, operationType == AS_SAFE ? RttiOperation.SAFE_AS : RttiOperation.AS);
for (RttiExpressionChecker checker : components.rttiExpressionCheckers) {
checker.check(rttiInformation, expression, context.trace);
}
return resultTypeInfo;
}
Aggregations