Fixed lexical error when a C++ file contains an empty character literal L''.

This commit fixes a lexical error when a C++ file contains an empty
character literal L''. The following code could not be tokenized:

std::wstring wsMessage( sMessage.length(), L'');

It triggers the following error:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file
'foo.cpp' at line 1, column 46.  Encountered: "\'" (39), after : "\'"
This commit is contained in:
Jan van Nunen
2015-01-13 09:37:55 +01:00
parent ceef6cd236
commit d830974842
2 changed files with 7 additions and 1 deletions

View File

@ -319,7 +319,7 @@ TOKEN :
{
< CHARACTER : ("L")? "'"
( (~["'","\\","\n","\r"])+
( (~["'","\\","\n","\r"])*
| ("\\" (
["n","t","v","b","r","f","a","\\","?","'","\""]
|

View File

@ -107,6 +107,12 @@ public class CPPTokenizerTest {
parse("#define LSTFVLES_CPP //*" + PMD.EOL);
}
@Test
public void testEmptyCharacter() {
Tokens tokens = parse("std::wstring wsMessage( sMessage.length(), L'');" + PMD.EOL);
assertEquals(15, tokens.size());
}
private Tokens parse(String snippet) {
return parse(snippet, false);
}