diff --git a/RegExpSupport/resources/messages/RegExpBundle.properties b/RegExpSupport/resources/messages/RegExpBundle.properties index 0465ec66d92d..a7ec83c55e30 100644 --- a/RegExpSupport/resources/messages/RegExpBundle.properties +++ b/RegExpSupport/resources/messages/RegExpBundle.properties @@ -31,6 +31,7 @@ error.dangling.opening.bracket=Unexpected start of quantifier '{' error.embedded.comments.are.not.supported.in.this.regex.dialect=Embedded comments are not supported in this regex dialect error.empty.group=Empty group error.group.reference.is.nested.into.the.named.group.it.refers.to=Group reference is nested into the named group it refers to +error.define.subpattern.contains.more.than.one.branch=DEFINE subpattern contains more than one branch error.group.reference.not.allowed.inside.lookbehind=Group reference not allowed inside lookbehind error.group.with.name.0.already.defined=Group with name ''{0}'' already defined error.illegal.character.range.to.from=Illegal character range (to < from) diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java index 407f1fe98ce3..f4c853f35402 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpGroupImpl.java @@ -102,6 +102,10 @@ public class RegExpGroupImpl extends RegExpElementImpl implements RegExpGroup { return node != null && node.findChildByType(RegExpTT.PCRE_CONDITION) != null; } + public static boolean isPcreDefine(ASTNode node) { + return node != null && node.findChildByType(RegExpTT.PCRE_DEFINE) != null; + } + @Override public String getGroupName() { final ASTNode nameNode = getNode().findChildByType(RegExpTT.NAME); diff --git a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java index f5e2176ffb96..d8c826815f57 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java @@ -29,10 +29,10 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.StringEscapesTokenTypes; import com.intellij.psi.tree.IElementType; import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import org.intellij.lang.regexp.*; import org.intellij.lang.regexp.psi.*; -import org.intellij.lang.regexp.psi.impl.RegExpNamedGroupRefImpl; import org.intellij.lang.regexp.psi.impl.RegExpGroupImpl; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; @@ -232,9 +232,22 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot @Override public void visitRegExpGroup(RegExpGroup group) { + if (RegExpGroupImpl.isPcreConditionalGroup(group.getNode())) { + if (RegExpGroupImpl.isPcreDefine(group.getNode())) { + RegExpConditional conditional = ObjectUtils.tryCast(group.getParent(), RegExpConditional.class); + if (conditional != null) { + RegExpBranch[] branches = PsiTreeUtil.getChildrenOfType(conditional, RegExpBranch.class); + if (branches != null && branches.length > 1) { + myHolder.newAnnotation(HighlightSeverity.ERROR, + RegExpBundle.message("error.define.subpattern.contains.more.than.one.branch")).create(); + } + } + } + return; + } final RegExpPattern pattern = group.getPattern(); final RegExpBranch[] branches = pattern.getBranches(); - if (!RegExpGroupImpl.isPcreConditionalGroup(group.getNode()) && isEmpty(branches) && group.getNode().getLastChildNode().getElementType() == RegExpTT.GROUP_END) { + if (isEmpty(branches) && group.getNode().getLastChildNode().getElementType() == RegExpTT.GROUP_END) { // catches "()" as well as "(|)" myHolder.newAnnotation(HighlightSeverity.WARNING, RegExpBundle.message("error.empty.group")).create(); }