diff --git a/python/src/META-INF/python-plugin-common.xml b/python/src/META-INF/python-plugin-common.xml
index 72a7d9785d2b..5da125853010 100644
--- a/python/src/META-INF/python-plugin-common.xml
+++ b/python/src/META-INF/python-plugin-common.xml
@@ -198,7 +198,8 @@
-
+
+
diff --git a/python/src/com/jetbrains/python/codeInsight/PythonRegexpInjector.java b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java
similarity index 95%
rename from python/src/com/jetbrains/python/codeInsight/PythonRegexpInjector.java
rename to python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java
index 5cd092bab0d8..4e024c3444a7 100644
--- a/python/src/com/jetbrains/python/codeInsight/PythonRegexpInjector.java
+++ b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpInjector.java
@@ -1,4 +1,4 @@
-package com.jetbrains.python.codeInsight;
+package com.jetbrains.python.codeInsight.regexp;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.InjectedLanguagePlaces;
@@ -57,7 +57,7 @@ public class PythonRegexpInjector implements LanguageInjector {
if (element != null && element.getContainingFile().getName().equals("re.py") && isRegexpMethod(element, index)) {
List ranges = ((PyStringLiteralExpression)host).getStringValueTextRanges();
if (ranges.size() == 1) {
- injectionPlacesRegistrar.addPlace(RegExpLanguage.INSTANCE, ranges.get(0), null, null);
+ injectionPlacesRegistrar.addPlace(PythonRegexpLanguage.INSTANCE, ranges.get(0), null, null);
}
}
}
diff --git a/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpLanguage.java b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpLanguage.java
new file mode 100644
index 000000000000..6aa920bcb3e3
--- /dev/null
+++ b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpLanguage.java
@@ -0,0 +1,15 @@
+package com.jetbrains.python.codeInsight.regexp;
+
+import com.intellij.lang.Language;
+import org.intellij.lang.regexp.RegExpLanguage;
+
+/**
+ * @author yole
+ */
+public class PythonRegexpLanguage extends Language {
+ public static final PythonRegexpLanguage INSTANCE = new PythonRegexpLanguage();
+
+ public PythonRegexpLanguage() {
+ super(RegExpLanguage.INSTANCE, "PythonRegExp");
+ }
+}
diff --git a/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpParserDefinition.java b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpParserDefinition.java
new file mode 100644
index 000000000000..1daa0095591a
--- /dev/null
+++ b/python/src/com/jetbrains/python/codeInsight/regexp/PythonRegexpParserDefinition.java
@@ -0,0 +1,33 @@
+package com.jetbrains.python.codeInsight.regexp;
+
+import com.intellij.lexer.Lexer;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.FileViewProvider;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.tree.IFileElementType;
+import org.intellij.lang.regexp.RegExpFile;
+import org.intellij.lang.regexp.RegExpLexer;
+import org.intellij.lang.regexp.RegExpParserDefinition;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author yole
+ */
+public class PythonRegexpParserDefinition extends RegExpParserDefinition {
+ public static final IFileElementType PYTHON_REGEXP_FILE = new IFileElementType("PYTHON_REGEXP_FILE", PythonRegexpLanguage.INSTANCE);
+
+ @NotNull
+ public Lexer createLexer(Project project) {
+ return new RegExpLexer(false, true, false);
+ }
+
+ @Override
+ public IFileElementType getFileNodeType() {
+ return PYTHON_REGEXP_FILE;
+ }
+
+ @Override
+ public PsiFile createFile(FileViewProvider viewProvider) {
+ return new RegExpFile(viewProvider, PythonRegexpLanguage.INSTANCE);
+ }
+}
diff --git a/python/testData/regexp/nestedCharacterClasses.py b/python/testData/regexp/nestedCharacterClasses.py
new file mode 100644
index 000000000000..aad746bb04ba
--- /dev/null
+++ b/python/testData/regexp/nestedCharacterClasses.py
@@ -0,0 +1,3 @@
+import re
+
+re.compile('[][]')
diff --git a/python/testData/regexp/nestedCharacterClasses2.py b/python/testData/regexp/nestedCharacterClasses2.py
new file mode 100644
index 000000000000..2a26444a3b2d
--- /dev/null
+++ b/python/testData/regexp/nestedCharacterClasses2.py
@@ -0,0 +1,3 @@
+import re
+
+re.compile(r'''[[\]]''')
\ No newline at end of file
diff --git a/python/testSrc/com/jetbrains/python/PyRegexpTest.java b/python/testSrc/com/jetbrains/python/PyRegexpTest.java
new file mode 100644
index 000000000000..285394c9f9fd
--- /dev/null
+++ b/python/testSrc/com/jetbrains/python/PyRegexpTest.java
@@ -0,0 +1,20 @@
+package com.jetbrains.python;
+
+import com.jetbrains.python.fixtures.PyLightFixtureTestCase;
+
+/**
+ * @author yole
+ */
+public class PyRegexpTest extends PyLightFixtureTestCase {
+ public void testNestedCharacterClasses() { // PY-2908
+ doTest();
+ }
+
+ public void testNestedCharacterClasses2() { // PY-2908
+ doTest();
+ }
+
+ private void doTest() {
+ myFixture.testHighlighting(true, false, false, "regexp/" + getTestName(true) + ".py");
+ }
+}