diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpChar.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpChar.java index 096aeef65a53..4af07e5e5205 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpChar.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpChar.java @@ -18,22 +18,30 @@ package org.intellij.lang.regexp.psi; import org.jetbrains.annotations.NotNull; /** - * Represents a simple or escaped character + * Represents a simple, escaped, encoded or named character */ public interface RegExpChar extends RegExpAtom, RegExpClassElement, RegExpCharRange.Endpoint { - /** - * Character type enumeration. Represents either a plain character ("a"), - * a hex encoded character value ("\x61"), - * an octal encoded character value ("\0141"), or - * a unicode escape character ("\u0061") - */ + /** Character type */ enum Type { - CHAR, HEX, OCT, UNICODE, INVALID + /** a plain character ("a") */ + CHAR, + + /** a hex encoded character value ("\x61") */ + HEX, + + /** an octal encoded character value ("\0141") */ + OCT, + + /** a unicode escape character ("\u0061") */ + UNICODE, + + /** a named character (\N{LATIN SMALL LETTER A}) */ + NAMED, } /** * Returns the type of this character. - * @see org.intellij.lang.regexp.psi.RegExpChar.Type + * @see Type */ @NotNull Type getType(); diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpElementVisitor.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpElementVisitor.java index 0d795e417b98..4d12b6aba501 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpElementVisitor.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpElementVisitor.java @@ -20,6 +20,7 @@ import com.intellij.psi.PsiElementVisitor; public class RegExpElementVisitor extends PsiElementVisitor { public void visitRegExpElement(RegExpElement element) { + visitElement(element); } public void visitRegExpChar(RegExpChar ch) { @@ -51,7 +52,7 @@ public class RegExpElementVisitor extends PsiElementVisitor { } public void visitRegExpNamedCharacter(RegExpNamedCharacter namedCharacter) { - visitRegExpElement(namedCharacter); + visitRegExpChar(namedCharacter); } public void visitRegExpBranch(RegExpBranch branch) { diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpNamedCharacter.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpNamedCharacter.java index a2a2581afcb1..16a4c8848f6b 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpNamedCharacter.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/RegExpNamedCharacter.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. @@ -21,7 +21,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Bas Leijdekkers */ -public interface RegExpNamedCharacter extends RegExpAtom, RegExpClassElement { +public interface RegExpNamedCharacter extends RegExpChar { @Nullable ASTNode getNameNode(); diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpCharImpl.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpCharImpl.java index 8ab33635e926..f3ef85e2b22a 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpCharImpl.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpCharImpl.java @@ -17,7 +17,6 @@ package org.intellij.lang.regexp.psi.impl; import com.intellij.lang.ASTNode; import com.intellij.psi.StringEscapesTokenTypes; -import com.intellij.psi.TokenType; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import org.intellij.lang.regexp.RegExpTT; @@ -47,8 +46,8 @@ public class RegExpCharImpl extends RegExpElementImpl implements RegExpChar { return Type.HEX; } else if (UNICODE_CHARS.contains(t)) { return Type.UNICODE; - } else if (t == TokenType.ERROR_ELEMENT) { - return Type.INVALID; + } else if (t == RegExpTT.NAMED_CHARACTER) { + return Type.NAMED; } else { return Type.CHAR; } @@ -92,6 +91,15 @@ public class RegExpCharImpl extends RegExpElementImpl implements RegExpChar { return '\b'; case 'c': return (char)(ch ^ 64); + case 'N': + if (length < idx + 3 || s.charAt(idx + 1) != '{' || s.charAt(length - 1) != '}') { + return -1; + } + final int codePoint = UnicodeCharacterNames.getCodePoint(s.substring(idx + 2, length - 1)); + if (codePoint == -1) { + return -1; + } + return codePoint; case 'x': if (length <= idx + 1) return -1; if (s.charAt(idx + 1) == '{') { diff --git a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpNamedCharacterImpl.java b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpNamedCharacterImpl.java index 93ce7ff790bd..85f9dfce2e63 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpNamedCharacterImpl.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/psi/impl/RegExpNamedCharacterImpl.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. @@ -24,7 +24,8 @@ import org.jetbrains.annotations.Nullable; /** * @author Bas Leijdekkers */ -public class RegExpNamedCharacterImpl extends RegExpElementImpl implements RegExpNamedCharacter { +public class RegExpNamedCharacterImpl extends RegExpCharImpl implements RegExpNamedCharacter { + public RegExpNamedCharacterImpl(ASTNode node) { super(node); } diff --git a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java index e5bb1fbc1240..6df47e75d60f 100644 --- a/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java +++ b/RegExpSupport/src/org/intellij/lang/regexp/validation/RegExpAnnotator.java @@ -477,12 +477,6 @@ public final class RegExpAnnotator extends RegExpElementVisitor implements Annot myLength++; } - @Override - public void visitRegExpNamedCharacter(RegExpNamedCharacter namedCharacter) { - super.visitRegExpNamedCharacter(namedCharacter); - myLength++; - } - @Override public void visitRegExpBackref(RegExpBackref backref) { super.visitRegExpBackref(backref);