diff options
author | Andrey Mozzhuhin | 2020-01-04 15:33:44 +0000 |
---|---|---|
committer | Andrey Mozzhuhin | 2020-01-05 22:05:53 +0000 |
commit | fecd602c1be263eed7c95256bf48f0df2da5ac5b (patch) | |
tree | 1ab3851e36ce7ecdb7fa5f810ad33c5dd5916364 /core/org.eclipse.cdt.ui | |
parent | a7c5168c7aad4bd1e8ae295bfdb62d62f90edf29 (diff) | |
download | org.eclipse.cdt-fecd602c1be263eed7c95256bf48f0df2da5ac5b.tar.gz org.eclipse.cdt-fecd602c1be263eed7c95256bf48f0df2da5ac5b.tar.xz org.eclipse.cdt-fecd602c1be263eed7c95256bf48f0df2da5ac5b.zip |
Bug 534070: Fix syntax highlight for numbers with C++14 separators
Change-Id: I1e1f335dadb3fa30e035c5a61ccef1f3eed43358
Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
Diffstat (limited to 'core/org.eclipse.cdt.ui')
-rw-r--r-- | core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java | 12 | ||||
-rw-r--r-- | core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/NumberRule.java | 22 |
2 files changed, 26 insertions, 8 deletions
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java index c38dd0526d1..21fcd848045 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java @@ -62,6 +62,7 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa private static final int BACKSLASH_BACKSLASH = 7; // postfix for STRING, CHARACTER private static final int RAW_STRING_R = 8; // prefix for RAW_STRING private static final int IDENT = 9; + private static final int NUMBER = 10; /** The scanner. */ private final BufferedDocumentScanner fScanner = new BufferedDocumentScanner(1000); // faster implementation @@ -311,6 +312,11 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa } case '\'': + if (fLast == NUMBER) { + // C++14 digit separator + fTokenOffset++; + break; + } fLast = NONE; // ignore fLast if (fTokenLength > 0) { return preFix(CCODE, CHARACTER, NONE, 1); @@ -373,10 +379,14 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa break; default: if ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_') { - fLast = IDENT; + if (fLast != NUMBER) + fLast = IDENT; fTokenOffset++; } else if ('0' <= ch && ch <= '9' && fLast == IDENT) { fTokenOffset++; + } else if (('0' <= ch && ch <= '9') || ch == '.') { + fLast = NUMBER; + fTokenOffset++; } else { consume(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/NumberRule.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/NumberRule.java index 20fc9e96b4f..2cb82d0b281 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/NumberRule.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/NumberRule.java @@ -58,7 +58,7 @@ public class NumberRule implements IRule { // hexnumber starting with [+-]?0[xX] do { ch = scanner.read(); - } while (isHexNumberPart((char) ch)); + } while (isHexDigitOrSeparator(ch)); scanner.unread(); return token; } @@ -72,12 +72,12 @@ public class NumberRule implements IRule { // need at least one digit do { ch = scanner.read(); - } while (Character.isDigit((char) ch)); + } while (isDecDigitOrSeparator(ch)); if (ch == '.' && startCh != '.') { // fraction do { ch = scanner.read(); - } while (Character.isDigit((char) ch)); + } while (isDecDigitOrSeparator(ch)); } if (ch == 'e' || ch == 'E') { // exponent @@ -85,7 +85,7 @@ public class NumberRule implements IRule { if (ch == '-' || ch == '+' || Character.isDigit((char) ch)) { do { ch = scanner.read(); - } while (Character.isDigit((char) ch)); + } while (isDecDigitOrSeparator(ch)); } } scanner.unread(); @@ -108,12 +108,20 @@ public class NumberRule implements IRule { } /** + * Checks if part of decimal number; + * @param ch Char to check. + * @return <b>true</b> + */ + private boolean isDecDigitOrSeparator(int ch) { + return Character.isDigit((char) ch) || (ch == '\''); + } + + /** * Checks if part of hex number; * @param ch Char to check. * @return <b>true</b> */ - private boolean isHexNumberPart(int ch) { - return Character.isDigit((char) ch) || ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'e' - || ch == 'f' || ch == 'A' || ch == 'B' || ch == 'C' || ch == 'D' || ch == 'E' || ch == 'F'; + private boolean isHexDigitOrSeparator(int ch) { + return Character.isDigit((char) ch) || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') || (ch == '\''); } } |