more fixes for unclosed string literal highlighting

This commit is contained in:
Dmitry Jemerov
2010-01-14 20:54:10 +03:00
parent 0ad02d6b80
commit 4f9a806b06
4 changed files with 23 additions and 1 deletions
@@ -1,5 +1,6 @@
package com.jetbrains.python.validation;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.psi.PyStringLiteralExpression;
/**
@@ -9,6 +10,8 @@ import com.jetbrains.python.psi.PyStringLiteralExpression;
*/
public class StringConstantAnnotator extends PyAnnotator {
public static final String MISSING_Q = "Missing closing quote";
private static final String TRIPLE_QUOTES = "\"\"\"";
//public static final String PREMATURE_Q = "Premature closing quote";
public void visitPyStringLiteralExpression(final PyStringLiteralExpression node) {
String s = node.getText();
@@ -21,6 +24,14 @@ public class StringConstantAnnotator extends PyAnnotator {
if ((first_quote == 'u') || (first_quote == 'U')) index += 1;
first_quote = s.charAt(index);
if ((first_quote == 'r') || (first_quote == 'R')) index += 1;
if (StringUtil.startsWith(s.substring(index, s.length()), TRIPLE_QUOTES)) {
if (s.length() < 6 + index || !s.endsWith(TRIPLE_QUOTES)) {
getHolder().createErrorAnnotation(node, "Missing closing triple quotes");
}
return;
}
first_quote = s.charAt(index);
// s can't begin with a non-quote, else parser would not say it's a string
index += 1;
@@ -38,7 +49,7 @@ public class StringConstantAnnotator extends PyAnnotator {
else if (c == '\'' || c == '\"') {
if (first_quote == '\0')
first_quote = c;
else
else if (c == first_quote)
first_quote = '\0';
}
@@ -0,0 +1,3 @@
a = 1 # to make the text below non-doc
<error descr="Missing closing triple quotes">"""Hello World"</error>
@@ -1,2 +1,6 @@
print "Hello"\
'World'
print 'Hello "World" '
"""Foo "bar """
@@ -90,6 +90,10 @@ public class PythonHighlightingTest extends PyLightFixtureTestCase {
doTest();
}
public void testMalformedStringTripleQuoteUnterminated() throws Exception {
doTest();
}
public void testYieldInNestedFunction() throws Exception {
// highlight func declaration first, lest we get an "Extra fragment highlighted" error.
EditorColorsManager manager = EditorColorsManager.getInstance();