1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 00:05:53 +02:00

Scanner2 - Allow escaped newlines within identifiers.

This commit is contained in:
John Camelon 2004-07-15 14:17:45 +00:00
parent 96ddf17ee8
commit 6f274623f2

View file

@ -634,6 +634,13 @@ public class Scanner2 implements IScanner, IScannerData {
++len; ++len;
continue; continue;
} }
else if( c == '\\' && bufferPos[bufferStackPos] + 1 < buffer.length && buffer[ bufferPos[bufferStackPos] + 1 ] == '\n')
{
// escaped newline
++bufferPos[bufferStackPos];
len += 2;
continue;
}
break; break;
} }
@ -671,8 +678,9 @@ public class Scanner2 implements IScanner, IScannerData {
} }
int tokenType = keywords.get(buffer, start, len); int tokenType = keywords.get(buffer, start, len);
char [] result = removedEscapedNewline( CharArrayUtils.extract( buffer, start, len ) );
if (tokenType == keywords.undefined) if (tokenType == keywords.undefined)
return new ImagedToken(IToken.tIDENTIFIER, new String(buffer, start, len)); return new ImagedToken(IToken.tIDENTIFIER, new String( result));
return new SimpleToken(tokenType); return new SimpleToken(tokenType);
} }
@ -1188,8 +1196,7 @@ public class Scanner2 implements IScanner, IScannerData {
if( encounteredMultilineComment ) if( encounteredMultilineComment )
text = removeMultilineCommentFromBuffer( text ); text = removeMultilineCommentFromBuffer( text );
if( CharArrayUtils.indexOf( '\n', text ) != -1 ) text = removedEscapedNewline( text );
text = removedEscapedNewline( text );
// Throw it in // Throw it in
definitions.put(name, definitions.put(name,
@ -1198,11 +1205,14 @@ public class Scanner2 implements IScanner, IScannerData {
: new FunctionStyleMacro(name, text, arglist)); : new FunctionStyleMacro(name, text, arglist));
} }
/** /**
* @param text * @param text
* @return * @return
*/ */
private char[] removedEscapedNewline(char[] text) { private char[] removedEscapedNewline(char[] text) {
if( CharArrayUtils.indexOf( '\n', text ) == -1 )
return text;
char [] result = new char[ text.length ]; char [] result = new char[ text.length ];
Arrays.fill( result, ' '); Arrays.fill( result, ' ');
int counter = 0; int counter = 0;