SlickEdit Community

SlickEdit Product Discussion => SlickEdit® => Features and/or Improvements => Topic started by: jporkkahtc on October 30, 2017, 11:06:07 PM

Title: Python "block comments"
Post by: jporkkahtc on October 30, 2017, 11:06:07 PM
Unfortunately Python doesn't support block comments.
So, people tend to use block quotes, """ or '''.
Ugh, but they do.

Slick oughta recognize this and treat them as comments.

For example if I have
Code: [Select]
a='''hello'''then clearly, this is not a comment.
But, a stand alone string that isn't a function parameter or an assignment or otherwise part of an expression is a comment
Code: [Select]
'''
This is a block comment
'''

Title: Re: Python "block comments"
Post by: Clark on November 01, 2017, 02:50:58 PM
A regex can do a good job for color coding. This will require regex’s which do look behind.
Title: Re: Python "block comments"
Post by: Dennis on November 01, 2017, 11:37:59 PM
Would it not be adequate to check if the triple-quote starts at the beginning of the line? 

Even if that would work, we would also have to watch out for this:
Code: [Select]
   a = (
     """
     This is a real string.
     Not a comment. 
     Strings should be strings.
     Comments should be comments.
     Don't cross the streams.
     Why?
     It would be bad.
     """
   )

Title: Re: Python "block comments"
Post by: jporkkahtc on November 01, 2017, 11:55:53 PM
WRT beginning of the line: Unfortunately, no.
They can appear anywhere, so they must also get indented.

Worse yet doc strings: https://www.python.org/dev/peps/pep-0257/#rationale
So, if it is the first thing in a module, function or class, then it is assigned to the __doc__ attribute of the same.

So, does that count as a comment or a string?
I'd vote for comment - as it typically isn't going to be used by the script itself.

Title: Re: Python "block comments"
Post by: Dennis on November 02, 2017, 12:02:34 AM
By beginning of line, I was referring to first-non-blank, not literally column 1.
Title: Re: Python "block comments"
Post by: jporkkahtc on November 02, 2017, 12:26:48 AM
Right, of course :-)
Thats probably pretty good.

A new color coding tag might be in order?
block-string
raw-string might be good too.