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

 
 

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

Submitted by:  None
Submitted on:  Tue 09 Jun 2009 11:41:19 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: None
Privacy: PublicAssigned to: Benno Schulenberg <bens>
Open/Closed: OpenRelease: None

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 26 Feb 2014 12:49:49 PM UTCbensAssigned toNone=>bens
      Summaryhighlight of python triple-quoted strings=>the highlighting of Python triple-quoted strings

    Back to the top


    Powered by Savane 3.1-cleanup