mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 14:12:10 +02:00
Bug 534070: Fix syntax highlight for numbers with C++14 separators
Change-Id: I1e1f335dadb3fa30e035c5a61ccef1f3eed43358 Signed-off-by: Andrey Mozzhuhin <amozzhuhin@yandex.ru>
This commit is contained in:
parent
a7c5168c7a
commit
fecd602c1b
4 changed files with 45 additions and 8 deletions
|
@ -1192,4 +1192,15 @@ public class CPartitionerTest extends TestCase {
|
||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNumberSeparators() {
|
||||||
|
try {
|
||||||
|
fDocument.replace(0, fDocument.getLength(), "1'123'456\n0x1000'1000\n0111'1000\n0xAABB'CCDD");
|
||||||
|
ITypedRegion[] result = fDocument.computePartitioning(0, fDocument.getLength());
|
||||||
|
TypedRegion[] expectation = { new TypedRegion(0, 43, IDocument.DEFAULT_CONTENT_TYPE) };
|
||||||
|
checkPartitioning(expectation, result);
|
||||||
|
} catch (BadLocationException x) {
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,6 +125,14 @@ public class NumberRuleTest extends TestCase {
|
||||||
assertNoNumber("+ 9");
|
assertNoNumber("+ 9");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSeparators() {
|
||||||
|
assertNumber("1'123'456");
|
||||||
|
assertNumber("0x1000'1000");
|
||||||
|
assertNumber("0111'1000");
|
||||||
|
assertNumber("0xAABB'CCDD");
|
||||||
|
assertNoNumber("'");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that given string is recognized as a number.
|
* Validate that given string is recognized as a number.
|
||||||
* @param string
|
* @param string
|
||||||
|
|
|
@ -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 BACKSLASH_BACKSLASH = 7; // postfix for STRING, CHARACTER
|
||||||
private static final int RAW_STRING_R = 8; // prefix for RAW_STRING
|
private static final int RAW_STRING_R = 8; // prefix for RAW_STRING
|
||||||
private static final int IDENT = 9;
|
private static final int IDENT = 9;
|
||||||
|
private static final int NUMBER = 10;
|
||||||
|
|
||||||
/** The scanner. */
|
/** The scanner. */
|
||||||
private final BufferedDocumentScanner fScanner = new BufferedDocumentScanner(1000); // faster implementation
|
private final BufferedDocumentScanner fScanner = new BufferedDocumentScanner(1000); // faster implementation
|
||||||
|
@ -311,6 +312,11 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
||||||
}
|
}
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
|
if (fLast == NUMBER) {
|
||||||
|
// C++14 digit separator
|
||||||
|
fTokenOffset++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
fLast = NONE; // ignore fLast
|
fLast = NONE; // ignore fLast
|
||||||
if (fTokenLength > 0) {
|
if (fTokenLength > 0) {
|
||||||
return preFix(CCODE, CHARACTER, NONE, 1);
|
return preFix(CCODE, CHARACTER, NONE, 1);
|
||||||
|
@ -373,10 +379,14 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_') {
|
if ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_') {
|
||||||
fLast = IDENT;
|
if (fLast != NUMBER)
|
||||||
|
fLast = IDENT;
|
||||||
fTokenOffset++;
|
fTokenOffset++;
|
||||||
} else if ('0' <= ch && ch <= '9' && fLast == IDENT) {
|
} else if ('0' <= ch && ch <= '9' && fLast == IDENT) {
|
||||||
fTokenOffset++;
|
fTokenOffset++;
|
||||||
|
} else if (('0' <= ch && ch <= '9') || ch == '.') {
|
||||||
|
fLast = NUMBER;
|
||||||
|
fTokenOffset++;
|
||||||
} else {
|
} else {
|
||||||
consume();
|
consume();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class NumberRule implements IRule {
|
||||||
// hexnumber starting with [+-]?0[xX]
|
// hexnumber starting with [+-]?0[xX]
|
||||||
do {
|
do {
|
||||||
ch = scanner.read();
|
ch = scanner.read();
|
||||||
} while (isHexNumberPart((char) ch));
|
} while (isHexDigitOrSeparator(ch));
|
||||||
scanner.unread();
|
scanner.unread();
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
@ -72,12 +72,12 @@ public class NumberRule implements IRule {
|
||||||
// need at least one digit
|
// need at least one digit
|
||||||
do {
|
do {
|
||||||
ch = scanner.read();
|
ch = scanner.read();
|
||||||
} while (Character.isDigit((char) ch));
|
} while (isDecDigitOrSeparator(ch));
|
||||||
if (ch == '.' && startCh != '.') {
|
if (ch == '.' && startCh != '.') {
|
||||||
// fraction
|
// fraction
|
||||||
do {
|
do {
|
||||||
ch = scanner.read();
|
ch = scanner.read();
|
||||||
} while (Character.isDigit((char) ch));
|
} while (isDecDigitOrSeparator(ch));
|
||||||
}
|
}
|
||||||
if (ch == 'e' || ch == 'E') {
|
if (ch == 'e' || ch == 'E') {
|
||||||
// exponent
|
// exponent
|
||||||
|
@ -85,7 +85,7 @@ public class NumberRule implements IRule {
|
||||||
if (ch == '-' || ch == '+' || Character.isDigit((char) ch)) {
|
if (ch == '-' || ch == '+' || Character.isDigit((char) ch)) {
|
||||||
do {
|
do {
|
||||||
ch = scanner.read();
|
ch = scanner.read();
|
||||||
} while (Character.isDigit((char) ch));
|
} while (isDecDigitOrSeparator(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scanner.unread();
|
scanner.unread();
|
||||||
|
@ -107,13 +107,21 @@ public class NumberRule implements IRule {
|
||||||
return ch == '-' || ch == '+' || ch == '.' || Character.isDigit((char) ch);
|
return ch == '-' || ch == '+' || ch == '.' || Character.isDigit((char) ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
* Checks if part of hex number;
|
||||||
* @param ch Char to check.
|
* @param ch Char to check.
|
||||||
* @return <b>true</b>
|
* @return <b>true</b>
|
||||||
*/
|
*/
|
||||||
private boolean isHexNumberPart(int ch) {
|
private boolean isHexDigitOrSeparator(int ch) {
|
||||||
return Character.isDigit((char) ch) || ch == 'a' || ch == 'b' || ch == 'c' || ch == 'd' || ch == 'e'
|
return Character.isDigit((char) ch) || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F') || (ch == '\'');
|
||||||
|| ch == 'f' || ch == 'A' || ch == 'B' || ch == 'C' || ch == 'D' || ch == 'E' || ch == 'F';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue