mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
RegExp: more clear error message
GitOrigin-RevId: aa6b5d2de81037f7291867c314dbdc1b5cd9549e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ccc210eeb2
commit
6fecec667a
@@ -27,6 +27,7 @@ error.back.reference.is.nested.into.the.capturing.group.it.refers.to=Back refere
|
||||
error.conditional.group.reference.not.allowed.inside.lookbehind=Conditional group reference not allowed inside lookbehind
|
||||
error.conditionals.are.not.supported.in.this.regex.dialect=Conditionals are not supported in this regex dialect
|
||||
error.dangling.metacharacter=Dangling quantifier ''{0}''
|
||||
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
|
||||
|
||||
@@ -192,7 +192,7 @@ public class RegExpParser implements PsiParser, LightPsiParser {
|
||||
}
|
||||
else {
|
||||
if (RegExpTT.QUANTIFIERS.contains(builder.getTokenType())) {
|
||||
builder.error(RegExpBundle.message("error.dangling.metacharacter"));
|
||||
builder.error(RegExpBundle.message("error.dangling.metacharacter", builder.getTokenText()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -600,11 +600,22 @@ public class RegExpParser implements PsiParser, LightPsiParser {
|
||||
|
||||
private static void patternExpected(PsiBuilder builder) {
|
||||
final IElementType token = builder.getTokenType();
|
||||
if (token == RegExpTT.GROUP_END) {
|
||||
builder.error(RegExpBundle.message("parse.error.unmatched.closing.parenthesis"));
|
||||
if (token == RegExpTT.GROUP_END || token == RegExpTT.RBRACE || token == RegExpTT.CLASS_END) {
|
||||
builder.error(RegExpBundle.message("parse.error.unmatched.closing.bracket", builder.getTokenText()));
|
||||
}
|
||||
else if (RegExpTT.QUANTIFIERS.contains(token) || token == RegExpTT.RBRACE || token == RegExpTT.CLASS_END) {
|
||||
builder.error(RegExpBundle.message("error.dangling.metacharacter"));
|
||||
else if (token == RegExpTT.LBRACE) {
|
||||
builder.error(RegExpBundle.message("error.dangling.opening.bracket"));
|
||||
// try to recover
|
||||
builder.advanceLexer();
|
||||
while (builder.getTokenType() == RegExpTT.NUMBER || builder.getTokenType() == RegExpTT.COMMA) {
|
||||
builder.advanceLexer();
|
||||
}
|
||||
if (builder.getTokenType() == RegExpTT.RBRACE) {
|
||||
builder.advanceLexer();
|
||||
}
|
||||
}
|
||||
else if (RegExpTT.QUANTIFIERS.contains(token)) {
|
||||
builder.error(RegExpBundle.message("error.dangling.metacharacter", builder.getTokenText()));
|
||||
}
|
||||
else {
|
||||
builder.error(RegExpBundle.message("parse.error.pattern.expected"));
|
||||
|
||||
@@ -357,8 +357,9 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot
|
||||
@Override
|
||||
public void visitRegExpClosure(RegExpClosure closure) {
|
||||
if (closure.getAtom() instanceof RegExpSetOptions) {
|
||||
myHolder.newAnnotation(HighlightSeverity.ERROR, RegExpBundle.message("error.dangling.metacharacter"))
|
||||
.range(closure.getQuantifier())
|
||||
final RegExpQuantifier quantifier = closure.getQuantifier();
|
||||
myHolder.newAnnotation(HighlightSeverity.ERROR, RegExpBundle.message("error.dangling.metacharacter", quantifier.getUnescapedText()))
|
||||
.range(quantifier)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
JS_UNICODE_REGEXP_FILE
|
||||
RegExpPatternImpl: <{>
|
||||
RegExpBranchImpl: <{>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Unexpected start of quantifier '{'
|
||||
<empty list>
|
||||
PsiElement(LBRACE)('{')
|
||||
@@ -1,6 +1,6 @@
|
||||
JS_UNICODE_REGEXP_FILE
|
||||
RegExpPatternImpl: <}>
|
||||
RegExpBranchImpl: <}>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Unmatched closing '}'
|
||||
<empty list>
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -1,6 +1,6 @@
|
||||
JS_UNICODE_REGEXP_FILE
|
||||
RegExpPatternImpl: <]>
|
||||
RegExpBranchImpl: <]>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Unmatched closing ']'
|
||||
<empty list>
|
||||
PsiElement(CLASS_END)(']')
|
||||
@@ -1,6 +1,6 @@
|
||||
REGEXP_FILE
|
||||
RegExpPatternImpl: <{>
|
||||
RegExpBranchImpl: <{>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Unexpected start of quantifier '{'
|
||||
<empty list>
|
||||
PsiElement(LBRACE)('{')
|
||||
@@ -8,7 +8,7 @@ REGEXP_FILE
|
||||
PsiElement(COLON)(':')
|
||||
RegExpPatternImpl: <*>
|
||||
RegExpBranchImpl: <*>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
PsiElement(GROUP_END)(')')
|
||||
@@ -7,7 +7,7 @@ REGEXP_FILE
|
||||
PsiElement(GT)('>')
|
||||
RegExpPatternImpl: <{>
|
||||
RegExpBranchImpl: <{>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Unexpected start of quantifier '{'
|
||||
<empty list>
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiErrorElement:')' expected
|
||||
|
||||
@@ -32,7 +32,7 @@ REGEXP_FILE
|
||||
PsiElement(CHARACTER)('n')
|
||||
PsiElement(UNION)('|')
|
||||
RegExpBranchImpl: <{>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Unexpected start of quantifier '{'
|
||||
<empty list>
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiErrorElement:')' expected
|
||||
|
||||
@@ -5,7 +5,7 @@ REGEXP_FILE
|
||||
PsiElement(GROUP_BEGIN)('(')
|
||||
RegExpPatternImpl: <*>
|
||||
RegExpBranchImpl: <*>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
PsiElement(GROUP_END)(')')
|
||||
|
||||
@@ -5,6 +5,6 @@ REGEXP_FILE
|
||||
PsiElement(CHARACTER)('a')
|
||||
PsiElement(UNION)('|')
|
||||
RegExpBranchImpl: <*>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
@@ -6,6 +6,6 @@ REGEXP_FILE
|
||||
PsiElement(CHARACTER)('1')
|
||||
RegExpQuantifierImpl: <*>
|
||||
PsiElement(STAR)('*')
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
@@ -6,6 +6,6 @@ REGEXP_FILE
|
||||
PsiElement(CHARACTER)('a')
|
||||
RegExpQuantifierImpl: <*>
|
||||
PsiElement(STAR)('*')
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
@@ -1,15 +1,10 @@
|
||||
REGEXP_FILE
|
||||
RegExpPatternImpl: <{1,2>
|
||||
RegExpBranchImpl: <{1,2>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
RegExpPatternImpl: <{1,2}>
|
||||
RegExpBranchImpl: <{1,2}>
|
||||
PsiErrorElement:Unexpected start of quantifier '{'
|
||||
<empty list>
|
||||
PsiElement(LBRACE)('{')
|
||||
RegExpCharImpl: <1>
|
||||
PsiElement(CHARACTER)('1')
|
||||
RegExpCharImpl: <,>
|
||||
PsiElement(CHARACTER)(',')
|
||||
RegExpCharImpl: <2>
|
||||
PsiElement(CHARACTER)('2')
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
<empty list>
|
||||
PsiElement(RBRACE)('}')
|
||||
PsiElement(NUMBER)('1')
|
||||
PsiElement(COMMA)(',')
|
||||
PsiElement(NUMBER)('2')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -1,7 +1,7 @@
|
||||
REGEXP_FILE
|
||||
RegExpPatternImpl: <*a>
|
||||
RegExpBranchImpl: <*a>
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
RegExpCharImpl: <a>
|
||||
|
||||
@@ -6,6 +6,6 @@ REGEXP_FILE
|
||||
PsiElement(CHARACTER)('a')
|
||||
RegExpQuantifierImpl: <*>
|
||||
PsiElement(STAR)('*')
|
||||
PsiErrorElement:Dangling metacharacter
|
||||
PsiErrorElement:Dangling quantifier '*'
|
||||
<empty list>
|
||||
PsiElement(STAR)('*')
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.java.codeInsight;
|
||||
|
||||
import com.intellij.ide.highlighter.JavaFileType;
|
||||
@@ -214,9 +214,9 @@ public class RegExpHighlightingTest extends LightJavaCodeInsightFixtureTestCase
|
||||
}
|
||||
|
||||
public void testOptions() {
|
||||
doTest("(?i)<error descr=\"Dangling metacharacter\">+</error>");
|
||||
doTest("(?i)<error descr=\"Dangling metacharacter\">*</error>");
|
||||
doTest("(?i)<error descr=\"Dangling metacharacter\">{5,6}</error>");
|
||||
doTest("(?i)<error descr=\"Dangling quantifier '+'\">+</error>");
|
||||
doTest("(?i)<error descr=\"Dangling quantifier '*'\">*</error>");
|
||||
doTest("(?i)<error descr=\"Dangling quantifier '{5,6}'\">{5,6}</error>");
|
||||
}
|
||||
|
||||
public void testLookbehind() {
|
||||
|
||||
@@ -2,7 +2,7 @@ class SuspicousRegexExpressionArgument {{
|
||||
|
||||
"a.s.d.f".split(<warning descr="Suspicious regex expression \".\" in call to 'split()'"><caret>"."</warning>);
|
||||
"vb|amna".replaceAll(<warning descr="Suspicious regex expression \"|\" in call to 'replaceAll()'">"|"</warning>, "-");
|
||||
"1+2+3".split("<error descr="Dangling metacharacter">+</error>");
|
||||
"1+2+3".split("<error descr="Dangling quantifier '+'">+</error>");
|
||||
"one two".split(" ");
|
||||
"[][][]".split("]");
|
||||
"{}{}{}".split("}");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
<xs:simpleType name="TestType">
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:pattern value="[0-9]+-([0-9]+|<error descr="Dangling metacharacter">*</error>)"/>
|
||||
<xs:pattern value="[0-9]+-([0-9]+|<error descr="Dangling quantifier '*'">*</error>)"/>
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
<xs:simpleType name="TestType2">
|
||||
|
||||
Reference in New Issue
Block a user