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:
parent
b97efa10b3
commit
d94a068c23
3 changed files with 12 additions and 26 deletions
|
@ -30,7 +30,7 @@ public class SpeedTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
runTest(10);
|
runTest(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runTest(int n) throws Exception {
|
private void runTest(int n) throws Exception {
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class SpeedTest2 extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
runTest(10);
|
runTest(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runTest(int n) throws Exception {
|
private void runTest(int n) throws Exception {
|
||||||
|
|
|
@ -223,6 +223,7 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IToken lastToken;
|
||||||
private IToken nextToken;
|
private IToken nextToken;
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
|
||||||
|
@ -239,41 +240,26 @@ public class Scanner2 implements IScanner, IScannerData {
|
||||||
throw EOF;
|
throw EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
IToken token = nextToken;
|
if (lastToken != null)
|
||||||
|
lastToken.setNext(nextToken);
|
||||||
|
IToken oldToken = lastToken;
|
||||||
|
lastToken = nextToken;
|
||||||
nextToken = fetchToken();
|
nextToken = fetchToken();
|
||||||
token.setNext(nextToken);
|
|
||||||
|
|
||||||
if (nextToken == null)
|
if (nextToken == null)
|
||||||
finished = true;
|
finished = true;
|
||||||
else if (nextToken.getType() == IToken.tPOUNDPOUND) {
|
else if (lastToken.getType() == IToken.tSTRING) {
|
||||||
// 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) {
|
|
||||||
while (nextToken != null && nextToken.getType() == IToken.tSTRING) {
|
while (nextToken != null && nextToken.getType() == IToken.tSTRING) {
|
||||||
// Concatenate the adjacent strings
|
// Concatenate the adjacent strings
|
||||||
String t1 = token.getImage();
|
String t1 = lastToken.getImage();
|
||||||
String t2 = nextToken.getImage();
|
String t2 = nextToken.getImage();
|
||||||
token = new ImagedToken(IToken.tSTRING, t1 + t2);
|
lastToken = new ImagedToken(IToken.tSTRING, t1 + t2);
|
||||||
|
oldToken.setNext(lastToken);
|
||||||
nextToken = fetchToken();
|
nextToken = fetchToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Check if token is ## and proceed with pasting
|
return lastToken;
|
||||||
|
|
||||||
return token;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return null to signify end of file
|
// Return null to signify end of file
|
||||||
|
|
Loading…
Add table
Reference in a new issue