22import sys
33
44# Reason last stmt is continued (or C_NONE if it's not).
5- C_NONE , C_BACKSLASH , C_STRING , C_BRACKET = range (4 )
5+ (C_NONE , C_BACKSLASH , C_STRING_FIRST_LINE ,
6+ C_STRING_NEXT_LINES , C_BRACKET ) = range (5 )
67
78if 0 : # for throwaway debugging output
89 def dump (* stuff ):
@@ -281,6 +282,7 @@ def _study1(self):
281282 quote = ch
282283 if str [i - 1 :i + 2 ] == quote * 3 :
283284 quote = quote * 3
285+ firstlno = lno
284286 w = len (quote ) - 1
285287 i = i + w
286288 while i < n :
@@ -315,7 +317,12 @@ def _study1(self):
315317 else :
316318 # didn't break out of the loop, so we're still
317319 # inside a string
318- continuation = C_STRING
320+ if (lno - 1 ) == firstlno :
321+ # before the previous \n in str, we were in the first
322+ # line of the string
323+ continuation = C_STRING_FIRST_LINE
324+ else :
325+ continuation = C_STRING_NEXT_LINES
319326 continue # with outer loop
320327
321328 if ch == '#' :
@@ -335,7 +342,8 @@ def _study1(self):
335342 # The last stmt may be continued for all 3 reasons.
336343 # String continuation takes precedence over bracket
337344 # continuation, which beats backslash continuation.
338- if continuation != C_STRING and level > 0 :
345+ if (continuation != C_STRING_FIRST_LINE
346+ and continuation != C_STRING_NEXT_LINES and level > 0 ):
339347 continuation = C_BRACKET
340348 self .continuation = continuation
341349
0 commit comments