Home Download Buy Blog Forum Support

Python syntax highlighting bug

Python syntax highlighting bug

Postby ampedandwired on Sun Jul 01, 2012 1:30 am

Using build 2207. This file breaks Sublime's python syntax highlighting: http://httplib2.googlecode.com/hg/pytho ... _init__.py

Problem is a regular expression that can be distilled down to this:
Code: Select all
import re
e = re.compile(r"[[]+")
# Syntax highlighting broken from here down
print e.match("[[[")


Odd regex of course, but seems to be valid from Python's perspective.
ampedandwired
 
Posts: 1
Joined: Sun Jul 01, 2012 1:10 am

Re: Python syntax highlighting bug

Postby EmilStenstrom on Tue Jul 10, 2012 11:03 am

I have a similar problem with a regexp that breaks syntax highlighting for Python files due to a regexp:

Code: Select all
ESCAPE_CHARS_RE = re.compile(r'(?<!\\)(?P<char>[&|+\-!(){}[\]^"~*?:])')

def lucene_escape(value):
    r"""Escape un-escaped special characters and return escaped value.

    >>> solr_escape(r'foo+') == r'foo\+'
    True
    >>> solr_escape(r'foo\+') == r'foo\+'
    True
    >>> solr_escape(r'foo\\+') == r'foo\\+'
    True
    """
    return ESCAPE_CHARS_RE.sub(r'\\\g<char>', value)
EmilStenstrom
 
Posts: 1
Joined: Tue Jul 10, 2012 9:25 am

Re: Python syntax highlighting bug

Postby krevetka on Tue Jul 10, 2012 11:31 am

As for me it's a feature indicating something wrong with your pattern
To match a literal ']' inside a set, precede it with a backslash
krevetka
 
Posts: 5
Joined: Mon Jul 09, 2012 11:37 am

Re: Python syntax highlighting bug

Postby ntenney on Tue Jul 10, 2012 5:29 pm

krevetka wrote:As for me it's a feature indicating something wrong with your pattern
To match a literal ']' inside a set, precede it with a backslash


There's nothing wrong with the OP's pattern. They aren't matching a ], they are matching a [ which doesn't require that you escape it (though it is also valid to escape it as well).

Also, if you don't use a raw string, then the syntax highlighting bug doesn't appear.
ntenney
 
Posts: 64
Joined: Thu May 03, 2012 9:10 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 14 guests