The overrides for TSyntaxParser::ParseLine, e.g. in TCSyntaxParser for C++, handles escape characters in string and character literals incorrectly. The code only checks for two preceding escape characters ('\'
) to determine whether the current quote is escaped. It fails for strings that have more than two preceding escape characters. This bug leads to visual errors in source code highlighting in the CoolPrj editor class.
For example, for the string "\\\"..."
(a backslash followed by a double-quote and some more text), the code assumes that the escaped double-quote is not escaped, because it is preceded by two escape characters, thus prematurely terminating the string literal.
The correct test is to check for an odd number of preceding escape characters to determine whether a character is escaped. The attached patch implements this fix. However, it only fixes the problem for TCSyntaxParser. Almost all of the syntax parsers have this flaw, so the code should be refactored to implement the fix in a reusable manner so that all parsers share common code. Currently, the parsers are implemented by cut-and-paste of the same code.
PS. Back-tracking is an awkward and inefficient way to find the end of a string literal. A better parsing solution should be used.