PreviousNextTracker indexSee it online !

(41/231) 1780785 - C/C++ string syntax doesn't recognise '\' for strings

The C/C++ syntax highlighting doesn't recognise this (correct) syntax:

1 char paragraph[] = "There once was a string \
2 that was far too long, so his father \
3 cut him to pieces with newlines.";

Lines 2 and 3 are not highlighted as strings when they should be.

Submitted bhelyer - 2007-08-24 - 05:57:49z Assigned nobody
Priority 5 Category None
Status Open Group None
Resolution None Visibility No

Comments

2007-08-24 - 11:27:05z
shlomy
Logged In: YES
user_id=1477607
Originator: NO

Wow, for those interested, it seems this very example makes it easy to reproduce the text area corruption bug. If you type this text in a new buffer, then save it in a file with ".cpp" extension, and then use the jEdit menu to open the modes in the FSB, the text area will get corrupted and remain corrupted even as buffers are switched.
2007-08-24 - 11:30:41z
shlomy
Logged In: YES
user_id=1477607
Originator: NO

The text area corruption in this example seems to be related to folding mode. E.g. I reproduce it easily with CtagsSideKick folding mode, but when no folding mode is used, I can't.
2007-09-09 - 23:02:03z
shlomy
Logged In: YES
user_id=1477607
Originator: NO

File Added: cpatch
2007-09-09 - 23:03:58z
shlomy
Logged In: YES
user_id=1477607
Originator: NO

I've attached a tiny patch to the modes/c.xml mode file, which enables strings to span multiple lines. I don't know why the mode files limit strings to a single line, anyone knows?
I think this is also the same for Java.
2007-09-10 - 00:11:34z
k_satoda
Logged In: YES
user_id=1483238
Originator: NO

ISO C/C++ doesn't allow new-line characters in string leterals. I think
the right way to fix this bug is escaping the new-line character which
is immediately preceded by a backslash as non-line-break in syntax
analysis. It will fix some other problems; e.g. multi line macro
definitions.
2009-12-07 - 16:39:58z
k_satoda
There are some more comments on #1235126 which was closed as a duplicate
of this item.
https://sourceforge.net/support/tracker.php?aid=1235126

An easy user side workaround is closing the quote at the end of line,
and opening it again at the start of the next line. That is also a
correct syntax, and less confusing for jEdit, other tools, and possibly
some poeple.
2012-01-15 - 21:54:28z
ezust
Shlomy, can you please open a fresh ticket on how to reproduce the text area corruption bug?
Also, your attached patch does not have context and no longer is good. Please update it.
2012-06-09 - 01:11:55z
ezust
Figured out what line you were talking about and committed rev# 21774
2012-06-09 - 01:13:41z
ezust
oh damn. It works but it also makes certain invalid C++ code valid.
So if you forget the \ at the end of the line, you still have multiline strings which is forbidden in C++ and C.
Damn. So The patch is invalid, and I will remove it and roll back # 21774.

Attachments