Sublime Forum

Python syntax highlighting bug

#1

Using build 2207. This file breaks Sublime’s python syntax highlighting: httplib2.googlecode.com/hg/pytho … init_.py

Problem is a regular expression that can be distilled down to this:

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.

0 Likes

#2

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

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)
0 Likes

#3

As for me it’s a feature indicating something wrong with your pattern

0 Likes

#4

[quote=“krevetka”]As for me it’s a feature indicating something wrong with your pattern

[/quote]

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.

0 Likes