use of com.jetbrains.python.lexer.PyStringLiteralLexer in project intellij-community by JetBrains.
the class PyHighlighter method getHighlightingLexer.
@NotNull
public Lexer getHighlightingLexer() {
LayeredLexer ret = new LayeredLexer(createHighlightingLexer(myLanguageLevel));
ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_STRING), PyTokenTypes.SINGLE_QUOTED_STRING);
ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), PyTokenTypes.SINGLE_QUOTED_UNICODE);
ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.TRIPLE_QUOTED_STRING), PyTokenTypes.TRIPLE_QUOTED_STRING);
ret.registerLayer(new PyStringLiteralLexer(PyTokenTypes.TRIPLE_QUOTED_UNICODE), PyTokenTypes.TRIPLE_QUOTED_UNICODE);
return ret;
}
use of com.jetbrains.python.lexer.PyStringLiteralLexer in project intellij-community by JetBrains.
the class PyLiteralSelectionHandler method select.
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
final PyStringLiteralExpression literal = PsiTreeUtil.getParentOfType(e, PyStringLiteralExpression.class);
if (literal != null) {
List<TextRange> ranges = literal.getStringValueTextRanges();
List<ASTNode> nodes = literal.getStringNodes();
for (int i = 0; i < ranges.size(); i++) {
TextRange stringRange = ranges.get(i);
TextRange offsetRange = stringRange.shiftRight(literal.getTextRange().getStartOffset());
if (offsetRange.contains(cursorOffset) && offsetRange.getLength() > 1) {
List<TextRange> result = new ArrayList<>();
SelectWordUtil.addWordHonoringEscapeSequences(editorText, nodes.get(i).getTextRange(), cursorOffset, new PyStringLiteralLexer(nodes.get(i).getElementType()), result);
result.add(offsetRange);
return result;
}
}
}
return Collections.emptyList();
}
use of com.jetbrains.python.lexer.PyStringLiteralLexer in project intellij-community by JetBrains.
the class PyStringLiteralLexerTest method testIllegalPrefixes.
// PY-20921
public void testIllegalPrefixes() {
PyLexerTestCase.doLexerTest("ff'foo'", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), "Py:SINGLE_QUOTED_UNICODE");
PyLexerTestCase.doLexerTest("fff'foo'", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), "Py:SINGLE_QUOTED_UNICODE");
PyLexerTestCase.doLexerTest("rrr'''foo'''", new PyStringLiteralLexer(PyTokenTypes.TRIPLE_QUOTED_UNICODE), "Py:TRIPLE_QUOTED_UNICODE");
}
use of com.jetbrains.python.lexer.PyStringLiteralLexer in project intellij-community by JetBrains.
the class PyStringLiteralLexerTest method testBackslashBreaksAnyEscapeSequence.
// PY-21399
public void testBackslashBreaksAnyEscapeSequence() {
PyLexerTestCase.doLexerTest("'\\u\\')", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), true, "'", "\\u", "\\'", ")");
PyLexerTestCase.doLexerTest("'\\u\\')", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), "Py:SINGLE_QUOTED_UNICODE", "INVALID_UNICODE_ESCAPE_TOKEN", "VALID_STRING_ESCAPE_TOKEN", "Py:SINGLE_QUOTED_UNICODE");
PyLexerTestCase.doLexerTest("'\\x\\')", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), true, "'", "\\x", "\\'", ")");
PyLexerTestCase.doLexerTest("'\\x\\')", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), "Py:SINGLE_QUOTED_UNICODE", "INVALID_UNICODE_ESCAPE_TOKEN", "VALID_STRING_ESCAPE_TOKEN", "Py:SINGLE_QUOTED_UNICODE");
PyLexerTestCase.doLexerTest("'\\N{F\\')", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), true, "'", "\\N{F", "\\'", ")");
PyLexerTestCase.doLexerTest("'\\N{F\\')", new PyStringLiteralLexer(PyTokenTypes.SINGLE_QUOTED_UNICODE), "Py:SINGLE_QUOTED_UNICODE", "INVALID_UNICODE_ESCAPE_TOKEN", "VALID_STRING_ESCAPE_TOKEN", "Py:SINGLE_QUOTED_UNICODE");
}
Aggregations