24 Commits

Author SHA1 Message Date
Clément Fournier
b56e9e6708 Fix floats 2020-06-18 20:56:42 +02:00
Clément Fournier
c429a4e0c4 Fix wrong grammar for digit separators 2020-06-18 20:56:18 +02:00
Clément Fournier
673fe3934d Fix hex numbers in uppercase 2020-06-18 20:56:00 +02:00
Clément Fournier
185c172b3c c++ ident unicode support 2020-06-18 20:54:41 +02:00
Clément Fournier
af537034a9 Use getters for tokens in javacc grammars 2020-01-06 15:01:18 +01:00
Maikel Steneker
0708f69627
Merge branch 'master' into cpp_raw_string_literals 2019-05-13 14:37:16 +02:00
Maikel Steneker
95673a0bfc Added support for character prefixes + various other improvements. 2019-05-13 14:31:33 +02:00
Maikel Steneker
d73a5505c2 Added support for C++ raw string literals. 2019-05-10 15:46:07 +02:00
Maikel Steneker
6bb83a71dd Added support for various C++ string prefixes.
These were already tokenized without errors, but the prefixes were considered to be a separate token.
2019-05-10 15:45:32 +02:00
Maikel Steneker
af41fc4230 Added support for C++14 digit separators. 2019-05-10 14:33:22 +02:00
Juan Martín Sotuyo Dodero
47e345945e [cpp] Allow CPD suppressions with comments 2018-04-14 22:33:37 -03:00
Andreas Dangel
ead8d964c5 [cpp] Undo changes to String literals in grammar, it's not needed anymore
Such slightly illegal char escape sequences can still be parsed now.
2017-07-08 11:48:06 +02:00
Andreas Dangel
ec631f3993 [cpp] Don't skip the continuation character in the grammar anymore
Since we now have a CppCharStream, we can remove the changes
introduced for #431
2017-07-07 23:11:27 +02:00
Andreas Dangel
0f9a4a97c0 cpp: skip line continuation character in grammar
Fixes #431

Note: the tokens separate by such continuation characters are not
merged and appear as two separate tokens, which could lead to false
negatives in duplication detection.

ContinuationReader is deleted, since skipping characters in the stream
makes it difficult to provide accurate line numbers/positions.
2017-06-17 12:42:13 +02:00
Andreas Dangel
2c861a2f6c cpp: add missing "finally" token, move ID Token to beginning of file 2017-06-17 12:27:47 +02:00
Jan van Nunen
c099d50397 Added support for Raw String Literals (C++11). 2015-12-10 16:15:40 +01:00
Jan van Nunen
c92dc9706c Relaxed C++ tokenizer so a '\'(backslash) can be use to escape any character inside a string or character.
The following 2 code snippets could not be tokenized:

1:  if (*pbuf == '\0x05'), the problem is the '\0' in the character
literal '\0x05'.
2:  szPath = m_sdcacheDir + _T("\    oMedia");, the problem is the '\ '
in the string literal "\    oMedia".

I relaxed the lexical grammar so a '\' (backslash) can escape any
character inside a string or character literal. We can relax the grammar
because CPD only needs the tokens, so it is no problem to accept
'invalid' string / character literals. (according to the ANSI C
standard).  Failing too fast because the tokenizer is too strict is
annoying because then we can't check the files for duplicated code.

Both snippets were taken from existing projects and be successfully
compiled, so for some C / C++ compilers it is valid code.
2015-01-13 11:36:54 +01:00
Jan van Nunen
d830974842 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 : "\'"
2015-01-13 11:36:54 +01:00
Jan van Nunen
ceef6cd236 Fixed lexical eror when a preprocessor directive is followed by a single line comment that starts with "//*".
This commit fixes a lexical eror when a preprocessor directive is
followed by a single line comment that starts with "//*".

The following code could not be tokenized:

#define LSTFVLES_CPP  //*

It triggers the following error:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file
'foo.cpp' at line 2, column 0.  Encountered: <EOF> after : ""
2015-01-13 11:36:53 +01:00
Jan van Nunen
5c2df4c877 Fixed lexical error when a C++ file contains ASM with the '@' character.
This commit fixes a lexical error when a C++ file contains ASM with the
'@' character. The following code cannot be tokenized and triggers a
lexical error:

asm void eSPI_boot()
{
// setup stack pointer
lis r1, _stack_addr@h
ori r1, r1, _stack_addr@l
}

The error that occurs:

net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file
CODE_LOADED_FROM_STRING at line 4, column 22.  Encountered: "@" (64),
after : ""
2015-01-13 11:36:53 +01:00
Andreas Dangel
26b4f850b1 #1252 net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file xxx.cpp 2014-12-12 18:58:51 +01:00
Andreas Dangel
6b3b9d0ccc #1252 implement BOM detection differently for cpp 2014-12-12 17:45:38 +01:00
Andreas Dangel
5f9bd17ee6 #1252 net.sourceforge.pmd.lang.ast.TokenMgrError: Lexical error in file xxx.cpp 2014-10-18 12:33:40 +02:00
Andreas Dangel
cdf293f9fc Move cpp into own sub-module 2014-10-04 18:48:35 +02:00