Menu

#2935 C/C++ string syntax doesn't recognise '\' for strings

minor bug
open
None
5
2017-12-04
2007-08-24
Bernard
No

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.

Discussion

  • Anonymous

    Anonymous - 2007-08-24

    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.

     
  • Anonymous

    Anonymous - 2007-08-24

    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.

     
  • Anonymous

    Anonymous - 2007-09-09

    Logged In: YES
    user_id=1477607
    Originator: NO

    File Added: cpatch

     
  • Anonymous

    Anonymous - 2007-09-09

    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.

     
  • Kazutoshi 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.

     
  • Kazutoshi 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.

     
  • Alan Ezust

    Alan Ezust - 2012-01-15
    • assigned_to: nobody --> shlomy
     
  • Alan Ezust

    Alan Ezust - 2012-01-15

    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.

     
  • Anonymous

    Anonymous - 2012-02-29
    • assigned_to: shlomy --> nobody
     
  • Alan Ezust

    Alan Ezust - 2012-06-09

    Figured out what line you were talking about and committed rev# 21774

     
  • Alan Ezust

    Alan Ezust - 2012-06-09
    • assigned_to: nobody --> ezust
    • labels: 102669 -->
    • status: open --> closed-accepted
     
  • Alan Ezust

    Alan Ezust - 2012-06-09

    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.

     
  • Alan Ezust

    Alan Ezust - 2012-06-09
    • status: closed-accepted --> open
     
  • Alan Ezust

    Alan Ezust - 2012-06-09
    • assigned_to: ezust --> nobody
     
  • Roman Tsourick

    Roman Tsourick - 2017-12-04
    • assigned_to: Roman Tsourick
    • Group: --> minor bug
     

Log in to post a comment.