mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-12 18:55:38 +02:00
Scanner2 - added char literals and string concatenation.
This commit is contained in:
parent
4d440deec4
commit
ed0afd6243
2 changed files with 54 additions and 16 deletions
|
@ -203,8 +203,6 @@ public class BaseScanner2Test extends TestCase {
|
||||||
public void validateDefinition(String name, String value)
|
public void validateDefinition(String name, String value)
|
||||||
{
|
{
|
||||||
Object expObject = scanner.getRealDefinitions().get(name.toCharArray());
|
Object expObject = scanner.getRealDefinitions().get(name.toCharArray());
|
||||||
if (expObject == null)
|
|
||||||
System.out.println("Hi");
|
|
||||||
assertNotNull(expObject);
|
assertNotNull(expObject);
|
||||||
assertTrue(expObject instanceof ObjectStyleMacro);
|
assertTrue(expObject instanceof ObjectStyleMacro);
|
||||||
assertTrue(CharArrayUtils.equals(value.toCharArray(), ((ObjectStyleMacro)expObject).expansion));
|
assertTrue(CharArrayUtils.equals(value.toCharArray(), ((ObjectStyleMacro)expObject).expansion));
|
||||||
|
|
|
@ -245,6 +245,14 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
nextToken = null;
|
nextToken = null;
|
||||||
return nextToken();
|
return nextToken();
|
||||||
}
|
}
|
||||||
|
} else if (token.getType() == IToken.tSTRING) {
|
||||||
|
while (nextToken != null && nextToken.getType() == IToken.tSTRING) {
|
||||||
|
// Concatenate the adjacent strings
|
||||||
|
String t1 = token.getImage();
|
||||||
|
String t2 = nextToken.getImage();
|
||||||
|
token = new ImagedToken(IToken.tSTRING, t1 + t2);
|
||||||
|
nextToken = fetchToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Check if token is ## and proceed with pasting
|
// TODO Check if token is ## and proceed with pasting
|
||||||
|
@ -287,6 +295,9 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
case '"':
|
case '"':
|
||||||
return scanString();
|
return scanString();
|
||||||
|
|
||||||
|
case '\'':
|
||||||
|
return scanCharLiteral();
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -660,22 +671,19 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
boolean escaped = false;
|
boolean escaped = false;
|
||||||
loop:
|
loop:
|
||||||
while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
|
while (++bufferPos[bufferStackPos] < bufferLimit[bufferStackPos]) {
|
||||||
switch (buffer[bufferPos[bufferStackPos]]) {
|
++stringLen;
|
||||||
case '\\':
|
char c = buffer[bufferPos[bufferStackPos]];
|
||||||
++stringLen;
|
if (c == '"') {
|
||||||
escaped = !escaped;
|
if (!escaped)
|
||||||
continue;
|
break;
|
||||||
case '"':
|
}
|
||||||
if (escaped) {
|
else if (c == '\\') {
|
||||||
escaped = false;
|
escaped = !escaped;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
break loop;
|
|
||||||
default:
|
|
||||||
++stringLen;
|
|
||||||
escaped = false;
|
|
||||||
}
|
}
|
||||||
|
escaped = false;
|
||||||
}
|
}
|
||||||
|
--stringLen;
|
||||||
|
|
||||||
// We should really throw an exception if we didn't get the terminating
|
// We should really throw an exception if we didn't get the terminating
|
||||||
// quote before the end of buffer
|
// quote before the end of buffer
|
||||||
|
@ -683,6 +691,38 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
return new ImagedToken(tokenType, new String(buffer, stringStart, stringLen));
|
return new ImagedToken(tokenType, new String(buffer, stringStart, stringLen));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IToken scanCharLiteral() {
|
||||||
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
|
int start = bufferPos[bufferStackPos] + 1;
|
||||||
|
int limit = bufferLimit[bufferStackPos];
|
||||||
|
|
||||||
|
if (start >= limit) {
|
||||||
|
return new ImagedToken(IToken.tCHAR, new String(emptyCharArray));
|
||||||
|
}
|
||||||
|
|
||||||
|
int length = 0;
|
||||||
|
boolean escaped = false;
|
||||||
|
while (++bufferPos[bufferStackPos] < limit) {
|
||||||
|
++length;
|
||||||
|
int pos = bufferPos[bufferStackPos];
|
||||||
|
if (buffer[pos] == '\'') {
|
||||||
|
if (!escaped)
|
||||||
|
break;
|
||||||
|
} else if (buffer[pos] == '\\') {
|
||||||
|
escaped = !escaped;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
escaped = false;
|
||||||
|
}
|
||||||
|
--length;
|
||||||
|
|
||||||
|
char[] image = length > 0
|
||||||
|
? CharArrayUtils.extract(buffer, start, length)
|
||||||
|
: emptyCharArray;
|
||||||
|
|
||||||
|
return new ImagedToken(IToken.tCHAR, new String(image));
|
||||||
|
}
|
||||||
|
|
||||||
private IToken scanNumber() {
|
private IToken scanNumber() {
|
||||||
char[] buffer = bufferStack[bufferStackPos];
|
char[] buffer = bufferStack[bufferStackPos];
|
||||||
int start = bufferPos[bufferStackPos];
|
int start = bufferPos[bufferStackPos];
|
||||||
|
|
Loading…
Add table
Reference in a new issue