1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Scanner2 - fixed the nextToken() to match previous scanner's behavior.

This commit is contained in:
Doug Schaefer 2004-06-23 15:01:50 +00:00
parent b97efa10b3
commit d94a068c23
3 changed files with 12 additions and 26 deletions

View file

@ -30,7 +30,7 @@ public class SpeedTest extends TestCase {
}
public void test() throws Exception {
runTest(10);
runTest(20);
}
private void runTest(int n) throws Exception {

View file

@ -36,7 +36,7 @@ public class SpeedTest2 extends TestCase {
}
public void test() throws Exception {
runTest(10);
runTest(20);
}
private void runTest(int n) throws Exception {

View file

@ -223,6 +223,7 @@ public class Scanner2 implements IScanner, IScannerData {
return false;
}
private IToken lastToken;
private IToken nextToken;
private boolean finished = false;
@ -239,41 +240,26 @@ public class Scanner2 implements IScanner, IScannerData {
throw EOF;
}
IToken token = nextToken;
if (lastToken != null)
lastToken.setNext(nextToken);
IToken oldToken = lastToken;
lastToken = nextToken;
nextToken = fetchToken();
token.setNext(nextToken);
if (nextToken == null)
finished = true;
else if (nextToken.getType() == IToken.tPOUNDPOUND) {
// time for a pasting
IToken token2 = fetchToken();
if (token2 == null) {
nextToken = null;
finished = true;
} else {
String t1 = token.getImage();
String t2 = token2.getImage();
char[] pb = new char[t1.length() + t2.length()];
t1.getChars(0, t1.length(), pb, 0);
t2.getChars(0, t2.length(), pb, t1.length());
pushContext(pb);
nextToken = null;
return nextToken();
}
} else if (token.getType() == IToken.tSTRING) {
else if (lastToken.getType() == IToken.tSTRING) {
while (nextToken != null && nextToken.getType() == IToken.tSTRING) {
// Concatenate the adjacent strings
String t1 = token.getImage();
String t1 = lastToken.getImage();
String t2 = nextToken.getImage();
token = new ImagedToken(IToken.tSTRING, t1 + t2);
lastToken = new ImagedToken(IToken.tSTRING, t1 + t2);
oldToken.setNext(lastToken);
nextToken = fetchToken();
}
}
// TODO Check if token is ## and proceed with pasting
return token;
return lastToken;
}
// Return null to signify end of file