mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
DS-5427 Reformat break paths in IPython magic commands
GitOrigin-RevId: bfc5b6a9c473ac832b09ca723b41b22d7502b133
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8e3db58b3a
commit
0b85ca9bea
@@ -29,6 +29,7 @@ public class PyConsoleParser extends PyParser {
|
||||
PyConsoleTokenTypes.PLING,
|
||||
PyConsoleTokenTypes.QUESTION_MARK,
|
||||
PyConsoleTokenTypes.SHELL_COMMAND,
|
||||
PyConsoleTokenTypes.MAGIC_COMMAND_LINE,
|
||||
PyTokenTypes.COMMA,
|
||||
PyTokenTypes.DIV,
|
||||
PyTokenTypes.PERC,
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.jetbrains.python.parsing.ParsingContext;
|
||||
import com.jetbrains.python.parsing.StatementParsing;
|
||||
import com.jetbrains.python.psi.LanguageLevel;
|
||||
|
||||
import static com.jetbrains.python.parsing.console.PyConsoleTokenTypes.MAGIC_COMMAND_LINE;
|
||||
import static com.jetbrains.python.parsing.console.PyConsoleTokenTypes.SHELL_COMMAND;
|
||||
|
||||
public class PyConsoleParsingContext extends ParsingContext {
|
||||
@@ -201,7 +202,7 @@ public class PyConsoleParsingContext extends ParsingContext {
|
||||
}
|
||||
|
||||
private boolean parseIPythonCaptureExpression() {
|
||||
if (myBuilder.getTokenType() == SHELL_COMMAND) {
|
||||
if (myBuilder.getTokenType() == SHELL_COMMAND || myBuilder.getTokenType() == MAGIC_COMMAND_LINE) {
|
||||
captureIPythonExpression();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public final class PyConsoleTokenTypes {
|
||||
public static final PyElementType DOLLAR = new PyElementType("DOLLAR"); //$
|
||||
|
||||
public static final PyElementType SHELL_COMMAND = new PyElementType("SHELL_COMMAND");
|
||||
public static final PyElementType MAGIC_COMMAND_LINE = new PyElementType("MAGIC_COMMAND_LINE");
|
||||
|
||||
private PyConsoleTokenTypes() {
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package com.jetbrains.python.parsing.console;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.intellij.lexer.Lexer;
|
||||
import com.intellij.lexer.MergeFunction;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.jetbrains.python.lexer.PythonIndentingLexer;
|
||||
@@ -25,6 +27,7 @@ import com.jetbrains.python.psi.PyElementType;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.jetbrains.python.PyTokenTypes.*;
|
||||
import static com.jetbrains.python.parsing.console.PyConsoleTokenTypes.MAGIC_COMMAND_LINE;
|
||||
import static com.jetbrains.python.parsing.console.PyConsoleTokenTypes.SHELL_COMMAND;
|
||||
|
||||
public class PythonConsoleLexer extends PythonIndentingLexer {
|
||||
@@ -56,17 +59,26 @@ public class PythonConsoleLexer extends PythonIndentingLexer {
|
||||
MergeFunction origMergeFunction = super.getMergeFunction();
|
||||
return (type, originalLexer) -> {
|
||||
if (type == BAD_CHARACTER && getElementType(getBaseTokenText()) == PyConsoleTokenTypes.PLING) {
|
||||
while (originalLexer.getTokenType() != LINE_BREAK &&
|
||||
originalLexer.getTokenType() != STATEMENT_BREAK &&
|
||||
originalLexer.getTokenType() != null) {
|
||||
originalLexer.advance();
|
||||
}
|
||||
collectFullLine(originalLexer);
|
||||
return SHELL_COMMAND;
|
||||
}
|
||||
if (type == PERC &&
|
||||
(getBaseTokenStart() == 0 || (!myTokenQueue.isEmpty() && Iterables.getLast(myTokenQueue).getType() == STATEMENT_BREAK))) {
|
||||
collectFullLine(originalLexer);
|
||||
return MAGIC_COMMAND_LINE;
|
||||
}
|
||||
return origMergeFunction.merge(type, originalLexer);
|
||||
};
|
||||
}
|
||||
|
||||
private static void collectFullLine(Lexer originalLexer) {
|
||||
while (originalLexer.getTokenType() != LINE_BREAK &&
|
||||
originalLexer.getTokenType() != STATEMENT_BREAK &&
|
||||
originalLexer.getTokenType() != null) {
|
||||
originalLexer.advance();
|
||||
}
|
||||
}
|
||||
|
||||
public static PyElementType getElementType(String token) {
|
||||
return SPECIAL_IPYTHON_SYMBOLS.get(token);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
PyFile:magic1.py
|
||||
PyEmptyExpression
|
||||
PsiElement(Py:PERC)('%')
|
||||
PsiElement(Py:IDENTIFIER)('xmode')
|
||||
PsiElement(Py:MAGIC_COMMAND_LINE)('%xmode')
|
||||
@@ -1,8 +1,3 @@
|
||||
PyFile:magic2.py
|
||||
PyEmptyExpression
|
||||
PsiElement(Py:PERC)('%')
|
||||
PsiElement(Py:IDENTIFIER)('alias_magic')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(Py:IDENTIFIER)('t')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(Py:IDENTIFIER)('timeit')
|
||||
PsiElement(Py:MAGIC_COMMAND_LINE)('%alias_magic t timeit')
|
||||
@@ -1,10 +1,3 @@
|
||||
PyFile:magic3.py
|
||||
PyEmptyExpression
|
||||
PsiElement(Py:PERC)('%')
|
||||
PsiElement(Py:IDENTIFIER)('config')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(Py:IDENTIFIER)('Class')
|
||||
PsiElement(Py:DOT)('.')
|
||||
PsiElement(Py:IDENTIFIER)('trait')
|
||||
PsiElement(Py:EQ)('=')
|
||||
PsiElement(Py:IDENTIFIER)('value')
|
||||
PsiElement(Py:MAGIC_COMMAND_LINE)('%config Class.trait=value')
|
||||
@@ -1,8 +1,6 @@
|
||||
PyFile:magicMultiline.py
|
||||
PyEmptyExpression
|
||||
PsiElement(Py:PERC)('%')
|
||||
PsiElement(Py:PERC)('%')
|
||||
PsiElement(Py:IDENTIFIER)('bash')
|
||||
PsiElement(Py:MAGIC_COMMAND_LINE)('%%bash')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(Py:IDENTIFIER)('echo')
|
||||
PsiWhiteSpace(' ')
|
||||
|
||||
Reference in New Issue
Block a user