bugGNU nano - Bugs: bug #26762, the highlighting of Python...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #26762: the highlighting of Python triple-quoted strings

Submitter:  None
Submitted:  Tue 09 Jun 2009 11:41:19 AM UTC
   
 
Severity:  3 - Normal Status:  Duplicate
Assigned to:  bens Open/Closed:  Closed

Mon 23 Mar 2015 12:49:22 PM UTC, comment #1: 

Marking this as a duplicate of bug #41313, to keep things in one place.

Benno Schulenberg <bens>
Group administrator
Tue 09 Jun 2009 11:41:19 AM UTC, original submission:  


I see that this topic was already discussed a few times, but it's
still unsatisfactory, and I have improved regexes (bottom).

The problem is that Python multiline strings have the same start and
end delimiters: """...""" and '''...'''
And nano's multi-line coloring logic (src/winio.c:2579) is optimized
for things like C /*...*/ comments where they differ:
 - Nano starts from current line and goes backward searching for the
last start/end.
  But if start==end, you can't know if the last match is a start or
an end - the only reliable way is to parse from the start of the file!
  (An optimization might still be possible but requires relying on
previous coloring and knowing which parts of the file changed.
  Sounds complicated to get right.)
 - Nano ignores repeated occurences of start until it sees the end.
This is ok for /*.../*...*/ but not for """..."""...""".

Perhaps the algorithm can be slightly tweaked to consider something
that matches both start and end as an end?
This could slightly improve some corner cases.  But in any case start
and end must differ for multi-line coloring to work.

The current Python string syntaxes are:

color brightgreen "['][^']*[^\\][']" "[']{3}.*[^\\][']{3}"
color brightgreen "["][^"]*[^\\]["]" "["]{3}.*[^\\]["]{3}"
color brightgreen start=""""[^"]" end=""""" start="'''[^']" end="'''"

This takes the approximation that """ only starts a string if it's not
at the end of the line.
It does cover:
   """Single line"""
and:
   """Compact two
   lines"""
but there is absolutely no way to color this string:
   """
   Separate lines.
   """
OK, so it won't be colored.  What's most important is that string
coloring never spills over to the rest of the file.

Unfortunately, the current regex is too subtle.  For example adding a
single space after the closing """ will
turn it into a start match, causing the dreaded spillover.
Here are better regexes:

color magenta "['][^']*[^\\][']"
color magenta "["][^"]*[^\\]["]"
color magenta start="["]{3}[ \t]*[^ \t"]" end="["]{3}[ \t]*"
color magenta start="[']{3}[ \t]*[^ \t']" end="[']{3}[ \t]*"

These consider """ as a start only if it's followed by any
non-whitespace on the same line.

P.S. it appears that \t doesn't work and has to be replaced with a
literal tab in all occurences.
That's a pity, now I have to use M-P to edit nanorc ;-(.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bens (Updated the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-03-23 bens StatusNone Duplicate
        Open/ClosedOpen Closed
    2014-02-26 bens Assigned toNone bens
        Summaryhighlight of python triple-quoted strings the highlighting of Python triple-quoted strings

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code