diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java index 4a568d6f779f..61f3d12ac341 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -95,4 +95,28 @@ public interface RegExpLanguageHost { default Number getQuantifierValue(@NotNull RegExpNumber number) { return Double.parseDouble(number.getText()); } + + default Lookbehind supportsLookbehind(@NotNull RegExpGroup lookbehindGroup) { + return Lookbehind.FULL; // to not break existing implementations, although rarely actually supported. + } + + enum Lookbehind { + /** Lookbehind not supported. */ + NOT_SUPPORTED, + + /** + * Alternation inside lookbehind (a|b|c) branches must have same length, + * finite repetition with identical min, max values (a{3} or a{3,3}) allowed. + */ + FIXED_LENGTH_ALTERNATION, + + /** Alternation (a|bc|def) branches inside look behind may have different length */ + VARIABLE_LENGTH_ALTERNATION, + + /** Finite repetition inside lookbehind with different minimum, maximum values allowed */ + FINITE_REPETITION, + + /** Full regex syntax inside lookbehind ,i.e. star (*) and plus (*) repetition and backreferences, allowed. */ + FULL + } } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java index 79aafff773af..85f81e97d72c 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -162,6 +162,14 @@ public final class RegExpLanguageHosts extends ClassExtension= 0; } + @Override + public Lookbehind supportsLookbehind(@NotNull RegExpGroup lookbehindGroup) { + return Lookbehind.FINITE_REPETITION; + } + @Override public Integer getQuantifierValue(@NotNull RegExpNumber number) { try { diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/RegExpHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/RegExpHighlightingTest.java index be2419645b4d..69318f732372 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/RegExpHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/RegExpHighlightingTest.java @@ -212,6 +212,14 @@ public class RegExpHighlightingTest extends LightCodeInsightFixtureTestCase { doTest("(?i){5,6}"); } + public void testLookbehind() { + doTest("(?*)"); + doTest("(?+)"); + doTest("(?\\1)"); + } + private void doTest(@Language("RegExp") String code) { code = StringUtil.escapeBackSlashes(code); myFixture.configureByText(JavaFileType.INSTANCE, "class X {{ java.util.regex.Pattern.compile(\"" + code + "\"); }}");