use of com.jetbrains.python.parsing.PyParser in project intellij-community by JetBrains.
the class PyFileElementType method parseContents.
@Nullable
@Override
public ASTNode parseContents(ASTNode node) {
final LanguageLevel languageLevel = getLanguageLevel(node.getPsi());
if (PydevConsoleRunner.isPythonConsole(node)) {
return parseConsoleCode(node, PydevConsoleRunner.getPythonConsoleData(node));
} else {
final PsiElement psi = node.getPsi();
if (psi != null) {
final Project project = psi.getProject();
final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
final Language language = getLanguage();
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
if (parserDefinition == null) {
return null;
}
final Lexer lexer = parserDefinition.createLexer(project);
final PsiParser parser = parserDefinition.createParser(project);
final PsiBuilder builder = factory.createBuilder(project, node, lexer, language, node.getChars());
if (parser instanceof PyParser) {
final PyParser pythonParser = (PyParser) parser;
pythonParser.setLanguageLevel(languageLevel);
if (languageLevel == LanguageLevel.PYTHON26 && psi.getContainingFile().getName().equals("__builtin__.py")) {
pythonParser.setFutureFlag(StatementParsing.FUTURE.PRINT_FUNCTION);
}
}
return parser.parse(this, builder).getFirstChildNode();
}
return null;
}
}
use of com.jetbrains.python.parsing.PyParser in project intellij-community by JetBrains.
the class PyFileElementType method parseConsoleCode.
@Nullable
private ASTNode parseConsoleCode(@NotNull ASTNode node, PythonConsoleData consoleData) {
final Lexer lexer = createConsoleLexer(node, consoleData);
final PsiElement psi = node.getPsi();
if (psi != null) {
final Project project = psi.getProject();
final PsiBuilderFactory factory = PsiBuilderFactory.getInstance();
final PsiBuilder builder = factory.createBuilder(project, node, lexer, getLanguage(), node.getChars());
final PyParser parser = new PyConsoleParser(consoleData, getLanguageLevel(psi));
return parser.parse(this, builder).getFirstChildNode();
}
return null;
}
Aggregations