correctly handle triple apostrophe strings in annotator (PY-502)

This commit is contained in:
Dmitry Jemerov
2010-02-10 16:56:31 +03:00
parent e7d84d56ea
commit d2191dcde6
2 changed files with 16 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ 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 = "\"\"\"";
private static final String TRIPLE_APOS = "'''";
//public static final String PREMATURE_Q = "Premature closing quote";
public void visitPyStringLiteralExpression(final PyStringLiteralExpression node) {
@@ -25,13 +26,9 @@ public class StringConstantAnnotator extends PyAnnotator {
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;
}
if (checkTripleQuotedString(node, s, index, TRIPLE_QUOTES)) return;
if (checkTripleQuotedString(node, s, index, TRIPLE_APOS)) 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;
@@ -72,4 +69,14 @@ public class StringConstantAnnotator extends PyAnnotator {
getHolder().createErrorAnnotation(node, msg);
}
}
private boolean checkTripleQuotedString(PyStringLiteralExpression node, String s, int index, final String quotes) {
if (StringUtil.startsWith(s.substring(index, s.length()), quotes)) {
if (s.length() < 6 + index || !s.endsWith(quotes)) {
getHolder().createErrorAnnotation(node, "Missing closing triple quotes");
}
return true;
}
return false;
}
}

View File

@@ -4,3 +4,5 @@ print "Hello"\
print 'Hello "World" '
"""Foo "bar """
'''Here the ' is just another character'''