Sublime Forum

BUG: Python syntax highlight fail

#1

SL will fail to syntax highlight the rest of python code when encountered this

m = re.compile(r'^]+\(\d+/[A-Za-z]+/\d+):^\d]*').match(line)

perhaps ^ is treated as ANSI escape char?


0 Likes

#2

There is an unpaired opening bracket in that regular expression, and the syntax highlighter is waiting for the pair to be closed. Are you sure the very first bracket in the regexp is intended?

Edit: oh, I get it now. I did not notice it at first, but ^] is a well-formed character class.

This issue should really be fixed upstream in TextMate, but meanwhile here is a patch to %APPDATA%\Sublime Text\Packages\Python\Regular Expressions (Python).tmLanguage:[code]— original/Regular Expressions (Python).tmLanguage Thu Oct 15 20:57:32 2009
+++ modified/Regular Expressions (Python).tmLanguage Tue Sep 14 01:07:19 2010
@@ -235,7 +235,7 @@


begin

  •   			<string>(\)(\^)?</string>
    
  •   			<string>(\)(\^)?\]?</string>
      			<key>beginCaptures</key>
      			<dict>
      				<key>1</key>
    

@@ -264,8 +264,16 @@
patterns

  •   					<key>include</key>
    
  •   					<string>#character-class</string>
    
  •   					<key>match</key>
    
  •   					<string>\\[wWsSdDhH]</string>
    
  •   					<key>name</key>
    
  •   					<string>constant.character.character-class.regexp</string>
    
  •   				</dict>
    
  •   				<dict>
    
  •   					<key>match</key>
    
  •   					<string>\\.</string>
    
  •   					<key>name</key>
    
  •   					<string>constant.character.escape.backslash.regexp</string>
      				</dict>
      				<dict>
      					<key>captures</key>[/code]
0 Likes

#3

Thanks for the patch, Chortos-2

I didn’t expect it’s a Textmate bug.

0 Likes