[TxMt] Re: PHP Grammar / Syntax Highlight Bug

Tobias Jung newsgr at tobiasjung.net
Wed Feb 10 17:07:21 UTC 2010


Sean Gilbertson <sean.gilbertson at gmail.com> wrote (Wed, 10 Feb 2010
09:56:45 -0600):

>> And I would not like to see slow TextMate down (using much more complex
>> regex syntax for the grammar rules) because some people like to write
>> code that is, by ALL means that I can think of, disadvantageous at least.
> 
> This should be more than possible without slowing anyone's computers 
> down. If our computers can render full-screen bluray movies and 
> better-than-1080p video games, I think they can parse text.

On my Mac mini 2 GHz Intel Core 2 Duo, TextMate already needs a few
seconds to parse long PHP files. Not long enough to bother me in any way
but if it'd take, say, twice as long, I'd call it a nuisance.


And in case you don't believe that parsing text CAN occupy your computer
for a VERY long time:

1. Copy the section between the equals signs to TextMate (keep the
quotation marks):
===========================================
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum."
===========================================


2. Copy the following regular expression to TextMate's search box (don't
forget to tick "Regular Expression", and again: Keep the quotation
marks) and hit "Next".
===========================================
"([^"\\]+|\\.)*"
===========================================

3. TextMate will select the complete text in no time.

4. Now, delete the quotation mark at the end of the text (i.e. behind
'laborum.').

5. Make sure that you have no other files open in TextMate that you
haven't saved yet.

6. Put the cursor at the beginning of the text, and hit command + G to
search again.

==> TextMate will stall completely, eating about 100% of your CPU power
according to Activity Monitor.


The thing is, TextMate doesn't crash.
It's still trying to find text matching the regular expression.
I don't know how long it'll take before TextMate will see that the regex
doesn't match at all, I've always used a force quit after five or six minutes.


Now, of course changing TextMate's PHP grammar will most likely not
result in parsing PHP files for years... ;-)

This, of course, is an extreme example that merely shows that the wrong
regex used on the wrong text (keep in mind that it works fine until you
delete the closing quotation mark) CAN indeed be harder than rendering
full-screen bluray movies.

Thus, it _is_ possible that changing the regex might result in slower
syntax coloring.

I'd like to stress again that I don't believe that changing the grammar
will be bad.
But it is a matter that is not to be taken lightly.

Kind regards,
Tobias Jung






More information about the textmate mailing list