diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java index 2cbfe75f05ed..75273238f1de 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHost.java @@ -17,6 +17,9 @@ public interface RegExpLanguageHost { boolean characterNeedsEscaping(char c); boolean supportsPerl5EmbeddedComments(); boolean supportsPossessiveQuantifiers(); + default boolean isDuplicateGroupNamesAllowed(@NotNull RegExpGroup group) { + return false; + } /** * @return true, if this dialects support conditionals, i.e. the following construct: {@code (?(1)then|else)} diff --git a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java index ef5f42894f01..c36b5909b3f3 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/RegExpLanguageHosts.java @@ -111,6 +111,11 @@ public final class RegExpLanguageHosts extends ClassExtension namedGroups = NAMED_GROUP_MAP.get(session, new HashMap<>()); if (namedGroups.isEmpty()) session.putUserData(NAMED_GROUP_MAP, namedGroups); - if (namedGroups.put(name, group) != null) { + if (namedGroups.put(name, group) != null && !myLanguageHosts.isDuplicateGroupNamesAllowed(group)) { final ASTNode node = group.getNode().findChildByType(RegExpTT.NAME); if (node != null) myHolder.newAnnotation(HighlightSeverity.ERROR, RegExpBundle.message("error.group.with.name.0.already.defined", name)).range(node).create();