correct highlighting of string literals with mixed quotes (PY-299)

This commit is contained in:
Dmitry Jemerov
2010-01-14 14:22:43 +03:00
parent 7f7953b8d9
commit a2e32cde4c
3 changed files with 17 additions and 6 deletions

View File

@@ -4,9 +4,8 @@ import com.jetbrains.python.psi.PyStringLiteralExpression;
/**
* Looks for well-formedness of string constants.
* User: dcheryasov
* Date: Jul 5, 2008
* Time: 11:58:57 PM
*
* @author dcheryasov
*/
public class StringConstantAnnotator extends PyAnnotator {
public static final String MISSING_Q = "Missing closing quote";
@@ -34,9 +33,15 @@ public class StringConstantAnnotator extends PyAnnotator {
char c = s.charAt(index);
if (esc) esc = false;
else {
if (c != first_quote) {
if (c == '\\') esc = true;
// a line may consist of multiple fragments with different quote chars (PY-299)
else if (c == '\'' || c == '\"') {
if (first_quote == '\0')
first_quote = c;
else
first_quote = '\0';
}
/*
else { // impossible with current lexer, but who knows :)
msg = PREMATURE_Q + " [" + first_quote + "]";

View File

@@ -0,0 +1,2 @@
print "Hello"\
'World'

View File

@@ -86,6 +86,10 @@ public class PythonHighlightingTest extends PyLightFixtureTestCase {
doTest();
}
public void testStringMixedSeparatorsOK() throws Exception { // PY-299
doTest();
}
public void testYieldInNestedFunction() throws Exception {
// highlight func declaration first, lest we get an "Extra fragment highlighted" error.
EditorColorsManager manager = EditorColorsManager.getInstance();