Sublime Forum

tmLanguage - RegEx crash

#1

Hi,

I’ve just started evaluating Sublime, looking to move out from e, and I’ve found a problem when transferring tmLanguage I made there.
It seems that positive/negative lookahead/lookbehind when used in this way crashes Sublime:

<key>eztpl</key>
<dict>
	<key>patterns</key>
	<array>
		<dict>
			<key>begin</key>
			<string>(?={)</string>
			<key>name</key>
			<string>source.eztpl.embedded.html</string>
			<key>patterns</key>
			<array>
				<dict>
					<key>include</key>
					<string>source.eztpl</string>
				</dict>
			</array>
			<key>end</key>
			<string>(?&lt;=})</string>
		</dict>
	</array>
</dict>
0 Likes

#2

Could you send me the full .tmLanguage you’re using that’s causing the crash?

0 Likes

#3

Here it is, it is actually standard HTML.tmLanguage modified to work with eZ template.tmLanguage.
Just try to enter curly brackets in some eZ template file (or just plain HTML file) and down it goes.
html_ezp.zip (4.56 KB)

0 Likes

#4

As you mention, then excerpt you posted is indeed making Sublime Text unhappy: the regex (?={) doesn’t consume any characters, which in-and-of-itself doesn’t cause any issues, however patterns available after matching (?={) is everything in source.eztpl, which in turn includes everything in text.html.basic, which means the pattern (?={) is again available for matching. It’s sitting there recursively matching (?={) in an infinite loop.

0 Likes

#5

You are right, I’m at fault. It seems that e has some logic to resolve the loop, because this combination is working there.
I’ll try to rework that definition.

Thanks for looking it up.

0 Likes

#6

There’s a good argument that Sublime Text should also prevent this to some degree, such as not matching the same rule twice in a row if the rule doesn’t consume any text. I’ve put this on the todo list, but I’m not sure how quickly it’s going to get done.

0 Likes