Don't mark named unicode character as an error in Python 3.8+ (PY-36004)

GitOrigin-RevId: 59b52a42e5c820a6603e6734e768f035c5c593e5
This commit is contained in:
Semyon Proshev
2019-08-01 16:03:35 +03:00
committed by intellij-monorepo-bot
parent f292ca33ef
commit 2a559ec31a
4 changed files with 27 additions and 0 deletions
@@ -40,6 +40,7 @@ import com.jetbrains.python.psi.types.TypeEvalContext;
import one.util.streamex.StreamEx;
import org.intellij.lang.regexp.DefaultRegExpPropertiesProvider;
import org.intellij.lang.regexp.RegExpLanguageHost;
import org.intellij.lang.regexp.UnicodeCharacterNames;
import org.intellij.lang.regexp.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -422,4 +423,14 @@ public class PyStringLiteralExpressionImpl extends PyElementImpl implements PySt
public String[][] getKnownCharacterClasses() {
return myPropertiesProvider.getKnownCharacterClasses();
}
@Override
public boolean supportsNamedCharacters(RegExpNamedCharacter namedCharacter) {
return LanguageLevel.forElement(this).isAtLeast(LanguageLevel.PYTHON38);
}
@Override
public boolean isValidNamedCharacter(RegExpNamedCharacter namedCharacter) {
return UnicodeCharacterNames.getCodePoint(namedCharacter.getName()) >= 0;
}
}
@@ -0,0 +1,3 @@
import re
re.match(r'\N{LESS-THAN SIGN}', '<')
re.match(r'\N{<error descr="Unknown character name">LESS-THAN SIG</error>}', '<')
@@ -0,0 +1,3 @@
import re
re.match(r'<error descr="Named Unicode characters are not allowed in this regex dialect">\N{LESS-THAN SIGN}</error>', '<')
re.match(r'<error descr="Named Unicode characters are not allowed in this regex dialect">\N{LESS-THAN SIG}</error>', '<')
@@ -436,6 +436,16 @@ public class PythonHighlightingTest extends PyTestCase {
doTest(LanguageLevel.PYTHON37, false, false);
}
// PY-36004
public void testNamedUnicodeBefore38() {
doTest(LanguageLevel.PYTHON37, false, false);
}
// PY-36004
public void testNamedUnicode() {
doTest(LanguageLevel.PYTHON38, false, false);
}
@NotNull
private static EditorColorsScheme createTemporaryColorScheme() {
EditorColorsManager manager = EditorColorsManager.getInstance();